Conditions | 3 |
Paths | 3 |
Total Lines | 22 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
23 | public function doValidation(Response $response) |
||
24 | { |
||
25 | $domDocument = new \DOMDocument(); |
||
26 | @$domDocument->loadHTML((string) $response->getBody()); |
||
|
|||
27 | |||
28 | $domXPath = new \DOMXPath($domDocument); |
||
29 | |||
30 | foreach ($this->cssSelectors as $selector) { |
||
31 | $converter = new CssSelectorConverter(); |
||
32 | $selectorAsXPath = $converter->toXPath($selector); |
||
33 | |||
34 | $count = $domXPath->query($selectorAsXPath)->length; |
||
35 | |||
36 | if ($count > 0) { |
||
37 | $result = $count; |
||
38 | $message = 'The xpath "' . $selector . '" was found ' . $count . ' times.'; |
||
39 | } else { |
||
40 | throw new \RuntimeException('CSS Selector ' . $selector .' not found in DOM.'); |
||
41 | } |
||
42 | $this->assert($result, $message); |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 |
If you suppress an error, we recommend checking for the error condition explicitly: