Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Remove Query\Builder::__constructor overload #26

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
// 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
22 changes: 6 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)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get the argument name from the parent method.

{
// 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 @@ -856,7 +846,7 @@ public function drop($columns)
*/
public function newQuery()
{
return new self($this->connection, $this->processor);
return new self($this->connection, null, $this->processor);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a null second argument equivalent to constructing a new Grammar object (perhaps by way of calling Connection::getQueryGrammar()), as was done in the original overridden constructor (before the changes in this PR)?

Just want to confirm there's no behavioral change here.

}

/**
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);
}
}
Loading