-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppliesResponseExpectations.php
46 lines (40 loc) · 1.29 KB
/
AppliesResponseExpectations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Aedart\Http\Clients\Middleware;
use Aedart\Contracts\Http\Clients\Middleware;
use Aedart\Contracts\Http\Clients\Requests\Builders\HttpRequestBuilderAware;
use Aedart\Contracts\Http\Clients\Requests\Handler;
use Aedart\Http\Clients\Traits\HttpRequestBuilderTrait;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Throwable;
/**
* Applies Response Expectations Middleware
*
* Applies assigned response expectations to the incoming response.
*
* @see \Aedart\Contracts\Http\Clients\Client::getExpectations
*
* @author Alin Eugen Deac <aedart@gmail.com>
* @package Aedart\Http\Clients\Middleware
*/
class AppliesResponseExpectations implements
Middleware,
HttpRequestBuilderAware
{
use HttpRequestBuilderTrait;
/**
* {@inheritDoc}
*
* @throws Throwable If response did not meet an expectation
*/
public function process(RequestInterface $request, Handler $handler): ResponseInterface
{
$response = $handler->handle($request);
// Obtain assigned response expectations from client
$expectations = $this->getHttpRequestBuilder()->getExpectations();
foreach ($expectations as $expectation) {
$expectation->apply($request, $response);
}
return $response;
}
}