|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace hanneskod\readmetester\Console; |
|
6
|
|
|
|
|
7
|
|
|
use hanneskod\readmetester\Example\Example; |
|
8
|
|
|
use hanneskod\readmetester\Expectation\Status; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Default text output formatter |
|
13
|
|
|
*/ |
|
14
|
|
|
class DefaultFormatter implements FormatterInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var OutputInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $output; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var int The number of files tested |
|
23
|
|
|
*/ |
|
24
|
|
|
private $fileCount = 0; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var int The number of examples |
|
28
|
|
|
*/ |
|
29
|
|
|
private $exampleCount = 0; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var int The number of ignored examples |
|
33
|
|
|
*/ |
|
34
|
|
|
private $ignoredCount = 0; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var int The number of assertions |
|
38
|
|
|
*/ |
|
39
|
|
|
private $expectationCount = 0; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var int The number of failed assertions |
|
43
|
|
|
*/ |
|
44
|
|
|
private $failureCount = 0; |
|
45
|
|
|
|
|
46
|
|
|
public function __construct(OutputInterface $output) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->output = $output; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function onInvokationStart(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->output->writeln("Readme-Tester by Hannes Forsgård."); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function onBootstrap(string $filename): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->output->writeln("Loading bootstrap <comment>$filename</comment>"); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function onFile(string $filename): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->fileCount++; |
|
64
|
|
|
$this->output->writeln("Testing examples in <comment>$filename</comment>"); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function onExample(Example $example): void |
|
68
|
|
|
{ |
|
69
|
|
|
$this->exampleCount++; |
|
70
|
|
|
$this->output->writeln("<info>@example {$example->getName()}</info>"); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function onIgnoredExample(Example $example): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->ignoredCount++; |
|
76
|
|
|
if ($this->output->isVerbose()) { |
|
|
|
|
|
|
77
|
|
|
$this->output->writeln("ignored <info>@example {$example->getName()}</info>"); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function onExpectation(Status $status): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->expectationCount++; |
|
84
|
|
|
|
|
85
|
|
|
if (!$status->isSuccess()) { |
|
86
|
|
|
$this->failureCount++; |
|
87
|
|
|
$this->output->writeln("\n<error>$status</error>\n"); |
|
88
|
|
|
return; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if ($this->output->isVerbose()) { |
|
92
|
|
|
$this->output->writeln(" $status"); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function onInvokationEnd(): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->output->writeln( |
|
99
|
|
|
sprintf( |
|
100
|
|
|
"<%s>%s file%s tested, %s example%s,%s %s assertion%s, %s failure%s.</%s>", |
|
101
|
|
|
$this->failureCount ? 'error' : 'comment', |
|
102
|
|
|
$this->fileCount, |
|
103
|
|
|
$this->fileCount == 1 ? '' : 's', |
|
104
|
|
|
$this->exampleCount, |
|
105
|
|
|
$this->exampleCount == 1 ? '' : 's', |
|
106
|
|
|
$this->ignoredCount ? " {$this->ignoredCount} ignored examples," : '', |
|
107
|
|
|
$this->expectationCount, |
|
108
|
|
|
$this->expectationCount == 1 ? '' : 's', |
|
109
|
|
|
$this->failureCount, |
|
110
|
|
|
$this->failureCount == 1 ? '' : 's', |
|
111
|
|
|
$this->failureCount ? 'error' : 'comment' |
|
112
|
|
|
) |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|