Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
18 / 18 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
StderrContains | |
100.00% |
18 / 18 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
fail | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
toString | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
matches | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php declare(strict_types=1); |
2 | /* |
3 | * This file is part of Aplus Framework Testing Library. |
4 | * |
5 | * (c) Natan Felles <natanfelles@gmail.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 Framework\Testing\Constraints; |
11 | |
12 | use PHPUnit\Framework\Constraint\Constraint; |
13 | use PHPUnit\Framework\ExpectationFailedException; |
14 | use SebastianBergmann\Comparator\ComparisonFailure; |
15 | |
16 | /** |
17 | * Class StderrContains. |
18 | * |
19 | * @package testing |
20 | */ |
21 | final class StderrContains extends Constraint |
22 | { |
23 | private string $string; |
24 | |
25 | public function __construct(string $string) |
26 | { |
27 | $this->string = $string; |
28 | } |
29 | |
30 | protected function fail($other, $description, ComparisonFailure $comparisonFailure = null) : void |
31 | { |
32 | $failureDescription = \sprintf( |
33 | 'Failed asserting that STDERR %s', |
34 | $this->failureDescription($other) |
35 | ); |
36 | if ( ! empty($description)) { |
37 | $failureDescription = $description . "\n" . $failureDescription; |
38 | } |
39 | throw new ExpectationFailedException( |
40 | $failureDescription, |
41 | $comparisonFailure |
42 | ); |
43 | } |
44 | |
45 | public function toString() : string |
46 | { |
47 | return \sprintf( |
48 | "contains '%s'.", |
49 | $this->string |
50 | ); |
51 | } |
52 | |
53 | protected function matches(mixed $other) : bool |
54 | { |
55 | if ('' === $this->string) { |
56 | return true; |
57 | } |
58 | return \str_contains($other, $this->string); |
59 | } |
60 | } |