Skip to content

Commit

Permalink
Remove Query\Builder::__constructor overload
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Aug 22, 2023
1 parent 49ec43c commit f38f5c7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-private/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-private/pull/21) by [@GromNaN](https://github.com/GromNaN).
- Support `%` and `_` in `like` expression [#17](https://github.com/GromNaN/laravel-mongodb-private/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

Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ public function chunkById($count, callable $callback, $column = '_id', $alias =
/**
* @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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ protected function newBaseQueryBuilder()
{
$connection = $this->getConnection();

return new QueryBuilder($connection, $connection->getPostProcessor());
return new QueryBuilder($connection, $connection->getQueryGrammar(), $connection->getPostProcessor());
}

/**
Expand Down
24 changes: 8 additions & 16 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,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.
*
Expand Down Expand Up @@ -758,16 +748,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
Expand Down Expand Up @@ -853,10 +843,12 @@ public function drop($columns)

/**
* @inheritdoc
*
* @return static
*/
public function newQuery()
{
return new self($this->connection, $this->processor);
return new self($this->connection, $this->grammar, $this->processor);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit f38f5c7

Please sign in to comment.