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

Skip to content

Commit 6547e37

Browse files
author
Amrouche Hamza
committed
[FrameworkBundle] show the unregistered command warning at the end of the list command
1 parent c12c078 commit 6547e37

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-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;
@@ -77,11 +78,21 @@ public function doRun(InputInterface $input, OutputInterface $output)
7778
*/
7879
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
7980
{
81+
if (!$command instanceof ListCommand) {
82+
if ($this->registrationErrors) {
83+
$this->renderRegistrationErrors($input, $output);
84+
}
85+
86< 8000 /code>+
return parent::doRunCommand($command, $input, $output);
87+
}
88+
89+
$returnCode = parent::doRunCommand($command, $input, $output);
90+
8091
if ($this->registrationErrors) {
8192
$this->renderRegistrationErrors($input, $output);
8293
}
8394

84-
return parent::doRunCommand($command, $input, $output);
95+
return $returnCode;
8596
}
8697

8798
/**

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165 8000 ,6 +165,54 @@ public function testRunOnlyWarnsOnUnregistrableCommand()
165165
$this->assertContains('fine', $output);
166166
}
167167

168+
public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
169+
{
170+
$container = new ContainerBuilder();
171+
$container->register('event_dispatcher', EventDispatcher::class);
172+
$container->register(ThrowingCommand::class, ThrowingCommand::class);
173+
$container->setParameter('console.command.ids', array(ThrowingCommand::class => ThrowingCommand::class));
174+
175+
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
176+
$kernel
177+
->method('getBundles')
178+
->willReturn(array($this->createBundleMock(
179+
array((new Command('fine'))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); }))
180+
)));
181+
$kernel
182+
->method('getContainer')
183+
->willReturn($container);
184+
185+
$application = new Application($kernel);
186+
$application->setAutoExit(false);
187+
188+
$tester = new ApplicationTester($application);
189+
$tester->run(array('command' => 'list'));
190+
191+
$this->assertSame(0, $tester->getStatusCode());
192+
$this->assertContains(trim('
193+
Usage:
194+
command [options] [arguments]
195+
196+
Options:
197+
-h, --help Display this help message
198+
-q, --quiet Do not output any message
199+
-V, --version Display this application version
200+
--ansi Force ANSI output
201+
--no-ansi Disable ANSI output
202+
-n, --no-interaction Do not ask any interactive question
203+
-e, --env=ENV The Environment name.
204+
--no-debug Switches off debug mode.
205+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
206+
207+
Available commands:
208+
fine
209+
help Displays help for a command
210+
list Lists commands
211+
212+
[WARNING] Some commands could not be registered:
213+
'), trim($tester->getDisplay()));
214+
}
215+
168216
private function getKernel(array $bundles, $useDispatcher = false)
169217
{
170218
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();

0 commit comments

Comments
 (0)
0