|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Exception\JSONLogNotFoundException; |
|
6
|
|
|
use Paraunit\Exception\RecoverableTestErrorException; |
|
7
|
|
|
use Paraunit\Lifecycle\ProcessEvent; |
|
8
|
|
|
use Paraunit\Process\ParaunitProcessAbstract; |
|
9
|
|
|
use Paraunit\Process\ProcessResultInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class JSONLogParser |
|
13
|
|
|
* @package Paraunit\Parser |
|
14
|
|
|
*/ |
|
15
|
|
|
class JSONLogParser |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var JSONLogFetcher */ |
|
18
|
|
|
private $logLocator; |
|
19
|
|
|
|
|
20
|
|
|
/** @var JSONParserChainElementInterface[] */ |
|
21
|
10 |
|
protected $parsers; |
|
22
|
|
|
|
|
23
|
10 |
|
/** |
|
24
|
10 |
|
* JSONLogParser constructor. |
|
25
|
|
|
* @param JSONLogFetcher $logLocator |
|
26
|
10 |
|
*/ |
|
27
|
|
|
public function __construct(JSONLogFetcher $logLocator) |
|
28
|
|
|
{ |
|
29
|
10 |
|
$this->logLocator = $logLocator; |
|
30
|
10 |
|
$this->parsers = array(); |
|
31
|
1 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
9 |
|
* @param JSONParserChainElementInterface $parser |
|
35
|
9 |
|
*/ |
|
36
|
9 |
|
public function addParser(JSONParserChainElementInterface $parser) |
|
37
|
|
|
{ |
|
38
|
9 |
|
$this->parsers[] = $parser; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return JSONParserChainElementInterface[] |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getParsers() |
|
45
|
9 |
|
{ |
|
46
|
|
|
return $this->parsers; |
|
47
|
9 |
|
} |
|
48
|
9 |
|
|
|
49
|
9 |
|
/** |
|
50
|
9 |
|
* @param ProcessEvent $processEvent |
|
51
|
9 |
|
*/ |
|
52
|
6 |
|
public function onProcessTerminated(ProcessEvent $processEvent) |
|
53
|
1 |
|
{ |
|
54
|
1 |
|
$this->parse($processEvent->getProcess()); |
|
55
|
6 |
|
} |
|
56
|
5 |
|
|
|
57
|
5 |
|
/** |
|
58
|
1 |
|
* @param ParaunitProcessAbstract $process |
|
59
|
1 |
|
*/ |
|
60
|
1 |
|
public function parse(ParaunitProcessAbstract $process) |
|
61
|
|
|
{ |
|
62
|
|
|
try { |
|
63
|
9 |
|
$logs = $this->logLocator->fetch($process); |
|
64
|
9 |
|
} catch (JSONLogNotFoundException $exception) { |
|
65
|
9 |
|
$process->addTestResult('X'); |
|
66
|
|
|
$process->reportAbnormalTerminationInFunction('Unknown function -- test log not found'); |
|
67
|
5 |
|
|
|
68
|
|
|
return; |
|
69
|
5 |
|
} |
|
70
|
5 |
|
|
|
71
|
1 |
|
$expectingTestResult = false; |
|
72
|
4 |
|
|
|
73
|
1 |
|
foreach ($logs as $singleLog) { |
|
74
|
3 |
|
if ($singleLog->event == 'test') { |
|
75
|
1 |
|
$expectingTestResult = false; |
|
76
|
2 |
|
$this->extractTestResult($process, $singleLog); |
|
77
|
2 |
|
} else { |
|
78
|
2 |
|
$expectingTestResult = true; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ($expectingTestResult) { |
|
83
|
|
|
$process->addTestResult('X'); |
|
84
|
|
|
$process->reportAbnormalTerminationInFunction($singleLog->test); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param ProcessResultInterface $process |
|
90
|
|
|
* @param \stdClass $logItem |
|
91
|
|
|
* @return bool False if the parsing is still waiting for a test to give results |
|
92
|
|
|
*/ |
|
93
|
|
|
private function extractTestResult(ProcessResultInterface $process, \stdClass $logItem) |
|
94
|
|
|
{ |
|
95
|
|
|
foreach ($this->parsers as $parser) { |
|
96
|
|
|
if ($parser->parsingFoundResult($process, $logItem)) { |
|
97
|
|
|
return true; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return false; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
It seems like you are relying on a variable being defined by an iteration: