From dfb5cc3922a4b54b8a1cf063853e7a6d9c616360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Fri, 21 Oct 2016 12:49:22 +0200 Subject: [PATCH] [DependencyInjection] Fix FactoryReturnTypePass position in PassConfig --- .../Compiler/PassConfig.php | 2 +- .../Compiler/FactoryReturnTypePassTest.php | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 71f2b3049c..8da6595cd9 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -44,10 +44,10 @@ class PassConfig 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 ae91a7975c..ecee63799c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/FactoryReturnTypePassTest.php @@ -30,8 +30,10 @@ class FactoryReturnTypePassTest extends \PHPUnit_Framework_TestCase $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 @@ class FactoryReturnTypePassTest extends \PHPUnit_Framework_TestCase $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()); + } }