friendship ended with social-app. php is my new best friend
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 CrawlerSelectorAttributeValueSame extends Constraint
18{
19 public function __construct(
20 private string $selector,
21 private string $attribute,
22 private string $expectedText,
23 ) {
24 }
25
26 public function toString(): string
27 {
28 return \sprintf('has a node matching selector "%s" with attribute "%s" of value "%s"', $this->selector, $this->attribute, $this->expectedText);
29 }
30
31 /**
32 * @param Crawler $crawler
33 */
34 protected function matches($crawler): bool
35 {
36 $crawler = $crawler->filter($this->selector);
37 if (!\count($crawler)) {
38 return false;
39 }
40
41 return $this->expectedText === trim($crawler->attr($this->attribute) ?? '');
42 }
43
44 /**
45 * @param Crawler $crawler
46 */
47 protected function failureDescription($crawler): string
48 {
49 return 'the Crawler '.$this->toString();
50 }
51}