bug #41214 [Console] fix registering command aliases when using the new "cmd|alias" syntax for names (nicolas-grekas)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[Console] fix registering command aliases when using the new "cmd|alias" syntax for names

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #41212
| License       | MIT
| Doc PR        | -

Commits
-------

6633b95597 [Console] fix registering command aliases when using the new "cmd|alias" syntax for names
This commit is contained in:
Robin Chalas 2021-05-13 12:34:14 +02:00
commit c61617e6ac
2 changed files with 5 additions and 1 deletions

View File

@ -94,6 +94,10 @@ class AddConsoleCommandPass implements CompilerPassInterface
$lazyCommandMap[$commandName] = $id; $lazyCommandMap[$commandName] = $id;
$lazyCommandRefs[$id] = new TypedReference($id, $class); $lazyCommandRefs[$id] = new TypedReference($id, $class);
foreach ($aliases as $alias) {
$lazyCommandMap[$alias] = $id;
}
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (isset($tag['command'])) { if (isset($tag['command'])) {
$aliases[] = $tag['command']; $aliases[] = $tag['command'];

View File

@ -135,7 +135,7 @@ class AddConsoleCommandPassTest extends TestCase
$commandLocator = $container->getDefinition((string) $commandLoader->getArgument(0)); $commandLocator = $container->getDefinition((string) $commandLoader->getArgument(0));
$this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass()); $this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
$this->assertSame(['cmdname' => 'with-defaults'], $commandLoader->getArgument(1)); $this->assertSame(['cmdname' => 'with-defaults', 'cmdalias' => 'with-defaults'], $commandLoader->getArgument(1));
$this->assertEquals([['with-defaults' => new ServiceClosureArgument(new Reference('.with-defaults.lazy'))]], $commandLocator->getArguments()); $this->assertEquals([['with-defaults' => new ServiceClosureArgument(new Reference('.with-defaults.lazy'))]], $commandLocator->getArguments());
$this->assertSame([], $container->getParameter('console.command.ids')); $this->assertSame([], $container->getParameter('console.command.ids'));