1 | <?php |
||
8 | abstract class ExecutableTest |
||
9 | { |
||
10 | /** |
||
11 | * The path to the test to run. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $path; |
||
16 | |||
17 | /** |
||
18 | * A path to the temp file created |
||
19 | * for this test. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $temp; |
||
24 | protected $fullyQualifiedClassName; |
||
25 | protected $pipes = []; |
||
26 | |||
27 | /** |
||
28 | * Path where the coveragereport is stored. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $coverageFileName; |
||
33 | |||
34 | /** |
||
35 | * @var Process |
||
36 | */ |
||
37 | protected $process; |
||
38 | |||
39 | /** |
||
40 | * A unique token value for a given |
||
41 | * process. |
||
42 | * |
||
43 | * @var int |
||
44 | */ |
||
45 | protected $token; |
||
46 | |||
47 | /** |
||
48 | * Last executed process command. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $lastCommand; |
||
53 | |||
54 | 66 | public function __construct($path, $fullyQualifiedClassName = null) |
|
59 | |||
60 | /** |
||
61 | * Get the expected count of tests to be executed. |
||
62 | * |
||
63 | * @return int |
||
64 | */ |
||
65 | abstract public function getTestCount(); |
||
66 | |||
67 | /** |
||
68 | * Get the path to the test being executed. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | 6 | public function getPath() |
|
76 | |||
77 | /** |
||
78 | * Returns the path to this test's temp file. |
||
79 | * If the temp file does not exist, it will be |
||
80 | * created. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 32 | public function getTempFile() |
|
92 | |||
93 | /** |
||
94 | * Return the test process' stderr contents. |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | public function getStderr() |
||
102 | |||
103 | /** |
||
104 | * Return any warnings that are in the test output, or false if there are none. |
||
105 | * |
||
106 | * @return mixed |
||
107 | */ |
||
108 | 11 | public function getWarnings() |
|
125 | |||
126 | /** |
||
127 | * Stop the process and return it's |
||
128 | * exit code. |
||
129 | * |
||
130 | * @return int |
||
131 | */ |
||
132 | 2 | public function stop() |
|
136 | |||
137 | /** |
||
138 | * Removes the test file. |
||
139 | */ |
||
140 | public function deleteFile() |
||
145 | |||
146 | /** |
||
147 | * Check if the process has terminated. |
||
148 | * |
||
149 | * @return bool |
||
150 | */ |
||
151 | 2 | public function isDoneRunning() |
|
155 | |||
156 | /** |
||
157 | * Return the exit code of the process. |
||
158 | * |
||
159 | * @return int |
||
160 | */ |
||
161 | 2 | public function getExitCode() |
|
165 | |||
166 | /** |
||
167 | * Return the last process command. |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public function getLastCommand() |
||
175 | |||
176 | /** |
||
177 | * Executes the test by creating a separate process. |
||
178 | * |
||
179 | * @param $binary |
||
180 | * @param array $options |
||
181 | * @param array $environmentVariables |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | 2 | public function run($binary, $options = [], $environmentVariables = []) |
|
197 | |||
198 | /** |
||
199 | * Returns the unique token for this test process. |
||
200 | * |
||
201 | * @return int |
||
202 | */ |
||
203 | 1 | public function getToken() |
|
207 | |||
208 | /** |
||
209 | * Generate command line with passed options suitable to handle through paratest. |
||
210 | * |
||
211 | * @param string $binary executable binary name |
||
212 | * @param array $options command line options |
||
213 | * |
||
214 | * @return string command line |
||
215 | */ |
||
216 | 3 | public function command($binary, $options = []) |
|
223 | |||
224 | /** |
||
225 | * Get covertage filename. |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | 3 | public function getCoverageFileName() |
|
237 | |||
238 | /** |
||
239 | * Get process stdout content. |
||
240 | * |
||
241 | * @return string |
||
242 | */ |
||
243 | public function getStdout() |
||
247 | |||
248 | /** |
||
249 | * Set process termporary filename. |
||
250 | * |
||
251 | * @param string $temp |
||
252 | */ |
||
253 | 37 | public function setTempFile($temp) |
|
257 | |||
258 | /** |
||
259 | * Assert that command line lenght is valid. |
||
260 | * |
||
261 | * In some situations process command line can became too long when combining different test |
||
262 | * cases in single --filter arguments so it's better to show error regarding that to user |
||
263 | * and propose him to decrease max batch size. |
||
264 | * |
||
265 | * @param string $cmd Command line |
||
266 | * |
||
267 | * @throws \RuntimeException on too long command line |
||
268 | */ |
||
269 | 2 | protected function assertValidCommandLineLength($cmd) |
|
283 | |||
284 | /** |
||
285 | * A template method that can be overridden to add necessary options for a test. |
||
286 | * |
||
287 | * @param array $options the options that are passed to the run method |
||
288 | * |
||
289 | * @return array $options the prepared options |
||
290 | */ |
||
291 | 3 | protected function prepareOptions($options) |
|
295 | |||
296 | /** |
||
297 | * Returns the command string that will be executed |
||
298 | * by proc_open. |
||
299 | * |
||
300 | * @param $binary |
||
301 | * @param array $options |
||
302 | * |
||
303 | * @return mixed |
||
304 | */ |
||
305 | 6 | protected function getCommandString($binary, $options = []) |
|
323 | |||
324 | /** |
||
325 | * Checks environment variables for the presence of a TEST_TOKEN |
||
326 | * variable and sets $this->token based on its value. |
||
327 | * |
||
328 | * @param $environmentVariables |
||
329 | */ |
||
330 | 3 | protected function handleEnvironmentVariables($environmentVariables) |
|
336 | |||
337 | /** |
||
338 | * Checks if the coverage-php option is set and redirects it to a unique temp file. |
||
339 | * This will ensure, that multiple tests write to separate coverage-files. |
||
340 | * |
||
341 | * @param array $options |
||
342 | * |
||
343 | * @return array $options |
||
344 | */ |
||
345 | 3 | protected function redirectCoverageOption($options) |
|
355 | } |
||
356 |