diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index bcdec7eee31b..2be849db17b1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -65,6 +65,8 @@ public function doRun(InputInterface $input, OutputInterface $output) $this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher')); + $this->registerCommands(); + if ($this->registrationErrors) { $this->renderRegistrationErrors($input, $output); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php index d06e98be7770..c977bb13a131 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php @@ -165,6 +165,33 @@ public function testRunOnlyWarnsOnUnregistrableCommand() $this->assertContains('fine', $output); } + public function testRegistrationErrorsAreDisplayedOnCommandNotFound() + { + $container = new ContainerBuilder(); + $container->register('event_dispatcher', EventDispatcher::class); + + $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); + $kernel + ->method('getBundles') + ->willReturn(array($this->createBundleMock( + array((new Command(null))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); })) + ))); + $kernel + ->method('getContainer') + ->willReturn($container); + + $application = new Application($kernel); + $application->setAutoExit(false); + + $tester = new ApplicationTester($application); + $tester->run(array('command' => 'fine')); + $output = $tester->getDisplay(); + + $this->assertSame(1, $tester->getStatusCode()); + $this->assertContains('Some commands could not be registered:', $output); + $this->assertContains('Command "fine" is not defined.', $output); + } + private function getKernel(array $bundles, $useDispatcher = false) { $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();