Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6497304

Browse files
[Console] Fix using #[AsCommand] without DI
1 parent ecc138b commit 6497304

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Command/Command.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,18 @@ public function __construct(string $name = null)
101101
{
102102
$this->definition = new InputDefinition();
103103

104-
if (null !== $name || null !== $name = static::getDefaultName()) {
104+
if (null === $name && null !== $name = static::getDefaultName()) {
105+
$aliases = explode('|', $name);
106+
107+
if ('' === $name = array_shift($aliases)) {
108+
$this->setHidden(true);
109+
$name = array_shift($aliases);
110+
}
111+
112+
$this->setAliases($aliases);
113+
}
114+
115+
if (null !== $name) {
105116
$this->setName($name);
106117
}
107118

Tests/Command/CommandTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ public function testCommandAttribute()
414414
{
415415
$this->assertSame('|foo|f', Php8Command::getDefaultName());
416416
$this->assertSame('desc', Php8Command::getDefaultDescription());
417+
418+
$command = new Php8Command();
419+
420+
$this->assertSame('foo', $command->getName());
421+
$this->assertSame('desc', $command->getDescription());
422+
$this->assertTrue($command->isHidden());
423+
$this->assertSame(['f'], $command->getAliases());
417424
}
418425
}
419426

0 commit comments

Comments
 (0)