Skip to content

Commit bca14aa

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: Fix undefined index for inconsistent command name definition
2 parents 804f194 + 33cacad commit bca14aa

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Symfony/Component/Console/Application.php

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

516+
// When the command has a different name than the one used at the command loader level
517+
if (!isset($this->commands[$name])) {
518+
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));
519+
}
520+
516521
$command = $this->commands[$name];
517522

518523
if ($this->wantHelps) {

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,20 @@ public function testThrowingErrorListener()
18021802
$tester = new ApplicationTester($application);
18031803
$tester->run(['command' => 'foo']);
18041804
}
1805+
1806+
public function testCommandNameMismatchWithCommandLoaderKeyThrows()
1807+
{
1808+
$this->expectException(CommandNotFoundException::class);
1809+
$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()".');
1810+
1811+
$app = new Application();
1812+
$loader = new FactoryCommandLoader([
1813+
'test' => static function () { return new Command('test-command'); },
1814+
]);
1815+
1816+
$app->setCommandLoader($loader);
1817+
$app->get('test');
1818+
}
18051819
}
18061820

18071821
class CustomApplication extends Application

0 commit comments

Comments
 (0)