8000 bug #26290 [FrameworkBundle] [Console][DX] add a warning when command… · symfony/symfony@4261b19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4261b19

Browse files
committed
bug #26290 [FrameworkBundle] [Console][DX] add a warning when command is not found (Simperfit)
This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] [Console][DX] add a warning when command is not found | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no <!-- 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 | none | License | MIT | Doc PR | This PR add DX on the the console `find()` and `get()` methods when a command is not found because it has not been registered properly. Commits ------- efd8f7f [FrameworkBundle] [Console] add a warning when command is not found
2 parents d419fd4 + efd8f7f commit 4261b19

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public function doRun(InputInterface $input, OutputInterface $output)
6565

6666
$this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));
6767

68+
$this->registerCommands();
69+
6870
if ($this->registrationErrors) {
6971
$this->renderRegistrationErrors($input, $output);
7072
}

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

Lines 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