Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d036d4a

Browse files
committed
Add test for pivotSync
1 parent 5674040 commit d036d4a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

‎tests/Integration/CachedBuilder/BelongsToManyTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,49 @@ public function testUncachedRelatedModelDoesntCache()
169169
$this->assertNotNull($uncachedResult);
170170
}
171171

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+
172215
// /** @group test */
173216
// public function testUncachedDetachesFromCached()
174217
// {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /