Skip to content

Commit c8fb0a0

Browse files
authored
PHPORM-159 Add tests on whereAny and whereAll (#2763)
New tests require Laravel v10.47
1 parent 411735a commit c8fb0a0

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

tests/Query/BuilderTest.php

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use stdClass;
2424

2525
use function collect;
26+
use function method_exists;
2627
use function now;
2728
use function var_export;
2829

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

11621301
/** @dataProvider provideExceptions */

0 commit comments

Comments
 (0)