From bef0ec00c4cb105798f83f3b26edf158713ef9ec Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 8 May 2026 16:45:22 +0400 Subject: [PATCH] test: verify touch refreshes stale entries --- tests/Cache/Base.php | 5 ++++- tests/Cache/MemoryTest.php | 16 ---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/Cache/Base.php b/tests/Cache/Base.php index 6f90730d00..d5f9f013ba 100644 --- a/tests/Cache/Base.php +++ b/tests/Cache/Base.php @@ -62,8 +62,11 @@ abstract class Base extends TestCase $result = self::$cache->save('touch-key', 'touch data', 'touch-key'); $this->assertEquals('touch data', $result); + sleep(2); + + $this->assertEquals(false, self::$cache->load('touch-key', 1, 'touch-key')); $this->assertEquals(true, self::$cache->touch('touch-key', 'touch-key')); - $this->assertEquals('touch data', self::$cache->load('touch-key', 60, 'touch-key')); + $this->assertEquals('touch data', self::$cache->load('touch-key', 1, 'touch-key')); $this->assertEquals(false, self::$cache->touch('missing-touch-key', 'missing-touch-key')); self::$cache->purge('touch-key'); diff --git a/tests/Cache/MemoryTest.php b/tests/Cache/MemoryTest.php index 6b99ffd117..b3e2a7683b 100644 --- a/tests/Cache/MemoryTest.php +++ b/tests/Cache/MemoryTest.php @@ -20,20 +20,4 @@ class MemoryTest extends Base self::$cache->save('test:file36', 'file36'); $this->assertEquals(4, self::$cache->getSize()); } - - public function testTouchExpiredEntry(): void - { - $adapter = new Memory(); - $cache = new Cache($adapter); - - $cache->save('expired-touch-key', 'expired data'); - /** @var array{time: int, data: string} $stored */ - $stored = $adapter->store['expired-touch-key']; - $stored['time'] = time() - 10; - $adapter->store['expired-touch-key'] = $stored; - - $this->assertEquals(false, $cache->load('expired-touch-key', 1)); - $this->assertEquals(true, $cache->touch('expired-touch-key')); - $this->assertEquals('expired data', $cache->load('expired-touch-key', 1)); - } }