[FrameworkBundle] show the unregistered command warning at the end of the list command

This commit is contained in:
Amrouche Hamza 2018-02-23 15:12:35 +01:00
parent 1f7b9f0fc5
commit 99b104ab5c
No known key found for this signature in database
GPG Key ID: 6968F2785ED4F012
2 changed files with 45 additions and 5 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\Console;
use Symfony\Component\Console\Command\ListCommand;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Debug\Exception\FatalThrowableError;
@ -79,11 +80,23 @@ class Application extends BaseApplication
*/
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
{
if ($this->registrationErrors) {
$this->renderRegistrationErrors($input, $output);
if (!$command instanceof ListCommand) {
if ($this->registrationErrors) {
$this->renderRegistrationErrors($input, $output);
$this->registrationErrors = array();
}
return parent::doRunCommand($command, $input, $output);
}
return parent::doRunCommand($command, $input, $output);
$returnCode = parent::doRunCommand($command, $input, $output);
if ($this->registrationErrors) {
$this->renderRegistrationErrors($input, $output);
$this->registrationErrors = array();
}
return $returnCode;
}
/**
@ -192,7 +205,5 @@ class Application extends BaseApplication
foreach ($this->registrationErrors as $error) {
$this->doRenderException($error, $output);
}
$this->registrationErrors = array();
}
}

View File

@ -192,6 +192,35 @@ class ApplicationTest extends TestCase
$this->assertContains('Command "fine" is not defined.', $output);
}
public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
{
$container = new ContainerBuilder();
$container->register('event_dispatcher', EventDispatcher::class);
$container->register(ThrowingCommand::class, ThrowingCommand::class);
$container->setParameter('console.command.ids', array(ThrowingCommand::class => ThrowingCommand::class));
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel
->method('getBundles')
->willReturn(array($this->createBundleMock(
array((new Command('fine'))->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' => 'list'));
$this->assertSame(0, $tester->getStatusCode());
$display = explode('Lists commands', $tester->getDisplay());
$this->assertContains(trim('[WARNING] Some commands could not be registered:'), trim($display[1]));
}
private function getKernel(array $bundles, $useDispatcher = false)
{
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();