JsonOutputtingSubscriber::onEvaluationSkipped()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Output;
6
7
use hanneskod\readmetester\Event;
8
9
final class JsonOutputtingSubscriber extends AbstractOutputtingSubscriber
10
{
11
    /**
12
     * @var array<string, mixed>
13
     */
14
    private $data;
15
16
    public function onExecutionStarted(Event\ExecutionStarted $event): void
17
    {
18
        $this->setOutput($event->getOutput());
19
20
        $this->data = [
21
            'bootstraps' => [],
22
            'files' => [],
23
            'errors' => [],
24
            'tests' => [],
25
            'counts' => [
26
                'files' => 0,
27
                'errors' => 0,
28
                'examples' => 0,
29
                'ignored' => 0,
30
                'skipped' => 0,
31
                'assertions' => 0,
32
                'failures' => 0,
33
            ]
34
        ];
35
    }
36
37
    public function onBootstrapIncluded(Event\BootstrapIncluded $event): void
38
    {
39
        $this->data['bootstraps'][] = $event->getFilename();
40
    }
41
42
    public function onFileIncluded(Event\FileIncluded $event): void
43
    {
44
        $this->data['files'][] = $event->getFilename();
45
    }
46
47
    public function onExampleIgnored(Event\ExampleIgnored $event): void
48
    {
49
        $name = $event->getExample()->getName();
50
        $this->data['tests'][$name->getNamespaceName()][$name->getShortName()] = 'IGNORED';
51
        $this->data['counts']['ignored']++;
52
    }
53
54
    public function onEvaluationSkipped(Event\EvaluationSkipped $event): void
55
    {
56
        $name = $event->getOutcome()->getExample()->getName();
57
        $this->data['tests'][$name->getNamespaceName()][$name->getShortName()] = 'SKIPPED';
58
        $this->data['counts']['skipped']++;
59
    }
60
61
    public function onEvaluationStarted(Event\EvaluationStarted $event): void
62
    {
63
        $name = $event->getOutcome()->getExample()->getName();
64
        $this->data['tests'][$name->getNamespaceName()][$name->getShortName()] = [];
65
        $this->data['counts']['examples']++;
66
    }
67
68
    public function onTestPassed(Event\TestPassed $event): void
69
    {
70
        $name = $event->getStatus()->getOutcome()->getExample()->getName();
71
72
        $this->data['tests'][$name->getNamespaceName()][$name->getShortName()][] = [
73
            'success' => $event->getStatus()->getContent()
74
        ];
75
76
        $this->data['counts']['assertions']++;
77
    }
78
79
    public function onTestFailed(Event\TestFailed $event): void
80
    {
81
        $name = $event->getStatus()->getOutcome()->getExample()->getName();
82
83
        $this->data['tests'][$name->getNamespaceName()][$name->getShortName()][] = [
84
            'failure' => $event->getStatus()->getContent()
85
        ];
86
87
        $this->data['counts']['assertions']++;
88
        $this->data['counts']['failures']++;
89
    }
90
91
    public function onInvalidInput(Event\InvalidInput $event): void
92
    {
93
        $this->data['errors'][] = $event->getMessage();
94
        $this->data['counts']['errors']++;
95
    }
96
97
    public function onExecutionStopped(Event\ExecutionStopped $event): void
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
    public function onExecutionStopped(/** @scrutinizer ignore-unused */ Event\ExecutionStopped $event): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
    {
99
        $this->data['counts']['files'] = count($this->data['files']);
100
        $this->getOutput()->writeln((string)json_encode($this->data, JSON_PRETTY_PRINT));
101
    }
102
}
103