@@ -45,7 +45,32 @@ public static function provideQueryBuilderToMql(): iterable
45
45
*/
46
46
$ date = new DateTimeImmutable ('2016-07-12 15:30:00 ' );
47
47
48
- yield 'find ' => [
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 ' ),
57
+ ];
58
+
59
+ yield 'find all with select ' => [
60
+ ['find ' => [[], ['projection ' => ['foo ' => 1 , 'bar ' => 1 ]]]],
61
+ fn (Builder $ builder ) => $ builder ->select ('foo ' , 'bar ' ),
62
+ ];
63
+
64
+ /** @see DatabaseQueryBuilderTest::testAddingSelects */
65
+ yield 'addSelect ' => [
66
+ ['find ' => [[], ['projection ' => ['foo ' => 1 , 'bar ' => 1 , 'baz ' => 1 , 'boom ' => 1 ]]]],
67
+ fn (Builder $ builder ) => $ builder ->select ('foo ' )
68
+ ->addSelect ('bar ' )
69
+ ->addSelect (['baz ' , 'boom ' ])
70
+ ->addSelect ('bar ' ),
71
+ ];
72
+
73
+ yield 'find equals ' => [
49
74
['find ' => [['foo ' => 'bar ' ], []]],
50
75
fn (Builder $ builder ) => $ builder ->where ('foo ' , 'bar ' ),
51
76
];
@@ -55,11 +80,59 @@ public static function provideQueryBuilderToMql(): iterable
55
80
fn (Builder $ builder ) => $ builder ->where ('foo ' , '> ' , $ date ),
56
81
];
57
82
58
- yield 'find in array ' => [
83
+ /** @see DatabaseQueryBuilderTest::testBasicWhereIns */
84
+ yield 'whereIn ' => [
59
85
['find ' => [['foo ' => ['$in ' => ['bar ' , 'baz ' ]]], []]],
60
86
fn (Builder $ builder ) => $ builder ->whereIn ('foo ' , ['bar ' , 'baz ' ]),
61
87
];
62
88
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
+
94
+ $ array = [['issue ' => 45582 ], ['id ' => 2 ], [3 ]];
95
+ yield 'whereIn nested array ' => [
96
+ ['find ' => [['id ' => ['$in ' => $ array ]], []]],
97
+ fn (Builder $ builder ) => $ builder ->whereIn ('id ' , $ array ),
98
+ ];
99
+
100
+ yield 'orWhereIn ' => [
101
+ ['find ' => [
102
+ ['$or ' => [
103
+ ['id ' => 1 ],
104
+ ['id ' => ['$in ' => [1 , 2 , 3 ]]],
105
+ ]],
106
+ [], // options
107
+ ]],
108
+ fn (Builder $ builder ) => $ builder ->where ('id ' , '= ' , 1 )
109
+ ->orWhereIn ('id ' , [1 , 2 , 3 ]),
110
+ ];
111
+
112
+ /** @see DatabaseQueryBuilderTest::testBasicWhereNotIns */
113
+ yield 'whereNotIn ' => [
114
+ ['find ' => [['id ' => ['$nin ' => [1 , 2 , 3 ]]], []]],
115
+ fn (Builder $ builder ) => $ builder ->whereNotIn ('id ' , [1 , 2 , 3 ]),
116
+ ];
117
+
118
+ yield 'orWhereNotIn ' => [
119
+ ['find ' => [
120
+ ['$or ' => [
121
+ ['id ' => 1 ],
122
+ ['id ' => ['$nin ' => [1 , 2 , 3 ]]],
123
+ ]],
124
+ [], // options
125
+ ]],
126
+ fn (Builder $ builder ) => $ builder ->where ('id ' , '= ' , 1 )
127
+ ->orWhereNotIn ('id ' , [1 , 2 , 3 ]),
128
+ ];
129
+
130
+ /** @see DatabaseQueryBuilderTest::testEmptyWhereIns */
131
+ yield 'whereIn empty array ' => [
132
+ ['find ' => [['id ' => ['$in ' => []]], []]],
133
+ fn (Builder $ builder ) => $ builder ->whereIn ('id ' , []),
134
+ ];
135
+
63
136
yield 'find limit offset select ' => [
64
137
['find ' => [[], ['limit ' => 10 , 'skip ' => 5 , 'projection ' => ['foo ' => 1 , 'bar ' => 1 ]]]],
65
138
fn (Builder $ builder ) => $ builder ->limit (10 )->offset (5 )->select ('foo ' , 'bar ' ),
@@ -251,11 +324,25 @@ function (Builder $builder) {
251
324
->orWhereNotBetween ('id ' , collect ([3 , 4 ])),
252
325
];
253
326
327
+ /** @see DatabaseQueryBuilderTest::testBasicSelectDistinct */
254
328
yield 'distinct ' => [
255
329
['distinct ' => ['foo ' , [], []]],
256
330
fn (Builder $ builder ) => $ builder ->distinct ('foo ' ),
257
331
];
258
332
333
+ yield 'select distinct ' => [
334
+ ['distinct ' => ['foo ' , [], []]],
335
+ fn (Builder $ builder ) => $ builder ->select ('foo ' , 'bar ' )
336
+ ->distinct (),
337
+ ];
338
+
339
+ /** @see DatabaseQueryBuilderTest::testBasicSelectDistinctOnColumns */
340
+ yield 'select distinct on ' => [
341
+ ['distinct ' => ['foo ' , [], []]],
342
+ fn (Builder $ builder ) => $ builder ->distinct ('foo ' )
343
+ ->select ('foo ' , 'bar ' ),
344
+ ];
345
+
259
346
yield 'groupBy ' => [
260
347
['aggregate ' => [
261
348
[['$group ' => ['_id ' => ['foo ' => '$foo ' ], 'foo ' => ['$last ' => '$foo ' ]]]],
@@ -361,6 +448,18 @@ public static function getEloquentMethodsNotSupported()
361
448
yield 'having ' => [fn (Builder $ builder ) => $ builder ->having ('baz ' , '= ' , 1 )];
362
449
yield 'havingBetween ' => [fn (Builder $ builder ) => $ builder ->havingBetween ('last_login_date ' , ['2018-11-16 ' , '2018-12-16 ' ])];
363
450
yield 'orHavingRaw ' => [fn (Builder $ builder ) => $ builder ->orHavingRaw ('user_foo < user_bar ' )];
451
+
452
+ /** @see DatabaseQueryBuilderTest::testWhereIntegerInRaw */
453
+ yield 'whereIntegerInRaw ' => [fn (Builder $ builder ) => $ builder ->whereIntegerInRaw ('id ' , ['1a ' , 2 ])];
454
+
455
+ /** @see DatabaseQueryBuilderTest::testOrWhereIntegerInRaw */
456
+ yield 'orWhereIntegerInRaw ' => [fn (Builder $ builder ) => $ builder ->orWhereIntegerInRaw ('id ' , ['1a ' , 2 ])];
457
+
458
+ /** @see DatabaseQueryBuilderTest::testWhereIntegerNotInRaw */
459
+ yield 'whereIntegerNotInRaw ' => [fn (Builder $ builder ) => $ builder ->whereIntegerNotInRaw ('id ' , ['1a ' , 2 ])];
460
+
461
+ /** @see DatabaseQueryBuilderTest::testOrWhereIntegerNotInRaw */
462
+ yield 'orWhereIntegerNotInRaw ' => [fn (Builder $ builder ) => $ builder ->orWhereIntegerNotInRaw ('id ' , ['1a ' , 2 ])];
364
463
}
365
464
366
465
private static function getBuilder (): Builder
0 commit comments