Completed
Push — master ( fdad86...4add92 )
by Alessandro
08:39
created

TestResultContainer::addTestResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A TestResultContainer::countTestResults() 0 4 1
1
<?php
2
3
namespace Paraunit\TestResult;
4
5
use Paraunit\Parser\JSONParserChainElementInterface;
6
use Paraunit\Process\OutputAwareInterface;
7
use Paraunit\Process\ProcessWithResultsInterface;
8
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface;
9
use Paraunit\TestResult\Interfaces\TestResultBearerInterface;
10
use Paraunit\TestResult\Interfaces\TestResultInterface;
11
12
/**
13
 * Class TestResultContainer
14
 * @package Paraunit\TestResult
15
 */
16
class TestResultContainer extends DumbTestResultContainer implements TestResultBearerInterface, JSONParserChainElementInterface
17
{
18
    /** @var JSONParserChainElementInterface */
19
    private $parser;
20
21
    /** @var  PrintableTestResultInterface[] */
22
    private $testResults;
23
24
    /**
25
     * TestResultContainer constructor.
26
     * @param JSONParserChainElementInterface $parser
27
     * @param TestResultFormat $testResultFormat
28
     */
29
    public function __construct(JSONParserChainElementInterface $parser, TestResultFormat $testResultFormat)
30
    {
31
        parent::__construct($testResultFormat);
32
        $this->parser = $parser;
33
        $this->testResults = array();
34
    }
35 33
36
    /**
37 33
     * @param ProcessWithResultsInterface $process
38 33
     * @param \stdClass $logItem
39 33
     * @return null|TestResultInterface|PrintableTestResultInterface Returned when the chain needs to stop
40 33
     */
41 33
    public function handleLogItem(ProcessWithResultsInterface $process, \stdClass $logItem)
42
    {
43
        $result = $this->parser->handleLogItem($process, $logItem);
44
45
        if ($result instanceof TestResultWithAbnormalTermination && $process instanceof OutputAwareInterface) {
46
            $this->addProcessOutputToResult($result, $process);
47
        }
48 25
49
        if ($result instanceof PrintableTestResultInterface) {
50 25
            $result->setTestResultFormat($this->testResultFormat);
51
            $this->testResults[] = $result;
52 25
53 11
            $this->addProcessToFilenames($process);
54 11
            $process->addTestResult($result);
55
        }
56 25
57 25
        return $result;
58 25
    }
59 25
60 25
    /**
61
     * @param TestResultWithAbnormalTermination $result
62 25
     * @param OutputAwareInterface $process
63
     */
64
    private function addProcessOutputToResult(TestResultWithAbnormalTermination $result, OutputAwareInterface $process)
65
    {
66
        $tag = $this->testResultFormat->getTag();
67
        $output = $process->getOutput() ?: sprintf('<%s><[NO OUTPUT FOUND]></%s>', $tag, $tag);
68
        $result->setTestOutput($output);
69 11
    }
70
71 11
    /**
72 11
     * @return PrintableTestResultInterface[]
73 11
     */
74 11
    public function getTestResults()
75
    {
76
        return $this->testResults;
77
    }
78
79
    /**
80 25
     * @return int
81
     */
82 25
    public function countTestResults()
83
    {
84 25
        return count($this->testResults);
85 25
    }
86
}
87