PropertyInfoPassTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. class PropertyInfoPassTest extends TestCase
  15. {
  16. public function testServicesAreOrderedAccordingToPriority()
  17. {
  18. $services = array(
  19. 'n3' => array(array()),
  20. 'n1' => array(array('priority' => 200)),
  21. 'n2' => array(array('priority' => 100)),
  22. );
  23. $expected = array(
  24. new Reference('n1'),
  25. new Reference('n2'),
  26. new Reference('n3'),
  27. );
  28. $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
  29. $container->expects($this->any())
  30. ->method('findTaggedServiceIds')
  31. ->will($this->returnValue($services));
  32. $propertyInfoPass = new PropertyInfoPass();
  33. $method = new \ReflectionMethod(
  34. 'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass',
  35. 'findAndSortTaggedServices'
  36. );
  37. $method->setAccessible(true);
  38. $actual = $method->invoke($propertyInfoPass, 'tag', $container);
  39. $this->assertEquals($expected, $actual);
  40. }
  41. public function testReturningEmptyArrayWhenNoService()
  42. {
  43. $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
  44. $container->expects($this->any())
  45. ->method('findTaggedServiceIds')
  46. ->will($this->returnValue(array()));
  47. $propertyInfoPass = new PropertyInfoPass();
  48. $method = new \ReflectionMethod(
  49. 'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass',
  50. 'findAndSortTaggedServices'
  51. );
  52. $method->setAccessible(true);
  53. $actual = $method->invoke($propertyInfoPass, 'tag', $container);
  54. $this->assertEquals(array(), $actual);
  55. }
  56. }