@@ -205,6 +205,36 @@ public function testCacheAddCallsRedisStoreAdd()
205
205
$ this ->assertTrue ($ repository ->add ('k ' , 'v ' , 60 ));
206
206
}
207
207
208
+ public function testAddMethodCanAcceptDateIntervals ()
209
+ {
210
+ $ storeWithAdd = m::mock (RedisStore::class);
211
+ $ storeWithAdd ->shouldReceive ('add ' )->once ()->with ('k ' , 'v ' , 61 )->andReturn (true );
212
+ $ repository = new Repository ($ storeWithAdd );
213
+ $ this ->assertTrue ($ repository ->add ('k ' , 'v ' , DateInterval::createFromDateString ('61 seconds ' )));
214
+
215
+ $ storeWithoutAdd = m::mock (ArrayStore::class);
216
+ $ this ->assertFalse (method_exists (ArrayStore::class, 'add ' ), 'This store should not have add method on it. ' );
217
+ $ storeWithoutAdd ->shouldReceive ('get ' )->once ()->with ('k ' )->andReturn (null );
218
+ $ storeWithoutAdd ->shouldReceive ('put ' )->once ()->with ('k ' , 'v ' , 60 )->andReturn (true );
219
+ $ repository = new Repository ($ storeWithoutAdd );
220
+ $ this ->assertTrue ($ repository ->add ('k ' , 'v ' , DateInterval::createFromDateString ('60 seconds ' )));
221
+ }
222
+
223
+ public function testAddMethodCanAcceptDateTimeInterface ()
224
+ {
225
+ $ withAddStore = m::mock (RedisStore::class);
226
+ $ withAddStore ->shouldReceive ('add ' )->once ()->with ('k ' , 'v ' , 61 )->andReturn (true );
227
+ $ repository = new Repository ($ withAddStore );
228
+ $ this ->assertTrue ($ repository ->add ('k ' , 'v ' , Carbon::now ()->addSeconds (61 )));
229
+
230
+ $ noAddStore = m::mock (ArrayStore::class);
231
+ $ this ->assertFalse (method_exists (ArrayStore::class, 'add ' ), 'This store should not have add method on it. ' );
232
+ $ noAddStore ->shouldReceive ('get ' )->once ()->with ('k ' )->andReturn (null );
233
+ $ noAddStore ->shouldReceive ('put ' )->once ()->with ('k ' , 'v ' , 62 )->andReturn (true );
234
+ $ repository = new Repository ($ noAddStore );
235
+ $ this ->assertTrue ($ repository ->add ('k ' , 'v ' , Carbon::now ()->addSeconds (62 )));
236
+ }
237
+
208
238
public function testAddWithNullTTLRemembersItemForever ()
209
239
{
210
240
$ repo = $ this ->getRepository ();
@@ -221,6 +251,8 @@ public function testAddWithDatetimeInPastOrZeroSecondsReturnsImmediately()
221
251
$ this ->assertFalse ($ result );
222
252
$ result = $ repo ->add ('foo ' , 'bar ' , Carbon::now ());
223
253
$ this ->assertFalse ($ result );
254
+ $ result = $ repo ->add ('foo ' , 'bar ' , -1 );
255
+ $ this ->assertFalse ($ result );
224
256
}
225
257
226
258
public function dataProviderTestGetSeconds ()
0 commit comments