@@ -197,6 +197,24 @@ public function testAllModelResultsCreatesCache()
197
197
$ this ->assertEmpty ($ liveResults ->diffAssoc ($ cachedResults ));
198
198
}
199
199
200
+ public function testAvgModelResultsCreatesCache ()
201
+ {
202
+ $ authorId = (new Author )->with ('books ' , 'profile ' )
203
+ ->avg ('id ' );
204
+ $ key = 'genealabslaravelmodelcachingtestsfixturesauthor-avg_id ' ;
205
+ $ tags = [
206
+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
207
+ ];
208
+
209
+ $ cachedResult = cache ()->tags ($ tags )
210
+ ->get ($ key );
211
+ $ liveResult = (new UncachedAuthor )->with ('books ' , 'profile ' )
212
+ ->avg ('id ' );
213
+
214
+ $ this ->assertEquals ($ authorId , $ cachedResult );
215
+ $ this ->assertEquals ($ liveResult , $ cachedResult );
216
+ }
217
+
200
218
public function testChunkModelResultsCreatesCache ()
201
219
{
202
220
$ cachedChunks = collect ([
@@ -257,6 +275,24 @@ public function testCountModelResultsCreatesCache()
257
275
$ this ->assertEquals ($ liveResults , $ cachedResults );
258
276
}
259
277
278
+ public function testCursorModelResultsCreatesCache ()
279
+ {
280
+ $ authors = (new Author )->with ('books ' , 'profile ' )
281
+ ->cursor ();
282
+ $ key = 'genealabslaravelmodelcachingtestsfixturesauthor-cursor ' ;
283
+ $ tags = [
284
+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
285
+ ];
286
+
287
+ $ cachedResults = cache ()->tags ($ tags )
288
+ ->get ($ key );
289
+ $ liveResults = collect ((new UncachedAuthor )->with ('books ' , 'profile ' )
290
+ ->cursor ());
291
+
292
+ $ this ->assertEmpty ($ authors ->diffAssoc ($ cachedResults ));
293
+ $ this ->assertEmpty ($ liveResults ->diffAssoc ($ cachedResults ));
294
+ }
295
+
260
296
public function testFindModelResultsCreatesCache ()
261
297
{
262
298
$ author = (new Author )->find (1 );
@@ -293,15 +329,99 @@ public function testGetModelResultsCreatesCache()
293
329
$ this ->assertEmpty ($ liveResults ->diffAssoc ($ cachedResults ));
294
330
}
295
331
296
- // test cursor()
332
+ public function testMaxModelResultsCreatesCache ()
333
+ {
334
+ $ authorId = (new Author )->with ('books ' , 'profile ' )
335
+ ->max ('id ' );
336
+ $ key = 'genealabslaravelmodelcachingtestsfixturesauthor-max_id ' ;
337
+ $ tags = [
338
+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
339
+ ];
340
+
341
+ $ cachedResult = cache ()->tags ($ tags )
342
+ ->get ($ key );
343
+ $ liveResult = (new UncachedAuthor )->with ('books ' , 'profile ' )
344
+ ->max ('id ' );
297
345
298
- // test max()
346
+ $ this ->assertEquals ($ authorId , $ cachedResult );
347
+ $ this ->assertEquals ($ liveResult , $ cachedResult );
348
+ }
299
349
300
- // test min()
350
+ public function testMinModelResultsCreatesCache ()
351
+ {
352
+ $ authorId = (new Author )->with ('books ' , 'profile ' )
353
+ ->min ('id ' );
354
+ $ key = 'genealabslaravelmodelcachingtestsfixturesauthor-min_id ' ;
355
+ $ tags = [
356
+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
357
+ ];
301
358
302
- // test avg()
359
+ $ cachedResult = cache ()->tags ($ tags )
360
+ ->get ($ key );
361
+ $ liveResult = (new UncachedAuthor )->with ('books ' , 'profile ' )
362
+ ->min ('id ' );
303
363
304
- // test value()
364
+ $ this ->assertEquals ($ authorId , $ cachedResult );
365
+ $ this ->assertEquals ($ liveResult , $ cachedResult );
366
+ }
305
367
306
- // test pluck()
368
+ public function testPluckModelResultsCreatesCache ()
369
+ {
370
+ $ authors = (new Author )->with ('books ' , 'profile ' )
371
+ ->pluck ('id ' );
372
+ $ key = 'genealabslaravelmodelcachingtestsfixturesauthor_id-books-profile-pluck_id ' ;
373
+ $ tags = [
374
+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
375
+ 'genealabslaravelmodelcachingtestsfixturesbook ' ,
376
+ 'genealabslaravelmodelcachingtestsfixturesprofile ' ,
377
+ ];
378
+
379
+ $ cachedResults = cache ()->tags ($ tags )
380
+ ->get ($ key );
381
+ $ liveResults = (new UncachedAuthor )->with ('books ' , 'profile ' )
382
+ ->pluck ('id ' );
383
+
384
+ $ this ->assertEmpty ($ authors ->diffAssoc ($ cachedResults ));
385
+ $ this ->assertEmpty ($ liveResults ->diffAssoc ($ cachedResults ));
386
+ }
387
+
388
+ public function testSumModelResultsCreatesCache ()
389
+ {
390
+ $ authorId = (new Author )->with ('books ' , 'profile ' )
391
+ ->sum ('id ' );
392
+ $ key = 'genealabslaravelmodelcachingtestsfixturesauthor-sum_id ' ;
393
+ $ tags = [
394
+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
395
+ ];
396
+
397
+ $ cachedResult = cache ()->tags ($ tags )
398
+ ->get ($ key );
399
+ $ liveResult = (new UncachedAuthor )->with ('books ' , 'profile ' )
400
+ ->sum ('id ' );
401
+
402
+ $ this ->assertEquals ($ authorId , $ cachedResult );
403
+ $ this ->assertEquals ($ liveResult , $ cachedResult );
404
+ }
405
+
406
+ public function testValueModelResultsCreatesCache ()
407
+ {
408
+ $ authors = (new Author )->with ('books ' , 'profile ' )
409
+ ->value ('name ' );
410
+ $ key = 'genealabslaravelmodelcachingtestsfixturesauthor_name-books-profile-first ' ;
411
+ $ tags = [
412
+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
413
+ 'genealabslaravelmodelcachingtestsfixturesbook ' ,
414
+ 'genealabslaravelmodelcachingtestsfixturesprofile ' ,
415
+ ];
416
+
417
+ $ cachedResults = cache ()->tags ($ tags )
418
+ ->get ($ key )
419
+ ->name ;
420
+
421
+ $ liveResults = (new UncachedAuthor )->with ('books ' , 'profile ' )
422
+ ->value ('name ' );
423
+
424
+ $ this ->assertEquals ($ authors , $ cachedResults );
425
+ $ this ->assertEquals ($ liveResults , $ cachedResults );
426
+ }
307
427
}
0 commit comments