|
12 | 12 | namespace Symfony\Component\Cache\Tests\Adapter;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\MockObject\MockObject;
|
| 15 | +use Psr\Cache\CacheItemInterface; |
15 | 16 | use Symfony\Component\Cache\Adapter\AdapterInterface;
|
16 | 17 | use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
17 | 18 | use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
@@ -160,6 +161,39 @@ public function testPrune()
|
160 | 161 | $this->assertFalse($cache->prune());
|
161 | 162 | }
|
162 | 163 |
|
| 164 | + public function testKnownTagVersionsTtl() |
| 165 | + { |
| 166 | + $itemsPool = new FilesystemAdapter('', 10); |
| 167 | + $tagsPool = $this |
| 168 | + ->getMockBuilder(AdapterInterface::class) |
| 169 | + ->getMock(); |
| 170 | + |
| 171 | + $pool = new TagAwareAdapter($itemsPool, $tagsPool, 10); |
| 172 | + |
| 173 | + $item = $pool->getItem('foo'); |
| 174 | + $item->tag(['baz']); |
| 175 | + $item->expiresAfter(100); |
| 176 | + |
| 177 | + $tag = $this->getMockBuilder(CacheItemInterface::class)->getMock(); |
| 178 | + $tag->expects(self::exactly(2))->method('get')->willReturn(10); |
| 179 | + |
| 180 | + $tagsPool->expects(self::exactly(2))->method('getItems')->willReturn([ |
| 181 | + 'baz'.TagAwareAdapter::TAGS_PREFIX => $tag, |
| 182 | + ]); |
| 183 | + |
| 184 | + $pool->save($item); |
| 185 | + $this->assertTrue($pool->getItem('foo')->isHit()); |
| 186 | + $this->assertTrue($pool->getItem('foo')->isHit()); |
| 187 | + |
| 188 | + sleep(20); |
| 189 | + |
| 190 | + $this->assertTrue($pool->getItem('foo')->isHit()); |
| 191 | + |
| 192 | + sleep(5); |
| 193 | + |
| 194 | + $this->assertTrue($pool->getItem('foo')->isHit()); |
| 195 | + } |
| 196 | + |
163 | 197 | /**
|
164 | 198 | * @return MockObject|PruneableCacheInterface
|
165 | 199 | */
|
|
0 commit comments