Test Failed
Push — master ( 540a9b...b1e763 )
by Hannes
02:14
created

PhpunitListener::onExample()   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 1
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\PHPUnit;
6
7
use hanneskod\readmetester\ListenerInterface;
8
use hanneskod\readmetester\Example\Example;
9
use hanneskod\readmetester\Expectation\Status;
10
use PHPUnit\Framework\TestCase;
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use PHPUnit\Framework\AssertionFailedError;
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\AssertionFailedError was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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