Skip to content

Commit 18c5fd1

Browse files
committed
[Console] Fix exception message when abbreviation matches multiple hidden commands
1 parent 7f0dd9a commit 18c5fd1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,9 @@ public function find(string $name)
788788
}
789789
}
790790

791-
$command = $this->get(reset($commands));
791+
$command = $commands ? $this->get(reset($commands)) : null;
792792

793-
if ($command->isHidden()) {
793+
if (!$command || $command->isHidden()) {
794794
throw new CommandNotFoundException(\sprintf('The command "%s" does not exist.', $name));
795795
}
796796

Tests/ApplicationTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,6 +2424,21 @@ public function testOriginalHandlerRestoredAfterPop()
24242424
$this->assertSame(\SIG_DFL, pcntl_signal_get_handler(\SIGUSR1), 'OS-level handler must remain SIG_DFL after a second run.');
24252425
}
24262426

2427+
public function testFindAmbiguousHiddenCommands()
2428+
{
2429+
$application = new Application();
2430+
2431+
$application->add(new Command('test:foo'));
2432+
$application->add(new Command('test:foobar'));
2433+
$application->get('test:foo')->setHidden(true);
2434+
$application->get('test:foobar')->setHidden(true);
2435+
2436+
$this->expectException(CommandNotFoundException::class);
2437+
$this->expectExceptionMessage('The command "t:f" does not exist.');
2438+
2439+
$application->find('t:f');
2440+
}
2441+
24272442
/**
24282443
* Reads the private "signalHandlers" property of the SignalRegistry for assertions.
24292444
*/

0 commit comments

Comments
 (0)