From f8dc4e31be03df5b0c644e215cf1fe92c0a62bd0 Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Mon, 30 Dec 2024 11:31:44 +0100 Subject: [PATCH] Add failing test for https://github.com/yiisoft/yii2/issues/20300 --- tests/framework/caching/FileCacheTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/framework/caching/FileCacheTest.php b/tests/framework/caching/FileCacheTest.php index aa12bf9cc13..868bae40c85 100644 --- a/tests/framework/caching/FileCacheTest.php +++ b/tests/framework/caching/FileCacheTest.php @@ -82,4 +82,24 @@ public function testKeyPrefix() $this->assertTrue(is_dir(dirname($cacheFile)), 'File not found ' . $cacheFile); $this->assertEquals($value, $refMethodGet->invoke($cache, $key)); } + + public function testStatCache() + { + $cache = $this->getCacheInstance(); + $cache->set(__FUNCTION__, 'cache1', 2); + + $normalizeKey = $cache->buildKey(__FUNCTION__); + $refClass = new \ReflectionClass($cache); + $refMethodGetCacheFile = $refClass->getMethod('getCacheFile'); + $refMethodGetCacheFile->setAccessible(true); + $cacheFile = $refMethodGetCacheFile->invoke($cache, $normalizeKey); + + // simulate cache expire 10 seconds ago + touch($cacheFile, time() - 10); + clearstatcache(); + + $this->assertFalse($cache->get(__FUNCTION__)); + $this->assertTrue($cache->set(__FUNCTION__, 'cache2', 2)); + $this->assertSame('cache2', $cache->get(__FUNCTION__)); + } }