8000 [FrameworkBundle] show the unregistered command warning at the end of the list command by Simperfit · Pull Request #26288 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,11 +80,23 @@ public function doRun(InputInterface $input, OutputInterface $output)
*/
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
{
if (!$command instanceof ListCommand) {
if ($this->registrationErrors) {
$this->renderRegistrationErrors($input, $output);
$this->registrationErrors = array();
}

return parent::doRunCommand($command, $input, $output);
}

$returnCode = parent::doRunCommand($command, $input, $output);

if ($this->registrationErrors) {
$this->renderRegistrationErrors($input, $output);
$this->registrationErrors = array();
}

return parent::doRunCommand($command, $input, $output);
return $returnCode;
}

/**
Expand Down Expand Up @@ -192,7 +205,5 @@ private function renderRegistrationErrors(InputInterface $input, OutputInterface
foreach ($this->registrationErrors as $error) {
$this->doRenderException($error, $output);
}

$this->registrationErrors = array();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,35 @@ public function testRegistrationErrorsAreDisplayedOnCommandNotFound()
$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();
Expand Down
0