|
23 | 23 | use Psr\Container\ContainerInterface; |
24 | 24 | use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface; |
25 | 25 | use Symfony\Component\Console\Application; |
| 26 | +use Symfony\Component\Console\Command\Command; |
26 | 27 | use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
27 | 28 |
|
28 | 29 | /** |
@@ -72,4 +73,34 @@ public function testInvokeApplicationWithoutSymfonyEventDispatcher() |
72 | 73 | $application = new ClassInvoker((new ApplicationFactory())($container)); |
73 | 74 | $this->assertNull($application->dispatcher); |
74 | 75 | } |
| 76 | + |
| 77 | + public function testApplicationFactoryUsesAddCommandWhenAvailable() |
| 78 | + { |
| 79 | + $container = Mockery::mock(ContainerInterface::class); |
| 80 | + $container->shouldReceive('has')->andReturnFalse(); |
| 81 | + $container->shouldReceive('get')->with(ConfigInterface::class)->andReturn( |
| 82 | + new Config([ |
| 83 | + 'commands' => [TestCommand::class], |
| 84 | + ]) |
| 85 | + ); |
| 86 | + $testCommand = new TestCommand(); |
| 87 | + $container->shouldReceive('get')->with(TestCommand::class)->andReturn($testCommand); |
| 88 | + |
| 89 | + /** @var Application $application */ |
| 90 | + $application = (new ApplicationFactory())($container); |
| 91 | + $this->assertInstanceOf(Application::class, $application); |
| 92 | + |
| 93 | + // Verify that the command was added to the application |
| 94 | + // The Application should have the command whether using add() or addCommand() |
| 95 | + $this->assertTrue($application->has('test:command')); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +// Mock command class for testing |
| 100 | +class TestCommand extends Command |
| 101 | +{ |
| 102 | + protected function configure(): void |
| 103 | + { |
| 104 | + $this->setName('test:command'); |
| 105 | + } |
75 | 106 | } |
0 commit comments