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 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..2cd155aa22de 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,15 @@ protected function setUp(): void // Clear cache before each test cache()->clean(); + + Time::setTestNow('2026-01-10 12:00:00'); + } + + protected function tearDown(): void + { + parent::tearDown(); + + Time::setTestNow(); } public function testConstructorDefaults(): void @@ -73,7 +83,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 +134,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);