From ade448cf10b0331952dd6bc892b53c23e58a2b1d Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Mon, 6 Jan 2014 22:31:09 +0000 Subject: [PATCH] [Console] Fixed command name guessing if an alternative is an alias. --- src/Symfony/Component/Console/Application.php | 10 ++++++++++ .../Component/Console/Tests/ApplicationTest.php | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index fcfa48fe8a..bfd71fcb26 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -562,6 +562,16 @@ class Application throw new \InvalidArgumentException($message); } + // filter out aliases for commands which are already on the list + if (count($commands) > 1) { + $commandList = $this->commands; + $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) { + $commandName = $commandList[$nameOrAlias]->getName(); + + return $commandName === $nameOrAlias || !in_array($commandName, $commands); + }); + } + $exact = in_array($name, $commands, true); if (count($commands) > 1 && !$exact) { $suggestions = $this->getAbbreviationSuggestions(array_values($commands)); diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 719a98b32b..14ae8e1ddd 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -393,6 +393,19 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase } } + public function testFindAlternativeCommandsWithAnAlias() + { + $fooCommand = new \FooCommand(); + $fooCommand->setAliases(array('foo2')); + + $application = new Application(); + $application->add($fooCommand); + + $result = $application->find('foo'); + + $this->assertSame($fooCommand, $result); + } + public function testFindAlternativeNamespace() { $application = new Application();