1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Paraunit\Parser\JSON; |
6
|
|
|
|
7
|
|
|
use Paraunit\Process\AbstractParaunitProcess; |
8
|
|
|
use Paraunit\TestResult\NullTestResult; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class TestStartParser |
12
|
|
|
* @package Paraunit\Parser\JSON |
13
|
|
|
*/ |
14
|
|
|
class TestStartParser implements ParserChainElementInterface |
15
|
|
|
{ |
16
|
|
|
const UNKNOWN_FUNCTION = 'UNKNOWN -- log not found'; |
17
|
|
|
|
18
|
|
|
/** @var AbstractParaunitProcess */ |
19
|
|
|
private $lastProcess; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
private $lastFunction; |
23
|
|
|
|
24
|
43 |
|
public function handleLogItem(AbstractParaunitProcess $process, \stdClass $logItem) |
25
|
|
|
{ |
26
|
43 |
|
if (property_exists($logItem, 'status') && $logItem->status === LogFetcher::LOG_ENDING_STATUS) { |
27
|
39 |
|
return $this->handleLogTermination($process, $logItem); |
28
|
|
|
} |
29
|
|
|
|
30
|
39 |
|
if (property_exists($logItem, 'event')) { |
31
|
39 |
|
if ($logItem->event === 'testStart' || $logItem->event === 'suiteStart') { |
32
|
36 |
|
$process->setWaitingForTestResult(true); |
33
|
36 |
|
$this->saveProcessFunction($process, $logItem); |
34
|
36 |
|
$this->saveTestFQCN($process, $logItem); |
35
|
|
|
|
36
|
36 |
|
return new NullTestResult(); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
33 |
|
return null; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param AbstractParaunitProcess $process |
45
|
|
|
* @param \stdClass $logItem |
46
|
|
|
* @return null|NullTestResult |
47
|
|
|
*/ |
48
|
39 |
|
private function handleLogTermination(AbstractParaunitProcess $process, \stdClass $logItem) |
49
|
|
|
{ |
50
|
39 |
|
if ($process->isWaitingForTestResult()) { |
51
|
14 |
|
$this->injectLastFunctionInEndingLog($process, $logItem); |
52
|
|
|
|
53
|
14 |
|
return null; |
54
|
|
|
} |
55
|
|
|
|
56
|
29 |
|
return new NullTestResult(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param AbstractParaunitProcess $process |
61
|
|
|
* @param \stdClass $logItem |
62
|
|
|
*/ |
63
|
36 |
|
private function saveProcessFunction(AbstractParaunitProcess $process, \stdClass $logItem) |
64
|
|
|
{ |
65
|
36 |
|
$this->lastProcess = $process; |
66
|
36 |
|
$this->lastFunction = property_exists($logItem, 'test') ? $logItem->test : self::UNKNOWN_FUNCTION; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param AbstractParaunitProcess $process |
71
|
|
|
* @param \stdClass $logItem |
72
|
|
|
*/ |
73
|
14 |
|
private function injectLastFunctionInEndingLog(AbstractParaunitProcess $process, \stdClass $logItem) |
74
|
|
|
{ |
75
|
14 |
|
$logItem->test = $this->lastFunction; |
76
|
|
|
|
77
|
14 |
|
if ($this->lastFunction === null || $process !== $this->lastProcess) { |
78
|
6 |
|
$logItem->test = self::UNKNOWN_FUNCTION; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
36 |
|
private function saveTestFQCN(AbstractParaunitProcess $process, \stdClass $logItem) |
83
|
|
|
{ |
84
|
36 |
|
if ($process->getTestClassName()) { |
85
|
26 |
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
36 |
|
if (! property_exists($logItem, 'suite')) { |
89
|
4 |
|
return; |
90
|
|
|
} |
91
|
|
|
|
92
|
32 |
|
if (! property_exists($logItem, 'test')) { |
93
|
32 |
|
return; |
94
|
|
|
} |
95
|
|
|
|
96
|
32 |
|
$suiteName = explode('::', $logItem->suite); |
97
|
32 |
|
$process->setTestClassName($suiteName[0]); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|