1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Paraunit\Printer; |
4
|
|
|
|
5
|
|
|
use Paraunit\Lifecycle\ProcessEvent; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ProcessPrinter |
10
|
|
|
* @package Paraunit\Printer |
11
|
|
|
*/ |
12
|
|
|
class ProcessPrinter |
13
|
|
|
{ |
14
|
|
|
/** @var OutputInterface */ |
15
|
|
|
private $output; |
16
|
|
|
|
17
|
|
|
/** @var int */ |
18
|
|
|
private $counter = 0; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param ProcessEvent $processEvent |
22
|
|
|
*/ |
23
|
24 |
|
public function onProcessTerminated(ProcessEvent $processEvent) |
24
|
|
|
{ |
25
|
24 |
|
$process = $processEvent->getProcess(); |
26
|
|
|
|
27
|
24 |
|
if ( ! $processEvent->has('output_interface')) { |
28
|
|
|
throw new \BadMethodCallException('missing output_interface'); |
29
|
|
|
} |
30
|
|
|
|
31
|
24 |
|
$this->output = $processEvent->get('output_interface'); |
32
|
|
|
|
33
|
24 |
|
if ( ! $this->output instanceof OutputInterface) { |
34
|
|
|
throw new \BadMethodCallException('output_interface, unexpected type: ' . get_class($this->output)); |
35
|
|
|
} |
36
|
|
|
|
37
|
24 |
|
switch (true) { |
38
|
24 |
|
case $process->isToBeRetried(): |
39
|
4 |
|
$this->printWithCounter('<ok>A</ok>'); |
40
|
4 |
|
break; |
41
|
23 |
|
case $process->hasSegmentationFaults(): |
42
|
2 |
|
$this->printWithCounter('<segfault>X</segfault>'); |
43
|
2 |
|
break; |
44
|
21 |
|
case $process->hasFatalErrors(): |
45
|
2 |
|
$this->printWithCounter('<fatal>X</fatal>'); |
46
|
2 |
|
break; |
47
|
19 |
|
case count($process->getTestResults()) == 0: |
48
|
1 |
|
$this->printWithCounter('<warning>?</warning>'); |
49
|
1 |
|
break; |
50
|
18 |
|
default: |
51
|
18 |
|
foreach ($process->getTestResults() as $testResult) { |
52
|
18 |
|
$this->printSingleTestResult($testResult); |
53
|
18 |
|
} |
54
|
18 |
|
} |
55
|
24 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $testResult |
59
|
|
|
*/ |
60
|
18 |
|
private function printSingleTestResult($testResult) |
61
|
|
|
{ |
62
|
|
|
switch ($testResult) { |
63
|
18 |
|
case 'E': |
64
|
4 |
|
$this->printWithCounter('<error>E</error>'); |
65
|
4 |
|
break; |
66
|
14 |
|
case 'F': |
67
|
7 |
|
$this->printWithCounter('<fail>F</fail>'); |
68
|
7 |
|
break; |
69
|
7 |
|
case 'W': |
70
|
2 |
|
$this->printWithCounter('<warning>W</warning>'); |
71
|
2 |
|
break; |
72
|
5 |
|
case 'I': |
73
|
1 |
|
$this->printWithCounter('<incomplete>I</incomplete>'); |
74
|
1 |
|
break; |
75
|
4 |
|
case 'S': |
76
|
1 |
|
$this->printWithCounter('<skipped>S</skipped>'); |
77
|
1 |
|
break; |
78
|
3 |
|
case 'R': |
79
|
1 |
|
$this->printWithCounter('<risky>R</risky>'); |
80
|
1 |
|
break; |
81
|
2 |
|
case '.': |
82
|
1 |
|
$this->printWithCounter('<ok>.</ok>'); |
83
|
1 |
|
break; |
84
|
1 |
|
default: |
85
|
1 |
|
$this->printWithCounter('<warning>?</warning>'); |
86
|
1 |
|
break; |
87
|
1 |
|
} |
88
|
18 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $string |
92
|
|
|
*/ |
93
|
24 |
|
private function printWithCounter($string) |
94
|
|
|
{ |
95
|
24 |
|
if ($this->counter % 80 == 0 && $this->counter > 1) { |
96
|
4 |
|
$this->output->writeln(''); |
97
|
4 |
|
} |
98
|
|
|
|
99
|
24 |
|
++$this->counter; |
100
|
|
|
|
101
|
24 |
|
$this->output->write($string); |
102
|
24 |
|
} |
103
|
|
|
} |
104
|
|
|
|