-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Console] Fix name/alias/usages when an invokable command has an alias #61367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.4
Are you sure you want to change the base?
Conversation
if (\is_callable($this) && self::class === (new \ReflectionMethod($this, 'execute'))->getDeclaringClass()->name) { | ||
$this->code = new InvokableCommand($this, $this(...)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lines are here to support invokable classes that extend the Command
class. This is a supported feature, see InvokableCommandTest::testCallInvokeMethodWhenExtendingCommandClass
that is now failing.
I would add if (!$code && ...
to the condition.
#[RequiresPhpExtension('pcntl')] | ||
public function testSignalableInvokableCommandThatExtendsBaseCommand() | ||
{ | ||
$command = new class extends Command implements SignalableCommandInterface { | ||
use SignalableInvokableCommandTrait; | ||
}; | ||
$command->setName('signal-invokable'); | ||
|
||
$application = $this->createSignalableApplication($command, null); | ||
$application->setSignalsToDispatchEvent(\SIGUSR1); | ||
|
||
$this->assertSame(1, $application->run(new ArrayInput(['signal-invokable']))); | ||
$this->assertTrue($command->signaled); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not related to the fix. This change should be reverted.
Invokable commands don't construct their command name properly when an alias is present. This makes the command uncallable. The name has a pipe and alias appended such as
example:name | my-alias
. This appending is done by#[AsCommand]
. You can see the effect by looking the test failure in the first commit to this PR.The PR fixes the issue by removing a
return
when handling of invokables in Command::__construct(). We can mostly use same logic as non-invokables.I discovered this while moving Drush (Drupal's CLI) to invokable commands.