|
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
|
|
|
|