|
27 | 27 | use PHPUnit\Framework\TestCase; |
28 | 28 | use Psr\Container\ContainerInterface; |
29 | 29 | use Psr\EventDispatcher\EventDispatcherInterface; |
| 30 | +use Symfony\Component\Console\Application as ConsoleApplication; |
30 | 31 | use Symfony\Component\Console\Input\InputInterface; |
31 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
| 33 | +use Throwable; |
32 | 34 |
|
33 | 35 | /** |
34 | 36 | * @internal |
@@ -57,27 +59,40 @@ public function testExitCodeWhenThrowException() |
57 | 59 | ApplicationContext::setContainer($container = Mockery::mock(ContainerInterface::class)); |
58 | 60 | $container->shouldReceive('has')->with(EventDispatcherInterface::class)->andReturnFalse(); |
59 | 61 |
|
| 62 | + $output = Mockery::mock(OutputInterface::class); |
| 63 | + $application = Mockery::mock(ConsoleApplication::class); |
| 64 | + $application->shouldReceive('renderThrowable') |
| 65 | + ->with(Mockery::type(Throwable::class), $output) |
| 66 | + ->times(1); |
| 67 | + $application->shouldReceive('getHelperSet'); |
| 68 | + |
60 | 69 | /** @var FooExceptionCommand $command */ |
61 | 70 | $command = new ClassInvoker(new FooExceptionCommand('foo')); |
| 71 | + $command->setApplication($application); |
| 72 | + $command->setOutput($output); |
62 | 73 | $input = Mockery::mock(InputInterface::class); |
63 | 74 | $input->shouldReceive('getOption')->andReturnFalse(); |
64 | | - $output = Mockery::mock(OutputInterface::class); |
65 | | - $output->shouldReceive('writeln')->withAnyArgs()->andReturnNull(); |
66 | 75 |
|
67 | 76 | $exitCode = $command->execute($input, $output); |
68 | 77 | $this->assertSame(1, $exitCode); |
69 | 78 |
|
70 | 79 | /** @var FooExitCommand $command */ |
71 | 80 | $command = new ClassInvoker(new FooExitCommand()); |
| 81 | + $command->setApplication($application); |
| 82 | + $command->setOutput($output); |
72 | 83 | $exitCode = $command->execute($input, $output); |
73 | 84 | $this->assertSame(11, $exitCode); |
74 | 85 |
|
75 | 86 | /** @var FooCommand $command */ |
76 | 87 | $command = new ClassInvoker(new FooCommand()); |
| 88 | + $command->setApplication($application); |
| 89 | + $command->setOutput($output); |
77 | 90 | $exitCode = $command->execute($input, $output); |
78 | 91 | $this->assertSame(0, $exitCode); |
79 | 92 |
|
80 | 93 | $command = new FooTraitCommand(); |
| 94 | + $command->setApplication($application); |
| 95 | + $command->setOutput($output); |
81 | 96 | $this->assertArrayHasKey(Foo::class, (fn () => $this->setUpTraits($input, $output))->call($command)); |
82 | 97 | $this->assertSame('foo', (fn () => $this->propertyFoo)->call($command)); |
83 | 98 | } |
|
0 commit comments