|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Paraunit\Printer; |
|
5
|
|
|
|
|
6
|
|
|
use Paraunit\TestResult\TestResultContainer; |
|
7
|
|
|
use Paraunit\TestResult\TestResultList; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Symfony\Component\Stopwatch\Stopwatch; |
|
10
|
|
|
use Symfony\Component\Stopwatch\StopwatchEvent; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class FinalPrinter |
|
14
|
|
|
* @package Paraunit\Printer |
|
15
|
|
|
*/ |
|
16
|
|
|
class FinalPrinter extends AbstractFinalPrinter |
|
17
|
|
|
{ |
|
18
|
|
|
const STOPWATCH_NAME = 'engine'; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Stopwatch */ |
|
21
|
|
|
private $stopWatch; |
|
22
|
|
|
|
|
23
|
|
|
/** @var int */ |
|
24
|
|
|
private $processCompleted; |
|
25
|
|
|
|
|
26
|
|
|
/** @var int */ |
|
27
|
|
|
private $processRetried; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* FinalPrinter constructor. |
|
31
|
|
|
* @param TestResultList $testResultList |
|
32
|
|
|
* @param OutputInterface $output |
|
33
|
|
|
*/ |
|
34
|
16 |
|
public function __construct(TestResultList $testResultList, OutputInterface $output) |
|
35
|
|
|
{ |
|
36
|
16 |
|
parent::__construct($testResultList, $output); |
|
37
|
|
|
|
|
38
|
16 |
|
$this->stopWatch = new Stopwatch(); |
|
39
|
16 |
|
$this->processCompleted = 0; |
|
40
|
16 |
|
$this->processRetried = 0; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
16 |
|
public function onEngineStart() |
|
44
|
|
|
{ |
|
45
|
16 |
|
$this->stopWatch->start(self::STOPWATCH_NAME); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
16 |
|
public function onEngineEnd() |
|
49
|
|
|
{ |
|
50
|
16 |
|
$stopEvent = $this->stopWatch->stop(self::STOPWATCH_NAME); |
|
51
|
|
|
|
|
52
|
16 |
|
$this->printExecutionTime($stopEvent); |
|
53
|
16 |
|
$this->printTestCounters(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
15 |
|
public function onProcessTerminated() |
|
57
|
|
|
{ |
|
58
|
15 |
|
$this->processCompleted++; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
5 |
|
public function onProcessToBeRetried() |
|
62
|
|
|
{ |
|
63
|
5 |
|
$this->processRetried++; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
16 |
|
private function printExecutionTime(StopwatchEvent $stopEvent) |
|
67
|
|
|
{ |
|
68
|
16 |
|
$this->getOutput()->writeln(''); |
|
69
|
16 |
|
$this->getOutput()->writeln(''); |
|
70
|
16 |
|
$this->getOutput()->writeln('Execution time -- ' . gmdate('H:i:s', (int)($stopEvent->getDuration() / 1000))); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
16 |
|
private function printTestCounters() |
|
74
|
|
|
{ |
|
75
|
16 |
|
$testsCount = 0; |
|
76
|
16 |
|
foreach ($this->testResultList->getTestResultContainers() as $container) { |
|
77
|
16 |
|
if ($container instanceof TestResultContainer) { |
|
78
|
16 |
|
$testsCount += $container->countTestResults(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
16 |
|
$this->getOutput()->writeln(''); |
|
83
|
16 |
|
$this->getOutput()->writeln(sprintf( |
|
84
|
16 |
|
'Executed: %d test classes, %d tests (%d retried)', |
|
85
|
16 |
|
$this->processCompleted - $this->processRetried, |
|
86
|
16 |
|
$testsCount, |
|
87
|
16 |
|
$this->processRetried |
|
88
|
|
|
)); |
|
89
|
16 |
|
$this->getOutput()->writeln(''); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|