8000 fix setDefaultCommand · symfony/symfony@725001b · GitHub
[go: up one dir, main page]

Skip to content

Commit 725001b

Browse files
committed
fix setDefaultCommand
1 parent 6d51019 commit 725001b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,9 @@ private function findAlternatives(string $name, iterable $collection): array
11471147
*/
11481148
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
11491149
{
1150+
$commandName = ltrim($commandName, '|');
1151+
$commandName = explode('|', $commandName)[0];
1152+
11501153
$this->defaultCommand = $commandName;
11511154

11521155
if ($isSingleCommand) {

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,25 @@ public function testCommandAttribute()
422422
$this->assertTrue($command->isHidden());
423423
$this->assertSame(['f'], $command->getAliases());
424424
}
425+
426+
/**
427+
* @requires PHP 8
428+
*/
429+
public function testDefaultCommand()
430+
{
431+
$apl = new Application();
432+
$apl->setDefaultCommand(Php8Command::getDefaultName());
433+
$property = new \ReflectionProperty($apl, 'defaultCommand');
434+
$property->setAccessible(true);
435+
436+
$this->assertEquals('foo', $property->getValue($apl));
437+
438+
$apl->setDefaultCommand(Php8Command2::getDefaultName());
439+
$property = new \ReflectionProperty($apl, 'defaultCommand');
440+
$property->setAccessible(true);
441+
442+
$this->assertEquals('foo2', $property->getValue($apl));
443+
}
425444
}
426445

427446
// In order to get an unbound closure, we should create it outside a class
@@ -437,3 +456,8 @@ function createClosure()
437456
class Php8Command extends Command
438457
{
439458
}
459+
460+
#[AsCommand(name: 'foo2', description: 'desc2', hidden: true)]
461+
class Php8Command2 extends Command
462+
{
463+
}

0 commit comments

Comments
 (0)
0