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