diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 1683957fb9..62fda89423 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -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(), ]]; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index b69e875a7e..8986232c8c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -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();