From 6ffbcc20abefc31977ea0fb1bfc9e3655d133965 Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 10 Jan 2026 11:30:54 +0100 Subject: [PATCH 1/3] fix: make router cache attributes time independent --- system/Router/Attributes/Cache.php | 6 ++++-- tests/system/Router/Attributes/CacheTest.php | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/system/Router/Attributes/Cache.php b/system/Router/Attributes/Cache.php index 5bf083f5fe4a..447f9e48c260 100644 --- a/system/Router/Attributes/Cache.php +++ b/system/Router/Attributes/Cache.php @@ -16,6 +16,7 @@ use Attribute; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\I18n\Time; /** * Cache Attribute @@ -74,7 +75,8 @@ public function before(RequestInterface $request): RequestInterface|ResponseInte foreach ($cached['headers'] as $name => $value) { $response->setHeader($name, $value); } - $response->setHeader('Age', (string) (time() - ($cached['timestamp'] ?? time()))); + $time = Time::now()->getTimestamp(); + $response->setHeader('Age', (string) ($time - ($cached['timestamp'] ?? $time))); return $response; } @@ -122,7 +124,7 @@ public function after(RequestInterface $request, ResponseInterface $response): ? 'body' => $response->getBody(), 'headers' => $headers, 'status' => $response->getStatusCode(), - 'timestamp' => time(), + 'timestamp' => Time::now()->getTimestamp(), ]; cache()->save($cacheKey, $data, $this->for); diff --git a/tests/system/Router/Attributes/CacheTest.php b/tests/system/Router/Attributes/CacheTest.php index 2eb114c9cd87..a8c2184ebe41 100644 --- a/tests/system/Router/Attributes/CacheTest.php +++ b/tests/system/Router/Attributes/CacheTest.php @@ -17,6 +17,7 @@ use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\SiteURI; use CodeIgniter\HTTP\UserAgent; +use CodeIgniter\I18n\Time; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockAppConfig; use Config\Services; @@ -34,6 +35,8 @@ protected function setUp(): void // Clear cache before each test cache()->clean(); + + Time::setTestNow('2026-01-10 12:00:00'); } public function testConstructorDefaults(): void @@ -73,7 +76,7 @@ public function testBeforeReturnsCachedResponseWhenFound(): void 'body' => 'Cached content', 'status' => 200, 'headers' => ['Content-Type' => 'text/html'], - 'timestamp' => time() - 10, + 'timestamp' => Time::now()->getTimestamp() - 10, ]; cache()->save($cacheKey, $cachedData, 3600); @@ -124,7 +127,7 @@ public function testBeforeUsesCustomCacheKey(): void 'body' => 'Custom cached content', 'status' => 200, 'headers' => [], - 'timestamp' => time(), + 'timestamp' => Time::now()->getTimestamp(), ]; cache()->save('my_custom_key', $cachedData, 3600); From 4afc622b6e611237414b0273b6bd45a6c32966b9 Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 10 Jan 2026 12:29:27 +0100 Subject: [PATCH 2/3] reset test time --- tests/system/Router/Attributes/CacheTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/system/Router/Attributes/CacheTest.php b/tests/system/Router/Attributes/CacheTest.php index a8c2184ebe41..2cd155aa22de 100644 --- a/tests/system/Router/Attributes/CacheTest.php +++ b/tests/system/Router/Attributes/CacheTest.php @@ -39,6 +39,13 @@ protected function setUp(): void Time::setTestNow('2026-01-10 12:00:00'); } + protected function tearDown(): void + { + parent::tearDown(); + + Time::setTestNow(); + } + public function testConstructorDefaults(): void { $cache = new Cache(); From 7230ce8498164bca8077e1632c1fb5cbc805910e Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 10 Jan 2026 12:29:38 +0100 Subject: [PATCH 3/3] update deptrac --- deptrac.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/deptrac.yaml b/deptrac.yaml index a35887183f05..4f7d8367bae6 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -226,6 +226,7 @@ deptrac: - +Controller Router: - HTTP + - I18n Security: - Cookie - I18n