AddCacheWarmerPassTest.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\AddCacheWarmerPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. class AddCacheWarmerPassTest extends TestCase
  16. {
  17. public function testThatCacheWarmersAreProcessedInPriorityOrder()
  18. {
  19. $container = new ContainerBuilder();
  20. $cacheWarmerDefinition = $container->register('cache_warmer')->addArgument(array());
  21. $container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', array('priority' => 100));
  22. $container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', array('priority' => 200));
  23. $container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer');
  24. $addCacheWarmerPass = new AddCacheWarmerPass();
  25. $addCacheWarmerPass->process($container);
  26. $this->assertEquals(
  27. array(
  28. new Reference('my_cache_warmer_service2'),
  29. new Reference('my_cache_warmer_service1'),
  30. new Reference('my_cache_warmer_service3'),
  31. ),
  32. $cacheWarmerDefinition->getArgument(0)
  33. );
  34. }
  35. public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
  36. {
  37. $container = new ContainerBuilder();
  38. $addCacheWarmerPass = new AddCacheWarmerPass();
  39. $addCacheWarmerPass->process($container);
  40. // we just check that the pass does not break if no cache warmer is registered
  41. $this->addToAssertionCount(1);
  42. }
  43. public function testThatCacheWarmersMightBeNotDefined()
  44. {
  45. $container = new ContainerBuilder();
  46. $cacheWarmerDefinition = $container->register('cache_warmer')->addArgument(array());
  47. $addCacheWarmerPass = new AddCacheWarmerPass();
  48. $addCacheWarmerPass->process($container);
  49. $this->assertSame(array(), $cacheWarmerDefinition->getArgument(0));
  50. }
  51. }