|
8 | 8 | use PHPUnit\Framework\MockObject\MockObject;
|
9 | 9 | use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
|
10 | 10 | use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
| 11 | +use Symfony\Component\Cache\Adapter\ArrayAdapter; |
11 | 12 | use Symfony\Component\Cache\Adapter\NullAdapter;
|
12 | 13 | use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
13 | 14 | use Symfony\Component\Cache\DoctrineProvider;
|
@@ -120,6 +121,36 @@ public function testClassAutoloadExceptionWithUnrelatedException()
|
120 | 121 | spl_autoload_unregister($classLoader);
|
121 | 122 | }
|
122 | 123 |
|
| 124 | + public function testWarmupRemoveCacheMisses() |
| 125 | + { |
| 126 | + $cacheFile = tempnam($this->cacheDir, __FUNCTION__); |
| 127 | + $warmer = $this->getMockBuilder(AnnotationsCacheWarmer::class) |
| 128 | + ->setConstructorArgs([new AnnotationReader(), $cacheFile]) |
| 129 | + ->onlyMethods(['doWarmUp']) |
| 130 | + ->getMock(); |
| 131 | + |
| 132 | + $warmer->method('doWarmUp')->willReturnCallback(function ($cacheDir, ArrayAdapter $arrayAdapter) { |
| 133 | + $arrayAdapter->getItem('foo_miss'); |
| 134 | + |
| 135 | + $item = $arrayAdapter->getItem('bar_hit'); |
| 136 | + $item->set('data'); |
| 137 | + $arrayAdapter->save($item); |
| 138 | + |
| 139 | + $item = $arrayAdapter->getItem('baz_hit_null'); |
| 140 | + $item->set(null); |
| 141 | + $arrayAdapter->save($item); |
| 142 | + |
| 143 | + return true; |
| 144 | + }); |
| 145 | + |
| 146 | + $warmer->warmUp($this->cacheDir); |
| 147 | + $data = include $cacheFile; |
| 148 | + |
| 149 | + $this->assertCount(2, $data[0]); |
| 150 | + $this->assertTrue(isset($data[0]['bar_hit'])); |
| 151 | + $this->assertTrue(isset($data[0]['baz_hit_null'])); |
| 152 | + } |
| 153 | + |
123 | 154 | /**
|
124 | 155 | * @return MockObject|Reader
|
125 | 156 | */
|
|
0 commit comments