Skip to content

Commit 255ef9f

Browse files
pvandommelenfabpot
authored andcommitted
[DependencyInjection] Fixed the getServiceIds implementation to always return aliases
1 parent 2e2ab9f commit 255ef9f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public function getServiceIds()
405405
}
406406
$ids[] = 'service_container';
407407

408-
return array_map('strval', array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->services))));
408+
return array_map('strval', array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->aliases), array_keys($this->services))));
409409
}
410410

411411
/**

Tests/ContainerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testGetServiceIds()
156156

157157
$sc = new ProjectServiceContainer();
158158
$sc->set('foo', $obj = new \stdClass());
159-
$this->assertEquals(['service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()');
159+
$this->assertEquals(['service_container', 'internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'alias', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()');
160160
}
161161

162162
/**
@@ -168,7 +168,7 @@ public function testGetLegacyServiceIds()
168168
$sc = new LegacyProjectServiceContainer();
169169
$sc->set('foo', $obj = new \stdClass());
170170

171-
$this->assertEquals(['internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
171+
$this->assertEquals(['internal', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'alias', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
172172
}
173173

174174
public function testSet()

Tests/Dumper/PhpDumperTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,30 @@ public function testScalarService()
11391139
$this->assertTrue($container->has('foo'));
11401140
$this->assertSame('some value', $container->get('foo'));
11411141
}
1142+
1143+
public function testAliasCanBeFoundInTheDumpedContainerWhenBothTheAliasAndTheServiceArePublic()
1144+
{
1145+
$container = new ContainerBuilder();
1146+
1147+
$container->register('foo', 'stdClass')->setPublic(true);
1148+
$container->setAlias('bar', 'foo')->setPublic(true);
1149+
1150+
$container->compile();
1151+
1152+
// Bar is found in the compiled container
1153+
$service_ids = $container->getServiceIds();
1154+
$this->assertContains('bar', $service_ids);
1155+
1156+
$dumper = new PhpDumper($container);
1157+
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer']);
1158+
eval('?>'.$dump);
1159+
1160+
$container = new \Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer();
1161+
1162+
// Bar should still be found in the compiled container
1163+
$service_ids = $container->getServiceIds();
1164+
$this->assertContains('bar', $service_ids);
1165+
}
11421166
}
11431167

11441168
class Rot13EnvVarProcessor implements EnvVarProcessorInterface

0 commit comments

Comments
 (0)