From d59140e857a5dc0ec54f42daaee8a3c9b9270529 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 1 Sep 2020 19:03:51 +0200 Subject: [PATCH] Fix undefined index for inconsistent command name definition --- src/Symfony/Component/Console/Application.php | 5 +++++ .../Component/Console/Tests/ApplicationTest.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index c576ec050aa6b..320d53919ebb3 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -490,6 +490,11 @@ public function get($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) { diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index f813083985f36..212379a7c39db 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -1715,6 +1715,20 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn $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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy