From cd162dabc2a23b0f3773b058c4470a0088998c68 Mon Sep 17 00:00:00 2001 From: alexandresalome Date: Tue, 8 Nov 2011 22:52:15 +0100 Subject: [PATCH 1/2] [DependencyInjection] Add a failing test for shared private service --- .../Compiler/IntegrationTest.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/IntegrationTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/IntegrationTest.php index f461cc4d52f36..546a0d8f25d80 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/IntegrationTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/IntegrationTest.php @@ -108,4 +108,36 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe $this->assertFalse($container->hasDefinition('b')); $this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.'); } + + /** + * This tests a private service A which is argument of B and C cannot be + * accessed if A is declared as private. + * + * A (private) + * B --> A + * C --> A + */ + public function testSharedPrivateService() + { + $container = new ContainerBuilder(); + + $container + ->register('a', 'stdClass') + ->setPublic(false) + ; + + $container + ->register('b', 'stdClass') + ->addArgument(new Reference('a')) + ; + + $container + ->register('c', 'stdClass') + ->addArgument(new Reference('a')) + ; + + $container->compile(); + + $this->assertFalse($container->has('a'), "Cannot access the service A because is private"); + } } From d8a9f9999d2de67ebb5231ad65193fe74db8de77 Mon Sep 17 00:00:00 2001 From: alexandresalome Date: Tue, 8 Nov 2011 23:20:56 +0100 Subject: [PATCH 2/2] [DependencyInjection] Add some tests for private factory --- .../Compiler/IntegrationTest.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/IntegrationTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/IntegrationTest.php index 546a0d8f25d80..ec580be1f8ebc 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/IntegrationTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/IntegrationTest.php @@ -140,4 +140,39 @@ public function testSharedPrivateService() $this->assertFalse($container->has('a'), "Cannot access the service A because is private"); } + + /** + * This tests that a service A, which is a private factory is present and + * cannot be accessed. + * + * A: factory (private) + * B: A->get() + * C: A->get() + */ + public function testSharedPrivateFactory() + { + $container = new ContainerBuilder(); + + $container + ->register('a', 'stdClass') + ->setPublic(false) + ; + + $container + ->register('b', 'stdClass') + ->setFactoryService('a') + ->setFactoryMethod('get') + ; + + $container + ->register('c', 'stdClass') + ->setFactoryService('a') + ->setFactoryMethod('get') + ; + + $container->compile(); + + $this->assertTrue($container->hasDefinition('a'), 'Service A is still present'); + $this->assertFalse($container->has('a'), 'Service A is not accessible'); + } }