ControllerArgumentValueResolverPassTest.php 2.3 KB

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