Version 1
[yaffs-website] / vendor / symfony / http-kernel / Tests / CacheWarmer / CacheWarmerAggregateTest.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\CacheWarmerAggregate;
16
17 class CacheWarmerAggregateTest extends TestCase
18 {
19     protected static $cacheDir;
20
21     public static function setUpBeforeClass()
22     {
23         self::$cacheDir = tempnam(sys_get_temp_dir(), 'sf2_cache_warmer_dir');
24     }
25
26     public static function tearDownAfterClass()
27     {
28         @unlink(self::$cacheDir);
29     }
30
31     public function testInjectWarmersUsingConstructor()
32     {
33         $warmer = $this->getCacheWarmerMock();
34         $warmer
35             ->expects($this->once())
36             ->method('warmUp');
37         $aggregate = new CacheWarmerAggregate(array($warmer));
38         $aggregate->warmUp(self::$cacheDir);
39     }
40
41     public function testInjectWarmersUsingAdd()
42     {
43         $warmer = $this->getCacheWarmerMock();
44         $warmer
45             ->expects($this->once())
46             ->method('warmUp');
47         $aggregate = new CacheWarmerAggregate();
48         $aggregate->add($warmer);
49         $aggregate->warmUp(self::$cacheDir);
50     }
51
52     public function testInjectWarmersUsingSetWarmers()
53     {
54         $warmer = $this->getCacheWarmerMock();
55         $warmer
56             ->expects($this->once())
57             ->method('warmUp');
58         $aggregate = new CacheWarmerAggregate();
59         $aggregate->setWarmers(array($warmer));
60         $aggregate->warmUp(self::$cacheDir);
61     }
62
63     public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled()
64     {
65         $warmer = $this->getCacheWarmerMock();
66         $warmer
67             ->expects($this->never())
68             ->method('isOptional');
69         $warmer
70             ->expects($this->once())
71             ->method('warmUp');
72
73         $aggregate = new CacheWarmerAggregate(array($warmer));
74         $aggregate->enableOptionalWarmers();
75         $aggregate->warmUp(self::$cacheDir);
76     }
77
78     public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsNotEnabled()
79     {
80         $warmer = $this->getCacheWarmerMock();
81         $warmer
82             ->expects($this->once())
83             ->method('isOptional')
84             ->will($this->returnValue(true));
85         $warmer
86             ->expects($this->never())
87             ->method('warmUp');
88
89         $aggregate = new CacheWarmerAggregate(array($warmer));
90         $aggregate->warmUp(self::$cacheDir);
91     }
92
93     protected function getCacheWarmerMock()
94     {
95         $warmer = $this->getMockBuilder('Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface')
96             ->disableOriginalConstructor()
97             ->getMock();
98
99         return $warmer;
100     }
101 }