|
14 | 14 | namespace Webmozarts\Console\Parallelization\Process; |
15 | 15 |
|
16 | 16 | use PHPUnit\Framework\TestCase; |
| 17 | +use Prophecy\Argument; |
| 18 | +use Prophecy\PhpUnit\ProphecyTrait; |
17 | 19 | use Symfony\Component\Console\Output\BufferedOutput; |
18 | 20 | use Symfony\Component\Console\Output\OutputInterface; |
| 21 | +use Symfony\Component\Process\Process; |
19 | 22 | use Webmozarts\Console\Parallelization\FakeCallable; |
20 | 23 | use Webmozarts\Console\Parallelization\Logger\DummyLogger; |
21 | 24 | use Webmozarts\Console\Parallelization\Logger\FakeLogger; |
|
31 | 34 | */ |
32 | 35 | final class SymfonyProcessLauncherTest extends TestCase |
33 | 36 | { |
| 37 | + use ProphecyTrait; |
| 38 | + |
34 | 39 | public function test_it_does_nothing_if_there_is_no_items(): void |
35 | 40 | { |
36 | 41 | $launcher = new SymfonyProcessLauncher( |
@@ -268,6 +273,43 @@ public static function inputProvider(): iterable |
268 | 273 | ]; |
269 | 274 | } |
270 | 275 |
|
| 276 | + public function test_it_caps_the_exit_code_to_255(): void |
| 277 | + { |
| 278 | + $output = new BufferedOutput(); |
| 279 | + |
| 280 | + $processProphecy = $this->prophesize(Process::class); |
| 281 | + $processProphecy->getPid()->willReturn(10); |
| 282 | + $processProphecy->getCommandLine()->willReturn(''); |
| 283 | + $processProphecy->isRunning()->willReturn(false); |
| 284 | + $processProphecy->getExitCode()->willReturn(500); |
| 285 | + |
| 286 | + $processFactoryProphecy = $this->prophesize(SymfonyProcessFactory::class); |
| 287 | + $processFactoryProphecy |
| 288 | + ->startProcess(Argument::cetera()) |
| 289 | + ->willReturn($processProphecy->reveal()); |
| 290 | + |
| 291 | + $processOutput = self::createProcessOutput($output); |
| 292 | + $numberOfTicksRecorded = 0; |
| 293 | + |
| 294 | + $launcher = new SymfonyProcessLauncher( |
| 295 | + [], |
| 296 | + '', |
| 297 | + null, |
| 298 | + 1, |
| 299 | + 1, |
| 300 | + new DummyLogger(), |
| 301 | + $processOutput, |
| 302 | + static function () use (&$numberOfTicksRecorded): void { |
| 303 | + ++$numberOfTicksRecorded; |
| 304 | + }, |
| 305 | + $processFactoryProphecy->reveal(), |
| 306 | + ); |
| 307 | + |
| 308 | + $exitCode = $launcher->run(['item0']); |
| 309 | + |
| 310 | + self::assertSame(255, $exitCode); |
| 311 | + } |
| 312 | + |
271 | 313 | /** |
272 | 314 | * @return ProcessOutput |
273 | 315 | */ |
|
0 commit comments