Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DependencyInjection] Fixed the getServiceIds implementation to always return aliases #33335

Merged
merged 1 commit into from Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -405,7 +405,7 @@ public function getServiceIds()
}
$ids[] = 'service_container';

return array_map('strval', array_unique(array_merge($ids, array_keys($this->methodMap), array_keys($this->fileMap), array_keys($this->services))));
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))));
}

/**
Expand Down
Expand Up @@ -156,7 +156,7 @@ public function testGetServiceIds()

$sc = new ProjectServiceContainer();
$sc->set('foo', $obj = new \stdClass());
$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()');
$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()');
}

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

$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()');
$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()');
}

public function testSet()
Expand Down
Expand Up @@ -1139,6 +1139,30 @@ public function testScalarService()
$this->assertTrue($container->has('foo'));
$this->assertSame('some value', $container->get('foo'));
}

public function testAliasCanBeFoundInTheDumpedContainerWhenBothTheAliasAndTheServiceArePublic()
{
$container = new ContainerBuilder();

$container->register('foo', 'stdClass')->setPublic(true);
$container->setAlias('bar', 'foo')->setPublic(true);

$container->compile();

// Bar is found in the compiled container
$service_ids = $container->getServiceIds();
$this->assertContains('bar', $service_ids);

$dumper = new PhpDumper($container);
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer']);
eval('?>'.$dump);

$container = new \Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer();

// Bar should still be found in the compiled container
$service_ids = $container->getServiceIds();
$this->assertContains('bar', $service_ids);
}
}

class Rot13EnvVarProcessor implements EnvVarProcessorInterface
Expand Down