CrawlerSelectorExists.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DomCrawler\Test\Constraint;
  11. use PHPUnit\Framework\Constraint\Constraint;
  12. use Symfony\Component\DomCrawler\Crawler;
  13. final class CrawlerSelectorExists extends Constraint
  14. {
  15. private $selector;
  16. public function __construct(string $selector)
  17. {
  18. $this->selector = $selector;
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function toString(): string
  24. {
  25. return sprintf('matches selector "%s"', $this->selector);
  26. }
  27. /**
  28. * @param Crawler $crawler
  29. *
  30. * {@inheritdoc}
  31. */
  32. protected function matches($crawler): bool
  33. {
  34. return 0 < \count($crawler->filter($this->selector));
  35. }
  36. /**
  37. * @param Crawler $crawler
  38. *
  39. * {@inheritdoc}
  40. */
  41. protected function failureDescription($crawler): string
  42. {
  43. return 'the Crawler '.$this->toString();
  44. }
  45. }