1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace hanneskod\readmetester\Output; |
6
|
|
|
|
7
|
|
|
use hanneskod\readmetester\Event; |
8
|
|
|
|
9
|
|
|
class DefaultOutputtingSubscriber extends AbstractOutputtingSubscriber |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The number of files tested |
13
|
|
|
*/ |
14
|
|
|
protected int $fileCount = 0; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The number of examples |
18
|
|
|
*/ |
19
|
|
|
protected int $exampleCount = 0; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The number of ignored examples |
23
|
|
|
*/ |
24
|
|
|
protected int $ignoredCount = 0; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The number of skipped examples |
28
|
|
|
*/ |
29
|
|
|
protected int $skippedCount = 0; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The number of assertions |
33
|
|
|
*/ |
34
|
|
|
protected int $expectationCount = 0; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The number of failed assertions |
38
|
|
|
*/ |
39
|
|
|
protected int $failureCount = 0; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Flag if the current example is passing |
43
|
|
|
*/ |
44
|
|
|
protected bool $examplePassed = true; |
45
|
|
|
|
46
|
|
|
public function onExecutionStarted(Event\ExecutionStarted $event): void |
47
|
|
|
{ |
48
|
|
|
$this->setOutput($event->getOutput()); |
49
|
|
|
$this->getOutput()->writeln("Readme-Tester by Hannes Forsgård"); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function onBootstrapIncluded(Event\BootstrapIncluded $event): void |
53
|
|
|
{ |
54
|
|
|
if ($this->getOutput()->isVerbose()) { |
55
|
|
|
$this->getOutput()->writeln("Using bootstrap <comment>{$event->getFilename()}</comment>"); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function onConfigurationIncluded(Event\ConfigurationIncluded $event): void |
60
|
|
|
{ |
61
|
|
|
$this->getOutput()->writeln("Reading configuration from <comment>{$event->getFilename()}</comment>"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function onDebugEvent(Event\DebugEvent $event): void |
65
|
|
|
{ |
66
|
|
|
if ($this->getOutput()->isVerbose()) { |
67
|
|
|
$this->getOutput()->writeln($event->getMessage()); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function onFileIncluded(Event\FileIncluded $event): void |
72
|
|
|
{ |
73
|
|
|
$this->fileCount++; |
74
|
|
|
if ($this->getOutput()->isVerbose()) { |
75
|
|
|
$this->getOutput()->writeln("Reading example from <comment>{$event->getFilename()}</comment>"); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function onSuiteStarted(Event\SuiteStarted $event): void |
80
|
|
|
{ |
81
|
|
|
$this->getOutput()->writeln("Using suite <comment>{$event->getSuite()->getSuiteName()}</comment>"); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function onSuiteDone(Event\SuiteDone $event): void |
85
|
|
|
{ |
86
|
|
|
if ($this->getOutput()->isVerbose()) { |
87
|
|
|
$this->getOutput()->writeln( |
88
|
|
|
"Done executing suite <comment>{$event->getSuite()->getSuiteName()}</comment>" |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function onExampleIgnored(Event\ExampleIgnored $event): void |
94
|
|
|
{ |
95
|
|
|
$this->ignoredCount++; |
96
|
|
|
if ($this->getOutput()->isVerbose()) { |
97
|
|
|
$this->getOutput()->writeln( |
98
|
|
|
"<comment>{$event->getMessage()}</comment>" |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function onEvaluationSkipped(Event\EvaluationSkipped $event): void |
104
|
|
|
{ |
105
|
|
|
$this->skippedCount++; |
106
|
|
|
$this->getOutput()->writeln( |
107
|
|
|
"<comment>{$event->getMessage()}</comment>" |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function onEvaluationStarted(Event\EvaluationStarted $event): void |
112
|
|
|
{ |
113
|
|
|
$this->examplePassed = true; |
114
|
|
|
$this->exampleCount++; |
115
|
|
|
$this->getOutput()->write("<info>{$event->getOutcome()->getExample()->getName()->getFullName()}</info>"); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function onTestPassed(Event\TestPassed $event): void |
119
|
|
|
{ |
120
|
|
|
$this->expectationCount++; |
121
|
|
|
|
122
|
|
|
$msg = $this->getOutput()->isVeryVerbose() |
123
|
|
|
? $event->getStatus()->getContent() |
124
|
|
|
: $event->getStatus()->getTruncatedContent(); |
125
|
|
|
|
126
|
|
|
if ($this->getOutput()->isVerbose()) { |
127
|
|
|
$this->getOutput()->write("\n> $msg"); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function onTestFailed(Event\TestFailed $event): void |
132
|
|
|
{ |
133
|
|
|
$this->examplePassed = false; |
134
|
|
|
$this->expectationCount++; |
135
|
|
|
$this->failureCount++; |
136
|
|
|
|
137
|
|
|
$msg = $this->getOutput()->isVerbose() |
138
|
|
|
? $event->getStatus()->getContent() |
139
|
|
|
: $event->getStatus()->getTruncatedContent(); |
140
|
|
|
|
141
|
|
|
$this->getOutput()->writeln("\n<error>> $msg</error>"); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function onEvaluationDone(Event\EvaluationDone $event): void |
|
|
|
|
145
|
|
|
{ |
146
|
|
|
if ($this->examplePassed) { |
147
|
|
|
$this->getOutput()->writeln(" <comment>\u{2713}</comment>"); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function onInvalidInput(Event\InvalidInput $event): void |
152
|
|
|
{ |
153
|
|
|
$message = $this->getOutput()->isVerbose() ? $event->getVerboseMessage() : $event->getMessage(); |
154
|
|
|
$this->getOutput()->writeln("<error>$message</error>"); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function onExecutionStopped(Event\ExecutionStopped $event): void |
|
|
|
|
158
|
|
|
{ |
159
|
|
|
$this->getOutput()->writeln( |
160
|
|
|
sprintf( |
161
|
|
|
"<%s>%s file%s, %s tested example%s,%s%s %s assertion%s, %s failure%s</%s>", |
162
|
|
|
$this->failureCount ? 'error' : 'comment', |
163
|
|
|
$this->fileCount, |
164
|
|
|
$this->fileCount == 1 ? '' : 's', |
165
|
|
|
$this->exampleCount, |
166
|
|
|
$this->exampleCount == 1 ? '' : 's', |
167
|
|
|
$this->ignoredCount && $this->getOutput()->isVerbose() ? " {$this->ignoredCount} ignored," : '', |
168
|
|
|
$this->skippedCount ? " {$this->skippedCount} skipped," : '', |
169
|
|
|
$this->expectationCount, |
170
|
|
|
$this->expectationCount == 1 ? '' : 's', |
171
|
|
|
$this->failureCount, |
172
|
|
|
$this->failureCount == 1 ? '' : 's', |
173
|
|
|
$this->failureCount ? 'error' : 'comment' |
174
|
|
|
) |
175
|
|
|
); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.