Skip to content

Commit 79dfde9

Browse files
Merge branch '2.3' into 2.7
* 2.3: [DomCrawler] Clarify the value returned by getPhpFiles() [DependencyInjection] Fix #16461 Let Container::set() replace existing aliases Added more exceptions to singularify method
2 parents ad97d11 + 6bd9ea2 commit 79dfde9

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

196+
if (isset($this->aliases[$id])) {
197+
unset($this->aliases[$id]);
198+
}
199+
196200
$this->services[$id] = $service;
197201

198202
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
@@ -218,6 +218,16 @@ public function testAddAliases()
218218
$this->assertTrue(isset($aliases['foobar']));
219219
}
220220

221+
public function testSetReplacesAlias()
222+
{
223+
$builder = new ContainerBuilder();
224+
$builder->setAlias('alias', 'aliased');
225+
$builder->set('aliased', new \stdClass());
226+
227+
$builder->set('alias', $foo = new \stdClass());
228+
$this->assertSame($foo, $builder->get('alias'), '->set() replaces an existing alias');
229+
}
230+
221231
public function testAddGetCompilerPass()
222232
{
223233
$builder = new ContainerBuilder();

Tests/ContainerTest.php

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

187+
public function testSetReplacesAlias()
188+
{
189+
$c = new ProjectServiceContainer();
190+
191+
$c->set('alias', $foo = new \stdClass());
192+
$this->assertSame($foo, $c->get('alias'), '->set() replaces an existing alias');
193+
}
194+
187195
public function testGet()
188196
{
189197
$sc = new ProjectServiceContainer();

0 commit comments

Comments
 (0)