1616use Symfony \Component \Cache \Adapter \ArrayAdapter ;
1717use Symfony \Component \Cache \Adapter \ChainAdapter ;
1818use Symfony \Component \Cache \Adapter \FilesystemAdapter ;
19+ use Symfony \Component \Cache \CacheItem ;
1920use Symfony \Component \Cache \Tests \Fixtures \ExternalAdapter ;
2021use Symfony \Component \Cache \Tests \Fixtures \PrunableAdapter ;
22+ use Symfony \Contracts \Cache \ItemInterface ;
2123
2224/**
2325 * @author Kévin Dunglas <dunglas@gmail.com>
@@ -34,6 +36,11 @@ public function createCachePool(int $defaultLifetime = 0, string $testMethod = n
3436return new ChainAdapter ([new ArrayAdapter ($ defaultLifetime ),new ExternalAdapter ($ defaultLifetime ),new FilesystemAdapter ('' ,$ defaultLifetime )],$ defaultLifetime );
3537 }
3638
39+ public static function tearDownAfterClass ():void
40+ {
41+ FilesystemAdapterTest::rmdir (sys_get_temp_dir ().'/symfony-cache ' );
42+ }
43+
3744public function testEmptyAdaptersException ()
3845 {
3946$ this ->expectException ('Symfony\Component\Cache\Exception\InvalidArgumentException ' );
@@ -187,6 +194,48 @@ public function testMultipleCachesExpirationWhenCommonTtlIsSet()
187194$ this ->assertFalse ($ item ->isHit ());
188195 }
189196
197+ public function testExpirationOnAllAdapters ()
198+ {
199+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
200+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
201+ }
202+
203+ $ itemValidator =function (CacheItem $ item ) {
204+ $ refl =new \ReflectionObject ($ item );
205+ $ propExpiry =$ refl ->getProperty ('expiry ' );
206+ $ propExpiry ->setAccessible (true );
207+ $ expiry =$ propExpiry ->getValue ($ item );
208+ $ this ->assertGreaterThan (10 ,$ expiry -time (),'Item should be saved with the given ttl, not the default for the adapter. ' );
209+
210+ return true ;
211+ };
212+
213+ $ adapter1 =$ this ->getMockBuilder (FilesystemAdapter::class)
214+ ->setConstructorArgs (['' ,2 ])
215+ ->setMethods (['save ' ])
216+ ->getMock ();
217+ $ adapter1 ->expects ($ this ->once ())
218+ ->method ('save ' )
219+ ->with ($ this ->callback ($ itemValidator ))
220+ ->willReturn (true );
221+
222+ $ adapter2 =$ this ->getMockBuilder (FilesystemAdapter::class)
223+ ->setConstructorArgs (['' ,4 ])
224+ ->setMethods (['save ' ])
225+ ->getMock ();
226+ $ adapter2 ->expects ($ this ->once ())
227+ ->method ('save ' )
228+ ->with ($ this ->callback ($ itemValidator ))
229+ ->willReturn (true );
230+
231+ $ cache =new ChainAdapter ([$ adapter1 ,$ adapter2 ],6 );
232+ $ cache ->get ('test_key ' ,function (ItemInterface $ item ) {
233+ $ item ->expiresAfter (15 );
234+
235+ return 'chain ' ;
236+ });
237+ }
238+
190239private function getPruneableMock ():AdapterInterface
191240 {
192241$ pruneable =$ this ->createMock (PrunableAdapter::class);