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

Commit 7e0f82d

Browse files
committed
review
1 parent a2ff851 commit 7e0f82d

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/Query/Builder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
923923
}
924924
}
925925

926+
if (func_num_args() == 1 && is_string($column)) {
927+
throw new \ArgumentCountError(sprintf('Too few arguments to function %s("%s"), 1 passed and at least 2 expected when the 1st is a string.', __METHOD__, $column));
928+
}
929+
926930
return parent::where(...$params);
927931
}
928932

tests/Query/BuilderTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,14 @@ public static function provideQueryBuilderToMql(): iterable
4545
*/
4646
$date = new DateTimeImmutable('2016-07-12 15:30:00');
4747

48-
/** @see DatabaseQueryBuilderTest::testBasicSelectWithGetColumns */
49-
yield 'find all' => [
50-
['find' => [[], []]],
51-
fn (Builder $builder) => $builder->select('*'),
48+
yield 'select replaces previous select' => [
49+
['find' => [[], ['projection' => ['bar' => 1]]]],
50+
fn (Builder $builder) => $builder->select('foo')->select('bar'),
5251
];
5352

54-
yield 'find default null' => [
55-
['find' => [['foo' => null], []]],
56-
fn (Builder $builder) => $builder->where('foo'),
57-
];
58-
59-
yield 'find all with select' => [
53+
yield 'select array' => [
6054
['find' => [[], ['projection' => ['foo' => 1, 'bar' => 1]]]],
61-
fn (Builder $builder) => $builder->select('foo', 'bar'),
55+
fn (Builder $builder) => $builder->select(['foo', 'bar']),
6256
];
6357

6458
/** @see DatabaseQueryBuilderTest::testAddingSelects */
@@ -70,6 +64,16 @@ public static function provideQueryBuilderToMql(): iterable
7064
->addSelect('bar'),
7165
];
7266

67+
yield 'select all' => [
68+
['find' => [[], []]],
69+
fn (Builder $builder) => $builder->select('*'),
70+
];
71+
72+
yield 'find all with select' => [
73+
['find' => [[], ['projection' => ['foo' => 1, 'bar' => 1]]]],
74+
fn (Builder $builder) => $builder->select('foo', 'bar'),
75+
];
76+
7377
yield 'find equals' => [
7478
['find' => [['foo' => 'bar'], []]],
7579
fn (Builder $builder) => $builder->where('foo', 'bar'),
@@ -97,11 +101,7 @@ public static function provideQueryBuilderToMql(): iterable
97101
fn (Builder $builder) => $builder->whereIn('foo', ['bar', 'baz']),
98102
];
99103

100-
yield 'whereIn associative array' => [
101-
['find' => [['id' => ['$in' => [45582, 2, 3]]], []]],
102-
fn (Builder $builder) => $builder->whereIn('id', ['issue' => 45582, 'id' => 2, 3]),
103-
];
104-
104+
// Nested array are not flattened like in the Eloquent builder whereas MongoDB can compare objects.
105105
$array = [['issue' => 45582], ['id' => 2], [3]];
106106
yield 'whereIn nested array' => [
107107
['find' => [['id' => ['$in' => $array]], []]],
@@ -320,18 +320,12 @@ public static function provideQueryBuilderToMql(): iterable
320320
]),
321321
];
322322

323-
324323
/** @see DatabaseQueryBuilderTest::testForPage() */
325324
yield 'forPage' => [
326325
['find' => [[], ['limit' => 20, 'skip' => 40]]],
327326
fn (Builder $builder) => $builder->forPage(3, 20),
328327
];
329328

330-
yield 'skip limit' => [
331-
['find' => [[], ['skip' => 5, 'limit' => 10]]],
332-
fn (Builder $builder) => $builder->offset(5)->limit(10),
333-
];
334-
335329
/** @see DatabaseQueryBuilderTest::testLimitsAndOffsets() */
336330
yield 'offset limit' => [
337331
['find' => [[], ['skip' => 5, 'limit' => 10]]],
@@ -656,6 +650,12 @@ public static function provideExceptions(): iterable
656650
'Between $values must be a list with exactly two elements: [min, max]',
657651
fn (Builder $builder) => $builder->whereBetween('id', ['min' => 1, 'max' => 2]),
658652
];
653+
654+
yield 'find with single string argument' => [
655+
\ArgumentCountError::class,
656+
'Too few arguments to function Jenssegers\Mongodb\Query\Builder::where("foo"), 1 passed and at least 2 expected when the 1st is a string',
657+
fn (Builder $builder) => $builder->where('foo'),
658+
];
659659
}
660660

661661
/** @dataProvider getEloquentMethodsNotSupported */

0 commit comments

Comments
 (0)