@@ -45,20 +45,14 @@ public static function provideQueryBuilderToMql(): iterable
45
45
*/
46
46
$ date = new DateTimeImmutable ('2016-07-12 15:30:00 ' );
47
47
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 ' ),
57
51
];
58
52
59
- yield 'find all with select ' => [
53
+ yield 'select array ' => [
60
54
['find ' => [[], ['projection ' => ['foo ' => 1 , 'bar ' => 1 ]]]],
61
- fn (Builder $ builder ) => $ builder ->select ('foo ' , 'bar ' ),
55
+ fn (Builder $ builder ) => $ builder ->select ([ 'foo ' , 'bar ' ] ),
62
56
];
63
57
64
58
/** @see DatabaseQueryBuilderTest::testAddingSelects */
@@ -70,6 +64,16 @@ public static function provideQueryBuilderToMql(): iterable
70
64
->addSelect ('bar ' ),
71
65
];
72
66
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
+
73
77
yield 'find equals ' => [
74
78
['find ' => [['foo ' => 'bar ' ], []]],
75
79
fn (Builder $ builder ) => $ builder ->where ('foo ' , 'bar ' ),
@@ -86,11 +90,8 @@ public static function provideQueryBuilderToMql(): iterable
86
90
fn (Builder $ builder ) => $ builder ->whereIn ('foo ' , ['bar ' , 'baz ' ]),
87
91
];
88
92
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.
94
95
$ array = [['issue ' => 45582 ], ['id ' => 2 ], [3 ]];
95
96
yield 'whereIn nested array ' => [
96
97
['find ' => [['id ' => ['$in ' => $ array ]], []]],
@@ -138,7 +139,7 @@ public static function provideQueryBuilderToMql(): iterable
138
139
fn (Builder $ builder ) => $ builder ->limit (10 )->offset (5 )->select ('foo ' , 'bar ' ),
139
140
];
140
141
141
- yield 'skip limit ' => [
142
+ yield 'offset limit ' => [
142
143
['find ' => [[], ['skip ' => 5 , 'limit ' => 10 ]]],
143
144
fn (Builder $ builder ) => $ builder ->offset (5 )->limit (10 ),
144
145
];
@@ -159,7 +160,7 @@ public static function provideQueryBuilderToMql(): iterable
159
160
fn (Builder $ builder ) => $ builder ->skip (5 )->take (10 ),
160
161
];
161
162
162
- yield 'kip 0 take 0 ' => [
163
+ yield 'skip 0 take 0 ' => [
163
164
['find ' => [[], []]],
164
165
fn (Builder $ builder ) => $ builder ->skip (0 )->take (0 ),
165
166
];
@@ -475,6 +476,19 @@ public static function provideExceptions(): iterable
475
476
'Between $values must be a list with exactly two elements: [min, max] ' ,
476
477
fn (Builder $ builder ) => $ builder ->whereBetween ('id ' , ['min ' => 1 , 'max ' => 2 ]),
477
478
];
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
+
478
492
}
479
493
480
494
/** @dataProvider getEloquentMethodsNotSupported */
0 commit comments