Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
StdoutNotContains
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fail
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
 toString
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 matches
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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 */
10namespace Framework\Testing\Constraints;
11
12use PHPUnit\Framework\Constraint\Constraint;
13use PHPUnit\Framework\ExpectationFailedException;
14use SebastianBergmann\Comparator\ComparisonFailure;
15
16/**
17 * Class StdoutNotContains.
18 *
19 * @package testing
20 */
21final class StdoutNotContains 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 STDOUT %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            "does not contain '%s'.",
49            $this->string
50        );
51    }
52
53    protected function matches(mixed $other) : bool
54    {
55        return ! \str_contains($other, $this->string);
56    }
57}