Skip to content

Commit

Permalink
bug #20598 [DI] Aliases should preserve the aliased invalid behavior …
Browse files Browse the repository at this point in the history
…(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
  • Loading branch information
fabpot committed Nov 24, 2016
2 parents 34b9fd6 + 7752308 commit af9c279
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 af9c279

Please sign in to comment.