Skip to content

Commit

Permalink
New tests require Laravel v10.47
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Mar 12, 2024
1 parent cc9dd94 commit 18b0eab
Showing 1 changed file with 113 additions and 106 deletions.
219 changes: 113 additions & 106 deletions tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use stdClass;

use function collect;
use function method_exists;
use function now;
use function var_export;

Expand Down Expand Up @@ -1158,137 +1159,143 @@ function (Builder $elemMatchQuery): void {
),
];

/** @see DatabaseQueryBuilderTest::testWhereAll */
yield 'whereAll' => [
[
'find' => [
['$and' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
[], // options
// Method added in Laravel v10.47.0
if (method_exists(Builder::class, 'whereAll')) {
/** @see DatabaseQueryBuilderTest::testWhereAll */
yield 'whereAll' => [
[
'find' => [
['$and' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
[], // options
],
],
],
fn (Builder $builder) => $builder->whereAll(['last_name', 'email'], 'Doe'),
];

yield 'whereAll operator' => [
[
'find' => [
[
'$and' => [
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
fn(Builder $builder) => $builder->whereAll(['last_name', 'email'], 'Doe'),
];

yield 'whereAll operator' => [
[
'find' => [
[
'$and' => [
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
],
],
[], // options
],
[], // options
],
],
fn (Builder $builder) => $builder->whereAll(['last_name', 'email'], 'not like', '%Doe%'),
];

/** @see DatabaseQueryBuilderTest::testOrWhereAll */
yield 'orWhereAll' => [
[
'find' => [
[
'$or' => [
['first_name' => 'John'],
['$and' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
fn(Builder $builder) => $builder->whereAll(['last_name', 'email'], 'not like', '%Doe%'),
];

/** @see DatabaseQueryBuilderTest::testOrWhereAll */
yield 'orWhereAll' => [
[
'find' => [
[
'$or' => [
['first_name' => 'John'],
['$and' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
],
],
[], // options
],
[], // options
],
],
fn (Builder $builder) => $builder
->where('first_name', 'John')
->orWhereAll(['last_name', 'email'], 'Doe'),
];

yield 'orWhereAll operator' => [
[
'find' => [
[
'$or' => [
['first_name' => new Regex('^.*John.*$', 'i')],
[
'$and' => [
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
fn(Builder $builder) => $builder
->where('first_name', 'John')
->orWhereAll(['last_name', 'email'], 'Doe'),
];

yield 'orWhereAll operator' => [
[
'find' => [
[
'$or' => [
['first_name' => new Regex('^.*John.*$', 'i')],
[
'$and' => [
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
],
],
],
],
[], // options
],
[], // options
],
],
fn (Builder $builder) => $builder
->where('first_name', 'like', '%John%')
->orWhereAll(['last_name', 'email'], 'not like', '%Doe%'),
];
fn(Builder $builder) => $builder
->where('first_name', 'like', '%John%')
->orWhereAll(['last_name', 'email'], 'not like', '%Doe%'),
];
}

/** @see DatabaseQueryBuilderTest::testWhereAny */
yield 'whereAny' => [
[
'find' => [
['$or' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
[], // options
// Method added in Laravel v10.47.0
if (method_exists(Builder::class, 'whereAny')) {
/** @see DatabaseQueryBuilderTest::testWhereAny */
yield 'whereAny' => [
[
'find' => [
['$or' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
[], // options
],
],
],
fn (Builder $builder) => $builder->whereAny(['last_name', 'email'], 'Doe'),
];

yield 'whereAny operator' => [
[
'find' => [
[
'$or' => [
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
fn(Builder $builder) => $builder->whereAny(['last_name', 'email'], 'Doe'),
];

yield 'whereAny operator' => [
[
'find' => [
[
'$or' => [
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
],
],
[], // options
],
[], // options
],
],
fn (Builder $builder) => $builder->whereAny(['last_name', 'email'], 'not like', '%Doe%'),
];

/** @see DatabaseQueryBuilderTest::testOrWhereAny */
yield 'orWhereAny' => [
[
'find' => [
[
'$or' => [
['first_name' => 'John'],
['$or' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
fn(Builder $builder) => $builder->whereAny(['last_name', 'email'], 'not like', '%Doe%'),
];

/** @see DatabaseQueryBuilderTest::testOrWhereAny */
yield 'orWhereAny' => [
[
'find' => [
[
'$or' => [
['first_name' => 'John'],
['$or' => [['last_name' => 'Doe'], ['email' => 'Doe']]],
],
],
[], // options
],
[], // options
],
],
fn (Builder $builder) => $builder
->where('first_name', 'John')
->orWhereAny(['last_name', 'email'], 'Doe'),
];

yield 'orWhereAny operator' => [
[
'find' => [
[
'$or' => [
['first_name' => new Regex('^.*John.*$', 'i')],
[
'$or' => [
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
fn(Builder $builder) => $builder
->where('first_name', 'John')
->orWhereAny(['last_name', 'email'], 'Doe'),
];

yield 'orWhereAny operator' => [
[
'find' => [
[
'$or' => [
['first_name' => new Regex('^.*John.*$', 'i')],
[
'$or' => [
['last_name' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
['email' => ['$not' => new Regex('^.*Doe.*$', 'i')]],
],
],
],
],
[], // options
],
[], // options
],
],
fn (Builder $builder) => $builder
->where('first_name', 'like', '%John%')
->orWhereAny(['last_name', 'email'], 'not like', '%Doe%'),
];
fn(Builder $builder) => $builder
->where('first_name', 'like', '%John%')
->orWhereAny(['last_name', 'email'], 'not like', '%Doe%'),
];
}
}

/** @dataProvider provideExceptions */
Expand Down

0 comments on commit 18b0eab

Please sign in to comment.