Completed
Push — master ( c02786...ba52e0 )
by Alessandro
5s
created

FinalPrinter::printAllFailuresOutput()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 10
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 5
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Paraunit\Printer;
4
5
use Paraunit\Lifecycle\EngineEvent;
6
use Paraunit\Parser\JSONLogParser;
7
use Paraunit\Parser\OutputContainerBearerInterface;
8
use Paraunit\Process\ParaunitProcessAbstract;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Class FinalPrinter.
13
 */
14
class FinalPrinter
15
{
16
    /** @var  JSONLogParser */
17
    private $logParser;
18
19
    /** @var  OutputInterface */
20
    private $output;
21
22
    /**
23
     * FinalPrinter constructor.
24
     * @param JSONLogParser $logParser
25
     */
26 10
    public function __construct(JSONLogParser $logParser)
27
    {
28 10
        $this->logParser = $logParser;
29 10
    }
30
31
    /**
32
     * @param EngineEvent $engineEvent
33
     */
34 10
    public function onEngineEnd(EngineEvent $engineEvent)
35
    {
36 10
        if ( ! $engineEvent->has('start') || ! $engineEvent->has('end') || ! $engineEvent->has('process_completed')) {
37
            throw new \BadMethodCallException('missing argument/s');
38
        }
39
40 10
        $this->output = $engineEvent->getOutputInterface();
41
        /** @var \DateInterval $elapsedTime */
42 10
        $elapsedTime = $engineEvent->get('start')->diff($engineEvent->get('end'));
43 10
        $completedProcesses = $engineEvent->get('process_completed');
44
45 10
        $this->output->writeln('');
46 10
        $this->output->writeln('');
47 10
        $this->output->writeln($elapsedTime->format('Execution time -- %H:%I:%S '));
48
49 10
        $testsCount = 0;
50
        /** @var ParaunitProcessAbstract $process */
51 10
        foreach ($completedProcesses as $process) {
52 10
            $testsCount += count($process->getTestResults());
53 10
        }
54
55 10
        $this->output->writeln('');
56 10
        $this->output->writeln(sprintf('Executed: %d test classes, %d tests', count($completedProcesses), $testsCount));
57
58 10
        $this->printAllFailuresOutput();
59 10
        $this->printAllFilesRecap();
60
61 10
        $this->output->writeln('');
62 10
    }
63
64 10 View Code Duplication
    private function printAllFailuresOutput()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66 10
        $this->printFailuresOutput($this->logParser->getAbnormalTerminatedOutputContainer());
67
68 10
        foreach ($this->logParser->getParsersForPrinting() as $parser) {
69 10
            if ($parser instanceof OutputContainerBearerInterface) {
70 10
                $this->printFailuresOutput($parser->getOutputContainer());
71 10
            }
72 10
        }
73 10
    }
74
75
    /**
76
     * @param OutputContainerInterface $outputContainer
77
     */
78 10
    private function printFailuresOutput(OutputContainerInterface $outputContainer)
79
    {
80 10
        $buffer = $outputContainer->getOutputBuffer();
81 10
        if (count($buffer)) {
82 9
            $tag = $outputContainer->getTag();
83 9
            $this->output->writeln('');
84 9
            $this->output->writeln(sprintf('<%s>%s output:</%s>', $tag, ucwords($outputContainer->getTitle()), $tag));
85
86 9
            $i = 1;
87
88 9
            foreach ($buffer as $filename => $messages) {
89 9
                foreach ($messages as $message) {
90 9
                    $this->output->writeln('');
91 9
                    $this->output->writeln(
92 9
                        sprintf('<%s>%d)</%s> %s', $tag, $i++, $tag, $message)
93 9
                    );
94 9
                }
95 9
            }
96 9
        }
97 10
    }
98
99 10 View Code Duplication
    private function printAllFilesRecap()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101 10
        $this->printFileRecap($this->logParser->getAbnormalTerminatedOutputContainer());
102
103 10
        foreach ($this->logParser->getParsersForPrinting() as $parser) {
104 10
            if ($parser instanceof OutputContainerBearerInterface) {
105 10
                $this->printFileRecap($parser->getOutputContainer());
106 10
            }
107 10
        }
108 10
    }
109
110
    /**
111
     * @param OutputContainerInterface $outputContainer
112
     */
113 10
    private function printFileRecap(OutputContainerInterface $outputContainer)
114
    {
115 10
        if ($outputContainer->countFiles()) {
116 9
            $tag = $outputContainer->getTag();
117 9
            $this->output->writeln('');
118 9
            $this->output->writeln(
119 9
                sprintf(
120 9
                    '<%s>%d files with %s:</%s>',
121 9
                    $tag,
122 9
                    $outputContainer->countFiles(),
123 9
                    strtoupper($outputContainer->getTitle()),
124
                    $tag
125 9
                )
126 9
            );
127
128 9
            foreach ($outputContainer->getFileNames() as $fileName) {
129 9
                $this->output->writeln(sprintf(' <%s>%s</%s>', $tag, $fileName, $tag));
130 9
            }
131 9
        }
132 10
    }
133
}
134