|
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 int */ |
|
15
|
|
|
protected $counter = 0; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param ProcessEvent $processEvent |
|
19
|
|
|
*/ |
|
20
|
21 |
|
public function onProcessTerminated(ProcessEvent $processEvent) |
|
21
|
|
|
{ |
|
22
|
21 |
|
$process = $processEvent->getProcess(); |
|
23
|
|
|
|
|
24
|
21 |
|
if ( ! $processEvent->has('output_interface')) { |
|
25
|
|
|
throw new \BadMethodCallException('missing output_interface'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
21 |
|
$output = $processEvent->get('output_interface'); |
|
29
|
|
|
|
|
30
|
21 |
|
if ( ! $output instanceof OutputInterface) { |
|
31
|
|
|
throw new \BadMethodCallException('output_interface, unexpected type: ' . get_class($output)); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
21 |
|
if ($process->isToBeRetried()) { |
|
35
|
4 |
|
$this->printWithCounter($output, '<ok>A</ok>'); |
|
36
|
|
|
|
|
37
|
4 |
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
20 |
|
if (empty($process->getTestResults())) { |
|
41
|
|
|
// TODO --- this operation should be done somewhere else! |
|
42
|
5 |
|
$process->setTestResults(array('X')); |
|
43
|
5 |
|
} |
|
44
|
|
|
|
|
45
|
20 |
|
foreach ($process->getTestResults() as $testResult) { |
|
46
|
20 |
|
$this->printSingleTestResult($output, $testResult); |
|
47
|
20 |
|
} |
|
48
|
20 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param OutputInterface $output |
|
52
|
|
|
* @param int $testResult |
|
53
|
|
|
*/ |
|
54
|
20 |
|
protected function printSingleTestResult(OutputInterface $output, $testResult) |
|
55
|
|
|
{ |
|
56
|
|
|
switch ($testResult) { |
|
57
|
20 |
|
case 'E': |
|
58
|
4 |
|
$this->printWithCounter($output, '<error>E</error>'); |
|
59
|
4 |
|
break; |
|
60
|
16 |
|
case 'F': |
|
61
|
7 |
|
$this->printWithCounter($output, '<fail>F</fail>'); |
|
62
|
7 |
|
break; |
|
63
|
9 |
|
case 'I': |
|
64
|
1 |
|
$this->printWithCounter($output, '<incomplete>I</incomplete>'); |
|
65
|
1 |
|
break; |
|
66
|
8 |
|
case 'S': |
|
67
|
|
|
$this->printWithCounter($output, '<skipped>S</skipped>'); |
|
68
|
|
|
break; |
|
69
|
8 |
|
case '.': |
|
70
|
1 |
|
$this->printWithCounter($output, '<ok>.</ok>'); |
|
71
|
1 |
|
break; |
|
72
|
7 |
|
default: |
|
73
|
7 |
|
$this->printWithCounter($output, '<error>X</error>'); |
|
74
|
7 |
|
break; |
|
75
|
7 |
|
} |
|
76
|
20 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param OutputInterface $output |
|
80
|
|
|
* @param string $string |
|
81
|
|
|
*/ |
|
82
|
21 |
|
protected function printWithCounter(OutputInterface $output, $string) |
|
83
|
|
|
{ |
|
84
|
21 |
|
if ($this->counter % 80 == 0 && $this->counter > 1) { |
|
85
|
4 |
|
$output->writeln(''); |
|
86
|
4 |
|
} |
|
87
|
|
|
|
|
88
|
21 |
|
++$this->counter; |
|
89
|
|
|
|
|
90
|
21 |
|
$output->write($string); |
|
91
|
21 |
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|