|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass; |
| 15 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | +use Symfony\Component\DependencyInjection\Definition; |
| 17 | +use Symfony\Component\DependencyInjection\Reference; |
| 18 | +use Symfony\Component\HttpKernel\Controller\ArgumentResolver; |
| 19 | + |
| 20 | +class ControllerArgumentValueResolverPassTest extends \PHPUnit_Framework_TestCase |
| 21 | +{ |
| 22 | + public function testServicesAreOrderedAccordingToPriority() |
| 23 | + { |
| 24 | + $services = array( |
| 25 | + 'n3' => array(array()), |
| 26 | + 'n1' => array(array('priority' => 200)), |
| 27 | + 'n2' => array(array('priority' => 100)), |
| 28 | + ); |
| 29 | + |
| 30 | + $expected = array( |
| 31 | + new Reference('n1'), |
| 32 | + new Reference('n2'), |
| 33 | + new Reference('n3'), |
| 34 | + ); |
| 35 | + |
| 36 | + $definition = new Definition(ArgumentResolver::class, array(null, array())); |
| 37 | + $container = new ContainerBuilder(); |
| 38 | + $container->setDefinition('argument_resolver', $definition); |
| 39 | + |
| 40 | + foreach ($services as $id => list($tag)) { |
| 41 | + $container->register($id)->addTag('controller.argument_value_resolver', $tag); |
| 42 | + } |
| 43 | + |
| 44 | + (new ControllerArgumentValueResolverPass())->process($container); |
| 45 | + $this->assertEquals($expected, $definition->getArgument(1)); |
| 46 | + } |
| 47 | + |
| 48 | + public function testReturningEmptyArrayWhenNoService() |
| 49 | + { |
| 50 | + $definition = new Definition(ArgumentResolver::class, array(null, array())); |
| 51 | + $container = new ContainerBuilder(); |
| 52 | + $container->setDefinition('argument_resolver', $definition); |
| 53 | + |
| 54 | + (new ControllerArgumentValueResolverPass())->process($container); |
| 55 | + $this->assertEquals(array(), $definition->getArgument(1)); |
| 56 | + } |
| 57 | + |
| 58 | + public function testNoArgumentResolver() |
| 59 | + { |
| 60 | + $container = new ContainerBuilder(); |
| 61 | + |
| 62 | + (new ControllerArgumentValueResolverPass())->process($container); |
| 63 | + } |
| 64 | +} |
0 commit comments