Skip to content

Commit af9c279

Browse files
committed
bug symfony#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
2 parents 34b9fd6 + 7752308 commit af9c279

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
430430
}
431431

432432
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
433-
return $this->get($this->aliasDefinitions[$id]);
433+
return $this->get($this->aliasDefinitions[$id], $invalidBehavior);
434434
}
435435

436436
try {

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ public function testSetReplacesAlias()
231231
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
232232
}
233233

234+
public function testAliasesKeepInvalidBehavior()
235+
{
236+
$builder = new ContainerBuilder();
237+
238+
$aliased = new Definition('stdClass');
239+
$aliased->addMethodCall('setBar', array(new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
240+
$builder->setDefinition('aliased', $aliased);
241+
$builder->setAlias('alias', 'aliased');
242+
243+
$this->assertEquals(new \stdClass(), $builder->get('alias'));
244+
}
245+
234246
public function testAddGetCompilerPass()
235247
{
236248
$builder = new ContainerBuilder();

0 commit comments

Comments
 (0)