Completed
Push — master ( 83aeed...e335a8 )
by Alessandro
05:08
created

FinalPrinter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Paraunit\Printer;
4
5
use Paraunit\Lifecycle\EngineEvent;
6
use Paraunit\Process\AbstractParaunitProcess;
7
use Paraunit\TestResult\TestResultContainer;
8
9
/**
10
 * Class FinalPrinter.
11
 */
12
class FinalPrinter extends AbstractFinalPrinter
13
{
14
    /**
15
     * @param EngineEvent $engineEvent
16
     */
17 11
    public function onEngineEnd(EngineEvent $engineEvent)
18
    {
19 11
        $this->output = $engineEvent->getOutputInterface();
20
        /** @var \DateInterval $elapsedTime */
21
22 11
        $this->printExecutionTime($engineEvent);
23 11
        $this->printTestCounters($engineEvent);
24
25 11
        $this->output->writeln('');
26 11
    }
27
28
    /**
29
     * @param EngineEvent $engineEvent
30
     */
31 11
    private function printExecutionTime(EngineEvent $engineEvent)
32
    {
33
        /** @var \DateInterval $elapsedTime */
34 11
        $elapsedTime = $engineEvent->get('start')->diff($engineEvent->get('end'));
35
36 11
        $this->output->writeln('');
37 11
        $this->output->writeln('');
38 11
        $this->output->writeln($elapsedTime->format('Execution time -- %H:%I:%S '));
39 11
    }
40
41
    /**
42
     * @param EngineEvent $engineEvent
43
     */
44 11
    private function printTestCounters(EngineEvent $engineEvent)
45
    {
46 11
        $completedProcesses = $engineEvent->get('process_completed');
47 11
        $testsCount = 0;
48
        /** @var AbstractParaunitProcess $process */
49 11
        foreach ($this->logParser->getParsersForPrinting() as $parser) {
50 11
            if ($parser instanceof TestResultContainer) {
51 11
                $testsCount += $parser->countTestResults();
52 11
            }
53 11
        }
54
55 11
        $this->output->writeln('');
56 11
        $this->output->writeln(sprintf('Executed: %d test classes, %d tests', count($completedProcesses), $testsCount));
57 11
    }
58
}
59