Skip to content

Commit 8bea4ff

Browse files
committed
PHPORM-159 Add tests on whereAny and whereAll
1 parent 19fc801 commit 8bea4ff

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

tests/Query/BuilderTest.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,138 @@ function (Builder $elemMatchQuery): void {
11571157
},
11581158
),
11591159
];
1160+
1161+
/** @see DatabaseQueryBuilderTest::testWhereAll */
1162+
yield 'whereAll' => [
1163+
[
1164+
'find' => [
1165+
['$and' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
1166+
[], // options
1167+
],
1168+
],
1169+
fn (Builder $builder) => $builder->whereAll(['last_name', 'email'], 'Doe'),
1170+
];
1171+
1172+
yield 'whereAll operator' => [
1173+
[
1174+
'find' => [
1175+
[
1176+
'$and' => [
1177+
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
1178+
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
1179+
],
1180+
],
1181+
[], // options
1182+
],
1183+
],
1184+
fn (Builder $builder) => $builder->whereAll(['last_name', 'email'], 'not like', '%Doe%'),
1185+
];
1186+
1187+
/** @see DatabaseQueryBuilderTest::testOrWhereAll */
1188+
yield 'orWhereAll' => [
1189+
[
1190+
'find' => [
1191+
[
1192+
'$or' => [
1193+
['first_name' => 'John'],
1194+
['$and' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
1195+
],
1196+
],
1197+
[], // options
1198+
],
1199+
],
1200+
fn (Builder $builder) => $builder
1201+
->where('first_name', 'John')
1202+
->orWhereAll(['last_name', 'email'], 'Doe'),
1203+
];
1204+
1205+
yield 'orWhereAll operator' => [
1206+
[
1207+
'find' => [
1208+
[
1209+
'$or' => [
1210+
['first_name' => new Regex('^.*John.*$', 'i')],
1211+
[
1212+
'$and' => [
1213+
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
1214+
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
1215+
],
1216+
],
1217+
],
1218+
],
1219+
[], // options
1220+
],
1221+
],
1222+
fn (Builder $builder) => $builder
1223+
->where('first_name', 'like', '%John%')
1224+
->orWhereAll(['last_name', 'email'], 'not like', '%Doe%'),
1225+
];
1226+
1227+
/** @see DatabaseQueryBuilderTest::testWhereAny */
1228+
yield 'whereAny' => [
1229+
[
1230+
'find' => [
1231+
['$or' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
1232+
[], // options
1233+
],
1234+
],
1235+
fn (Builder $builder) => $builder->whereAny(['last_name', 'email'], 'Doe'),
1236+
];
1237+
1238+
yield 'whereAny operator' => [
1239+
[
1240+
'find' => [
1241+
[
1242+
'$or' => [
1243+
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
1244+
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
1245+
],
1246+
],
1247+
[], // options
1248+
],
1249+
],
1250+
fn (Builder $builder) => $builder->whereAny(['last_name', 'email'], 'not like', '%Doe%'),
1251+
];
1252+
1253+
/** @see DatabaseQueryBuilderTest::testOrWhereAny */
1254+
yield 'orWhereAny' => [
1255+
[
1256+
'find' => [
1257+
[
1258+
'$or' => [
1259+
['first_name' => 'John'],
1260+
['$or' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
1261+
],
1262+
],
1263+
[], // options
1264+
],
1265+
],
1266+
fn (Builder $builder) => $builder
1267+
->where('first_name', 'John')
1268+
->orWhereAny(['last_name', 'email'], 'Doe'),
1269+
];
1270+
1271+
yield 'orWhereAny operator' => [
1272+
[
1273+
'find' => [
1274+
[
1275+
'$or' => [
1276+
['first_name' => new Regex('^.*John.*$', 'i')],
1277+
[
1278+
'$or' => [
1279+
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
1280+
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
1281+
],
1282+
],
1283+
],
1284+
],
1285+
[], // options
1286+
],
1287+
],
1288+
fn (Builder $builder) => $builder
1289+
->where('first_name', 'like', '%John%')
1290+
->orWhereAny(['last_name', 'email'], 'not like', '%Doe%'),
1291+
];
11601292
}
11611293

11621294
/** @dataProvider provideExceptions */

0 commit comments

Comments
 (0)