@@ -49,7 +49,7 @@ public function testCacheIsEmptyBeforeLoadingModels()
49
49
50
50
public function testCacheIsNotEmptyAfterLoadingModels ()
51
51
{
52
- (new Author )->with ('books ' )->get ()-> first () ;
52
+ (new Author )->with ('books ' )->get ();
53
53
54
54
$ results = cache ()->tags ([
55
55
'genealabslaravelmodelcachingtestsfixturesauthor ' ,
@@ -61,6 +61,21 @@ public function testCacheIsNotEmptyAfterLoadingModels()
61
61
}
62
62
63
63
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 ()
64
79
{
65
80
$ author = (new Author )->with ('books ' )->get ()->first ();
66
81
$ author ->name = "John Jinglheimer " ;
@@ -94,54 +109,71 @@ public function testHasManyRelationshipIsCached()
94
109
$ authors = (new Author )->with ('books ' )->get ();
95
110
$ authorIds = implode ('_ ' , $ authors ->pluck ('id ' )->toArray ());
96
111
97
- $ results = cache ()->tags ([
112
+ $ results = collect ( cache ()->tags ([
98
113
'genealabslaravelmodelcachingtestsfixturesauthor ' ,
99
114
'genealabslaravelmodelcachingtestsfixturesbook '
100
115
])
101
- ->get ("genealabslaravelmodelcachingtestsfixturesauthor_ {$ authorIds }-genealabslaravelmodelcachingtestsfixturesbooks " );
116
+ ->get ("genealabslaravelmodelcachingtestsfixturesauthor_ {$ authorIds }-genealabslaravelmodelcachingtestsfixturesbooks " )) ;
102
117
103
118
$ this ->assertNotNull ($ results );
119
+ $ this ->assertEmpty ($ authors ->diffAssoc ($ results ));
120
+ $ this ->assertNotEmpty ($ authors );
121
+ $ this ->assertNotEmpty ($ results );
122
+ $ this ->assertEquals ($ authors ->count (), $ results ->count ());
104
123
}
105
124
106
125
public function testBelongsToRelationshipIsCached ()
107
126
{
108
- $ books = (new Book )->with ('author ' )->get ()-> first () ;
127
+ $ books = (new Book )->with ('author ' )->get ();
109
128
$ bookIds = implode ('_ ' , $ books ->pluck ('id ' )->toArray ());
110
129
111
- $ results = cache ()->tags ([
130
+ $ results = collect ( cache ()->tags ([
112
131
'genealabslaravelmodelcachingtestsfixturesbook ' ,
113
132
'genealabslaravelmodelcachingtestsfixturesauthor '
114
133
])
115
- ->get ("genealabslaravelmodelcachingtestsfixturesbook_ {$ bookIds }-genealabslaravelmodelcachingtestsfixturesauthors " );
134
+ ->get ("genealabslaravelmodelcachingtestsfixturesbook_ {$ bookIds }-genealabslaravelmodelcachingtestsfixturesauthors " )) ;
116
135
117
136
$ this ->assertNotNull ($ results );
137
+ $ this ->assertEmpty ($ books ->diffAssoc ($ results ));
138
+ $ this ->assertNotEmpty ($ books );
139
+ $ this ->assertNotEmpty ($ results );
140
+ $ this ->assertEquals ($ books ->count (), $ results ->count ());
118
141
}
119
142
120
143
public function testBelongsToManyRelationshipIsCached ()
121
144
{
122
145
$ books = (new Book )->with ('stores ' )->get ();
123
146
$ bookIds = implode ('_ ' , $ books ->pluck ('id ' )->toArray ());
124
147
125
- $ results = cache ()->tags ([
148
+ $ results = collect ( cache ()->tags ([
126
149
'genealabslaravelmodelcachingtestsfixturesbook ' ,
127
150
'genealabslaravelmodelcachingtestsfixturesstore '
128
151
])
129
- ->get ("genealabslaravelmodelcachingtestsfixturesbook_ {$ bookIds }-genealabslaravelmodelcachingtestsfixturesstores " );
152
+ ->get ("genealabslaravelmodelcachingtestsfixturesbook_ {$ bookIds }-genealabslaravelmodelcachingtestsfixturesstores " )) ;
130
153
131
154
$ this ->assertNotNull ($ results );
155
+ $ this ->assertEmpty ($ books ->diffAssoc ($ results ));
156
+ $ this ->assertNotEmpty ($ books );
157
+ $ this ->assertNotEmpty ($ results );
158
+ $ this ->assertEquals ($ books ->count (), $ results ->count ());
132
159
}
133
160
134
161
public function testHasOneRelationshipIsCached ()
135
162
{
136
163
$ authors = (new Author )->with ('profile ' )->get ();
137
164
$ authorIds = implode ('_ ' , $ authors ->pluck ('id ' )->toArray ());
138
165
139
- $ results = cache ()->tags ([
166
+ $ results = collect (cache ()
167
+ ->tags ([
140
168
'genealabslaravelmodelcachingtestsfixturesauthor ' ,
141
169
'genealabslaravelmodelcachingtestsfixturesprofile '
142
170
])
143
- ->get ("genealabslaravelmodelcachingtestsfixturesauthor_ {$ authorIds }-genealabslaravelmodelcachingtestsfixturesprofiles " );
171
+ ->get ("genealabslaravelmodelcachingtestsfixturesauthor_ {$ authorIds }-genealabslaravelmodelcachingtestsfixturesprofiles " )) ;
144
172
145
173
$ this ->assertNotNull ($ results );
174
+ $ this ->assertEmpty ($ authors ->diffAssoc ($ results ));
175
+ $ this ->assertNotEmpty ($ authors );
176
+ $ this ->assertNotEmpty ($ results );
177
+ $ this ->assertEquals ($ authors ->count (), $ results ->count ());
146
178
}
147
179
}
0 commit comments