File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -624,7 +624,9 @@ protected function getSeconds($ttl)
624
624
$ duration = $ this ->parseDateInterval ($ ttl );
625
625
626
626
if ($ duration instanceof DateTimeInterface) {
627
- $ duration = Carbon::now ()->diffInSeconds ($ duration , false );
627
+ $ duration = (int ) ceil (
628
+ Carbon::now ()->diffInMilliseconds ($ duration , false ) / 1000
629
+ );
628
630
}
629
631
630
632
return (int ) ($ duration > 0 ? $ duration : 0 );
Original file line number Diff line number Diff line change 2
2
3
3
namespace Illuminate \Tests \Integration \Cache ;
4
4
5
+ use Illuminate \Cache \Events \KeyWritten ;
5
6
use Illuminate \Foundation \Testing \LazilyRefreshDatabase ;
6
7
use Illuminate \Support \Carbon ;
7
8
use Illuminate \Support \Facades \Cache ;
9
+ use Illuminate \Support \Facades \Event ;
8
10
use Orchestra \Testbench \Attributes \WithMigration ;
9
11
use Orchestra \Testbench \TestCase ;
10
12
@@ -235,4 +237,21 @@ public function testItImplicitlyClearsTtlKeysFromFileDriver()
235
237
$ this ->assertFalse ($ cache ->getFilesystem ()->exists ($ cache ->path ('illuminate:cache:flexible:created:count ' )));
236
238
$ this ->assertTrue ($ cache ->missing ('illuminate:cache:flexible:created:count ' ));
237
239
}
240
+
241
+ public function testItRoundsDateTimeValuesToAccountForTimePassedDuringScriptExecution ()
242
+ {
243
+ // do not freeze time as this test depends on time progressing duration execution.
244
+ $ cache = Cache::driver ('array ' );
245
+ $ events = [];
246
+ Event::listen (function (KeyWritten $ event ) use (&$ events ) {
247
+ $ events [] = $ event ;
248
+ });
249
+
250
+ $ result = $ cache ->put ('foo ' , 'bar ' , now ()->addSecond ());
251
+
252
+ $ this ->assertTrue ($ result );
253
+ $ this ->assertCount (1 , $ events );
254
+ $ this ->assertSame ('foo ' , $ events [0 ]->key );
255
+ $ this ->assertSame (1 , $ events [0 ]->seconds );
256
+ }
238
257
}
You can’t perform that action at this time.
0 commit comments