@@ -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
];
@@ -66,11 +91,59 @@ public static function provideQueryBuilderToMql(): iterable
66
91
fn (Builder $ builder ) => $ builder ->where ('foo ' , '> ' , $ date ),
67
92
];
68
93
69
- yield 'find in array ' => [
94
+ /** @see DatabaseQueryBuilderTest::testBasicWhereIns */
95
+ yield 'whereIn ' => [
70
96
['find ' => [['foo ' => ['$in ' => ['bar ' , 'baz ' ]]], []]],
71
97
fn (Builder $ builder ) => $ builder ->whereIn ('foo ' , ['bar ' , 'baz ' ]),
72
98
];
73
99
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
+
105
+ $ array = [['issue ' => 45582 ], ['id ' => 2 ], [3 ]];
106
+ yield 'whereIn nested array ' => [
107
+ ['find ' => [['id ' => ['$in ' => $ array ]], []]],
108
+ fn (Builder $ builder ) => $ builder ->whereIn ('id ' , $ array ),
109
+ ];
110
+
111
+ yield 'orWhereIn ' => [
112
+ ['find ' => [
113
+ ['$or ' => [
114
+ ['id ' => 1 ],
115
+ ['id ' => ['$in ' => [1 , 2 , 3 ]]],
116
+ ]],
117
+ [], // options
118
+ ]],
119
+ fn (Builder $ builder ) => $ builder ->where ('id ' , '= ' , 1 )
120
+ ->orWhereIn ('id ' , [1 , 2 , 3 ]),
121
+ ];
122
+
123
+ /** @see DatabaseQueryBuilderTest::testBasicWhereNotIns */
124
+ yield 'whereNotIn ' => [
125
+ ['find ' => [['id ' => ['$nin ' => [1 , 2 , 3 ]]], []]],
126
+ fn (Builder $ builder ) => $ builder ->whereNotIn ('id ' , [1 , 2 , 3 ]),
127
+ ];
128
+
129
+ yield 'orWhereNotIn ' => [
130
+ ['find ' => [
131
+ ['$or ' => [
132
+ ['id ' => 1 ],
133
+ ['id ' => ['$nin ' => [1 , 2 , 3 ]]],
134
+ ]],
135
+ [], // options
136
+ ]],
137
+ fn (Builder $ builder ) => $ builder ->where ('id ' , '= ' , 1 )
138
+ ->orWhereNotIn ('id ' , [1 , 2 , 3 ]),
139
+ ];
140
+
141
+ /** @see DatabaseQueryBuilderTest::testEmptyWhereIns */
142
+ yield 'whereIn empty array ' => [
143
+ ['find ' => [['id ' => ['$in ' => []]], []]],
144
+ fn (Builder $ builder ) => $ builder ->whereIn ('id ' , []),
145
+ ];
146
+
74
147
yield 'find limit offset select ' => [
75
148
['find ' => [[], ['limit ' => 10 , 'skip ' => 5 , 'projection ' => ['foo ' => 1 , 'bar ' => 1 ]]]],
76
149
fn (Builder $ builder ) => $ builder ->limit (10 )->offset (5 )->select ('foo ' , 'bar ' ),
@@ -439,11 +512,25 @@ function (Builder $builder) {
439
512
->orWhereNotBetween ('id ' , collect ([3 , 4 ])),
440
513
];
441
514
515
+ /** @see DatabaseQueryBuilderTest::testBasicSelectDistinct */
442
516
yield 'distinct ' => [
443
517
['distinct ' => ['foo ' , [], []]],
444
518
fn (Builder $ builder ) => $ builder ->distinct ('foo ' ),
445
519
];
446
520
521
+ yield 'select distinct ' => [
522
+ ['distinct ' => ['foo ' , [], []]],
523
+ fn (Builder $ builder ) => $ builder ->select ('foo ' , 'bar ' )
524
+ ->distinct (),
525
+ ];
526
+
527
+ /** @see DatabaseQueryBuilderTest::testBasicSelectDistinctOnColumns */
528
+ yield 'select distinct on ' => [
529
+ ['distinct ' => ['foo ' , [], []]],
530
+ fn (Builder $ builder ) => $ builder ->distinct ('foo ' )
531
+ ->select ('foo ' , 'bar ' ),
532
+ ];
533
+
447
534
yield 'groupBy ' => [
448
535
['aggregate ' => [
449
536
[['$group ' => ['_id ' => ['foo ' => '$foo ' ], 'foo ' => ['$last ' => '$foo ' ]]]],
@@ -549,6 +636,18 @@ public static function getEloquentMethodsNotSupported()
549
636
yield 'having ' => [fn (Builder $ builder ) => $ builder ->having ('baz ' , '= ' , 1 )];
550
637
yield 'havingBetween ' => [fn (Builder $ builder ) => $ builder ->havingBetween ('last_login_date ' , ['2018-11-16 ' , '2018-12-16 ' ])];
551
638
yield 'orHavingRaw ' => [fn (Builder $ builder ) => $ builder ->orHavingRaw ('user_foo < user_bar ' )];
639
+
640
+ /** @see DatabaseQueryBuilderTest::testWhereIntegerInRaw */
641
+ yield 'whereIntegerInRaw ' => [fn (Builder $ builder ) => $ builder ->whereIntegerInRaw ('id ' , ['1a ' , 2 ])];
642
+
643
+ /** @see DatabaseQueryBuilderTest::testOrWhereIntegerInRaw */
644
+ yield 'orWhereIntegerInRaw ' => [fn (Builder $ builder ) => $ builder ->orWhereIntegerInRaw ('id ' , ['1a ' , 2 ])];
645
+
646
+ /** @see DatabaseQueryBuilderTest::testWhereIntegerNotInRaw */
647
+ yield 'whereIntegerNotInRaw ' => [fn (Builder $ builder ) => $ builder ->whereIntegerNotInRaw ('id ' , ['1a ' , 2 ])];
648
+
649
+ /** @see DatabaseQueryBuilderTest::testOrWhereIntegerNotInRaw */
650
+ yield 'orWhereIntegerNotInRaw ' => [fn (Builder $ builder ) => $ builder ->orWhereIntegerNotInRaw ('id ' , ['1a ' , 2 ])];
552
651
}
553
652
554
653
private static function getBuilder (): Builder
0 commit comments