1717use CodeIgniter \HTTP \ResponseInterface ;
1818use CodeIgniter \HTTP \SiteURI ;
1919use CodeIgniter \HTTP \UserAgent ;
20+ use CodeIgniter \I18n \Time ;
2021use CodeIgniter \Test \CIUnitTestCase ;
2122use CodeIgniter \Test \Mock \MockAppConfig ;
2223use Config \Services ;
@@ -34,6 +35,15 @@ protected function setUp(): void
3435
3536 // Clear cache before each test
3637 cache ()->clean ();
38+
39+ Time::setTestNow ('2026-01-10 12:00:00 ' );
40+ }
41+
42+ protected function tearDown (): void
43+ {
44+ parent ::tearDown ();
45+
46+ Time::setTestNow ();
3747 }
3848
3949 public function testConstructorDefaults (): void
@@ -73,7 +83,7 @@ public function testBeforeReturnsCachedResponseWhenFound(): void
7383 'body ' => 'Cached content ' ,
7484 'status ' => 200 ,
7585 'headers ' => ['Content-Type ' => 'text/html ' ],
76- 'timestamp ' => time () - 10 ,
86+ 'timestamp ' => Time:: now ()-> getTimestamp () - 10 ,
7787 ];
7888 cache ()->save ($ cacheKey , $ cachedData , 3600 );
7989
@@ -124,7 +134,7 @@ public function testBeforeUsesCustomCacheKey(): void
124134 'body ' => 'Custom cached content ' ,
125135 'status ' => 200 ,
126136 'headers ' => [],
127- 'timestamp ' => time (),
137+ 'timestamp ' => Time:: now ()-> getTimestamp (),
128138 ];
129139 cache ()->save ('my_custom_key ' , $ cachedData , 3600 );
130140
0 commit comments