Skip to content

Commit

Permalink
bug #34451 [DependencyInjection] Fix dumping multiple deprecated alia…
Browse files Browse the repository at this point in the history
…ses (shyim)

This PR was merged into the 4.3 branch.

Discussion
----------

[DependencyInjection] Fix dumping multiple deprecated aliases

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Only the last deprecated alias wins, cause the content will not appended

Commits
-------

60b0dae [DependencyInjection] Fix dumping multiple deprecated aliases
  • Loading branch information
fabpot committed Nov 20, 2019
2 parents a7c66db + 60b0dae commit 996d8a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -1226,7 +1226,7 @@ private function addDeprecatedAliases(): string
$methodNameAlias = $this->generateMethodName($alias);
$idExported = $this->export($id);
$messageExported = $this->export($definition->getDeprecationMessage($alias));
$code = <<<EOF
$code .= <<<EOF
/*{$this->docStar}
* Gets the $public '$alias' alias.
Expand Down
Expand Up @@ -1283,6 +1283,30 @@ public function testWither()
$wither = $container->get('wither');
$this->assertInstanceOf(Foo::class, $wither->foo);
}

/**
* @group legacy
* @expectedDeprecation The "deprecated1" service alias is deprecated. You should stop using it, as it will be removed in the future.
* @expectedDeprecation The "deprecated2" service alias is deprecated. You should stop using it, as it will be removed in the future.
*/
public function testMultipleDeprecatedAliasesWorking()
{
$container = new ContainerBuilder();
$container->setDefinition('bar', new Definition('stdClass'))->setPublic(true);
$container->setAlias('deprecated1', 'bar')->setPublic(true)->setDeprecated('%alias_id% is deprecated');
$container->setAlias('deprecated2', 'bar')->setPublic(true)->setDeprecated('%alias_id% is deprecated');
$container->compile();

$dumper = new PhpDumper($container);
$dump = $dumper->dump(['class' => $class = __FUNCTION__]);

eval('?>'.$dump);
$container = new $class();

$this->assertInstanceOf(\stdClass::class, $container->get('bar'));
$this->assertInstanceOf(\stdClass::class, $container->get('deprecated1'));
$this->assertInstanceOf(\stdClass::class, $container->get('deprecated2'));
}
}

class Rot13EnvVarProcessor implements EnvVarProcessorInterface
Expand Down

0 comments on commit 996d8a7

Please sign in to comment.