ConfigCachePassTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\ConfigCachePass;
  13. use Symfony\Component\DependencyInjection\Reference;
  14. class ConfigCachePassTest extends TestCase
  15. {
  16. public function testThatCheckersAreProcessedInPriorityOrder()
  17. {
  18. $services = array(
  19. 'checker_2' => array(0 => array('priority' => 100)),
  20. 'checker_1' => array(0 => array('priority' => 200)),
  21. 'checker_3' => array(),
  22. );
  23. $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
  24. $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();
  25. $container->expects($this->atLeastOnce())
  26. ->method('findTaggedServiceIds')
  27. ->will($this->returnValue($services));
  28. $container->expects($this->atLeastOnce())
  29. ->method('getDefinition')
  30. ->with('config_cache_factory')
  31. ->will($this->returnValue($definition));
  32. $definition->expects($this->once())
  33. ->method('replaceArgument')
  34. ->with(0, array(
  35. new Reference('checker_1'),
  36. new Reference('checker_2'),
  37. new Reference('checker_3'),
  38. ));
  39. $pass = new ConfigCachePass();
  40. $pass->process($container);
  41. }
  42. public function testThatCheckersCanBeMissing()
  43. {
  44. $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
  45. $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
  46. $container->expects($this->atLeastOnce())
  47. ->method('findTaggedServiceIds')
  48. ->will($this->returnValue(array()));
  49. $pass = new ConfigCachePass();
  50. $pass->process($container);
  51. }
  52. }