[Dependency-Injection] Fix issue where non-defined services were attempted to be removed
This commit is contained in:
parent
f27c3a8584
commit
53155c9800
@ -60,7 +60,7 @@ class RemoveUnusedDefinitionsPass extends AbstractRecursivePass implements Repea
|
||||
$ids = $this->connectedIds;
|
||||
$this->connectedIds = array();
|
||||
foreach ($ids as $id) {
|
||||
if (!isset($connectedIds[$id]) && $container->has($id)) {
|
||||
if (!isset($connectedIds[$id]) && $container->hasDefinition($id)) {
|
||||
$connectedIds[$id] = true;
|
||||
$this->processValue($container->getDefinition($id));
|
||||
}
|
||||
|
@ -127,6 +127,21 @@ class RemoveUnusedDefinitionsPassTest extends TestCase
|
||||
$this->assertSame(1, $envCounters['FOOBAR']);
|
||||
}
|
||||
|
||||
public function testProcessDoesNotErrorOnServicesThatDoNotHaveDefinitions()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('defined')
|
||||
->addArgument(new Reference('not.defined'))
|
||||
->setPublic(true);
|
||||
|
||||
$container->set('not.defined', new \StdClass());
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertFalse($container->hasDefinition('not.defined'));
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
(new RemoveUnusedDefinitionsPass())->process($container);
|
||||
|
Reference in New Issue
Block a user