Merge branch '3.4' into 4.4

* 3.4:
  Fix undefined index for inconsistent command name definition
This commit is contained in:
Fabien Potencier 2020-09-02 09:07:21 +02:00
commit bca14aa5f8
2 changed files with 19 additions and 0 deletions

View File

@ -513,6 +513,11 @@ class Application implements ResetInterface
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

@ -1802,6 +1802,20 @@ class ApplicationTest extends TestCase
$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