Skip to content

[DependencyInjection] Fixed incorrect report for private services if required service does not exist #39151

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

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.
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 @@ -82,13 +82,14 @@ public function __construct()
new ReplaceAliasByActualDefinitionPass(),
new RemoveAbstractDefinitionsPass(),
new RemoveUnusedDefinitionsPass(),
new AnalyzeServiceReferencesPass(),
new CheckExceptionOnInvalidReferenceBehaviorPass(),
new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()),
new AnalyzeServiceReferencesPass(),
new DefinitionErrorExceptionPass(),
]];

$this->afterRemovingPasses = [[
new CheckExceptionOnInvalidReferenceBehaviorPass(),
new ResolveHotPathPass(),
]];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,47 @@ public function testNoClassFromNsSeparatorId()
$container->compile();
}

public function testGetThrownServiceNotFoundExceptionWithCorrectServiceId()
{
$this->expectException(ServiceNotFoundException::class);
$this->expectExceptionMessage('The service "child_service" has a dependency on a non-existent service "non_existent_service".');

$container = new ContainerBuilder();
$container->register('child_service', \stdClass::class)
->setPublic(false)
->addArgument([
'non_existent' => new Reference('non_existent_service'),
])
;
$container->register('parent_service', \stdClass::class)
->setPublic(true)
->addArgument([
'child_service' => new Reference('child_service'),
])
;

$container->compile();
}

public function testUnusedServiceRemovedByPassAndServiceNotFoundExceptionWasNotThrown()
{
$container = new ContainerBuilder();
$container->register('service', \stdClass::class)
->setPublic(false)
->addArgument([
'non_existent_service' => new Reference('non_existent_service'),
])
;

try {
$container->compile();
} catch (ServiceNotFoundException $e) {
$this->fail('Should not be thrown');
}

$this->addToAssertionCount(1);
}

public function testServiceLocator()
{
$container = new ContainerBuilder();
Expand Down