8000 feature #26288 [FrameworkBundle] show the unregistered command warnin… · symfony/symfony@bf120d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf120d0

Browse files
committed
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 ------- 99b104a [FrameworkBundle] show the unregistered command warning at the end of the list command
2 parents 912c7e1 + 99b104a commit bf120d0

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
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,23 @@ 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+
$this->registrationErrors = array();
87+
}
88+
89+
return parent::doRunCommand($command, $input, $output);
90+
}
91+
92+
$returnCode = parent::doRunCommand($command, $input, $output);
93+
8294
if ($this->registrationErrors) {
8395
$this->renderRegistrationErrors($input, $output);
96+
$this->registrationErrors = array();
8497
}
8598

86-
return parent::doRunCommand($command, $input, $output);
99+
return $returnCode;
87100
}
88101

89102
/**
@@ -192,7 +205,5 @@ private function renderRegistrationErrors(InputInterface $input, OutputInterface
192205
foreach ($this->registrationErrors as $error) {
193206
$this->doRenderException($error, $output);
194207
}
195-
196-
$this->registrationErrors = array();
197208
}
198209
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,35 @@ 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+
221+
$this->assertContains(trim('[WARNING] Some commands could not be registered:'), trim($display[1]));
222+
}
223+
195224
private function getKernel(array $bundles, $useDispatcher = false)
196225
{
197226
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();

0 commit comments

Comments
 (0)
0