diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 71f2b3049c766..8da6595cd9250 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -44,10 +44,10 @@ public function __construct() new ResolveDefinitionTemplatesPass(), new DecoratorServicePass(), new ResolveParameterPlaceHoldersPass(), + new FactoryReturnTypePass(), new CheckDefinitionValidityPass(), new ResolveReferencesToAliasesPass(), new ResolveInvalidReferencesPass(), - new FactoryReturnTypePass(), new AutowirePass(), new AnalyzeServiceReferencesPass(true), new CheckCircularReferencesPass(), diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php index ae91a7975cf8b..ecee63799c36b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php @@ -30,8 +30,10 @@ public function testProcess() $factory = $container->register('factory'); $factory->setFactory(array(FactoryDummy::class, 'createFactory')); + $container->setAlias('alias_factory', 'factory'); + $foo = $container->register('foo'); - $foo->setFactory(array(new Reference('factory'), 'create')); + $foo->setFactory(array(new Reference('alias_factory'), 'create')); $bar = $container->register('bar', __CLASS__); $bar->setFactory(array(new Reference('factory'), 'create')); @@ -100,4 +102,20 @@ public function testCircularReference() $this->assertNull($factory->getClass()); $this->assertNull($factory2->getClass()); } + + public function testCompile() + { + $container = new ContainerBuilder(); + + $factory = $container->register('factory'); + $factory->setFactory(array(FactoryDummy::class, 'createFactory')); + + if (!method_exists(\ReflectionMethod::class, 'getReturnType')) { + $this->setExpectedException(\RuntimeException::class, 'Please add the class to service "factory" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.'); + } + + $container->compile(); + + $this->assertEquals(FactoryDummy::class, $container->getDefinition('factory')->getClass()); + } }