Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 317b677

Browse files
[DI] Bug in autowiring collisions detection
1 parent 2fee5bc commit 317b677

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,29 @@ 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+
yield array('CannotBeAutowiredForwardOrder');
483+
yield array('CannotBeAutowiredReverseOrder');
484+
}
462485
}
463486

464487
class Foo
@@ -540,6 +563,20 @@ public function __construct(CollisionInterface $collision)
540563
}
541564
}
542565

566+
class CannotBeAutowiredForwardOrder
567+
{
568+
public function __construct(CollisionA $a, CollisionInterface $b, CollisionB $c)
569+
{
570+
}
571+
}
572+
573+
class CannotBeAutowiredReverseOrder
574+
{
575+
public function __construct(CollisionA $a, CollisionB $c, CollisionInterface $b)
576+
{
577+
}
578+
}
579+
543580
class Lille
544581
{
545582
}

0 commit comments

Comments
 (0)