Skip to content

Commit

Permalink
[Console] Fix using #[AsCommand] without DI
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 12, 2021
1 parent ecc138b commit 6497304
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,18 @@ public function __construct(string $name = null)
{
$this->definition = new InputDefinition();

if (null !== $name || null !== $name = static::getDefaultName()) {
if (null === $name && null !== $name = static::getDefaultName()) {
$aliases = explode('|', $name);

if ('' === $name = array_shift($aliases)) {
$this->setHidden(true);
$name = array_shift($aliases);
}

$this->setAliases($aliases);
}

if (null !== $name) {
$this->setName($name);
}

Expand Down
7 changes: 7 additions & 0 deletions Tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ public function testCommandAttribute()
{
$this->assertSame('|foo|f', Php8Command::getDefaultName());
$this->assertSame('desc', Php8Command::getDefaultDescription());

$command = new Php8Command();

$this->assertSame('foo', $command->getName());
$this->assertSame('desc', $command->getDescription());
$this->assertTrue($command->isHidden());
$this->assertSame(['f'], $command->getAliases());
}
}

Expand Down

0 comments on commit 6497304

Please sign in to comment.