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

FailuresPrinter::onEngineEnd()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Paraunit\Printer;
4
5
use Paraunit\Lifecycle\EngineEvent;
6
use Paraunit\TestResult\Interfaces\FailureMessageInterface;
7
use Paraunit\TestResult\Interfaces\FunctionNameInterface;
8
use Paraunit\TestResult\Interfaces\StackTraceInterface;
9
use Paraunit\TestResult\TestResultContainer;
10
11
/**
12
 * Class FailuresPrinter
13
 * @package Paraunit\Printer
14
 */
15
class FailuresPrinter extends AbstractFinalPrinter
16
{
17
    /**
18
     * @param EngineEvent $engineEvent
19
     */
20 10 View Code Duplication
    public function onEngineEnd(EngineEvent $engineEvent)
1 ignored issue
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...
21
    {
22 10
        $this->output = $engineEvent->getOutputInterface();
23
        /** @var \DateInterval $elapsedTime */
24
25 10
        foreach ($this->logParser->getParsersForPrinting() as $parser) {
26 10
            if ($parser instanceof TestResultContainer) {
27 10
                $this->printFailuresOutput($parser);
28 10
            }
29 10
        }
30 10
    }
31
32
    /**
33
     * @param TestResultContainer $testResultContainer
34
     */
35 10
    private function printFailuresOutput(TestResultContainer $testResultContainer)
36
    {
37 10
        if ( ! $testResultContainer->getTestResultFormat()->shouldPrintTestOutput()) {
38 10
            return;
39
        }
40
41 10
        $tag = $testResultContainer->getTestResultFormat()->getTag();
42 10
        $title = $testResultContainer->getTestResultFormat()->getTitle();
43 10
        $i = 1;
44
45 10
        foreach ($testResultContainer->getTestResults() as $testResult) {
46 9
            if ($i == 1) {
47 9
                $this->output->writeln('');
48 9
                $this->output->writeln(sprintf('<%s>%s output:</%s>', $tag, ucwords($title), $tag));
49 9
            }
50
51 9
            $this->output->writeln('');
52 9
            $this->output->write(sprintf('<%s>%d) ', $tag, $i++));
53
54 9
            if ($testResult instanceof FunctionNameInterface) {
55 9
                $this->output->writeln($testResult->getFunctionName());
56 9
            }
57
58 9
            $this->output->write(sprintf('</%s>', $tag));
59
60 9
            if ($testResult instanceof FailureMessageInterface) {
61 9
                $this->output->writeln($testResult->getFailureMessage());
62 9
            }
63
64 9
            if ($testResult instanceof StackTraceInterface) {
65 6
                foreach ($testResult->getTrace() as $traceStep) {
66 5
                    $this->output->writeln((string)$traceStep);
67 6
                }
68 6
            }
69 10
        }
70 10
    }
71
}
72