File tree 2 files changed +47
-0
lines changed
tests/Integration/CachedBuilder
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ public static function bootCachable()
75
75
// $instance->checkCooldownAndFlushAfterPersisting($instance);
76
76
// });
77
77
78
+ static ::pivotSynced (function ($ instance , $ secondInstance , $ relationship ) {
79
+ $ instance ->checkCooldownAndFlushAfterPersisting ($ instance , $ relationship );
80
+ });
81
+
78
82
static ::pivotAttached (function ($ instance , $ secondInstance , $ relationship ) {
79
83
$ instance ->checkCooldownAndFlushAfterPersisting ($ instance , $ relationship );
80
84
});
Original file line number Diff line number Diff line change @@ -169,6 +169,49 @@ public function testUncachedRelatedModelDoesntCache()
169
169
$ this ->assertNotNull ($ uncachedResult );
170
170
}
171
171
172
+ public function testInvalidatingCacheWhenSyncing ()
173
+ {
174
+ $ bookId = (new Store )
175
+ ->disableModelCaching ()
176
+ ->with ("books " )
177
+ ->first ()
178
+ ->books
179
+ ->first ()
180
+ ->id ;
181
+ $ key = sha1 ("genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:stores:genealabslaravelmodelcachingtestsfixturesstore-testing: {$ this ->testingSqlitePath }testing.sqlite:books-first " );
182
+ $ tags = [
183
+ "genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:genealabslaravelmodelcachingtestsfixturesstore " ,
184
+ ];
185
+
186
+ $ newStores = factory (Store::class, 2 )
187
+ ->create ();
188
+
189
+ $ result = Book::find ($ bookId )
190
+ ->stores ;
191
+
192
+ Book::find ($ bookId )
193
+ ->stores ()
194
+ ->attach ($ newStores [0 ]->id );
195
+
196
+ Book::find ($ bookId )
197
+ ->stores ()
198
+ ->sync ($ newStores ->pluck ('id ' ));
199
+
200
+ $ this ->assertEmpty (array_diff (
201
+ Book::find ($ bookId )->stores ()->pluck ((new Store )->getTable () . '.id ' )->toArray (),
202
+ $ newStores ->pluck ('id ' )->toArray ()
203
+ ));
204
+
205
+ $ cachedResult = $ this
206
+ ->cache ()
207
+ ->tags ($ tags )
208
+ ->get ($ key )['value ' ]
209
+ ?? null ;
210
+
211
+ $ this ->assertNotEmpty ($ result );
212
+ $ this ->assertNull ($ cachedResult );
213
+ }
214
+
172
215
// /** @group test */
173
216
// public function testUncachedDetachesFromCached()
174
217
// {
You can’t perform that action at this time.
0 commit comments