Test Failed
Push — master ( 22d245...e46311 )
by Hannes
02:55
created

OutputExpectation::__tostring()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\readmetester\Expectation;
6
7
use hanneskod\readmetester\Runner\OutcomeInterface;
8
use hanneskod\readmetester\Utils\Regexp;
9
10
/**
11
 * Validate that correct output is produced
12
 */
13
final class OutputExpectation implements ExpectationInterface
14
{
15
    /** @var Regexp */
16
    private $regexp;
17
18
    public function __construct(Regexp $regexp)
19
    {
20
        $this->regexp = $regexp;
21
    }
22
23
    public function getDescription(): string
24
    {
25
        return "expecting output to match regexp {$this->regexp->getRegexp()}";
26
    }
27
28
    public function handles(OutcomeInterface $outcome): bool
29
    {
30
        return $outcome->getType() == OutcomeInterface::TYPE_OUTPUT;
31
    }
32
33
    public function handle(OutcomeInterface $outcome): StatusInterface
34
    {
35
        if (!$this->regexp->isMatch($outcome->getContent())) {
36
            return new Failure(
37
                "Failed asserting that output '{$outcome->getContent()}' matches {$this->regexp->getRegexp()}"
38
            );
39
        }
40
41
        return new Success("Asserted that output '{$outcome->getContent()}' matches {$this->regexp->getRegexp()}");
42
    }
43
}
44