@@ 8-27 (lines=20) @@ | ||
5 | use Symfony\Component\DomCrawler\Crawler; |
|
6 | use Psr7Unitesting\Utils\KeyValueConstraintTrait; |
|
7 | ||
8 | class Contains extends AbstractConstraint |
|
9 | { |
|
10 | use KeyValueConstraintTrait; |
|
11 | ||
12 | public function toString() |
|
13 | { |
|
14 | return sprintf('has at least one element matching with the selector "%s" that contains "%s"', $this->key, $this->expected); |
|
15 | } |
|
16 | ||
17 | protected function runMatches(Crawler $html) |
|
18 | { |
|
19 | $texts = $html->filter($this->key)->each(function ($node) { |
|
20 | return trim($node->text()); |
|
21 | }); |
|
22 | ||
23 | return array_filter($texts, function ($value) { |
|
24 | return strpos($value, $this->expected) !== false; |
|
25 | }); |
|
26 | } |
|
27 | } |
|
28 |
@@ 8-27 (lines=20) @@ | ||
5 | use Symfony\Component\DomCrawler\Crawler; |
|
6 | use Psr7Unitesting\Utils\KeyValueConstraintTrait; |
|
7 | ||
8 | class NotContains extends AbstractConstraint |
|
9 | { |
|
10 | use KeyValueConstraintTrait; |
|
11 | ||
12 | public function toString() |
|
13 | { |
|
14 | return sprintf('has not any element matching with the selector "%s" and containing "%s"', $this->key, $this->expected); |
|
15 | } |
|
16 | ||
17 | protected function runMatches(Crawler $html) |
|
18 | { |
|
19 | $texts = $html->filter($this->key)->each(function ($node) { |
|
20 | return trim($node->text()); |
|
21 | }); |
|
22 | ||
23 | return count(array_filter($texts, function ($value) { |
|
24 | return strpos($value, $this->expected) !== false; |
|
25 | })) === 0; |
|
26 | } |
|
27 | } |
|
28 |