Sin descripción

CacheWarmerTest.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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->assertFileExists(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. }