| Conditions | 5 |
| Paths | 7 |
| Total Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function doValidation(ResponseInterface $response) |
||
| 25 | { |
||
| 26 | $content = (string)$response->getBody(); |
||
| 27 | |||
| 28 | $domDocument = new \DOMDocument(); |
||
| 29 | @$domDocument->loadHTML($content); |
||
|
|
|||
| 30 | |||
| 31 | $domXPath = new \DOMXPath($domDocument); |
||
| 32 | |||
| 33 | $error = false; |
||
| 34 | $snotFoundSelectors = array(); |
||
| 35 | |||
| 36 | $converter = new CssSelectorConverter(); |
||
| 37 | |||
| 38 | foreach ($this->cssSelectors as $selector) { |
||
| 39 | |||
| 40 | try { |
||
| 41 | $selectorAsXPath = $converter->toXPath($selector['pattern']); |
||
| 42 | } catch (\Exception $e) { |
||
| 43 | throw new ValidationFailedException('Invalid css selector (' . $selector['pattern'] . ').'); |
||
| 44 | } |
||
| 45 | |||
| 46 | $count = $domXPath->query($selectorAsXPath)->length; |
||
| 47 | |||
| 48 | if ($count === 0) { |
||
| 49 | $error = true; |
||
| 50 | $snotFoundSelectors[] = $selector['pattern']; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | if ($error === true) { |
||
| 55 | $allNotFoundSelectors = implode('", "', $snotFoundSelectors); |
||
| 56 | |||
| 57 | throw new ValidationFailedException('CSS Selector "' . $allNotFoundSelectors . '" not found in DOM.'); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 |
If you suppress an error, we recommend checking for the error condition explicitly: