Fix undefined index for inconsistent command name definition

This commit is contained in:
Robin Chalas 2020-09-01 19:03:51 +02:00
parent f4f7683861
commit d59140e857
2 changed files with 19 additions and 0 deletions

View File

@ -490,6 +490,11 @@ class Application
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) {

View File

@ -1715,6 +1715,20 @@ class ApplicationTest extends TestCase
$this->assertSame('Something went wrong.', $e->getMessage());
}
}
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