CrawlerSelectorExistsTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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\Tests\Test\Constraint;
  11. use PHPUnit\Framework\ExpectationFailedException;
  12. use PHPUnit\Framework\TestCase;
  13. use PHPUnit\Framework\TestFailure;
  14. use Symfony\Component\DomCrawler\Crawler;
  15. use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorExists;
  16. class CrawlerSelectorExistsTest extends TestCase
  17. {
  18. public function testConstraint(): void
  19. {
  20. $constraint = new CrawlerSelectorExists('title');
  21. $this->assertTrue($constraint->evaluate(new Crawler('<html><head><title>'), '', true));
  22. $constraint = new CrawlerSelectorExists('h1');
  23. $this->assertFalse($constraint->evaluate(new Crawler('<html><head><title>'), '', true));
  24. try {
  25. $constraint->evaluate(new Crawler('<html><head><title>'));
  26. } catch (ExpectationFailedException $e) {
  27. $this->assertEquals("Failed asserting that the Crawler matches selector \"h1\".\n", TestFailure::exceptionToString($e));
  28. return;
  29. }
  30. $this->fail();
  31. }
  32. }