[DependencyInjection] Fix #16461 Let Container::set() replace existing aliases
`Container::set()` now overrides any previously alias defined with the same name.
This commit is contained in:
parent
92d291a17c
commit
be85d16940
@ -200,6 +200,10 @@ class Container implements IntrospectableContainerInterface
|
||||
$this->scopedServices[$scope][$id] = $service;
|
||||
}
|
||||
|
||||
if (isset($this->aliases[$id])) {
|
||||
unset($this->aliases[$id]);
|
||||
}
|
||||
|
||||
$this->services[$id] = $service;
|
||||
|
||||
if (method_exists($this, $method = 'synchronize'.strtr($id, $this->underscoreMap).'Service')) {
|
||||
|
@ -217,6 +217,16 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(isset($aliases['foobar']));
|
||||
}
|
||||
|
||||
public function testSetReplacesAlias()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$builder->setAlias('alias', 'aliased');
|
||||
$builder->set('aliased', new \stdClass());
|
||||
|
||||
$builder->set('alias', $foo = new \stdClass());
|
||||
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
|
||||
}
|
||||
|
||||
public function testAddGetCompilerPass()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
|
@ -152,6 +152,14 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($foo, $services['foo']['foo']);
|
||||
}
|
||||
|
||||
public function testSetReplacesAlias()
|
||||
{
|
||||
$c = new ProjectServiceContainer();
|
||||
|
||||
$c->set('alias', $foo = new \stdClass());
|
||||
$this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias');
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
|
Reference in New Issue
Block a user