easy-http /
mock-builder
| 1 | <?php |
||
| 2 | |||
| 3 | namespace EasyHttp\MockBuilder\Expectations; |
||
| 4 | |||
| 5 | use EasyHttp\MockBuilder\Expectation; |
||
| 6 | use GuzzleHttp\Promise\RejectedPromise; |
||
| 7 | use Psr\Http\Message\RequestInterface; |
||
| 8 | |||
| 9 | class PathMatchExpectation |
||
| 10 | { |
||
| 11 | 121 | public static function from(Expectation $expectation): callable |
|
| 12 | { |
||
| 13 | 121 | return function ($request) use ($expectation) { |
|
| 14 | /** @var RequestInterface $request */ |
||
| 15 | 118 | if (!is_null($expectation->getPathRegex()) && !self::matches($expectation, $request)) { |
|
| 16 | 1 | return new RejectedPromise('path \'' . $request->getUri()->getPath() . '\' does not match expectation'); |
|
| 17 | } |
||
| 18 | |||
| 19 | 117 | return $request; |
|
| 20 | 121 | }; |
|
| 21 | } |
||
| 22 | |||
| 23 | 2 | private static function matches($expectation, $request): bool |
|
| 24 | { |
||
| 25 | 2 | return preg_match($expectation->getPathRegex(), $request->getUri()->getPath(), $matches); |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 26 | } |
||
| 27 | } |
||
| 28 |