8000 [DI] Bug in autowiring collisions detection · GuilhemN/symfony@6f578ee · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f578ee

Browse files
[DI] Bug in autowiring collisions detection
1 parent 2fee5bc commit 6f578ee

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,31 @@ public function testEmptyStringIsKept()
459459

460460
$this->assertEquals(array(new Reference('a'), '', new Reference('lille')), $container->getDefinition('foo')->getArguments());
461461
}
462+
463+
/**
464+
* @dataProvider provideAutodiscoveredAutowiringOrder
465+
*
466+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
467+
* @expectedExceptionMEssage Unable to autowire argument of type "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" for the service "a". Multiple services exist for this interface (autowired.Symfony\Component\DependencyInjection\Tests\Compiler\CollisionA, autowired.Symfony\Component\DependencyInjection\Tests\Compiler\CollisionB).
468+
*/
469+
public function testAutodiscoveredAutowiringOrder($class)
470+
{
471+
$container = new ContainerBuilder();
472+
473+
$container->register('a', __NAMESPACE__.'\\'.$class)
474+
->setAutowired(true);
475+
476+
$pass = new AutowirePass();
477+
$pass->process($container);
478+
}
479+
480+
public function provideAutodiscoveredAutowiringOrder()
481+
{
482+
return array(
483+
array('CannotBeAutowiredForwardOrder'),
484+
array('CannotBeAutowiredReverseOrder'),
485+
);
486+
}
462487
}
463488

464489
class Foo
@@ -540,6 +565,20 @@ public function __construct(CollisionInterface $collision)
540565
}
541566
}
542567

568+
class CannotBeAutowiredForwardOrder
569+
{
570+
public function __construct(CollisionA $a, CollisionInterface $b, CollisionB $c)
571+
{
572+
}
573+
}
574+
575+
class CannotBeAutowiredReverseOrder
576+
{
577+
public function __construct(CollisionA $a, CollisionB $c, CollisionInterface $b)
578+
{
579+
}
580+
}
581+
543582
class Lille
544583
{
545584
}

0 commit comments

Comments
 (0)
0