Completed
Pull Request — master (#94)
by Alessandro
05:58
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 55
    public static function getSubscribedEvents(): array
17
    {
18
        return [
19 55
            EngineEvent::END => ['onEngineEnd', 100],
20
        ];
21
    }
22
23 15
    public function onEngineEnd()
24
    {
25 15
        foreach ($this->testResultList->getTestResultContainers() as $parser) {
26 15
            $this->printFileRecap($parser);
27
        }
28
    }
29
30
    /**
31
     * @param TestResultContainerInterface $testResultContainer
32
     */
33 15
    private function printFileRecap(TestResultContainerInterface $testResultContainer)
34
    {
35 15
        if (! $testResultContainer->getTestResultFormat()->shouldPrintFilesRecap()) {
36 15
            return;
37
        }
38
39 15
        $filenames = $testResultContainer->getFileNames();
40
41 15
        if (count($filenames)) {
42 12
            $tag = $testResultContainer->getTestResultFormat()->getTag();
43 12
            $title = $testResultContainer->getTestResultFormat()->getTitle();
44 12
            $this->getOutput()->writeln('');
45 12
            $this->getOutput()->writeln(
46 12
                sprintf(
47 12
                    '<%s>%d files with %s:</%s>',
48 12
                    $tag,
49 12
                    count($filenames),
50 12
                    strtoupper($title),
51 12
                    $tag
52
                )
53
            );
54
55 12
            foreach ($filenames as $fileName) {
56 12
                $this->getOutput()->writeln(sprintf(' <%s>%s</%s>', $tag, $fileName, $tag));
57
            }
58
        }
59
    }
60
}
61