1 | <?php |
||||||
2 | /** |
||||||
3 | * This file is part of graze/parallel-process. |
||||||
4 | * |
||||||
5 | * Copyright © 2018 Nature Delivered Ltd. <https://www.graze.com> |
||||||
6 | * |
||||||
7 | * For the full copyright and license information, please view the LICENSE |
||||||
8 | * file that was distributed with this source code. |
||||||
9 | * |
||||||
10 | * @license https://github.com/graze/parallel-process/blob/master/LICENSE.md |
||||||
11 | * @link https://github.com/graze/parallel-process |
||||||
12 | */ |
||||||
13 | |||||||
14 | namespace Graze\ParallelProcess\Test\Unit\Display; |
||||||
15 | |||||||
16 | use Graze\ParallelProcess\CallbackRun; |
||||||
17 | use Graze\ParallelProcess\Event\RunEvent; |
||||||
18 | use Graze\ParallelProcess\Display\Lines; |
||||||
19 | use Graze\ParallelProcess\PriorityPool; |
||||||
20 | use Graze\ParallelProcess\ProcessRun; |
||||||
21 | use Graze\ParallelProcess\RunInterface; |
||||||
22 | use Graze\ParallelProcess\Test\BufferDiffOutput; |
||||||
23 | use Graze\ParallelProcess\Test\TestCase; |
||||||
24 | use Mockery; |
||||||
25 | use RuntimeException; |
||||||
26 | use Symfony\Component\Console\Output\OutputInterface; |
||||||
27 | use Symfony\Component\Process\Process; |
||||||
28 | |||||||
29 | class LinesTest extends TestCase |
||||||
30 | { |
||||||
31 | /** @var BufferDiffOutput */ |
||||||
32 | private $bufferOutput; |
||||||
33 | /** @var mixed */ |
||||||
34 | private $pool; |
||||||
35 | /** @var Lines */ |
||||||
36 | private $lines; |
||||||
37 | |||||||
38 | public function setUp() |
||||||
39 | { |
||||||
40 | mb_internal_encoding("UTF-8"); |
||||||
41 | $this->bufferOutput = new BufferDiffOutput(); |
||||||
42 | $this->pool = new PriorityPool(); |
||||||
43 | $this->lines = new Lines($this->bufferOutput, $this->pool); |
||||||
44 | } |
||||||
45 | |||||||
46 | public function testShowDuration() |
||||||
47 | { |
||||||
48 | $output = Mockery::mock(OutputInterface::class); |
||||||
49 | $lines = new Lines($output); |
||||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
50 | |||||||
51 | $this->assertTrue($lines->isShowDuration()); |
||||||
52 | |||||||
53 | $this->assertSame($lines, $lines->setShowDuration(false)); |
||||||
54 | |||||||
55 | $this->assertFalse($lines->isShowDuration()); |
||||||
56 | } |
||||||
57 | |||||||
58 | public function testShowType() |
||||||
59 | { |
||||||
60 | $output = Mockery::mock(OutputInterface::class); |
||||||
61 | $lines = new Lines($output); |
||||||
0 ignored issues
–
show
$output of type Mockery\MockInterface is incompatible with the type Symfony\Component\Console\Output\OutputInterface expected by parameter $output of Graze\ParallelProcess\Display\Lines::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
62 | |||||||
63 | $this->assertTrue($lines->isShowType()); |
||||||
64 | |||||||
65 | $this->assertSame($lines, $lines->setShowType(false)); |
||||||
66 | |||||||
67 | $this->assertFalse($lines->isShowType()); |
||||||
68 | } |
||||||
69 | |||||||
70 | public function testShowProcessColours() |
||||||
71 | { |
||||||
72 | $output = Mockery::mock(OutputInterface::class); |
||||||
73 | $lines = new Lines($output); |
||||||
0 ignored issues
–
show
$output of type Mockery\MockInterface is incompatible with the type Symfony\Component\Console\Output\OutputInterface expected by parameter $output of Graze\ParallelProcess\Display\Lines::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
74 | |||||||
75 | $this->assertTrue($lines->isColourProcesses()); |
||||||
76 | |||||||
77 | $this->assertSame($lines, $lines->setColourProcesses(false)); |
||||||
78 | |||||||
79 | $this->assertFalse($lines->isColourProcesses()); |
||||||
80 | } |
||||||
81 | |||||||
82 | public function testSingleProcessOutput() |
||||||
83 | { |
||||||
84 | $process = Mockery::mock(Process::class); |
||||||
85 | $process->shouldReceive('stop'); |
||||||
86 | $process->shouldReceive('start')->with( |
||||||
87 | Mockery::on( |
||||||
88 | function ($closure) { |
||||||
89 | call_user_func($closure, Process::OUT, 'first line'); |
||||||
90 | call_user_func($closure, Process::OUT, 'second line'); |
||||||
91 | call_user_func($closure, Process::OUT, 'third line'); |
||||||
92 | call_user_func($closure, Process::ERR, 'error line'); |
||||||
93 | return true; |
||||||
94 | } |
||||||
95 | ) |
||||||
96 | )->once(); |
||||||
97 | $process->shouldReceive('isStarted')->andReturn(false, false, false, true); // add, start, start, check |
||||||
98 | $process->shouldReceive('isRunning')->andReturn( |
||||||
99 | false, // add |
||||||
100 | false, // add2 |
||||||
101 | true, // check |
||||||
102 | true, // ... |
||||||
103 | true, |
||||||
104 | true, |
||||||
105 | true, |
||||||
106 | true, |
||||||
107 | true, |
||||||
108 | true, |
||||||
109 | true, |
||||||
110 | true, |
||||||
111 | true, |
||||||
112 | false // complete |
||||||
113 | ); |
||||||
114 | $process->shouldReceive('isSuccessful')->atLeast()->once()->andReturn(true); |
||||||
115 | |||||||
116 | $this->pool->add($process, ['key' => 'value']); |
||||||
117 | |||||||
118 | $this->lines->run(0); |
||||||
119 | |||||||
120 | $expected = [ |
||||||
121 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <fg=blue>→ Started</>%'], |
||||||
122 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) \(out\) first line%'], |
||||||
123 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) \(out\) second line%'], |
||||||
124 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) \(out\) third line%'], |
||||||
125 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) \(err\) error line%'], |
||||||
126 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <info>✓ Succeeded</info>%'], |
||||||
127 | ]; |
||||||
128 | |||||||
129 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
130 | } |
||||||
131 | |||||||
132 | public function testProcessColoursDisabled() |
||||||
133 | { |
||||||
134 | $process = Mockery::mock(Process::class); |
||||||
135 | $process->shouldReceive('stop'); |
||||||
136 | $process->shouldReceive('start')->with( |
||||||
137 | Mockery::on( |
||||||
138 | function ($closure) { |
||||||
139 | call_user_func($closure, Process::OUT, 'first line'); |
||||||
140 | call_user_func($closure, Process::OUT, 'second line'); |
||||||
141 | call_user_func($closure, Process::OUT, 'third line'); |
||||||
142 | call_user_func($closure, Process::ERR, 'error line'); |
||||||
143 | return true; |
||||||
144 | } |
||||||
145 | ) |
||||||
146 | )->once(); |
||||||
147 | $process->shouldReceive('isStarted')->andReturn(false, false, false, true); // add, add2, start, check |
||||||
148 | $process->shouldReceive('isRunning')->andReturn( |
||||||
149 | false, // add |
||||||
150 | false, // add2 |
||||||
151 | true, // check |
||||||
152 | false // complete |
||||||
153 | ); |
||||||
154 | $process->shouldReceive('isSuccessful')->atLeast()->once()->andReturn(true); |
||||||
155 | |||||||
156 | $this->lines->setColourProcesses(false); |
||||||
157 | $this->pool->add($process, ['key' => 'value']); |
||||||
158 | |||||||
159 | $this->lines->run(0); |
||||||
160 | |||||||
161 | $expected = [ |
||||||
162 | ['%<info>key</info>: value \(<comment>[ 0-9\.s]+</comment>\) <fg=blue>→ Started</>%'], |
||||||
163 | ['%<info>key</info>: value \(<comment>[ 0-9\.s]+</comment>\) \(out\) first line%'], |
||||||
164 | ['%<info>key</info>: value \(<comment>[ 0-9\.s]+</comment>\) \(out\) second line%'], |
||||||
165 | ['%<info>key</info>: value \(<comment>[ 0-9\.s]+</comment>\) \(out\) third line%'], |
||||||
166 | ['%<info>key</info>: value \(<comment>[ 0-9\.s]+</comment>\) \(err\) error line%'], |
||||||
167 | ['%<info>key</info>: value \(<comment>[ 0-9\.s]+</comment>\) <info>✓ Succeeded</info>%'], |
||||||
168 | ]; |
||||||
169 | |||||||
170 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
171 | } |
||||||
172 | |||||||
173 | public function testValueOnlyData() |
||||||
174 | { |
||||||
175 | $process = Mockery::mock(Process::class); |
||||||
176 | $process->shouldReceive('stop'); |
||||||
177 | $process->shouldReceive('start')->with( |
||||||
178 | Mockery::on( |
||||||
179 | function ($closure) { |
||||||
180 | call_user_func($closure, Process::OUT, 'first line'); |
||||||
181 | return true; |
||||||
182 | } |
||||||
183 | ) |
||||||
184 | )->once(); |
||||||
185 | $process->shouldReceive('isStarted')->andReturn(false, false, false, true); // add, add2, start, check |
||||||
186 | $process->shouldReceive('isRunning')->andReturn( |
||||||
187 | false, // add |
||||||
188 | false, // add2 |
||||||
189 | true, // check |
||||||
190 | true, // ... |
||||||
191 | true, |
||||||
192 | true, |
||||||
193 | false // complete |
||||||
194 | ); |
||||||
195 | $process->shouldReceive('isSuccessful')->atLeast()->once()->andReturn(true); |
||||||
196 | |||||||
197 | $this->pool->add($process, ['value']); |
||||||
198 | |||||||
199 | $this->lines->run(0); |
||||||
200 | |||||||
201 | $expected = [ |
||||||
202 | ['%<options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <fg=blue>→ Started</>%'], |
||||||
203 | ['%<options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) \(out\) first line%'], |
||||||
204 | ['%<options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <info>✓ Succeeded</info>%'], |
||||||
205 | ]; |
||||||
206 | |||||||
207 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
208 | } |
||||||
209 | |||||||
210 | public function testFailureReturnsErrors() |
||||||
211 | { |
||||||
212 | $process = Mockery::mock(Process::class); |
||||||
213 | $process->shouldReceive('stop'); |
||||||
214 | $process->shouldReceive('start')->with( |
||||||
215 | Mockery::on( |
||||||
216 | function ($closure) { |
||||||
217 | call_user_func($closure, Process::OUT, 'first line'); |
||||||
218 | return true; |
||||||
219 | } |
||||||
220 | ) |
||||||
221 | )->once(); |
||||||
222 | $process->shouldReceive('isStarted')->andReturn(false, false, false, true); // add, add2, start, check |
||||||
223 | $process->shouldReceive('isRunning')->andReturn( |
||||||
224 | false, // add |
||||||
225 | false, // add2 |
||||||
226 | true, // check |
||||||
227 | true, // ... |
||||||
228 | true, |
||||||
229 | true, |
||||||
230 | false // complete |
||||||
231 | ); |
||||||
232 | $process->shouldReceive('isSuccessful')->atLeast()->once()->andReturn(false); |
||||||
233 | $process->shouldReceive('getExitCode')->atLeast()->once()->andReturn(3); |
||||||
234 | $process->shouldReceive('getExitCodeText')->atLeast()->once()->andReturn('some error'); |
||||||
235 | $process->shouldReceive('getCommandLine')->andReturn('test'); |
||||||
236 | $process->shouldReceive('getExitCode')->andReturn(3); |
||||||
237 | $process->shouldReceive('getExitCodeText')->andReturn('some error'); |
||||||
238 | $process->shouldReceive('getWorkingDirectory')->andReturn('/tmp'); |
||||||
239 | $process->shouldReceive('isOutputDisabled')->andReturn(false); |
||||||
240 | $process->shouldReceive('getErrorOutput')->andReturn('some error text'); |
||||||
241 | $process->shouldReceive('getOutput')->andReturn('first line'); |
||||||
242 | |||||||
243 | $this->pool->add($process, ['key' => 'value']); |
||||||
244 | |||||||
245 | $this->lines->run(0); |
||||||
246 | |||||||
247 | $expected = [ |
||||||
248 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <fg=blue>→ Started</>%'], |
||||||
249 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) \(out\) first line%'], |
||||||
250 | [ |
||||||
251 | <<<TEXT |
||||||
252 | %<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <error>x Failed</error> \(0\) The command "test" failed. |
||||||
253 | |||||||
254 | Exit Code: 3\(some error\) |
||||||
255 | |||||||
256 | Working directory: /tmp |
||||||
257 | |||||||
258 | Output: |
||||||
259 | ================ |
||||||
260 | first line |
||||||
261 | |||||||
262 | Error Output: |
||||||
263 | ================ |
||||||
264 | some error text% |
||||||
265 | TEXT |
||||||
266 | , |
||||||
267 | ], |
||||||
268 | [ |
||||||
269 | <<<TEXT |
||||||
270 | %The command "test" failed. |
||||||
271 | |||||||
272 | Exit Code: 3\(some error\) |
||||||
273 | |||||||
274 | Working directory: /tmp |
||||||
275 | |||||||
276 | Output: |
||||||
277 | ================ |
||||||
278 | first line |
||||||
279 | |||||||
280 | Error Output: |
||||||
281 | ================ |
||||||
282 | some error text% |
||||||
283 | TEXT |
||||||
284 | , |
||||||
285 | ], |
||||||
286 | ]; |
||||||
287 | |||||||
288 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
289 | } |
||||||
290 | |||||||
291 | public function testShowTypeDoesNotOutputTheStdOrErrInformation() |
||||||
292 | { |
||||||
293 | $process = Mockery::mock(Process::class); |
||||||
294 | $process->shouldReceive('stop'); |
||||||
295 | $process->shouldReceive('start')->with( |
||||||
296 | Mockery::on( |
||||||
297 | function ($closure) { |
||||||
298 | call_user_func($closure, Process::OUT, 'first line'); |
||||||
299 | return true; |
||||||
300 | } |
||||||
301 | ) |
||||||
302 | )->once(); |
||||||
303 | $process->shouldReceive('isStarted')->andReturn(false, false, false, true); // add, start, check |
||||||
304 | $process->shouldReceive('isRunning')->andReturn( |
||||||
305 | false, // add |
||||||
306 | false, // add2 |
||||||
307 | true, // check |
||||||
308 | true, // ... |
||||||
309 | true, |
||||||
310 | true, |
||||||
311 | false // complete |
||||||
312 | ); |
||||||
313 | $process->shouldReceive('isSuccessful')->atLeast()->once()->andReturn(true); |
||||||
314 | $process->shouldReceive('getOutput')->andReturn('first line'); |
||||||
315 | |||||||
316 | $this->lines->setShowType(false); |
||||||
317 | $this->pool->add($process, ['key' => 'value']); |
||||||
318 | |||||||
319 | $this->lines->run(0); |
||||||
320 | |||||||
321 | $expected = [ |
||||||
322 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <fg=blue>→ Started</>%'], |
||||||
323 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) first line%'], |
||||||
324 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <info>✓ Succeeded</info>%'], |
||||||
325 | ]; |
||||||
326 | |||||||
327 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
328 | } |
||||||
329 | |||||||
330 | public function testShowDurationToFalseDoesNotShowTheDuration() |
||||||
331 | { |
||||||
332 | $process = Mockery::mock(Process::class); |
||||||
333 | $process->shouldReceive('stop'); |
||||||
334 | $process->shouldReceive('start')->with( |
||||||
335 | Mockery::on( |
||||||
336 | function ($closure) { |
||||||
337 | call_user_func($closure, Process::OUT, 'first line'); |
||||||
338 | return true; |
||||||
339 | } |
||||||
340 | ) |
||||||
341 | )->once(); |
||||||
342 | $process->shouldReceive('isStarted')->andReturn(false, false, false, true); // add, add2, start, check |
||||||
343 | $process->shouldReceive('isRunning')->andReturn( |
||||||
344 | false, // add |
||||||
345 | false, // add2 |
||||||
346 | true, // check |
||||||
347 | true, // ... |
||||||
348 | true, |
||||||
349 | true, |
||||||
350 | false // complete |
||||||
351 | ); |
||||||
352 | $process->shouldReceive('isSuccessful')->atLeast()->once()->andReturn(true); |
||||||
353 | $process->shouldReceive('getOutput')->andReturn('first line'); |
||||||
354 | |||||||
355 | $this->lines->setShowDuration(false); |
||||||
356 | $this->pool->add($process, ['key' => 'value']); |
||||||
357 | |||||||
358 | $this->lines->run(0); |
||||||
359 | |||||||
360 | $expected = [ |
||||||
361 | ['%<info>key</info>: <options=bold;fg=\w+>value</> <fg=blue>→ Started</>%'], |
||||||
362 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(out\) first line%'], |
||||||
363 | ['%<info>key</info>: <options=bold;fg=\w+>value</> <info>✓ Succeeded</info>%'], |
||||||
364 | ]; |
||||||
365 | |||||||
366 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
367 | } |
||||||
368 | |||||||
369 | public function testShowProgressShowsTheProgress() |
||||||
370 | { |
||||||
371 | $process = Mockery::mock(Process::class); |
||||||
372 | $process->shouldReceive('stop'); |
||||||
373 | $process->shouldReceive('start')->with( |
||||||
374 | Mockery::on( |
||||||
375 | function ($closure) { |
||||||
376 | call_user_func($closure, Process::OUT, 'first line'); |
||||||
377 | return true; |
||||||
378 | } |
||||||
379 | ) |
||||||
380 | )->once(); |
||||||
381 | $process->shouldReceive('isStarted')->andReturn(false, false, false, true); // add, add2, start, check |
||||||
382 | $process->shouldReceive('isRunning')->andReturn( |
||||||
383 | false, // add |
||||||
384 | false, // add2 |
||||||
385 | true, // check |
||||||
386 | true, // ... |
||||||
387 | true, |
||||||
388 | true, |
||||||
389 | false // complete |
||||||
390 | ); |
||||||
391 | $process->shouldReceive('isSuccessful')->atLeast()->once()->andReturn(true); |
||||||
392 | $process->shouldReceive('getOutput')->andReturn('first line'); |
||||||
393 | |||||||
394 | $run = Mockery::mock(ProcessRun::class, [$process, ['key' => 'value']])->makePartial(); |
||||||
395 | $run->allows() |
||||||
396 | ->getProgress() |
||||||
397 | ->andReturns([0, 100, 0], [50, 100, 0.5], [100, 100, 1]); |
||||||
398 | |||||||
399 | $this->lines->setShowProgress(true); |
||||||
400 | $this->pool->add($run); |
||||||
401 | |||||||
402 | $this->lines->run(0); |
||||||
403 | |||||||
404 | $expected = [ |
||||||
405 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) |<comment> </comment>| <fg=black;bg=cyan> 0\%</> <fg=blue>→ Started</>%'], |
||||||
406 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) |<comment>█ </comment>| <fg=black;bg=cyan> 50\%</> \(out\) first line%'], |
||||||
407 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) |<comment>██</comment>| <fg=black;bg=cyan>100\%</> <info>✓ Succeeded</info>%'], |
||||||
408 | ]; |
||||||
409 | |||||||
410 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
411 | } |
||||||
412 | |||||||
413 | public function testNonShowProgressShowsTheProgress() |
||||||
414 | { |
||||||
415 | $process = Mockery::mock(Process::class); |
||||||
416 | $process->shouldReceive('stop'); |
||||||
417 | $process->shouldReceive('start')->with( |
||||||
418 | Mockery::on( |
||||||
419 | function ($closure) { |
||||||
420 | call_user_func($closure, Process::OUT, 'first line'); |
||||||
421 | return true; |
||||||
422 | } |
||||||
423 | ) |
||||||
424 | )->once(); |
||||||
425 | $process->shouldReceive('isStarted')->andReturn(false, false, false, true); // add, add2, start, check |
||||||
426 | $process->shouldReceive('isRunning')->andReturn( |
||||||
427 | false, // add |
||||||
428 | false, // add2 |
||||||
429 | true, // check |
||||||
430 | true, // ... |
||||||
431 | true, |
||||||
432 | true, |
||||||
433 | false // complete |
||||||
434 | ); |
||||||
435 | $process->shouldReceive('isSuccessful')->atLeast()->once()->andReturn(true); |
||||||
436 | $process->shouldReceive('getOutput')->andReturn('first line'); |
||||||
437 | |||||||
438 | $run = Mockery::mock(ProcessRun::class, [$process, ['key' => 'value']])->makePartial(); |
||||||
439 | $run->allows() |
||||||
440 | ->getProgress() |
||||||
441 | ->andReturns([0, 100, 0], [50, 100, 0.5], [100, 100, 1]); |
||||||
442 | |||||||
443 | $this->lines->setShowProgress(false); |
||||||
444 | $this->assertFalse($this->lines->isShowProgress()); |
||||||
445 | $this->pool->add($run); |
||||||
446 | |||||||
447 | $this->lines->run(0); |
||||||
448 | |||||||
449 | $expected = [ |
||||||
450 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <fg=blue>→ Started</>%'], |
||||||
451 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) \(out\) first line%'], |
||||||
452 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <info>✓ Succeeded</info>%'], |
||||||
453 | ]; |
||||||
454 | |||||||
455 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
456 | } |
||||||
457 | |||||||
458 | public function testNonProcessRunFailure() |
||||||
459 | { |
||||||
460 | $exception = new RuntimeException('some error', 5); |
||||||
461 | $run = new CallbackRun( |
||||||
462 | function () use ($exception) { |
||||||
463 | throw $exception; |
||||||
464 | }, |
||||||
465 | ['key' => 'value'] |
||||||
466 | ); |
||||||
467 | |||||||
468 | $this->pool->add($run); |
||||||
469 | |||||||
470 | $this->lines->run(0); |
||||||
471 | |||||||
472 | $expected = [ |
||||||
473 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <fg=blue>→ Started</>%'], |
||||||
474 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <error>x Failed</error> \(5\) some error%'], |
||||||
475 | ['%some error%'], |
||||||
476 | ]; |
||||||
477 | |||||||
478 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
479 | } |
||||||
480 | |||||||
481 | public function testRunFailureWithNoException() |
||||||
482 | { |
||||||
483 | $run = Mockery::mock(RunInterface::class); |
||||||
484 | $run->shouldReceive('stop'); |
||||||
485 | $run->shouldReceive('start')->once(); |
||||||
486 | $run->shouldReceive('hasStarted')->andReturn(false, false, false, true); |
||||||
487 | $run->shouldReceive('isRunning')->andReturn( |
||||||
488 | false, // add |
||||||
489 | false, // add2 |
||||||
490 | true, // check |
||||||
491 | true, // ... |
||||||
492 | true, |
||||||
493 | true, |
||||||
494 | false // complete |
||||||
495 | ); |
||||||
496 | $run->shouldReceive('poll')->andReturn( |
||||||
497 | true, // check |
||||||
498 | true, // ... |
||||||
499 | true, |
||||||
500 | true, |
||||||
501 | false // complete |
||||||
502 | ); |
||||||
503 | $run->shouldReceive('isSuccessful')->atLeast()->andReturn(false); |
||||||
504 | $run->shouldReceive('getPriority')->atLeast()->once()->andReturn(1.0); |
||||||
505 | |||||||
506 | $startedEvent = $completedEvent = $updatedEvent = $successfulEvent = null; |
||||||
507 | $failedEvents = []; |
||||||
508 | |||||||
509 | $run->allows()->addListener( |
||||||
0 ignored issues
–
show
The method
addListener() does not exist on Mockery\Expectation .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
The method
addListener() does not exist on Mockery\ExpectationInterface . It seems like you code against a sub-type of Mockery\ExpectationInterface such as Mockery\CompositeExpectation .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
510 | RunEvent::STARTED, |
||||||
511 | Mockery::on(function (callable $callback) use (&$startedEvent) { |
||||||
512 | $startedEvent = $callback; |
||||||
513 | return true; |
||||||
514 | }) |
||||||
515 | ); |
||||||
516 | $run->allows()->addListener( |
||||||
517 | RunEvent::COMPLETED, |
||||||
518 | Mockery::on(function (callable $callback) use (&$completedEvent) { |
||||||
519 | $completedEvent = $callback; |
||||||
520 | return true; |
||||||
521 | }) |
||||||
522 | ); |
||||||
523 | $run->allows()->addListener( |
||||||
524 | RunEvent::FAILED, |
||||||
525 | Mockery::on(function (callable $callback) use (&$failedEvents) { |
||||||
526 | $failedEvents[] = $callback; |
||||||
527 | return true; |
||||||
528 | }) |
||||||
529 | ); |
||||||
530 | $run->allows()->addListener( |
||||||
531 | RunEvent::UPDATED, |
||||||
532 | Mockery::on(function (callable $callback) use (&$updatedEvent) { |
||||||
533 | $updatedEvent = $callback; |
||||||
534 | return true; |
||||||
535 | }) |
||||||
536 | ); |
||||||
537 | $run->allows()->addListener( |
||||||
538 | RunEvent::SUCCESSFUL, |
||||||
539 | Mockery::on(function (callable $callback) use (&$successfulEvent) { |
||||||
540 | $successfulEvent = $callback; |
||||||
541 | return true; |
||||||
542 | }) |
||||||
543 | ); |
||||||
544 | $run->allows(['getTags' => ['key' => 'value'], 'getProgress' => null]); |
||||||
545 | |||||||
546 | $this->pool->add($run); |
||||||
547 | |||||||
548 | $this->lines->run(0); |
||||||
549 | |||||||
550 | $run->allows()->getDuration()->andReturns(0, 0.1); |
||||||
0 ignored issues
–
show
The method
getDuration() does not exist on Mockery\ExpectationInterface . It seems like you code against a sub-type of Mockery\ExpectationInterface such as Mockery\CompositeExpectation .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The method
getDuration() does not exist on Mockery\Expectation .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
551 | |||||||
552 | $run->allows()->getExceptions()->andReturns([]); |
||||||
0 ignored issues
–
show
The method
getExceptions() does not exist on Mockery\ExpectationInterface . It seems like you code against a sub-type of Mockery\ExpectationInterface such as Mockery\CompositeExpectation .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The method
getExceptions() does not exist on Mockery\Expectation . Did you maybe mean getExceptionMessage() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
553 | |||||||
554 | call_user_func($startedEvent, new RunEvent($run)); |
||||||
0 ignored issues
–
show
$run of type Mockery\MockInterface is incompatible with the type Graze\ParallelProcess\RunInterface expected by parameter $run of Graze\ParallelProcess\Ev...RunEvent::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
555 | foreach ($failedEvents as $failedEvent) { |
||||||
556 | call_user_func($failedEvent, new RunEvent($run)); |
||||||
557 | } |
||||||
558 | call_user_func($completedEvent, new RunEvent($run)); |
||||||
559 | |||||||
560 | $expected = [ |
||||||
561 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <fg=blue>→ Started</>%'], |
||||||
562 | ['%<info>key</info>: <options=bold;fg=\w+>value</> \(<comment>[ 0-9\.s]+</comment>\) <error>x Failed</error>%'], |
||||||
563 | ]; |
||||||
564 | |||||||
565 | $this->compareOutputs($expected, $this->bufferOutput->getWritten()); |
||||||
566 | } |
||||||
567 | } |
||||||
568 |