Skip to content

PHPORM-145 Fix Query\Builder::dump and dd methods to dump MongoDB query #2727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [unreleased]

* Fix `Query\Builder::dump` and `dd` methods to dump the MongoDB query by @GromNaN in [#2727](https://github.com/mongodb/laravel-mongodb/pull/2727)

## [4.1.2]

* Fix support for subqueries using the query builder by @GromNaN in [#2717](https://github.com/mongodb/laravel-mongodb/pull/2717)
Expand Down
27 changes: 27 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use MongoDB\BSON\Regex;
use MongoDB\BSON\UTCDateTime;
use MongoDB\Driver\Cursor;
use Override;
use RuntimeException;

use function array_fill_keys;
Expand All @@ -37,6 +38,8 @@
use function call_user_func_array;
use function count;
use function ctype_xdigit;
use function dd;
use function dump;
use function end;
use function explode;
use function func_get_args;
Expand Down Expand Up @@ -250,6 +253,30 @@ public function cursor($columns = [])
throw new RuntimeException('Query not compatible with cursor');
}

/**
* Die and dump the current MongoDB query
*
* @return never-return
*/
#[Override]
Copy link
Member Author

Choose a reason for hiding this comment

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

Keeping track to add this attribute where necessary: https://jira.mongodb.org/browse/PHPORM-146

public function dd()
{
dd($this->toMql());
}

/**
* Dump the current MongoDB query
*
* @return $this
*/
#[Override]
public function dump()
{
dump($this->toMql());

return $this;
}

/**
* Return the MongoDB query to be run in the form of an element array like ['method' => [arguments]].
*
Expand Down
14 changes: 0 additions & 14 deletions tests/Eloquent/CallBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,5 @@ public static function provideUnsupportedMethods(): Generator
'This method is not supported by MongoDB. Try "toMql()" instead',
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
];

yield 'dd' => [
'dd',
BadMethodCallException::class,
'This method is not supported by MongoDB. Try "toMql()" instead',
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
];

yield 'dump' => [
'dump',
BadMethodCallException::class,
'This method is not supported by MongoDB. Try "toMql()" instead',
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
];
}
}