CacheWarmerAggregateTest.php 2.1 KB

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