CacheWarmerAggregateTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
  13. class CacheWarmerAggregateTest extends TestCase
  14. {
  15. protected static $cacheDir;
  16. public static function setUpBeforeClass()
  17. {
  18. self::$cacheDir = tempnam(sys_get_temp_dir(), 'sf_cache_warmer_dir');
  19. }
  20. public static function tearDownAfterClass()
  21. {
  22. @unlink(self::$cacheDir);
  23. }
  24. public function testInjectWarmersUsingConstructor()
  25. {
  26. $warmer = $this->getCacheWarmerMock();
  27. $warmer
  28. ->expects($this->once())
  29. ->method('warmUp');
  30. $aggregate = new CacheWarmerAggregate([$warmer]);
  31. $aggregate->warmUp(self::$cacheDir);
  32. }
  33. public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled()
  34. {
  35. $warmer = $this->getCacheWarmerMock();
  36. $warmer
  37. ->expects($this->never())
  38. ->method('isOptional');
  39. $warmer
  40. ->expects($this->once())
  41. ->method('warmUp');
  42. $aggregate = new CacheWarmerAggregate([$warmer]);
  43. $aggregate->enableOptionalWarmers();
  44. $aggregate->warmUp(self::$cacheDir);
  45. }
  46. public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsNotEnabled()
  47. {
  48. $warmer = $this->getCacheWarmerMock();
  49. $warmer
  50. ->expects($this->once())
  51. ->method('isOptional')
  52. ->will($this->returnValue(true));
  53. $warmer
  54. ->expects($this->never())
  55. ->method('warmUp');
  56. $aggregate = new CacheWarmerAggregate([$warmer]);
  57. $aggregate->warmUp(self::$cacheDir);
  58. }
  59. protected function getCacheWarmerMock()
  60. {
  61. $warmer = $this->getMockBuilder('Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface')
  62. ->disableOriginalConstructor()
  63. ->getMock();
  64. return $warmer;
  65. }
  66. }