diff --git a/composer.json b/composer.json index 2f73d4f..c815f10 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "sebastian/phpcpd": "*", "symfony/thanks": "*", "predis/predis": "*", - "codedungeon/phpunit-result-printer": "*" + "codedungeon/phpunit-result-printer": "^0.19.10" }, "autoload": { "psr-4": { diff --git a/src/CacheKey.php b/src/CacheKey.php index fde63ca..9ddc9a0 100644 --- a/src/CacheKey.php +++ b/src/CacheKey.php @@ -164,8 +164,6 @@ protected function getNestedClauses(array $where) : string return ""; } - $this->currentBinding++; - return "-" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres); } @@ -175,8 +173,6 @@ protected function getColumnClauses(array $where) : string return ""; } - $this->currentBinding++; - return "-{$where["boolean"]}_{$where["first"]}_{$where["operator"]}_{$where["second"]}"; } diff --git a/tests/Integration/CachedBuilder/WhereRawTest.php b/tests/Integration/CachedBuilder/WhereRawTest.php index ca30538..48a3acb 100644 --- a/tests/Integration/CachedBuilder/WhereRawTest.php +++ b/tests/Integration/CachedBuilder/WhereRawTest.php @@ -89,4 +89,19 @@ public function testNestedWhereRawClauses() $this->assertEquals($expectedIds, $authors->pluck("id")->toArray()); } + + public function testNestedWhereRawWithBindings() + { + $books = (new Book) + ->where(function ($query) { + $query->whereRaw("title like ? or description like ? or published_at like ? or price like ?", ['%larravel%', '%larravel%', '%larravel%', '%larravel%',]); + })->get(); + + $uncachedBooks = (new UncachedBook) + ->where(function ($query) { + $query->whereRaw("title like ? or description like ? or published_at like ? or price like ?", ['%larravel%', '%larravel%', '%larravel%', '%larravel%',]); + })->get(); + + $this->assertEquals($books->pluck("id"), $uncachedBooks->pluck("id")); + } } diff --git a/tests/Integration/CachedBuilderRelationshipsTest.php b/tests/Integration/CachedBuilderRelationshipsTest.php index 86184e1..22aa5dc 100644 --- a/tests/Integration/CachedBuilderRelationshipsTest.php +++ b/tests/Integration/CachedBuilderRelationshipsTest.php @@ -38,4 +38,23 @@ public function testHasRelationshipResults() $this->assertNotEmpty($booksWithStores); $this->assertEquals($booksWithStores, $cachedResults); } + + public function testWhereHasRelationship() + { + $books = (new Book) + ->with("stores") + ->whereHas("stores", function ($query) { + $query->whereRaw('address like ?', ['%s%']); + }) + ->get(); + + $uncachedBooks = (new UncachedBook) + ->with("stores") + ->whereHas("stores", function ($query) { + $query->whereRaw('address like ?', ['%s%']); + }) + ->get(); + + $this->assertEquals($books->pluck("id"), $uncachedBooks->pluck("id")); + } }