[ProxyManagerBridge] Fixed support of private services

This commit is contained in:
Nicolas Grekas 2018-06-11 16:08:45 +02:00
parent eeb53ee2ed
commit 198bee0916
2 changed files with 29 additions and 1 deletions

View File

@ -57,7 +57,7 @@ class ProxyDumper implements DumperInterface
$instantiation = 'return';
if ($definition->isShared()) {
$instantiation .= " \$this->services['$id'] =";
$instantiation .= sprintf(' $this->%s[\'%s\'] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', $id);
}
if (null === $factoryCode) {

View File

@ -83,6 +83,34 @@ class ProxyDumperTest extends TestCase
);
}
/**
* @dataProvider getPrivatePublicDefinitions
*/
public function testCorrectAssigning(Definition $definition, $access)
{
$definition->setLazy(true);
$code = $this->dumper->getProxyFactoryCode($definition, 'foo', '$this->getFoo2Service(false)');
$this->assertStringMatchesFormat('%A$this->'.$access.'[\'foo\'] = %A', $code);
}
public function getPrivatePublicDefinitions()
{
return array(
array(
(new Definition(__CLASS__))
->setPublic(false),
'privates',
),
array(
(new Definition(__CLASS__))
->setPublic(true),
'services',
),
);
}
/**
* @group legacy
*/