From 59812785378b6ff1970244869538c1aa5375d37b Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sun, 19 Feb 2017 12:32:55 +0100 Subject: [PATCH] [DependencyInjection] Fix using autowiring types when there are more than 2 services --- .../Component/DependencyInjection/Compiler/AutowirePass.php | 1 + .../DependencyInjection/Tests/Compiler/AutowirePassTest.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index 09a237caad..17464f2b80 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -169,6 +169,7 @@ class AutowirePass implements CompilerPassInterface foreach ($definition->getAutowiringTypes() as $type) { $this->definedTypes[$type] = true; $this->types[$type] = $id; + unset($this->notGuessableTypes[$type]); } if (!$reflectionClass = $this->getReflectionClass($id, $definition)) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 2d34cbff1d..986965255b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -173,7 +173,8 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase $container = new ContainerBuilder(); $container->register('a1', __NAMESPACE__.'\Foo'); - $container->register('a2', __NAMESPACE__.'\Foo')->addAutowiringType(__NAMESPACE__.'\Foo'); + $container->register('a2', __NAMESPACE__.'\Foo'); + $container->register('a3', __NAMESPACE__.'\Foo')->addAutowiringType(__NAMESPACE__.'\Foo'); $aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgument'); $aDefinition->setAutowired(true); @@ -181,7 +182,7 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase $pass->process($container); $this->assertCount(1, $container->getDefinition('a')->getArguments()); - $this->assertEquals('a2', (string) $container->getDefinition('a')->getArgument(0)); + $this->assertEquals('a3', (string) $container->getDefinition('a')->getArgument(0)); } public function testWithTypeSet()