Completed
Pull Request — master (#94)
by Alessandro
06:43
created

FilesRecapPrinter::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Printer;
5
6
use Paraunit\Lifecycle\EngineEvent;
7
use Paraunit\TestResult\Interfaces\TestResultContainerInterface;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
/**
11
 * Class FilesRecapPrinter
12
 * @package Paraunit\Printer
13
 */
14
class FilesRecapPrinter extends AbstractFinalPrinter implements EventSubscriberInterface
15
{
16
    public static function getSubscribedEvents(): array
17
    {
18 16
        return [
19
            EngineEvent::END => ['onEngineEnd', 100],
20 16
        ];
21
    }
22 16
23 16
    public function onEngineEnd()
24
    {
25 16
        foreach ($this->testResultList->getTestResultContainers() as $parser) {
26
            $this->printFileRecap($parser);
27
        }
28
    }
29
30
    /**
31 16
     * @param TestResultContainerInterface $testResultContainer
32
     */
33 16
    private function printFileRecap(TestResultContainerInterface $testResultContainer)
34 16
    {
35
        if (! $testResultContainer->getTestResultFormat()->shouldPrintFilesRecap()) {
36
            return;
37 16
        }
38
39 16
        $filenames = $testResultContainer->getFileNames();
40 13
41 13
        if (count($filenames)) {
42 13
            $tag = $testResultContainer->getTestResultFormat()->getTag();
43 13
            $title = $testResultContainer->getTestResultFormat()->getTitle();
44
            $this->getOutput()->writeln('');
45 13
            $this->getOutput()->writeln(
46
                sprintf(
47
                    '<%s>%d files with %s:</%s>',
48
                    $tag,
49
                    count($filenames),
50
                    strtoupper($title),
51
                    $tag
52
                )
53 13
            );
54 13
55
            foreach ($filenames as $fileName) {
56
                $this->getOutput()->writeln(sprintf(' <%s>%s</%s>', $tag, $fileName, $tag));
57 16
            }
58
        }
59
    }
60
}
61