From 70f2b3eb8c538dea6130959353e94a4017dde1cc Mon Sep 17 00:00:00 2001 From: spdionis Date: Tue, 18 Nov 2014 02:17:03 +0200 Subject: [PATCH 1/2] global commands are always first in command list --- .../Descriptor/ApplicationDescription.php | 8 +++-- .../Console/Tests/Command/ListCommandTest.php | 32 +++++++++++++++++++ .../Console/Tests/Fixtures/Foo6Command.php | 13 ++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php diff --git a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php index 81aa1b0e27213..511921cb2444c 100644 --- a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php +++ b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php @@ -134,15 +134,17 @@ private function inspectApplication() private function sortCommands(array $commands) { $namespacedCommands = array(); + $globalCommands = array(); foreach ($commands as $name => $command) { $key = $this->application->extractNamespace($name, 1); if (!$key) { - $key = '_global'; + $globalCommands['_global'][$name] = $command; + } else { + $namespacedCommands[$key][$name] = $command; } - - $namespacedCommands[$key][$name] = $command; } ksort($namespacedCommands); + $namespacedCommands = array_merge($globalCommands, $namespacedCommands); foreach ($namespacedCommands as &$commandsSet) { ksort($commandsSet); diff --git a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php index fbb9feeb68731..cfc1b99dd3a98 100644 --- a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php @@ -61,4 +61,36 @@ public function testExecuteListsCommandsWithNamespaceArgument() $this->assertEquals($output, $commandTester->getDisplay(true)); } + + public function testExecuteListsCommandsNameAndNamespaceRaw() + { + require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php'); + $application = new Application(); + $application->add(new \Foo6Command()); + $commandTester = new CommandTester($command = $application->get('list')); + $commandTester->execute(array('command' => $command->getName())); + $output = <<foo + foo:bar +EOF; + + $this->assertEquals($output, trim($commandTester->getDisplay(true))); + } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php b/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php new file mode 100644 index 0000000000000..20ec2679b7ba1 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php @@ -0,0 +1,13 @@ +setName('foo:bar'); + } + +} From 2984f8ed605c4bbdce9411e3ad6d86400df236c2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Oct 2015 15:59:28 +0200 Subject: [PATCH 2/2] fixed previous commit --- .../Console/Tests/Command/ListCommandTest.php | 44 +++++++++++++------ .../Console/Tests/Fixtures/Foo6Command.php | 3 +- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php index cfc1b99dd3a98..d5b5bfbdbb628 100644 --- a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php @@ -62,33 +62,49 @@ public function testExecuteListsCommandsWithNamespaceArgument() $this->assertEquals($output, $commandTester->getDisplay(true)); } - public function testExecuteListsCommandsNameAndNamespaceRaw() + public function testExecuteListsCommandsOrder() { require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php'); $application = new Application(); $application->add(new \Foo6Command()); $commandTester = new CommandTester($command = $application->get('list')); - $commandTester->execute(array('command' => $command->getName())); + $commandTester->execute(array('command' => $command->getName()), array('decorated' => false)); $output = <<foo - foo:bar + help Displays help for a command + list Lists commands +0foo + 0foo:bar 0foo:bar command +EOF; + + $this->assertEquals($output, trim($commandTester->getDisplay(true))); + } + + public function testExecuteListsCommandsOrderRaw() + { + require_once realpath(__DIR__.'/../Fixtures/Foo6Command.php'); + $application = new Application(); + $application->add(new \Foo6Command()); + $commandTester = new CommandTester($command = $application->get('list')); + $commandTester->execute(array('command' => $command->getName(), '--raw' => true)); + $output = <<assertEquals($output, trim($commandTester->getDisplay(true))); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php b/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php index 20ec2679b7ba1..6ae987e484255 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php @@ -7,7 +7,6 @@ class Foo6Command extends Command { protected function configure() { - $this->setName('foo:bar'); + $this->setName('0foo:bar')->setDescription('0foo:bar command'); } - }