Skip to content

Commit 57cdbcc

Browse files
Merge branch '2.7' into 2.8
* 2.7: [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 avoid (string) catchable fatal error for __PHP_Incomplete_Class instances sendContent return as parent. [FrameworkBundle] Fix a typo Added more exceptions to singularify method
2 parents 478a988 + 79dfde9 commit 57cdbcc

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
@@ -200,6 +200,10 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
200200
$this->scopedServices[$scope][$id] = $service;
201201
}
202202

203+
if (isset($this->aliases[$id])) {
204+
unset($this->aliases[$id]);
205+
}
206+
203207
$this->services[$id] = $service;
204208

205209
if (method_exists($this, $method = 'synchronize'.strtr($id, $this->underscoreMap).'Service')) {

Tests/ContainerBuilderTest.php

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

256+
public function testSetReplacesAlias()
257+
{
258+
$builder = new ContainerBuilder();
259+
$builder->setAlias('alias', 'aliased');
260+
$builder->set('aliased', new \stdClass());
261+
262+
$builder->set('alias', $foo = new \stdClass());
263+
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
264+
}
265+
256266
public function testAddGetCompilerPass()
257267
{
258268
$builder = new ContainerBuilder();

Tests/ContainerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ public function testSetAlsoCallsSynchronizeService()
192192
$this->assertTrue($c->synchronized, '->set() calls synchronize*Service() if it is defined for the service');
193193
}
194194

195+
public function testSetReplacesAlias()
196+
{
197+
$c = new ProjectServiceContainer();
198+
199+
$c->set('alias', $foo = new \stdClass());
200+
$this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias');
201+
}
202+
195203
public function testGet()
196204
{
197205
$sc = new ProjectServiceContainer();

0 commit comments

Comments
 (0)