Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c26aa09

Browse filesBrowse files
author
Amrouche Hamza
committed
[FrameworkBundle] [Console] add a warning when command is not found
1 parent 4271fec commit c26aa09
Copy full SHA for c26aa09

File tree

Expand file treeCollapse file tree

2 files changed

+32
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Application.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Console;
1313

14+
use Symfony\Component\Console\Exception\CommandNotFoundException;
15+
use Symfony\Component\Console\Exception\CommandNotRegisteredException;
1416
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1517
use Symfony\Component\Console\Style\SymfonyStyle;
1618
use Symfony\Component\Debug\Exception\FatalThrowableError;
@@ -64,7 +66,9 @@ public function doRun(InputInterface $input, OutputInterface $output)
6466
$this->kernel->boot();
6567

6668
$this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));
67-
69+
70+
$this->registerCommands();
71+
6872
if ($this->registrationErrors) {
6973
$this->renderRegistrationErrors($input, $output);
7074
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,33 @@ public function testRunOnlyWarnsOnUnregistrableCommand()
165165
$this->assertContains('fine', $output);
166166
}
167167

168+
public function testRegistrationErrorsAreDisplayedOnCommandNotFound()
169+
{
170+
$container = new ContainerBuilder();
171+
$container->register('event_dispatcher', EventDispatcher::class);
172+
173+
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
174+
$kernel
175+
->method('getBundles')
176+
->willReturn(array($this->createBundleMock(
177+
array((new Command(null))->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('fine'); }))
178+
)));
179+
$kernel
180+
->method('getContainer')
181+
->willReturn($container);
182+
183+
$application = new Application($kernel);
184+
$application->setAutoExit(false);
185+
186+
$tester = new ApplicationTester($application);
187+
$tester->run(array('command' => 'fine'));
188+
$output = $tester->getDisplay();
189+
190+
$this->assertSame(1, $tester->getStatusCode());
191+
$this->assertContains('Some commands could not be registered:', $output);
192+
$this->assertContains('Command "fine" is not defined.', $output);
193+
}
194+
168195
private function getKernel(array $bundles, $useDispatcher = false)
169196
{
170197
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.