@@ -193,22 +193,24 @@ public function testContainerWritesToStorage()
193193
194194 public function testSettingExpirationSecondsUpdatesStorageMetadataForFullContainer ()
195195 {
196+ $ currentTimestamp = time ();
196197 $ this ->container ->setExpirationSeconds (3600 );
197198 $ storage = $ this ->manager ->getStorage ();
198199 $ metadata = $ storage ->getMetadata ($ this ->container ->getName ());
199200 $ this ->assertArrayHasKey ('EXPIRE ' , $ metadata );
200- $ this ->assertEquals ($ _SERVER [ ' REQUEST_TIME ' ] + 3600 , $ metadata ['EXPIRE ' ]);
201+ $ this ->assertEquals ($ currentTimestamp + 3600 , $ metadata ['EXPIRE ' ]);
201202 }
202203
203204 public function testSettingExpirationSecondsForIndividualKeyUpdatesStorageMetadataForThatKey ()
204205 {
205206 $ this ->container ->foo = 'bar ' ;
207+ $ currentTimestamp = time ();
206208 $ this ->container ->setExpirationSeconds (3600 , 'foo ' );
207209 $ storage = $ this ->manager ->getStorage ();
208210 $ metadata = $ storage ->getMetadata ($ this ->container ->getName ());
209211 $ this ->assertArrayHasKey ('EXPIRE_KEYS ' , $ metadata );
210212 $ this ->assertArrayHasKey ('foo ' , $ metadata ['EXPIRE_KEYS ' ]);
211- $ this ->assertEquals ($ _SERVER [ ' REQUEST_TIME ' ] + 3600 , $ metadata ['EXPIRE_KEYS ' ]['foo ' ]);
213+ $ this ->assertEquals ($ currentTimestamp + 3600 , $ metadata ['EXPIRE_KEYS ' ]['foo ' ]);
212214 }
213215
214216 public function testMultipleCallsToExpirationSecondsAggregates ()
@@ -217,15 +219,29 @@ public function testMultipleCallsToExpirationSecondsAggregates()
217219 $ this ->container ->bar = 'baz ' ;
218220 $ this ->container ->baz = 'bat ' ;
219221 $ this ->container ->bat = 'bas ' ;
222+ $ currentTimestamp = time ();
220223 $ this ->container ->setExpirationSeconds (3600 );
221224 $ this ->container ->setExpirationSeconds (1800 , 'foo ' );
222225 $ this ->container ->setExpirationSeconds (900 , ['baz ' , 'bat ' ]);
223226 $ storage = $ this ->manager ->getStorage ();
224227 $ metadata = $ storage ->getMetadata ($ this ->container ->getName ());
225- $ this ->assertEquals ($ _SERVER ['REQUEST_TIME ' ] + 1800 , $ metadata ['EXPIRE_KEYS ' ]['foo ' ]);
226- $ this ->assertEquals ($ _SERVER ['REQUEST_TIME ' ] + 900 , $ metadata ['EXPIRE_KEYS ' ]['baz ' ]);
227- $ this ->assertEquals ($ _SERVER ['REQUEST_TIME ' ] + 900 , $ metadata ['EXPIRE_KEYS ' ]['bat ' ]);
228- $ this ->assertEquals ($ _SERVER ['REQUEST_TIME ' ] + 3600 , $ metadata ['EXPIRE ' ]);
228+ $ this ->assertEquals ($ currentTimestamp + 1800 , $ metadata ['EXPIRE_KEYS ' ]['foo ' ]);
229+ $ this ->assertEquals ($ currentTimestamp + 900 , $ metadata ['EXPIRE_KEYS ' ]['baz ' ]);
230+ $ this ->assertEquals ($ currentTimestamp + 900 , $ metadata ['EXPIRE_KEYS ' ]['bat ' ]);
231+ $ this ->assertEquals ($ currentTimestamp + 3600 , $ metadata ['EXPIRE ' ]);
232+ }
233+
234+ public function testSettingExpirationSecondsUsesCurrentTime ()
235+ {
236+ sleep (3 );
237+ $ this ->container ->setExpirationSeconds (2 );
238+ $ this ->container ->foo = 'bar ' ;
239+
240+ // Simulate a second request: overwrite the request time with current time()
241+ $ _SERVER ['REQUEST_TIME ' ] = time ();
242+ $ _SERVER ['REQUEST_TIME_FLOAT ' ] = microtime (true );
243+
244+ $ this ->assertEquals ('bar ' , $ this ->container ->foo );
229245 }
230246
231247 public function testPassingUnsetKeyToSetExpirationSecondsDoesNothing ()
0 commit comments