Skip to content

Commit

Permalink
[DI] Aliases should preserve the aliased invalid behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 22, 2016
1 parent 30d161c commit 7752308
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -430,7 +430,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
}

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 {
Expand Down
Expand Up @@ -231,6 +231,18 @@ public function testSetReplacesAlias()
$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();
Expand Down

0 comments on commit 7752308

Please sign in to comment.