8000 [DependencyInjection] Bugs with private services by alexandresalome · Pull Request #2586 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Bugs with private services #2586

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,71 @@ 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");
}

/**
* 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& 4BE2 #39;)
;

$container->compile();

$this->assertTrue($container->hasDefinition('a'), 'Service A is still present');
$this->assertFalse($container->has('a'), 'Service A is not accessible');
}
}
0