|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Printer\OutputContainerInterface; |
|
6
|
|
|
use Paraunit\Process\ProcessResultInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class AbstractParser |
|
10
|
|
|
* @package Paraunit\Parser |
|
11
|
|
|
*/ |
|
12
|
|
|
class AbstractParser implements JSONParserChainElementInterface, OutputContainerBearerInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var OutputContainerInterface */ |
|
15
|
|
|
protected $outputContainer; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
protected $singleResultMarker; |
|
19
|
|
|
|
|
20
|
37 |
|
/** @var string */ |
|
21
|
|
|
protected $title; |
|
22
|
37 |
|
|
|
23
|
37 |
|
/** @var string */ |
|
24
|
37 |
|
protected $status; |
|
25
|
|
|
|
|
26
|
37 |
|
/** @var string */ |
|
27
|
37 |
|
protected $messageStartsWith; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* AbstractParser constructor. |
|
31
|
|
|
* |
|
32
|
26 |
|
* @param OutputContainerInterface $outputContainer |
|
33
|
|
|
* @param string $singleResultMarker The output of the single test result (.FERW etc) |
|
34
|
26 |
|
* @param string $status The status that the parser should catch |
|
35
|
|
|
* @param string | null $messageStartsWith The start of the message that the parser should look for |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(OutputContainerInterface $outputContainer, $singleResultMarker, $status, $messageStartsWith = null) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->outputContainer = $outputContainer; |
|
40
|
|
|
$this->singleResultMarker = $singleResultMarker; |
|
41
|
24 |
|
$this->status = $status; |
|
42
|
|
|
$this->messageStartsWith = $messageStartsWith; |
|
43
|
24 |
|
} |
|
44
|
|
|
|
|
45
|
24 |
|
/** |
|
46
|
10 |
|
* @return OutputContainerInterface |
|
47
|
|
|
*/ |
|
48
|
10 |
|
public function getOutputContainer() |
|
49
|
|
|
{ |
|
50
|
10 |
|
return $this->outputContainer; |
|
51
|
10 |
|
} |
|
52
|
|
|
|
|
53
|
10 |
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
18 |
|
public function parsingFoundResult(ProcessResultInterface $process, \stdClass $log) |
|
57
|
|
|
{ |
|
58
|
|
|
if ($log->status != $this->status) { |
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if ($this->checkMessageStart($log)) { |
|
63
|
18 |
|
$process->addTestResult($this->singleResultMarker); |
|
64
|
|
|
$this->outputContainer->addToOutputBuffer($process, $log->message); |
|
65
|
18 |
|
|
|
66
|
4 |
|
return true; |
|
67
|
|
|
} |
|
68
|
4 |
|
|
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
15 |
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param \stdClass $log |
|
74
|
37 |
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
37 |
|
private function checkMessageStart(\stdClass $log) |
|
77
|
37 |
|
{ |
|
78
|
|
|
if (is_null($this->messageStartsWith)) { |
|
79
|
37 |
|
return true; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ( ! property_exists($log, 'message')) { |
|
83
|
|
|
return false; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
37 |
|
return 0 === strpos($log->message, $this->messageStartsWith); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|