05666cb0dcdc7570da7b8e8f55c48def351f3d3a
[yaffs-website] / vendor / symfony / http-kernel / Tests / CacheWarmer / CacheWarmerTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\CacheWarmer;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
16
17 class CacheWarmerTest extends TestCase
18 {
19     protected static $cacheFile;
20
21     public static function setUpBeforeClass()
22     {
23         self::$cacheFile = tempnam(sys_get_temp_dir(), 'sf2_cache_warmer_dir');
24     }
25
26     public static function tearDownAfterClass()
27     {
28         @unlink(self::$cacheFile);
29     }
30
31     public function testWriteCacheFileCreatesTheFile()
32     {
33         $warmer = new TestCacheWarmer(self::$cacheFile);
34         $warmer->warmUp(dirname(self::$cacheFile));
35
36         $this->assertFileExists(self::$cacheFile);
37     }
38
39     /**
40      * @expectedException \RuntimeException
41      */
42     public function testWriteNonWritableCacheFileThrowsARuntimeException()
43     {
44         $nonWritableFile = '/this/file/is/very/probably/not/writable';
45         $warmer = new TestCacheWarmer($nonWritableFile);
46         $warmer->warmUp(dirname($nonWritableFile));
47     }
48 }
49
50 class TestCacheWarmer extends CacheWarmer
51 {
52     protected $file;
53
54     public function __construct($file)
55     {
56         $this->file = $file;
57     }
58
59     public function warmUp($cacheDir)
60     {
61         $this->writeCacheFile($this->file, 'content');
62     }
63
64     public function isOptional()
65     {
66         return false;
67     }
68 }