8000 [FrameworkBundle] show the unregistered command warning at the end of… · symfony/symfony@9e0dfc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e0dfc3

Browse files
author
Amrouche Hamza
committed
[FrameworkBundle] show the unregistered command warning at the end of the list command
1 parent 1f7b9f0 commit 9e0dfc3

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Console;
1313

14+
use Symfony\Component\Console\Command\ListCommand;
1415
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1516
use Symfony\Component\Console\Style\SymfonyStyle;
1617
use Symfony\Component\Debug\Exception\FatalThrowableError;
@@ -79,11 +80,21 @@ public function doRun(InputInterface $input, OutputInterface $output)
7980
*/
8081
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
8182
{
83+
if (!$command instanceof ListCommand) {
84+
if ($this->registrationErrors) {
85+
$this->renderRegistrationErrors($input, $output);
86+
}
87+
88+
return parent::doRunCommand($command, $input, $output);
89+
}
90+
91+
$returnCode = parent::doRunCommand($command, $input, $output);
92+
8293
if ($this->registrationErrors) {
8394
$this->renderRegistrationErrors($input, $output);
8495
}
8596

86-
return parent::doRunCommand($command, $input, $output);
97+
return $returnCode;
8798
}
8899

89100
/**

src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,34 @@ public function testRegistrationErrorsAreDisplayedOnCommandNotFound()
192192
$this->assertContains('Command "fine" is not defined.', $output);
193193
}
194194

195+
public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
196+
{
197+
$container = new ContainerBuilder();
198+
$container->register('event_dispatcher', EventDispatcher::class);
199+
$container->register(ThrowingCommand::class, ThrowingCommand::class);
200+
$container->setParameter('console.command.ids', array(ThrowingCommand::class => ThrowingCommand::class));
201+
202+
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
203+
$kernel
204+
->method('getBundles')
205+
->willReturn(array($this->createBundleMock(
206+
array((new Command('fine'))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); }))
207+
)));
208+
$kernel
209+
->method('getContainer')
210+
->willReturn($container);
211+
212+
$application = new Application($kernel);
213+
$application->setAutoExit(false);
214+
215+
$tester = new ApplicationTester($application);
216+
$tester->run(array('command' => 'list'));
217+
218+
$this->assertSame(0, $tester->getStatusCode());
219+
$display = explode('Lists commands', $tester->getDisplay());
220+
$this->assertContains(trim('[WARNING] Some commands could not be registered:'), trim($display[1]));
221+
}
222+
195223
private function getKernel(array $bundles, $useDispatcher = false)
196224
{
197225
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();

0 commit comments

Comments
 (0)
0