bug #20598 [DI] Aliases should preserve the aliased invalid behavior (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
[DI] Aliases should preserve the aliased invalid behavior
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
7752308
[DI] Aliases should preserve the aliased invalid behavior
This commit is contained in:
commit
af9c279e23
|
@ -430,7 +430,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||
}
|
||||
|
||||
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
|
||||
return $this->get($this->aliasDefinitions[$id]);
|
||||
return $this->get($this->aliasDefinitions[$id], $invalidBehavior);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -231,6 +231,18 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
|
||||
}
|
||||
|
||||
public function testAliasesKeepInvalidBehavior()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
|
||||
$aliased = new Definition('stdClass');
|
||||
$aliased->addMethodCall('setBar', array(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
|
||||
$builder->setDefinition('aliased', $aliased);
|
||||
$builder->setAlias('alias', 'aliased');
|
||||
|
||||
$this->assertEquals(new \stdClass(), $builder->get('alias'));
|
||||
}
|
||||
|
||||
public function testAddGetCompilerPass()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
|
|
Reference in New Issue