easy-http /
mock-builder
| 1 | <?php |
||
| 2 | |||
| 3 | namespace EasyHttp\MockBuilder\Expectations; |
||
| 4 | |||
| 5 | use EasyHttp\MockBuilder\Contracts\ExpectationMatcher; |
||
| 6 | use EasyHttp\MockBuilder\Expectation; |
||
| 7 | use GuzzleHttp\Promise\RejectedPromise; |
||
| 8 | use Psr\Http\Message\RequestInterface; |
||
| 9 | |||
| 10 | class HeaderExistsExpectation implements ExpectationMatcher |
||
| 11 | { |
||
| 12 | 121 | public static function from(Expectation $expectation): callable |
|
| 13 | { |
||
| 14 | 121 | return function ($request) use ($expectation) { |
|
| 15 | /** @var RequestInterface $request */ |
||
| 16 | |||
| 17 | 72 | foreach ($expectation->emptyHeadersIterator() as $param => $value) { |
|
| 18 | 7 | if (!$request->hasHeader($param)) { |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 19 | 5 | return new RejectedPromise('header \'' . $param . '\' is missing'); |
|
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | 67 | return $request; |
|
| 24 | 121 | }; |
|
| 25 | } |
||
| 26 | } |
||
| 27 |