Skip to content

Commit e724cb9

Browse files
committed
bug #21670 [DependencyInjection] Fix autowiring types when there are more than 2 services colliding (GuilhemN)
This PR was merged into the 2.8 branch. Discussion ---------- [DependencyInjection] Fix autowiring types when there are more than 2 services colliding | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | There is a bug in the `AutowirePass`, when using more than 2 services colliding and you want to use the autowiring types: it may not work depending on their order because `notGuessableTypes` is not reset. Commits ------- 5981278537 [DependencyInjection] Fix using autowiring types when there are more than 2 services
2 parents bbcf9e4 + 28c532e commit e724cb9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Compiler/AutowirePass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ private function populateAvailableType($id, Definition $definition)
182182
foreach ($definition->getAutowiringTypes() as $type) {
183183
$this->definedTypes[$type] = true;
184184
$this->types[$type] = $id;
185+
unset($this->notGuessableTypes[$type]);
185186
}
186187

187188
if (!$reflectionClass = $this->getReflectionClass($id, $definition)) {

Tests/Compiler/AutowirePassTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,16 @@ public function testTypeNotGuessableWithTypeSet()
173173
$container = new ContainerBuilder();
174174

175175
$container->register('a1', __NAMESPACE__.'\Foo');
176-
$container->register('a2', __NAMESPACE__.'\Foo')->addAutowiringType(__NAMESPACE__.'\Foo');
176+
$container->register('a2', __NAMESPACE__.'\Foo');
177+
$container->register('a3', __NAMESPACE__.'\Foo')->addAutowiringType(__NAMESPACE__.'\Foo');
177178
$aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgument');
178179
$aDefinition->setAutowired(true);
179180

180181
$pass = new AutowirePass();
181182
$pass->process($container);
182183

183184
$this->assertCount(1, $container->getDefinition('a')->getArguments());
184-
$this->assertEquals('a2', (string) $container->getDefinition('a')->getArgument(0));
185+
$this->assertEquals('a3', (string) $container->getDefinition('a')->getArgument(0));
185186
}
186187

187188
public function testWithTypeSet()

0 commit comments

Comments
 (0)