Skip to content

Commit 18bde48

Browse files
Merge branch '3.0'
* 3.0: [VarDumper] Fix tests on PHP 7 [DomCrawler] Clarify the value returned by getPhpFiles() [DependencyInjection] Fix #16461 Let Container::set() replace existing aliases avoid (string) catchable fatal error for instances of __PHP_Incomplete_Class remove unnecessary retrieval and setting of data Update validators.fr.xlf avoid (string) catchable fatal error for __PHP_Incomplete_Class instances sendContent return as parent. [DomCrawler] Remove the overridden getHash() method to prevent problems when cloning the crawler [FrameworkBundle] Fix a typo Added more exceptions to singularify method Add width attribute on SVG [FrameworkBundle] Support autowiring for TranslationInterface [Validator] remove obsolete context and PropertyAccess code [WebProfiler] Fixed styles for search block and menu profiler for IE Edge
2 parents cf27aee + 98fc8c2 commit 18bde48

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Container.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ public function set($id, $service)
169169
throw new InvalidArgumentException('You cannot set service "service_container".');
170170
}
171171

172+
if (isset($this->aliases[$id])) {
173+
unset($this->aliases[$id]);
174+
}
175+
172176
$this->services[$id] = $service;
173177

174178
if (null === $service) {

Tests/ContainerBuilderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ public function testAddAliases()
231231
$this->assertTrue(isset($aliases['foobar']));
232232
}
233233

234+
public function testSetReplacesAlias()
235+
{
236+
$builder = new ContainerBuilder();
237+
$builder->setAlias('alias', 'aliased');
238+
$builder->set('aliased', new \stdClass());
239+
240+
$builder->set('alias', $foo = new \stdClass());
241+
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
242+
}
243+
234244
public function testAddGetCompilerPass()
235245
{
236246
$builder = new ContainerBuilder();

Tests/ContainerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ public function testSetWithNullResetTheService()
142142
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
143143
}
144144

145+
public function testSetReplacesAlias()
146+
{
147+
$c = new ProjectServiceContainer();
148+
149+
$c->set('alias', $foo = new \stdClass());
150+
$this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias');
151+
}
152+
145153
public function testGet()
146154
{
147155
$sc = new ProjectServiceContainer();

0 commit comments

Comments
 (0)