Conditions | 5 |
Paths | 5 |
Total Lines | 26 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
22 | public function doValidation(Response $response) |
||
23 | { |
||
24 | $domDocument = new \DOMDocument(); |
||
25 | @$domDocument->loadHTML((string) $response->getBody()); |
||
|
|||
26 | |||
27 | $domXPath = new \DOMXPath($domDocument); |
||
28 | |||
29 | foreach ($this->xPaths as $xpath) { |
||
30 | $count = $domXPath->query($xpath['pattern'])->length; |
||
31 | |||
32 | if ($xpath['relation'] = 'equals') { |
||
33 | $result = $count === $xpath['value']; |
||
34 | $message = 'The xpath "' . $xpath['pattern'] . '" was found ' . $count . ' times. Expected were exact ' . $xpath['value'] . ' occurencies.'; |
||
35 | } elseif ($xpath['relation'] === 'less than') { |
||
36 | $result = $count < $xpath['value']; |
||
37 | $message = 'The xpath "' . $xpath['pattern'] . '" was found ' . $count . ' times. Expected were less than ' . $xpath['value'] . '.'; |
||
38 | } elseif ($xpath['relation'] === 'greater than') { |
||
39 | $result = $count > $xpath['value']; |
||
40 | $message = 'The xpath "' . $xpath['pattern'] . '" was found ' . $count . ' times. Expected were more than ' . $xpath['value'] . '.'; |
||
41 | } else { |
||
42 | throw new \RuntimeException('Relation not defined. Given "' . $xpath['relation'] . '" expected [equals, greater than, less than]'); |
||
43 | } |
||
44 | |||
45 | $this->assert($result, $message); |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 |
If you suppress an error, we recommend checking for the error condition explicitly: