Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,9 +788,9 @@ public function find(string $name)
}
}

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

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

Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2424,6 +2424,21 @@ public function testOriginalHandlerRestoredAfterPop()
$this->assertSame(\SIG_DFL, pcntl_signal_get_handler(\SIGUSR1), 'OS-level handler must remain SIG_DFL after a second run.');
}

public function testFindAmbiguousHiddenCommands()
{
$application = new Application();

$application->add(new Command('test:foo'));
$application->add(new Command('test:foobar'));
$application->get('test:foo')->setHidden(true);
$application->get('test:foobar')->setHidden(true);

$this->expectException(CommandNotFoundException::class);
$this->expectExceptionMessage('The command "t:f" does not exist.');

$application->find('t:f');
}

/**
* Reads the private "signalHandlers" property of the SignalRegistry for assertions.
*/
Expand Down