| Conditions | 5 |
| Paths | 9 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function handle(string $routeName, Crawler $crawler, Client $client, array $options = []): void |
||
| 16 | { |
||
| 17 | $expectedResponseCode = Response::HTTP_OK; |
||
| 18 | $configuration = $this->configuration[$routeName]['handlers'][$this->getName()]; |
||
| 19 | |||
| 20 | if (!is_array($configuration)) { |
||
| 21 | $expectedResponseCode = $configuration; |
||
| 22 | } elseif (key_exists('code', $configuration)) { |
||
| 23 | $expectedResponseCode = $configuration['code']; |
||
| 24 | } |
||
| 25 | |||
| 26 | if (null === $client->getResponse()) { |
||
| 27 | throw new Exception('The client has no response. It should make a request before handle a response'); |
||
| 28 | } |
||
| 29 | $responseCode = $client->getResponse()->getStatus(); |
||
| 30 | |||
| 31 | if ((string) $expectedResponseCode !== (string) $responseCode) { |
||
| 32 | throw new Exception('Excepted code '.$expectedResponseCode.', got '.$responseCode.' for route '.$routeName); |
||
| 33 | } |
||
| 44 |