Commit 389d6635 authored by catch's avatar catch

Issue #2749819 by Fabianx, dawehner: OptimizedPhpArrayDumper does not resolve...

Issue #2749819 by Fabianx, dawehner: OptimizedPhpArrayDumper does not resolve references via aliases correctly
parent 7665462f
......@@ -60,6 +60,7 @@ public function dump(array $options = array()) {
*/
public function getArray() {
$definition = array();
$this->aliases = $this->getAliases();
$definition['aliases'] = $this->getAliases();
$definition['parameters'] = $this->getParameters();
$definition['services'] = $this->getServiceDefinitions();
......@@ -454,6 +455,9 @@ protected function getReferenceCall($id, Reference $reference = NULL) {
}
// Private shared service.
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
$definition = $this->container->getDefinition($id);
if (!$definition->isPublic()) {
// The ContainerBuilder does not share a private service, but this means a
......
......@@ -493,6 +493,60 @@ public function testGetServiceDefinitionWithInvalidScope() {
$this->dumper->getArray();
}
/**
* Tests that references to aliases work correctly.
*
* @covers ::getReferenceCall
*
* @dataProvider publicPrivateDataProvider
*/
public function testGetServiceDefinitionWithReferenceToAlias($public) {
$bar_definition = new Definition('\stdClass');
$bar_definition_php_array = array(
'class' => '\stdClass',
);
if (!$public) {
$bar_definition->setPublic(FALSE);
$bar_definition_php_array['public'] = FALSE;
}
$bar_definition_php_array['arguments_count'] = 0;
$services['bar'] = $bar_definition;
$aliases['bar.alias'] = 'bar';
$foo = new Definition('\stdClass');
$foo->addArgument(new Reference('bar.alias'));
$services['foo'] = $foo;
$this->containerBuilder->getAliases()->willReturn($aliases);
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->containerBuilder->getDefinition('bar')->willReturn($bar_definition);
$dump = $this->dumper->getArray();
if ($public) {
$service_definition = $this->getServiceCall('bar');
}
else {
$service_definition = $this->getPrivateServiceCall('bar', $bar_definition_php_array, TRUE);
}
$data = array(
'class' => '\stdClass',
'arguments' => $this->getCollection(array(
$service_definition,
)),
'arguments_count' => 1,
);
$this->assertEquals($this->serializeDefinition($data), $dump['services']['foo'], 'Expected definition matches dump.');
}
public function publicPrivateDataProvider() {
return array(
array(TRUE),
array(FALSE),
);
}
/**
* Tests that getDecoratedService() is unsupported.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment