friendship ended with social-app. php is my new best friend
at main 1.6 kB view raw
1<?php 2 3/* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Symfony\Component\DomCrawler\Test\Constraint; 13 14use PHPUnit\Framework\Constraint\Constraint; 15use Symfony\Component\DomCrawler\Crawler; 16 17final class CrawlerAnySelectorTextSame extends Constraint 18{ 19 public function __construct( 20 private string $selector, 21 private string $expectedText, 22 ) { 23 } 24 25 public function toString(): string 26 { 27 return \sprintf('has at least a node matching selector "%s" with content "%s"', $this->selector, $this->expectedText); 28 } 29 30 protected function matches($other): bool 31 { 32 if (!$other instanceof Crawler) { 33 throw new \InvalidArgumentException(\sprintf('"%s" constraint expected an argument of type "%s", got "%s".', self::class, Crawler::class, get_debug_type($other))); 34 } 35 36 $other = $other->filter($this->selector); 37 if (!\count($other)) { 38 return false; 39 } 40 41 $nodes = $other->each(fn (Crawler $node) => trim($node->text(null, true))); 42 43 return \in_array($this->expectedText, $nodes, true); 44 } 45 46 protected function failureDescription($other): string 47 { 48 if (!$other instanceof Crawler) { 49 throw new \InvalidArgumentException(\sprintf('"%s" constraint expected an argument of type "%s", got "%s".', self::class, Crawler::class, get_debug_type($other))); 50 } 51 52 return 'the Crawler '.$this->toString(); 53 } 54}