Conditions | 4 |
Paths | 1 |
Total Lines | 17 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 4 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
13 | 121 | public static function from(Expectation $expectation): callable |
|
14 | { |
||
15 | 121 | return function ($request) use ($expectation) { |
|
16 | /** @var RequestInterface $request */ |
||
17 | 87 | $headers = GuzzleHeaderParser::parse($request->getHeaders()); |
|
18 | |||
19 | 87 | foreach ($expectation->notEmptyHeadersIterator() as $header => $value) { |
|
20 | 14 | if (!array_key_exists($header, $headers)) { |
|
21 | 3 | return new RejectedPromise('header \'' . $header . '\' is missing'); |
|
22 | } |
||
23 | |||
24 | 11 | if ($headers[$header] !== $value) { |
|
25 | 7 | return new RejectedPromise('header \'' . $header . '\' does not match expectation'); |
|
26 | } |
||
27 | } |
||
28 | |||
29 | 77 | return $request; |
|
30 | 121 | }; |
|
33 |