feature #26288 [FrameworkBundle] show the unregistered command warning at the end of the list command (Simperfit)

This PR was merged into the 4.1-dev branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | no
| New feature?  | yes   <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no   <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #26203  <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | I don't think we need one.

This PR modify the warning error when you have unregistered command on the list command, it shows it at the end.

Commits
-------

99b104ab5c [FrameworkBundle] show the unregistered command warning at the end of the list command
This commit is contained in:
Fabien Potencier 2018-03-15 09:35:44 -07:00
commit bf120d042b
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();