Skip to content

Commit 0cef5dc

Browse files
authored
PHPORM-145 Fix Query\Builder::dump and dd methods to dump MongoDB query (#2727)
Can't be tested in a simple way. The code is trivial.
1 parent c694ca4 commit 0cef5dc

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [unreleased]
5+
6+
* Fix `Query\Builder::dump` and `dd` methods to dump the MongoDB query by @GromNaN in [#2727](https://github.com/mongodb/laravel-mongodb/pull/2727)
7+
48
## [4.1.2]
59

610
* Fix support for subqueries using the query builder by @GromNaN in [#2717](https://github.com/mongodb/laravel-mongodb/pull/2717)

Diff for: src/Query/Builder.php

+27
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use MongoDB\BSON\Regex;
2323
use MongoDB\BSON\UTCDateTime;
2424
use MongoDB\Driver\Cursor;
25+
use Override;
2526
use RuntimeException;
2627

2728
use function array_fill_keys;
@@ -37,6 +38,8 @@
3738
use function call_user_func_array;
3839
use function count;
3940
use function ctype_xdigit;
41+
use function dd;
42+
use function dump;
4043
use function end;
4144
use function explode;
4245
use function func_get_args;
@@ -250,6 +253,30 @@ public function cursor($columns = [])
250253
throw new RuntimeException('Query not compatible with cursor');
251254
}
252255

256+
/**
257+
* Die and dump the current MongoDB query
258+
*
259+
* @return never-return
260+
*/
261+
#[Override]
262+
public function dd()
263+
{
264+
dd($this->toMql());
265+
}
266+
267+
/**
268+
* Dump the current MongoDB query
269+
*
270+
* @return $this
271+
*/
272+
#[Override]
273+
public function dump()
274+
{
275+
dump($this->toMql());
276+
277+
return $this;
278+
}
279+
253280
/**
254281
* Return the MongoDB query to be run in the form of an element array like ['method' => [arguments]].
255282
*

Diff for: tests/Eloquent/CallBuilderTest.php

-14
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,5 @@ public static function provideUnsupportedMethods(): Generator
8989
'This method is not supported by MongoDB. Try "toMql()" instead',
9090
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
9191
];
92-
93-
yield 'dd' => [
94-
'dd',
95-
BadMethodCallException::class,
96-
'This method is not supported by MongoDB. Try "toMql()" instead',
97-
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
98-
];
99-
100-
yield 'dump' => [
101-
'dump',
102-
BadMethodCallException::class,
103-
'This method is not supported by MongoDB. Try "toMql()" instead',
104-
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
105-
];
10692
}
10793
}

0 commit comments

Comments
 (0)