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

This commit is contained in:
Islam Israfilov (Islam93) 2020-11-23 20:57:08 +03:00 committed by Alexander M. Turek
parent 42061de4e4
commit 39bd05c5bc
2 changed files with 43 additions and 1 deletions

View File

@ -82,13 +82,14 @@ class PassConfig
new ReplaceAliasByActualDefinitionPass(),
new RemoveAbstractDefinitionsPass(),
new RemoveUnusedDefinitionsPass(),
new AnalyzeServiceReferencesPass(),
new CheckExceptionOnInvalidReferenceBehaviorPass(),
new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()),
new AnalyzeServiceReferencesPass(),
new DefinitionErrorExceptionPass(),
]];
$this->afterRemovingPasses = [[
new CheckExceptionOnInvalidReferenceBehaviorPass(),
new ResolveHotPathPass(),
]];
}

View File

@ -1316,6 +1316,47 @@ class ContainerBuilderTest extends TestCase
$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();