|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Exception\JSONLogNotFoundException; |
|
6
|
|
|
use Paraunit\Exception\RecoverableTestErrorException; |
|
7
|
|
|
use Paraunit\Process\ProcessResultInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class JSONLogParser |
|
11
|
|
|
* @package Paraunit\Parser |
|
12
|
|
|
*/ |
|
13
|
|
|
class JSONLogParser |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var JSONLogFetcher */ |
|
16
|
|
|
private $logLocator; |
|
17
|
|
|
|
|
18
|
|
|
/** @var JSONParserChainElementInterface[] */ |
|
19
|
|
|
protected $parsers; |
|
20
|
|
|
|
|
21
|
10 |
|
/** |
|
22
|
|
|
* JSONLogParser constructor. |
|
23
|
10 |
|
* @param JSONLogFetcher $logLocator |
|
24
|
10 |
|
*/ |
|
25
|
|
|
public function __construct(JSONLogFetcher $logLocator) |
|
26
|
10 |
|
{ |
|
27
|
|
|
$this->logLocator = $logLocator; |
|
28
|
|
|
$this->parsers = array(); |
|
29
|
10 |
|
} |
|
30
|
10 |
|
|
|
31
|
1 |
|
/** |
|
32
|
|
|
* @param JSONParserChainElementInterface $parser |
|
33
|
|
|
*/ |
|
34
|
9 |
|
public function addParser(JSONParserChainElementInterface $parser) |
|
35
|
9 |
|
{ |
|
36
|
9 |
|
$this->parsers[] = $parser; |
|
37
|
|
|
} |
|
38
|
9 |
|
|
|
39
|
|
|
public function parse(ProcessResultInterface $process) |
|
40
|
|
|
{ |
|
41
|
|
|
$logs = json_decode($this->logLocator->fetch($process)); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
foreach ($logs as $singleLog) { |
|
44
|
|
|
$this->extractTestResult($process, $singleLog); |
|
45
|
9 |
|
} |
|
46
|
|
|
} |
|
47
|
9 |
|
|
|
48
|
9 |
|
/** |
|
49
|
9 |
|
* @param ProcessResultInterface $process |
|
50
|
9 |
|
* @param \stdClass $logItem |
|
51
|
9 |
|
* @return bool False if the parsing is still waiting for a test to give results |
|
52
|
6 |
|
*/ |
|
53
|
1 |
|
private function extractTestResult(ProcessResultInterface $process, \stdClass $logItem) |
|
54
|
1 |
|
{ |
|
55
|
6 |
|
foreach ($this->parsers as $parser) { |
|
56
|
5 |
|
if ($parser->parsingFoundResult($process, $logItem)) { |
|
57
|
5 |
|
return true; |
|
58
|
1 |
|
} |
|
59
|
1 |
|
} |
|
60
|
1 |
|
|
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
9 |
|
|
|
64
|
9 |
|
private function checkErrorMessage(\stdClass $logItem) |
|
|
|
|
|
|
65
|
9 |
|
{ |
|
66
|
|
|
switch (true) { |
|
|
|
|
|
|
67
|
5 |
|
case preg_match('/^Incomplete Test: /', $logItem->message): |
|
68
|
|
|
return 'I'; |
|
69
|
5 |
|
case preg_match('/^Skipped Test: /', $logItem->message): |
|
70
|
5 |
|
return 'S'; |
|
71
|
1 |
|
case preg_match('/^Risky Test: /', $logItem->message): |
|
72
|
4 |
|
return 'R'; |
|
73
|
1 |
|
default: |
|
74
|
3 |
|
return 'E'; |
|
75
|
1 |
|
} |
|
76
|
2 |
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: