diff --git a/CHANGELOG.md b/CHANGELOG.md index c722c9b5b..60c10feb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. - Remove `Query\Builder::whereAll($column, $values)`. Use `Query\Builder::where($column, 'all', $values)` instead. [#16](https://github.com/GromNaN/laravel-mongodb/pull/16) by [@GromNaN](https://github.com/GromNaN). - Fix validation of unique values when the validated value is found as part of an existing value. [#21](https://github.com/GromNaN/laravel-mongodb/pull/21) by [@GromNaN](https://github.com/GromNaN). - Support `%` and `_` in `like` expression [#17](https://github.com/GromNaN/laravel-mongodb/pull/17) by [@GromNaN](https://github.com/GromNaN). +- Change signature of `Query\Builder::__constructor` to match the parent class [#26](https://github.com/GromNaN/laravel-mongodb-private/pull/26) by [@GromNaN](https://github.com/GromNaN). ## [3.9.2] - 2022-09-01 diff --git a/src/Connection.php b/src/Connection.php index d6ed508a4..e2b036b4b 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -73,7 +73,7 @@ public function __construct(array $config) */ public function collection($collection) { - $query = new Query\Builder($this, $this->getPostProcessor()); + $query = new Query\Builder($this, $this->getQueryGrammar(), $this->getPostProcessor()); return $query->from($collection); } diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index 61a9de4b1..a0619f3d9 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -156,10 +156,10 @@ public function decrement($column, $amount = 1, array $extra = []) /** * @inheritdoc */ - public function raw($expression = null) + public function raw($value = null) { // Get raw results from the query builder. - $results = $this->query->raw($expression); + $results = $this->query->raw($value); // Convert MongoCursor results to a collection of models. if ($results instanceof Cursor) { diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index 1c66f7652..ff7f9a175 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -433,7 +433,7 @@ protected function newBaseQueryBuilder() { $connection = $this->getConnection(); - return new QueryBuilder($connection, $connection->getPostProcessor()); + return new QueryBuilder($connection, $connection->getQueryGrammar(), $connection->getPostProcessor()); } /** diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 69bcd8ea0..a65edd24a 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -133,16 +133,6 @@ class Builder extends BaseBuilder 'uniquedocs' => 'uniqueDocs', ]; - /** - * @inheritdoc - */ - public function __construct(Connection $connection, Processor $processor) - { - $this->grammar = new Grammar; - $this->connection = $connection; - $this->processor = $processor; - } - /** * Set the projections. * @@ -757,16 +747,16 @@ public function lists($column, $key = null) /** * @inheritdoc */ - public function raw($expression = null) + public function raw($value = null) { // Execute the closure on the mongodb collection - if ($expression instanceof Closure) { - return call_user_func($expression, $this->collection); + if ($value instanceof Closure) { + return call_user_func($value, $this->collection); } // Create an expression for the given value - if ($expression !== null) { - return new Expression($expression); + if ($value !== null) { + return new Expression($value); } // Quick access to the mongodb collection @@ -852,10 +842,12 @@ public function drop($columns) /** * @inheritdoc + * + * @return static */ public function newQuery() { - return new self($this->connection, $this->processor); + return new static($this->connection, $this->grammar, $this->processor); } /** diff --git a/tests/Query/BuilderTest.php b/tests/Query/BuilderTest.php index f34642274..60c05e23f 100644 --- a/tests/Query/BuilderTest.php +++ b/tests/Query/BuilderTest.php @@ -9,6 +9,7 @@ use Illuminate\Tests\Database\DatabaseQueryBuilderTest; use Jenssegers\Mongodb\Connection; use Jenssegers\Mongodb\Query\Builder; +use Jenssegers\Mongodb\Query\Grammar; use Jenssegers\Mongodb\Query\Processor; use Mockery as m; use MongoDB\BSON\Regex; @@ -838,7 +839,8 @@ private static function getBuilder(): Builder $connection = m::mock(Connection::class); $processor = m::mock(Processor::class); $connection->shouldReceive('getSession')->andReturn(null); + $connection->shouldReceive('getQueryGrammar')->andReturn(new Grammar()); - return new Builder($connection, $processor); + return new Builder($connection, null, $processor); } }