|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Paraunit\Printer; |
|
6
|
|
|
|
|
7
|
|
|
use Paraunit\Lifecycle\EngineEvent; |
|
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\EventDispatcher\EventSubscriberInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class FailuresPrinter |
|
16
|
|
|
* @package Paraunit\Printer |
|
17
|
|
|
*/ |
|
18
|
|
|
class FailuresPrinter extends AbstractFinalPrinter implements EventSubscriberInterface |
|
19
|
|
|
{ |
|
20
|
70 |
|
public static function getSubscribedEvents() |
|
21
|
|
|
{ |
|
22
|
|
|
return [ |
|
23
|
70 |
|
EngineEvent::END => ['onEngineEnd', 200], |
|
24
|
|
|
]; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
25 |
|
public function onEngineEnd() |
|
28
|
|
|
{ |
|
29
|
25 |
|
foreach ($this->testResultList->getTestResultContainers() as $parser) { |
|
30
|
25 |
|
if ($parser->getTestResultFormat()->shouldPrintTestOutput()) { |
|
31
|
25 |
|
$this->printFailuresOutput($parser); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param TestResultContainer $testResultContainer |
|
38
|
|
|
*/ |
|
39
|
25 |
|
private function printFailuresOutput(TestResultContainer $testResultContainer) |
|
40
|
|
|
{ |
|
41
|
25 |
|
if (empty($testResultContainer->getTestResults())) { |
|
42
|
25 |
|
return; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
13 |
|
$tag = $testResultContainer->getTestResultFormat()->getTag(); |
|
46
|
13 |
|
$title = $testResultContainer->getTestResultFormat()->getTitle(); |
|
47
|
|
|
|
|
48
|
13 |
|
$this->getOutput()->writeln(''); |
|
49
|
13 |
|
$this->getOutput()->writeln(sprintf('<%s>%s output:</%s>', $tag, ucwords($title), $tag)); |
|
50
|
|
|
|
|
51
|
13 |
|
$i = 1; |
|
52
|
13 |
|
foreach ($testResultContainer->getTestResults() as $testResult) { |
|
53
|
13 |
|
$this->getOutput()->writeln(''); |
|
54
|
13 |
|
$this->getOutput()->write(sprintf('<%s>%d) ', $tag, $i++)); |
|
55
|
|
|
|
|
56
|
13 |
|
if ($testResult instanceof FunctionNameInterface) { |
|
57
|
13 |
|
$this->getOutput()->writeln($testResult->getFunctionName()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
13 |
|
$this->getOutput()->write(sprintf('</%s>', $tag)); |
|
61
|
|
|
|
|
62
|
13 |
|
if ($testResult instanceof FailureMessageInterface) { |
|
63
|
13 |
|
$this->getOutput()->writeln($testResult->getFailureMessage()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
13 |
|
if ($testResult instanceof StackTraceInterface) { |
|
67
|
13 |
|
$this->getOutput()->writeln($testResult->getTrace()); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|