Skip to content

Commit e71af68

Browse files
Merge branch '7.4' into 8.0
* 7.4: (21 commits) [SecurityBundle] Fix tests with Symfony 7.4 [DependencyInjection] Ensure deprecation detection does not trigger a PHP error [DependencyInjection][FrameworkBundle] fix BC break when dumping container for build/lint commands [Form] Clean up wrong method docblocks in data transformers Fix merge [DependencyInjection] Throw when using `$this` or its internal scope from PHP config files; use the `$loader` variable instead [HttpClient] Fix sharing CurlClientState between clones of CurlHttpClient instances [FrameworkBundle] Don't exclude classes with constraint/serialization attributes from being registered as services Revert "[HttpClient] Lazily initialize CurlClientState" [Yaml] Fix regression handling blank lines in unquoted scalars [Cache] Fix NullAdapter must set taggable [FrameworkBundle] Order alphabetically known tags of `UnusedTagsPass` allow the installation of MercureBundle 0.4 [Console] don't discard existing aliases when constructing Command Import all node definition classes to DefinitionConfigurator Fix the creation of a redis connection with only ext-relay [FrameworkBundle] Dump bundles config reference first [DependencyInjection] Don't add the .container.known_envs parameter when empty [DependencyInjection] Reset resolved state when setting a parameter [HttpKernel] Don't reset services between fragments redering when using in HttpCache ...
2 parents d888ff3 + 5c557f6 commit e71af68

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Command/Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ public function __construct(?string $name = null, ?callable $code = null)
8484
$name = array_shift($aliases);
8585
}
8686

87+
// we must not overwrite existing aliases, combine new ones with existing ones
88+
$aliases = array_unique([
89+
...$this->aliases,
90+
...$aliases,
91+
]);
92+
8793
$this->setAliases($aliases);
8894
}
8995

Tests/Command/CommandTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Console\Tests\Command;
1313

1414
use PHPUnit\Framework\Attributes\DataProvider;
15-
use PHPUnit\Framework\Attributes\TestWithJson;
15+
use PHPUnit\Framework\Attributes\TestWith;
1616
use PHPUnit\Framework\TestCase;
1717
use Symfony\Component\Console\Application;
1818
use Symfony\Component\Console\Attribute\AsCommand;
@@ -196,14 +196,27 @@ public function testGetProcessedHelp()
196196
public function testGetSetAliases()
197197
{
198198
$command = new \TestCommand();
199-
$this->assertEquals(['name'], $command->getAliases(), '->getAliases() returns the aliases');
200199
$ret = $command->setAliases(['name1']);
201200
$this->assertEquals($command, $ret, '->setAliases() implements a fluent interface');
202201
$this->assertEquals(['name1'], $command->getAliases(), '->setAliases() sets the aliases');
203202
}
204203

205-
#[TestWithJson('["name|alias1|alias2", "name", ["alias1", "alias2"], false]')]
206-
#[TestWithJson('["|alias1|alias2", "alias1", ["alias2"], true]')]
204+
public function testAliasesSetBeforeParentConstructorArePreserved()
205+
{
206+
$command = new class extends Command {
207+
public function __construct()
208+
{
209+
// set aliases before calling parent constructor
210+
$this->setAliases(['existingalias']);
211+
parent::__construct('foo|newalias');
212+
}
213+
};
214+
215+
$this->assertSame(['existingalias', 'newalias'], $command->getAliases(), 'Aliases set before parent::__construct() must be preserved.');
216+
}
217+
218+
#[TestWith(['name|alias1|alias2', 'name', ['alias1', 'alias2'], false])]
219+
#[TestWith(['|alias1|alias2', 'alias1', ['alias2'], true])]
207220
public function testSetAliasesAndHiddenViaName(string $name, string $expectedName, array $expectedAliases, bool $expectedHidden)
208221
{
209222
$command = new Command($name);

0 commit comments

Comments
 (0)