Test Failed
Branch master (b1e763)
by Hannes
02:27
created

PhpunitListener::onExpectation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\readmetester\PHPUnit;
6
7
use hanneskod\readmetester\ListenerInterface;
8
use hanneskod\readmetester\Example\Example;
9
use hanneskod\readmetester\Expectation\Status;
10
use PHPUnit\Framework\TestCase;
11
use PHPUnit\Framework\AssertionFailedError;
12
13
class PhpunitListener implements ListenerInterface
14
{
15
    /**
16
     * @var TestCase
17
     */
18
    private $testCase;
19
20
    /**
21
     * @var string
22
     */
23
    private $exampleName;
24
25
    public function __construct(TestCase $testCase)
26
    {
27
        $this->testCase = $testCase;
28
    }
29
30
    public function onExample(Example $example): void
31
    {
32
        $this->exampleName = $example->getName();
33
    }
34
35
    public function onIgnoredExample(Example $example): void
36
    {
37
    }
38
39
    public function onExpectation(Status $status): void
40
    {
41
        $this->testCase->addToAssertionCount(1);
42
        if (!$status->isSuccess()) {
43
            $this->testCase->getTestResultObject()->addFailure(
44
                $this->testCase,
45
                new AssertionFailedError("Example {$this->exampleName}: $status"),
46
                0.0
47
            );
48
        }
49
    }
50
}
51