|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Printer; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Lifecycle\EngineEvent; |
|
6
|
|
|
use Paraunit\Parser\JSONLogParser; |
|
7
|
|
|
use Paraunit\Process\AbstractParaunitProcess; |
|
8
|
|
|
use Paraunit\TestResult\Interfaces\FailureMessageInterface; |
|
9
|
|
|
use Paraunit\TestResult\Interfaces\FunctionNameInterface; |
|
10
|
|
|
use Paraunit\TestResult\Interfaces\StackTraceInterface; |
|
11
|
|
|
use Paraunit\TestResult\TestResultContainer; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class FinalPrinter. |
|
16
|
|
|
*/ |
|
17
|
|
|
class FinalPrinter |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var JSONLogParser */ |
|
20
|
|
|
private $logParser; |
|
21
|
|
|
|
|
22
|
|
|
/** @var OutputInterface */ |
|
23
|
|
|
private $output; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* FinalPrinter constructor. |
|
27
|
|
|
* @param JSONLogParser $logParser |
|
28
|
|
|
*/ |
|
29
|
11 |
|
public function __construct(JSONLogParser $logParser) |
|
30
|
|
|
{ |
|
31
|
11 |
|
$this->logParser = $logParser; |
|
32
|
11 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param EngineEvent $engineEvent |
|
36
|
|
|
*/ |
|
37
|
11 |
|
public function onEngineEnd(EngineEvent $engineEvent) |
|
38
|
|
|
{ |
|
39
|
11 |
|
$this->output = $engineEvent->getOutputInterface(); |
|
40
|
|
|
/** @var \DateInterval $elapsedTime */ |
|
41
|
|
|
|
|
42
|
11 |
|
$this->printExecutionTime($engineEvent); |
|
43
|
11 |
|
$this->printTestCounters($engineEvent); |
|
44
|
11 |
|
$this->printAllFailuresOutput(); |
|
45
|
11 |
|
$this->printAllFilesRecap(); |
|
46
|
|
|
|
|
47
|
11 |
|
$this->output->writeln(''); |
|
48
|
11 |
|
} |
|
49
|
|
|
|
|
50
|
11 |
|
private function printAllFailuresOutput() |
|
51
|
|
|
{ |
|
52
|
11 |
|
foreach ($this->logParser->getParsersForPrinting() as $parser) { |
|
53
|
11 |
|
if ($parser instanceof TestResultContainer) { |
|
54
|
11 |
|
$this->printFailuresOutput($parser); |
|
55
|
11 |
|
} |
|
56
|
11 |
|
} |
|
57
|
11 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param TestResultContainer $testResultContainer |
|
61
|
|
|
* @todo Refactor |
|
62
|
|
|
*/ |
|
63
|
11 |
|
private function printFailuresOutput(TestResultContainer $testResultContainer) |
|
64
|
|
|
{ |
|
65
|
11 |
|
if ( ! $testResultContainer->getTestResultFormat()->shouldPrintTestOutput()) { |
|
66
|
11 |
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
9 |
|
$tag = $testResultContainer->getTestResultFormat()->getTag(); |
|
70
|
9 |
|
$title = $testResultContainer->getTestResultFormat()->getTitle(); |
|
71
|
9 |
|
$i = 1; |
|
72
|
|
|
|
|
73
|
9 |
|
foreach ($testResultContainer->getTestResults() as $testResult) { |
|
74
|
8 |
|
if ($i == 1) { |
|
75
|
8 |
|
$this->output->writeln(''); |
|
76
|
8 |
|
$this->output->writeln(sprintf('<%s>%s output:</%s>', $tag, ucwords($title), $tag)); |
|
77
|
8 |
|
} |
|
78
|
|
|
|
|
79
|
8 |
|
$this->output->writeln(''); |
|
80
|
8 |
|
$this->output->write(sprintf('<%s>%d) ', $tag, $i++)); |
|
81
|
|
|
|
|
82
|
8 |
|
if ($testResult instanceof FunctionNameInterface) { |
|
83
|
8 |
|
$this->output->writeln($testResult->getFunctionName()); |
|
84
|
8 |
|
} |
|
85
|
|
|
|
|
86
|
8 |
|
$this->output->write(sprintf('</%s>', $tag)); |
|
87
|
|
|
|
|
88
|
8 |
|
if ($testResult instanceof FailureMessageInterface) { |
|
89
|
8 |
|
$this->output->writeln($testResult->getFailureMessage()); |
|
90
|
8 |
|
} |
|
91
|
|
|
|
|
92
|
8 |
|
if ($testResult instanceof StackTraceInterface) { |
|
93
|
6 |
|
foreach ($testResult->getTrace() as $traceStep) { |
|
94
|
5 |
|
$this->output->writeln((string)$traceStep); |
|
95
|
6 |
|
} |
|
96
|
6 |
|
} |
|
97
|
9 |
|
} |
|
98
|
9 |
|
} |
|
99
|
|
|
|
|
100
|
11 |
|
private function printAllFilesRecap() |
|
101
|
|
|
{ |
|
102
|
11 |
|
foreach ($this->logParser->getParsersForPrinting() as $parser) { |
|
103
|
11 |
|
if ($parser instanceof TestResultContainer) { |
|
104
|
11 |
|
$this->printFileRecap($parser); |
|
105
|
11 |
|
} |
|
106
|
11 |
|
} |
|
107
|
11 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param TestResultContainer $testResultContainer |
|
111
|
|
|
*/ |
|
112
|
11 |
|
private function printFileRecap(TestResultContainer $testResultContainer) |
|
113
|
|
|
{ |
|
114
|
11 |
|
if ( ! $testResultContainer->getTestResultFormat()->shouldPrintFilesRecap()) { |
|
115
|
11 |
|
return; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
9 |
|
$filenames = $testResultContainer->getFileNames(); |
|
119
|
|
|
|
|
120
|
9 |
|
if (count($filenames)) { |
|
121
|
8 |
|
$tag = $testResultContainer->getTestResultFormat()->getTag(); |
|
122
|
8 |
|
$title = $testResultContainer->getTestResultFormat()->getTitle(); |
|
123
|
8 |
|
$this->output->writeln(''); |
|
124
|
8 |
|
$this->output->writeln( |
|
125
|
8 |
|
sprintf( |
|
126
|
8 |
|
'<%s>%d files with %s:</%s>', |
|
127
|
8 |
|
$tag, |
|
128
|
8 |
|
count($filenames), |
|
129
|
8 |
|
strtoupper($title), |
|
130
|
|
|
$tag |
|
131
|
8 |
|
) |
|
132
|
8 |
|
); |
|
133
|
|
|
|
|
134
|
8 |
|
foreach ($filenames as $fileName) { |
|
135
|
8 |
|
$this->output->writeln(sprintf(' <%s>%s</%s>', $tag, $fileName, $tag)); |
|
136
|
8 |
|
} |
|
137
|
8 |
|
} |
|
138
|
9 |
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param EngineEvent $engineEvent |
|
142
|
|
|
*/ |
|
143
|
11 |
|
private function printExecutionTime(EngineEvent $engineEvent) |
|
144
|
|
|
{ |
|
145
|
|
|
/** @var \DateInterval $elapsedTime */ |
|
146
|
11 |
|
$elapsedTime = $engineEvent->get('start')->diff($engineEvent->get('end')); |
|
147
|
|
|
|
|
148
|
11 |
|
$this->output->writeln(''); |
|
149
|
11 |
|
$this->output->writeln(''); |
|
150
|
11 |
|
$this->output->writeln($elapsedTime->format('Execution time -- %H:%I:%S ')); |
|
151
|
11 |
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param EngineEvent $engineEvent |
|
155
|
|
|
*/ |
|
156
|
11 |
|
private function printTestCounters(EngineEvent $engineEvent) |
|
157
|
|
|
{ |
|
158
|
11 |
|
$completedProcesses = $engineEvent->get('process_completed'); |
|
159
|
11 |
|
$testsCount = 0; |
|
160
|
|
|
/** @var AbstractParaunitProcess $process */ |
|
161
|
11 |
|
foreach ($this->logParser->getParsersForPrinting() as $parser) { |
|
162
|
11 |
|
if ($parser instanceof TestResultContainer) { |
|
163
|
11 |
|
$testsCount += $parser->countTestResults(); |
|
164
|
11 |
|
} |
|
165
|
11 |
|
} |
|
166
|
|
|
|
|
167
|
11 |
|
$this->output->writeln(''); |
|
168
|
11 |
|
$this->output->writeln(sprintf('Executed: %d test classes, %d tests', count($completedProcesses), $testsCount)); |
|
169
|
11 |
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|