|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Process; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface; |
|
6
|
|
|
use Paraunit\TestResult\TestResultWithAbnormalTermination; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class AbstractParaunitProcess |
|
10
|
|
|
* @package Paraunit\Process |
|
11
|
|
|
*/ |
|
12
|
|
|
abstract class AbstractParaunitProcess implements ParaunitProcessInterface, RetryAwareInterface, ProcessWithResultsInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var int */ |
|
15
|
|
|
protected $retryCount = 0; |
|
16
|
|
|
|
|
17
|
|
|
/** @var bool */ |
|
18
|
|
|
protected $shouldBeRetried = false; |
|
19
|
|
|
|
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
protected $uniqueId; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
protected $filename; |
|
25
|
|
|
|
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
protected $testClassName; |
|
28
|
|
|
|
|
29
|
|
|
/** @var PrintableTestResultInterface[] */ |
|
30
|
|
|
protected $testResults; |
|
31
|
|
|
|
|
32
|
|
|
/** @var bool */ |
|
33
|
|
|
private $waitingForTestResult; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
100 |
|
public function __construct($commandLine, $uniqueId) |
|
39
|
|
|
{ |
|
40
|
100 |
|
$this->uniqueId = $uniqueId; |
|
41
|
|
|
|
|
42
|
100 |
|
$filename = array(); |
|
43
|
100 |
|
if (preg_match('/(?<=[\/\\\])[A-z]+\.php/', $commandLine, $filename) === 1) { |
|
44
|
18 |
|
$this->filename = $filename[0]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
100 |
|
$this->testResults = array(); |
|
48
|
100 |
|
$this->waitingForTestResult = true; |
|
49
|
100 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
39 |
|
public function getUniqueId() |
|
55
|
|
|
{ |
|
56
|
39 |
|
return $this->uniqueId; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return int |
|
61
|
|
|
*/ |
|
62
|
37 |
|
public function getRetryCount() |
|
63
|
|
|
{ |
|
64
|
37 |
|
return $this->retryCount; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
*/ |
|
69
|
6 |
|
public function increaseRetryCount() |
|
70
|
|
|
{ |
|
71
|
6 |
|
++$this->retryCount; |
|
72
|
6 |
|
} |
|
73
|
|
|
|
|
74
|
9 |
|
public function markAsToBeRetried() |
|
75
|
|
|
{ |
|
76
|
9 |
|
$this->shouldBeRetried = true; |
|
77
|
9 |
|
$this->testResults = array(); |
|
78
|
9 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return bool |
|
82
|
|
|
*/ |
|
83
|
29 |
|
public function isToBeRetried() |
|
84
|
|
|
{ |
|
85
|
29 |
|
return $this->shouldBeRetried; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return $this |
|
90
|
|
|
*/ |
|
91
|
5 |
|
public function reset() |
|
92
|
|
|
{ |
|
93
|
5 |
|
$this->shouldBeRetried = false; |
|
94
|
|
|
|
|
95
|
5 |
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
13 |
|
public function getFilename() |
|
102
|
|
|
{ |
|
103
|
13 |
|
return $this->filename; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
37 |
|
public function getTestClassName() |
|
110
|
|
|
{ |
|
111
|
37 |
|
return $this->testClassName; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param string $testClassName |
|
116
|
|
|
*/ |
|
117
|
25 |
|
public function setTestClassName($testClassName) |
|
118
|
|
|
{ |
|
119
|
25 |
|
$this->testClassName = $testClassName; |
|
120
|
25 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return PrintableTestResultInterface[] |
|
124
|
|
|
*/ |
|
125
|
34 |
|
public function getTestResults() |
|
126
|
|
|
{ |
|
127
|
34 |
|
return $this->testResults; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param PrintableTestResultInterface $testResult |
|
132
|
|
|
*/ |
|
133
|
39 |
|
public function addTestResult(PrintableTestResultInterface $testResult) |
|
134
|
|
|
{ |
|
135
|
39 |
|
$this->testResults[] = $testResult; |
|
136
|
39 |
|
$this->waitingForTestResult = false; |
|
137
|
39 |
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* {@inheritdoc} |
|
141
|
|
|
*/ |
|
142
|
19 |
|
public function hasAbnormalTermination() |
|
143
|
|
|
{ |
|
144
|
19 |
|
return end($this->testResults) instanceof TestResultWithAbnormalTermination; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @return bool |
|
149
|
|
|
*/ |
|
150
|
35 |
|
public function isWaitingForTestResult() |
|
151
|
|
|
{ |
|
152
|
35 |
|
return $this->waitingForTestResult; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param boolean $waitingForTestResult |
|
157
|
|
|
*/ |
|
158
|
34 |
|
public function setWaitingForTestResult($waitingForTestResult) |
|
159
|
|
|
{ |
|
160
|
34 |
|
$this->waitingForTestResult = (bool) $waitingForTestResult; |
|
161
|
34 |
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|