@@ -49,7 +49,7 @@ public function testCacheIsEmptyBeforeLoadingModels()
4949
5050 public function testCacheIsNotEmptyAfterLoadingModels ()
5151 {
52- (new Author )->with ('books ' )->get ()-> first () ;
52+ (new Author )->with ('books ' )->get ();
5353
5454 $ results = cache ()->tags ([
5555 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
@@ -61,6 +61,21 @@ public function testCacheIsNotEmptyAfterLoadingModels()
6161 }
6262
6363 public function testCreatingModelClearsCache ()
64+ {
65+ $ author = (new Author )->with ('books ' )->get ();
66+
67+ factory (Author::class)->create ();
68+
69+ $ results = cache ()->tags ([
70+ 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
71+ 'genealabslaravelmodelcachingtestsfixturesbook '
72+ ])
73+ ->get ('genealabslaravelmodelcachingtestsfixturesauthor_1_2_3_4_5_6_7_8_9_10-genealabslaravelmodelcachingtestsfixturesbooks ' );
74+
75+ $ this ->assertNull ($ results );
76+ }
77+
78+ public function testUpdatingModelClearsCache ()
6479 {
6580 $ author = (new Author )->with ('books ' )->get ()->first ();
6681 $ author ->name = "John Jinglheimer " ;
@@ -94,54 +109,71 @@ public function testHasManyRelationshipIsCached()
94109 $ authors = (new Author )->with ('books ' )->get ();
95110 $ authorIds = implode ('_ ' , $ authors ->pluck ('id ' )->toArray ());
96111
97- $ results = cache ()->tags ([
112+ $ results = collect ( cache ()->tags ([
98113 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
99114 'genealabslaravelmodelcachingtestsfixturesbook '
100115 ])
101- ->get ("genealabslaravelmodelcachingtestsfixturesauthor_ {$ authorIds }-genealabslaravelmodelcachingtestsfixturesbooks " );
116+ ->get ("genealabslaravelmodelcachingtestsfixturesauthor_ {$ authorIds }-genealabslaravelmodelcachingtestsfixturesbooks " )) ;
102117
103118 $ this ->assertNotNull ($ results );
119+ $ this ->assertEmpty ($ authors ->diffAssoc ($ results ));
120+ $ this ->assertNotEmpty ($ authors );
121+ $ this ->assertNotEmpty ($ results );
122+ $ this ->assertEquals ($ authors ->count (), $ results ->count ());
104123 }
105124
106125 public function testBelongsToRelationshipIsCached ()
107126 {
108- $ books = (new Book )->with ('author ' )->get ()-> first () ;
127+ $ books = (new Book )->with ('author ' )->get ();
109128 $ bookIds = implode ('_ ' , $ books ->pluck ('id ' )->toArray ());
110129
111- $ results = cache ()->tags ([
130+ $ results = collect ( cache ()->tags ([
112131 'genealabslaravelmodelcachingtestsfixturesbook ' ,
113132 'genealabslaravelmodelcachingtestsfixturesauthor '
114133 ])
115- ->get ("genealabslaravelmodelcachingtestsfixturesbook_ {$ bookIds }-genealabslaravelmodelcachingtestsfixturesauthors " );
134+ ->get ("genealabslaravelmodelcachingtestsfixturesbook_ {$ bookIds }-genealabslaravelmodelcachingtestsfixturesauthors " )) ;
116135
117136 $ this ->assertNotNull ($ results );
137+ $ this ->assertEmpty ($ books ->diffAssoc ($ results ));
138+ $ this ->assertNotEmpty ($ books );
139+ $ this ->assertNotEmpty ($ results );
140+ $ this ->assertEquals ($ books ->count (), $ results ->count ());
118141 }
119142
120143 public function testBelongsToManyRelationshipIsCached ()
121144 {
122145 $ books = (new Book )->with ('stores ' )->get ();
123146 $ bookIds = implode ('_ ' , $ books ->pluck ('id ' )->toArray ());
124147
125- $ results = cache ()->tags ([
148+ $ results = collect ( cache ()->tags ([
126149 'genealabslaravelmodelcachingtestsfixturesbook ' ,
127150 'genealabslaravelmodelcachingtestsfixturesstore '
128151 ])
129- ->get ("genealabslaravelmodelcachingtestsfixturesbook_ {$ bookIds }-genealabslaravelmodelcachingtestsfixturesstores " );
152+ ->get ("genealabslaravelmodelcachingtestsfixturesbook_ {$ bookIds }-genealabslaravelmodelcachingtestsfixturesstores " )) ;
130153
131154 $ this ->assertNotNull ($ results );
155+ $ this ->assertEmpty ($ books ->diffAssoc ($ results ));
156+ $ this ->assertNotEmpty ($ books );
157+ $ this ->assertNotEmpty ($ results );
158+ $ this ->assertEquals ($ books ->count (), $ results ->count ());
132159 }
133160
134161 public function testHasOneRelationshipIsCached ()
135162 {
136163 $ authors = (new Author )->with ('profile ' )->get ();
137164 $ authorIds = implode ('_ ' , $ authors ->pluck ('id ' )->toArray ());
138165
139- $ results = cache ()->tags ([
166+ $ results = collect (cache ()
167+ ->tags ([
140168 'genealabslaravelmodelcachingtestsfixturesauthor ' ,
141169 'genealabslaravelmodelcachingtestsfixturesprofile '
142170 ])
143- ->get ("genealabslaravelmodelcachingtestsfixturesauthor_ {$ authorIds }-genealabslaravelmodelcachingtestsfixturesprofiles " );
171+ ->get ("genealabslaravelmodelcachingtestsfixturesauthor_ {$ authorIds }-genealabslaravelmodelcachingtestsfixturesprofiles " )) ;
144172
145173 $ this ->assertNotNull ($ results );
174+ $ this ->assertEmpty ($ authors ->diffAssoc ($ results ));
175+ $ this ->assertNotEmpty ($ authors );
176+ $ this ->assertNotEmpty ($ results );
177+ $ this ->assertEquals ($ authors ->count (), $ results ->count ());
146178 }
147179}
0 commit comments