Skip to content

Commit 07c9b9f

Browse files
committed
Add test to check that subsequently disabled queries do not cache
1 parent 3fa1fa1 commit 07c9b9f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/Unit/CachedBuilderTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ public function testHashCollision()
865865
->get();
866866
$key2 = sha1('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor');
867867

868-
cache()->tags($tags1)
868+
cache()
869+
->tags($tags1)
869870
->rememberForever(
870871
$key1,
871872
function () use ($key2, $authors) {
@@ -886,4 +887,22 @@ function () use ($key2, $authors) {
886887
$this->assertTrue($cachedResults->diffKeys($books)->isEmpty());
887888
$this->assertTrue($cachedResults->diffKeys($authors)->isNotEmpty());
888889
}
890+
891+
public function testSubsequentDisabledCacheQueriesDoNotCache()
892+
{
893+
(new Author)->disableCache()->get();
894+
$key = sha1('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor');
895+
$tags = ['genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor'];
896+
$cachedAuthors1 = cache()
897+
->tags($tags)
898+
->get($key)['value'];
899+
900+
(new Author)->disableCache()->get();
901+
$cachedAuthors2 = cache()
902+
->tags($tags)
903+
->get($key)['value'];
904+
905+
$this->assertEmpty($cachedAuthors1);
906+
$this->assertEmpty($cachedAuthors2);
907+
}
889908
}

0 commit comments

Comments
 (0)