WebDriverNot.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Codeception\PHPUnit\Constraint;
  3. use SebastianBergmann\Comparator\ComparisonFailure;
  4. use Codeception\Util\Locator;
  5. class WebDriverNot extends WebDriver
  6. {
  7. protected function matches($nodes)
  8. {
  9. return !parent::matches($nodes);
  10. }
  11. protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null)
  12. {
  13. $selectorString = Locator::humanReadableString($selector);
  14. if (!$this->string) {
  15. throw new \PHPUnit\Framework\ExpectationFailedException(
  16. "Element $selectorString was found",
  17. $comparisonFailure
  18. );
  19. }
  20. $output = "There was $selectorString element";
  21. $output .= $this->uriMessage("on page");
  22. $output .= $this->nodesList($nodes, $this->string);
  23. $output .= "\ncontaining '{$this->string}'";
  24. throw new \PHPUnit\Framework\ExpectationFailedException(
  25. $output,
  26. $comparisonFailure
  27. );
  28. }
  29. public function toString()
  30. {
  31. if ($this->string) {
  32. return 'that contains text "' . $this->string . '"';
  33. }
  34. }
  35. }