[FrameworkBundle] [Console] add a warning when command is not found

This commit is contained in:
Amrouche Hamza 2018-02-23 19:15:37 +01:00
parent 4271fecbea
commit efd8f7fa3a
No known key found for this signature in database
GPG Key ID: 6968F2785ED4F012
2 changed files with 29 additions and 0 deletions

View File

@ -65,6 +65,8 @@ class Application extends BaseApplication
$this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));
$this->registerCommands();
if ($this->registrationErrors) {
$this->renderRegistrationErrors($input, $output);
}

View File

@ -165,6 +165,33 @@ class ApplicationTest extends TestCase
$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();