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
This commit is contained in:
commit
3f5c0b1976
@ -182,6 +182,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)) {
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user