8000 bug #42009 [Console] Fix save correct name in setDefaultCommand() for… · symfony/symfony@4a03392 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a03392

Browse files
committed
bug #42009 [Console] Fix save correct name in setDefaultCommand() for PHP8 (a1812)
This PR was merged into the 5.3 branch. Discussion ---------- [Console] Fix save correct name in setDefaultCommand() for PHP8 | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #41942 | License | MIT | Doc PR | Fix save correct name in setDefaultCommand() for PHP8 Commits ------- 8a41694 fix setDefaultCommand
2 parents 19b96f8 + 8a41694 commit 4a03392

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ private function findAlternatives(string $name, iterable $collection): array
11471147
*/
11481148
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
11491149
{
1150-
$this->defaultCommand = $commandName;
1150+
$this->defaultCommand = explode('|', ltrim($commandName, '|'))[0];
11511151

11521152
if ($isSingleCommand) {
11531153
// Ensure the command exist

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