CacheWarmerAggregateTest.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(), 'sf2_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(array($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(array($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(array($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. }