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