Skip to content

Commit 186f395

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: Fix undefined index for inconsistent command name definition
2 parents 51ff337 + b39fd99 commit 186f395

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Application.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ public function get(string $name)
494494
throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
495495
}
496496

497+
// When the command has a different name than the one used at the command loader level
498+
if (!isset($this->commands[$name])) {
499+
throw new CommandNotFoundException(sprintf('The "%s" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".', $name));
500+
}
501+
497502
$command = $this->commands[$name];
498503

499504
if ($this->wantHelps) {

Tests/ApplicationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,20 @@ public function testThrowingErrorListener()
17881788
$tester = new ApplicationTester($application);
17891789
$tester->run(['command' => 'foo']);
17901790
}
1791+
1792+
public function testCommandNameMismatchWithCommandLoaderKeyThrows()
1793+
{
1794+
$this->expectException(CommandNotFoundException::class);
1795+
$this->expectExceptionMessage('The "test" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".');
1796+
1797+
$app = new Application();
1798+
$loader = new FactoryCommandLoader([
1799+
'test' => static function () { return new Command('test-command'); },
1800+
]);
1801+
1802+
$app->setCommandLoader($loader);
1803+
$app->get('test');
1804+
}
17911805
}
17921806

17931807
class CustomApplication extends Application

0 commit comments

Comments
 (0)