Completed
Pull Request — master (#94)
by Alessandro
04:59
created

FinalPrinter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 6
dl 0
loc 76
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A onEngineStart() 0 4 1
A onEngineEnd() 0 7 1
A onProcessTerminated() 0 4 1
A onProcessToBeRetried() 0 4 1
A printExecutionTime() 0 6 1
A printTestCounters() 0 18 3
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