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

Commit 965c107

Browse files
committed
review
1 parent 43b7fa5 commit 965c107

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
@@ -925,6 +925,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
925925
}
926926
}
927927

928+
if (func_num_args() == 1 && is_string($column)) {
929+
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));
930+
}
931+
928932
return parent::where(...$params);
929933
}
930934

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. MongoDB can compare objects.
105105
$array = [['issue' => 45582], ['id' => 2], [3]];
106106
yield 'whereIn nested array' => [
107107
['find' => [['id' => ['$in' => $array]], []]],
@@ -333,18 +333,12 @@ public static function provideQueryBuilderToMql(): iterable
333333
]),
334334
];
335335

336-
337336
/** @see DatabaseQueryBuilderTest::testForPage() */
338337
yield 'forPage' => [
339338
['find' => [[], ['limit' => 20, 'skip' => 40]]],
340339
fn (Builder $builder) => $builder->forPage(3, 20),
341340
];
342341

343-
yield 'skip limit' => [
344-
['find' => [[], ['skip' => 5, 'limit' => 10]]],
345-
fn (Builder $builder) => $builder->offset(5)->limit(10),
346-
];
347-
348342
/** @see DatabaseQueryBuilderTest::testLimitsAndOffsets() */
349343
yield 'offset limit' => [
350344
['find' => [[], ['skip' => 5, 'limit' => 10]]],
@@ -669,6 +663,12 @@ public static function provideExceptions(): iterable
669663
'Between $values must be a list with exactly two elements: [min, max]',
670664
fn (Builder $builder) => $builder->whereBetween('id', ['min' => 1, 'max' => 2]),
671665
];
666+
667+
yield 'find with single string argument' => [
668+
\ArgumentCountError::class,
669+
'Too few arguments to function Jenssegers\Mongodb\Query\Builder::where("foo"), 1 passed and at least 2 expected when the 1st is a string',
670+
fn (Builder $builder) => $builder->where('foo'),
671+
];
672672
}
673673

674674
/** @dataProvider getEloquentMethodsNotSupported */

0 commit comments

Comments
 (0)