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 SingleResultFormatter */ |
15
|
|
|
private $singleResultFormatter; |
16
|
|
|
|
17
|
|
|
/** @var OutputInterface */ |
18
|
|
|
private $output; |
19
|
|
|
|
20
|
|
|
/** @var int */ |
21
|
|
|
private $counter = 0; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* ProcessPrinter constructor. |
25
|
|
|
* @param SingleResultFormatter $singleResultFormatter |
26
|
|
|
*/ |
27
|
14 |
|
public function __construct(SingleResultFormatter $singleResultFormatter) |
28
|
|
|
{ |
29
|
14 |
|
$this->singleResultFormatter = $singleResultFormatter; |
30
|
14 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param ProcessEvent $processEvent |
34
|
|
|
*/ |
35
|
14 |
|
public function onProcessTerminated(ProcessEvent $processEvent) |
36
|
|
|
{ |
37
|
14 |
|
$process = $processEvent->getProcess(); |
38
|
|
|
|
39
|
14 |
|
if ( ! $processEvent->has('output_interface')) { |
40
|
|
|
throw new \BadMethodCallException('missing output_interface'); |
41
|
|
|
} |
42
|
|
|
|
43
|
14 |
|
$this->output = $processEvent->get('output_interface'); |
44
|
|
|
|
45
|
14 |
|
if ( ! $this->output instanceof OutputInterface) { |
46
|
|
|
throw new \BadMethodCallException('output_interface, unexpected type: ' . get_class($this->output)); |
47
|
|
|
} |
48
|
|
|
|
49
|
14 |
|
foreach ($process->getTestResults() as $testResult) { |
50
|
14 |
|
$this->printFormattedWithCounter($testResult); |
51
|
14 |
|
} |
52
|
14 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $singleTestResult |
56
|
|
|
*/ |
57
|
14 |
|
private function printFormattedWithCounter($singleTestResult) |
58
|
|
|
{ |
59
|
14 |
|
if ($this->counter % 80 == 0 && $this->counter > 1) { |
60
|
4 |
|
$this->output->writeln(''); |
61
|
4 |
|
} |
62
|
|
|
|
63
|
14 |
|
++$this->counter; |
64
|
|
|
|
65
|
14 |
|
$this->output->write( |
66
|
14 |
|
$this->singleResultFormatter->formatSingleResult($singleTestResult) |
67
|
14 |
|
); |
68
|
14 |
|
} |
69
|
|
|
} |
70
|
|
|
|