@@ -13,6 +13,8 @@ public function setUp()
1313 {
1414 parent ::setUp ();
1515
16+ cache ()->flush ();
17+
1618 factory (Author::class, 10 )->create ()
1719 ->each (function ($ author ) {
1820 factory (Book::class, random_int (2 , 10 ))->make ()
@@ -25,22 +27,54 @@ public function setUp()
2527
2628 public function testCacheIsEmptyBeforeLoadingModels ()
2729 {
28- $ this ->assertNull (cache ()->get ('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks ' ));
30+ $ results = cache ()->tags ([
31+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
32+ 'genealabslaravelmodelcachingtestsfixturesbook '
33+ ])
34+ ->get ('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks ' );
35+
36+ $ this ->assertNull ($ results );
2937 }
3038
3139 public function testCacheIsNotEmptyAfterLoadingModels ()
3240 {
33- (new Author )->with ('books ' )->get ();
41+ (new Author )->with ('books ' )->get ()->first ();
42+
43+ $ results = cache ()->tags ([
44+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
45+ 'genealabslaravelmodelcachingtestsfixturesbook '
46+ ])
47+ ->get ('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks ' );
3448
35- $ this ->assertNotNull (cache ()-> get ( ' genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks ' ) );
49+ $ this ->assertNotNull ($ results );
3650 }
3751
38- public function testChangingModelClearsCache ()
52+ public function testCreatingModelClearsCache ()
3953 {
40- $ author = (new Author )->with ('books ' )->first ();
54+ $ author = (new Author )->with ('books ' )->get ()-> first ();
4155 $ author ->name = "John Jinglheimer " ;
4256 $ author ->save ();
4357
44- $ this ->assertNull (cache ()->get ('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks ' ));
58+ $ results = cache ()->tags ([
59+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
60+ 'genealabslaravelmodelcachingtestsfixturesbook '
61+ ])
62+ ->get ('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks ' );
63+
64+ $ this ->assertNull ($ results );
65+ }
66+
67+ public function testDeletingModelClearsCache ()
68+ {
69+ $ author = (new Author )->with ('books ' )->get ()->first ();
70+ $ author ->delete ();
71+
72+ $ results = cache ()->tags ([
73+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
74+ 'genealabslaravelmodelcachingtestsfixturesbook '
75+ ])
76+ ->get ('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks ' );
77+
78+ $ this ->assertNull ($ results );
4579 }
4680}
0 commit comments