diff --git a/tests/Integration/CachedBuilder/WhereJsonLengthTest.php b/tests/Integration/CachedBuilder/WhereJsonLengthTest.php new file mode 100644 index 0000000..1fec6f9 --- /dev/null +++ b/tests/Integration/CachedBuilder/WhereJsonLengthTest.php @@ -0,0 +1,51 @@ +testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-finances->tags_=_$length-authors.deleted_at_null"); + $tags = [ + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", + ]; + + $authors = (new Author)->whereJsonLength("finances->tags", $length)->get(); + $liveResults = (new UncachedAuthor)->whereJsonLength("finances->tags", $length)->get(); + + $cachedResults = $this + ->cache() + ->tags($tags) + ->get($key)['value']; + + $this->assertCount(10, $liveResults); + $this->assertCount(10, $cachedResults); + $this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); + $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); + } + + public function testWithInUsingCollectionQueryWithOperator() + { + $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-finances->tags_>_1-authors.deleted_at_null"); + $tags = [ + "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", + ]; + + $authors = (new Author)->whereJsonLength("finances->tags", '>', 1)->get(); + $liveResults = (new UncachedAuthor)->whereJsonLength("finances->tags", '>', 1)->get(); + + $cachedResults = $this + ->cache() + ->tags($tags) + ->get($key)['value']; + + $this->assertCount(10, $liveResults); + $this->assertCount(10, $cachedResults); + $this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); + $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); + } +}