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

Commit 437d9cf

Browse files
committed
review
1 parent fb84adf commit 437d9cf

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/Query/Builder.php

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

943+
if (func_num_args() == 1 && is_string($column)) {
944+
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));
945+
}
946+
943947
return parent::where(...$params);
944948
}
945949

tests/Query/BuilderTest.php

Lines changed: 32 additions & 18 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('*'),
52-
];
53-
54-
yield 'find default null' => [
55-
['find' => [['foo' => null], []]],
56-
fn (Builder $builder) => $builder->where('foo'),
48+
yield 'select replaces previous select' => [
49+
['find' => [[], ['projection' => ['bar' => 1]]]],
50+
fn (Builder $builder) => $builder->select('foo')->select('bar'),
5751
];
5852

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'),
@@ -86,11 +90,8 @@ public static function provideQueryBuilderToMql(): iterable
8690
fn (Builder $builder) => $builder->whereIn('foo', ['bar', 'baz']),
8791
];
8892

89-
yield 'whereIn associative array' => [
90-
['find' => [['id' => ['$in' => [45582, 2, 3]]], []]],
91-
fn (Builder $builder) => $builder->whereIn('id', ['issue' => 45582, 'id' => 2, 3]),
92-
];
93-
93+
// Nested array are not flattened like in the Eloquent builder.
94+
// MongoDB can compare arrays.
9495
$array = [['issue' => 45582], ['id' => 2], [3]];
9596
yield 'whereIn nested array' => [
9697
['find' => [['id' => ['$in' => $array]], []]],
@@ -138,7 +139,7 @@ public static function provideQueryBuilderToMql(): iterable
138139
fn (Builder $builder) => $builder->limit(10)->offset(5)->select('foo', 'bar'),
139140
];
140141

141-
yield 'skip limit' => [
142+
yield 'offset limit' => [
142143
['find' => [[], ['skip' => 5, 'limit' => 10]]],
143144
fn (Builder $builder) => $builder->offset(5)->limit(10),
144145
];
@@ -159,7 +160,7 @@ public static function provideQueryBuilderToMql(): iterable
159160
fn (Builder $builder) => $builder->skip(5)->take(10),
160161
];
161162

162-
yield 'kip 0 take 0' => [
163+
yield 'skip 0 take 0' => [
163164
['find' => [[], []]],
164165
fn (Builder $builder) => $builder->skip(0)->take(0),
165166
];
@@ -475,6 +476,19 @@ public static function provideExceptions(): iterable
475476
'Between $values must be a list with exactly two elements: [min, max]',
476477
fn (Builder $builder) => $builder->whereBetween('id', ['min' => 1, 'max' => 2]),
477478
];
479+
480+
yield 'find with single string argument' => [
481+
\ArgumentCountError::class,
482+
'Too few arguments to function Jenssegers\Mongodb\Query\Builder::where("foo"), 1 passed and at least 2 expected when the 1st is a string',
483+
fn (Builder $builder) => $builder->where('foo'),
484+
];
485+
486+
yield 'whereIn associative array' => [
487+
\InvalidArgumentException::class,
488+
'whereIn() expects 2nd argument to be a list, associative array given with keys "issue", "id", "0"',
489+
fn (Builder $builder) => $builder->whereIn('id', ['issue' => 45582, 'id' => 2, 3]),
490+
];
491+
478492
}
479493

480494
/** @dataProvider getEloquentMethodsNotSupported */

0 commit comments

Comments
 (0)