From 2fce9a458f440d228ef1def2580ca9384a32f1a0 Mon Sep 17 00:00:00 2001 From: Nic Wortel Date: Thu, 15 Jun 2023 15:13:27 +0200 Subject: [PATCH] Sort the list of aliases alphabetically This will make it easier to find a specific alias in the list, and groups related aliases together. Fixes https://github.com/phar-io/phive/issues/408. --- src/commands/list/ListCommand.php | 3 +++ tests/unit/commands/list/ListCommandTest.php | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/commands/list/ListCommand.php b/src/commands/list/ListCommand.php index 93fc8171..e139a321 100644 --- a/src/commands/list/ListCommand.php +++ b/src/commands/list/ListCommand.php @@ -11,6 +11,7 @@ namespace PharIo\Phive; use function count; +use function sort; class ListCommand implements Cli\Command { /** @var SourcesList */ @@ -41,6 +42,8 @@ public function execute(): void { } private function printAliases(array $aliases): void { + sort($aliases); + foreach ($aliases as $aliasName) { $this->output->writeText("* {$aliasName}\n"); } diff --git a/tests/unit/commands/list/ListCommandTest.php b/tests/unit/commands/list/ListCommandTest.php index 7b215b8e..a9d7d7a3 100644 --- a/tests/unit/commands/list/ListCommandTest.php +++ b/tests/unit/commands/list/ListCommandTest.php @@ -35,15 +35,15 @@ public function testWritesExpectedAliasesToOutput(): void { $output->expects($this->at(3)) ->method('writeText') - ->with($this->stringContains('phpunit')); + ->with($this->stringContains('phpab')); $output->expects($this->at(4)) ->method('writeText') - ->with($this->stringContains('phpab')); + ->with($this->stringContains('phploc')); $output->expects($this->at(5)) ->method('writeText') - ->with($this->stringContains('phploc')); + ->with($this->stringContains('phpunit')); $command = new ListCommand($sourcesList, $localSources, $output); $command->execute();