Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  Fix undefined index for inconsistent command name definition
  • Loading branch information
fabpot committed Sep 2, 2020
2 parents 51ff337 + b39fd99 commit 186f395
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Application.php
Expand Up @@ -494,6 +494,11 @@ public function get(string $name)
throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
}

// When the command has a different name than the one used at the command loader level
if (!isset($this->commands[$name])) {
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));
}

$command = $this->commands[$name];

if ($this->wantHelps) {
Expand Down
14 changes: 14 additions & 0 deletions Tests/ApplicationTest.php
Expand Up @@ -1788,6 +1788,20 @@ public function testThrowingErrorListener()
$tester = new ApplicationTester($application);
$tester->run(['command' => 'foo']);
}

public function testCommandNameMismatchWithCommandLoaderKeyThrows()
{
$this->expectException(CommandNotFoundException::class);
$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()".');

$app = new Application();
$loader = new FactoryCommandLoader([
'test' => static function () { return new Command('test-command'); },
]);

$app->setCommandLoader($loader);
$app->get('test');
}
}

class CustomApplication extends Application
Expand Down

0 comments on commit 186f395

Please sign in to comment.