CacheWarmerTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\CacheWarmer;
  12. class CacheWarmerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected static $cacheFile;
  15. public static function setUpBeforeClass()
  16. {
  17. self::$cacheFile = tempnam(sys_get_temp_dir(), 'sf2_cache_warmer_dir');
  18. }
  19. public static function tearDownAfterClass()
  20. {
  21. @unlink(self::$cacheFile);
  22. }
  23. public function testWriteCacheFileCreatesTheFile()
  24. {
  25. $warmer = new TestCacheWarmer(self::$cacheFile);
  26. $warmer->warmUp(dirname(self::$cacheFile));
  27. $this->assertTrue(file_exists(self::$cacheFile));
  28. }
  29. /**
  30. * @expectedException \RuntimeException
  31. */
  32. public function testWriteNonWritableCacheFileThrowsARuntimeException()
  33. {
  34. $nonWritableFile = '/this/file/is/very/probably/not/writable';
  35. $warmer = new TestCacheWarmer($nonWritableFile);
  36. $warmer->warmUp(dirname($nonWritableFile));
  37. }
  38. }
  39. class TestCacheWarmer extends CacheWarmer
  40. {
  41. protected $file;
  42. public function __construct($file)
  43. {
  44. $this->file = $file;
  45. }
  46. public function warmUp($cacheDir)
  47. {
  48. $this->writeCacheFile($this->file, 'content');
  49. }
  50. public function isOptional()
  51. {
  52. return false;
  53. }
  54. }