Skip to content

Commit 6763914

Browse files
committed
Add test on where()
1 parent 5a79bec commit 6763914

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

tests/Query/BuilderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,31 @@ function (Builder $elemMatchQuery): void {
13811381
->orWhereAny(['last_name', 'email'], 'not like', '%Doe%'),
13821382
'orWhereAny',
13831383
];
1384+
1385+
yield 'raw filter with _id and date' => [
1386+
[
1387+
'find' => [
1388+
[
1389+
'$and' => [
1390+
[
1391+
'$or' => [
1392+
['foo._id' => 1],
1393+
['created_at' => ['$gte' => new UTCDateTime(new DateTimeImmutable('2018-09-30 00:00:00.000 +00:00'))]],
1394+
],
1395+
],
1396+
['age' => 15],
1397+
],
1398+
],
1399+
[], // options
1400+
],
1401+
],
1402+
fn (Builder $builder) => $builder->where([
1403+
'$or' => [
1404+
['foo.id' => 1],
1405+
['created_at' => ['$gte' => new DateTimeImmutable('2018-09-30 00:00:00 +00:00')]],
1406+
],
1407+
])->where('age', 15),
1408+
];
13841409
}
13851410

13861411
#[DataProvider('provideExceptions')]

tests/QueryBuilderTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use MongoDB\BSON\Regex;
1919
use MongoDB\BSON\UTCDateTime;
2020
use MongoDB\Collection;
21+
use MongoDB\Driver\Cursor;
2122
use MongoDB\Driver\Monitoring\CommandFailedEvent;
2223
use MongoDB\Driver\Monitoring\CommandStartedEvent;
2324
use MongoDB\Driver\Monitoring\CommandSubscriber;
@@ -313,16 +314,12 @@ public function testRaw()
313314
['name' => 'John Doe', 'age' => 25],
314315
]);
315316

316-
$results = DB::table('users')->raw(function ($collection) {
317-
return $collection->find(['age' => 20], ['typeMap' => ['root' => 'array', 'document' => 'array']]);
317+
$cursor = DB::table('users')->raw(function ($collection) {
318+
return $collection->find(['age' => 20]);
318319
});
319320

320-
$this->assertIsArray($results);
321-
$this->assertCount(1, $results);
322-
$this->assertArrayNotHasKey('_id', $results[0]);
323-
$this->assertArrayHasKey('id', $results[0]);
324-
$this->assertInstanceOf(ObjectId::class, $results[0]['id']);
325-
$this->assertSame(20, $results[0]['age']);
321+
$this->assertInstanceOf(Cursor::class, $cursor);
322+
$this->assertCount(1, $cursor->toArray());
326323

327324
$collection = DB::table('users')->raw();
328325
$this->assertInstanceOf(Collection::class, $collection);

0 commit comments

Comments
 (0)