mirror of
https://github.com/symfony/console.git
synced 2026-03-24 01:12:13 +01:00
[Console] Fix setting aliases & hidden via name
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
7.4
|
||||
---
|
||||
|
||||
* Allow setting aliases and the hidden flag via the command name passed to the constructor
|
||||
|
||||
7.3
|
||||
---
|
||||
|
||||
|
||||
@@ -97,13 +97,13 @@ class Command implements SignalableCommandInterface
|
||||
if (self::class !== (new \ReflectionMethod($this, 'getDefaultName'))->class) {
|
||||
trigger_deprecation('symfony/console', '7.3', 'Overriding "Command::getDefaultName()" in "%s" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', static::class);
|
||||
|
||||
$defaultName = static::getDefaultName();
|
||||
$name = static::getDefaultName();
|
||||
} else {
|
||||
$defaultName = $attribute?->name;
|
||||
$name = $attribute?->name;
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $name && null !== $name = $defaultName) {
|
||||
if (null !== $name) {
|
||||
$aliases = explode('|', $name);
|
||||
|
||||
if ('' === $name = array_shift($aliases)) {
|
||||
|
||||
@@ -205,6 +205,19 @@ class CommandTest extends TestCase
|
||||
$this->assertEquals(['name1'], $command->getAliases(), '->setAliases() sets the aliases');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testWith ["name|alias1|alias2", "name", ["alias1", "alias2"], false]
|
||||
* ["|alias1|alias2", "alias1", ["alias2"], true]
|
||||
*/
|
||||
public function testSetAliasesAndHiddenViaName(string $name, string $expectedName, array $expectedAliases, bool $expectedHidden)
|
||||
{
|
||||
$command = new Command($name);
|
||||
|
||||
self::assertSame($expectedName, $command->getName());
|
||||
self::assertSame($expectedHidden, $command->isHidden());
|
||||
self::assertSame($expectedAliases, $command->getAliases());
|
||||
}
|
||||
|
||||
public function testGetSynopsis()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
|
||||
Reference in New Issue
Block a user