No Description

CacheWarmerAggregateTest.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\CacheWarmer;
  11. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
  12. class CacheWarmerAggregateTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected static $cacheDir;
  15. public static function setUpBeforeClass()
  16. {
  17. self::$cacheDir = tempnam(sys_get_temp_dir(), 'sf2_cache_warmer_dir');
  18. }
  19. public static function tearDownAfterClass()
  20. {
  21. @unlink(self::$cacheDir);
  22. }
  23. public function testInjectWarmersUsingConstructor()
  24. {
  25. $warmer = $this->getCacheWarmerMock();
  26. $warmer
  27. ->expects($this->once())
  28. ->method('warmUp');
  29. $aggregate = new CacheWarmerAggregate(array($warmer));
  30. $aggregate->warmUp(self::$cacheDir);
  31. }
  32. public function testInjectWarmersUsingAdd()
  33. {
  34. $warmer = $this->getCacheWarmerMock();
  35. $warmer
  36. ->expects($this->once())
  37. ->method('warmUp');
  38. $aggregate = new CacheWarmerAggregate();
  39. $aggregate->add($warmer);
  40. $aggregate->warmUp(self::$cacheDir);
  41. }
  42. public function testInjectWarmersUsingSetWarmers()
  43. {
  44. $warmer = $this->getCacheWarmerMock();
  45. $warmer
  46. ->expects($this->once())
  47. ->method('warmUp');
  48. $aggregate = new CacheWarmerAggregate();
  49. $aggregate->setWarmers(array($warmer));
  50. $aggregate->warmUp(self::$cacheDir);
  51. }
  52. public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled()
  53. {
  54. $warmer = $this->getCacheWarmerMock();
  55. $warmer
  56. ->expects($this->never())
  57. ->method('isOptional');
  58. $warmer
  59. ->expects($this->once())
  60. ->method('warmUp');
  61. $aggregate = new CacheWarmerAggregate(array($warmer));
  62. $aggregate->enableOptionalWarmers();
  63. $aggregate->warmUp(self::$cacheDir);
  64. }
  65. public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsNotEnabled()
  66. {
  67. $warmer = $this->getCacheWarmerMock();
  68. $warmer
  69. ->expects($this->once())
  70. ->method('isOptional')
  71. ->will($this->returnValue(true));
  72. $warmer
  73. ->expects($this->never())
  74. ->method('warmUp');
  75. $aggregate = new CacheWarmerAggregate(array($warmer));
  76. $aggregate->warmUp(self::$cacheDir);
  77. }
  78. protected function getCacheWarmerMock()
  79. {
  80. $warmer = $this->getMockBuilder('Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface')
  81. ->disableOriginalConstructor()
  82. ->getMock();
  83. return $warmer;
  84. }
  85. }