8000 PHPORM-47 Improve Builder::whereBetween to support CarbonPeriod and reject invalid array by GromNaN · Pull Request #10 · GromNaN/laravel-mongodb · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

PHPORM-47 Improve Builder::whereBetween to support CarbonPeriod and reject invalid array #10

Merged
merged 8 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
review
  • Loading branch information
GromNaN committed Jul 19, 2023
commit 3d152435b0a5e1a6719dba414a38e4ee5a12c2e1
2 changes: 1 addition & 1 deletion src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public function whereAll($column, array $values, $boolean = 'and', $not = false)

/**
* @inheritdoc
* @param array{mixed, mixed}|CarbonPeriod $values
* @param list{mixed, mixed}|CarbonPeriod $values
*/
public function whereBetween($column, iterable $values, $boolean = 'and', $not = false)
{
Expand Down
34 changes: 17 additions & 17 deletions tests/Query/BuilderTest.php
804B
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,6 @@ function (Builder $builder) {
fn (Builder $builder) => $builder->whereBetween('id', [[1], [2, 3]]),
];

yield 'whereNotBetween array of numbers' => [
['find' => [
['$or' => [
['id' => ['$lte' => 1]],
['id' => ['$gte' => 2]],
]],
[], // options
]],
fn (Builder $builder) => $builder->whereNotBetween('id', [1, 2]),
];

$period = now()->toPeriod(now()->addMonth());
yield 'whereBetween CarbonPeriod' => [
['find' => [
Expand Down Expand Up @@ -202,6 +191,17 @@ function (Builder $builder) {
->orWhereBetween('id', collect([3, 4])),
];

yield 'whereNotBetween array of numbers' => [
['find' => [
['$or' => [
['id' => ['$lte' => 1]],
['id' => ['$gte' => 2]],
]],
[], // options
]],
fn (Builder $builder) => $builder->whereNotBetween('id', [1, 2]),
];

/** @see DatabaseQueryBuilderTest::testOrWhereNotBetween() */
yield 'orWhereNotBetween array of numbers' => [
['find' => [
Expand Down Expand Up @@ -292,6 +292,12 @@ public static function provideExceptions(): iterable
fn (Builder $builder) => $builder->whereBetween('id', [1]),
];

yield 'whereBetween array too short (nested)' => [
\InvalidArgumentException::class,
'Between $values must be a list with exactly two elements: [min, max]',
fn (Builder $builder) => $builder->whereBetween('id', [[1, 2]]),
];

yield 'whereBetween array too long' => [
\InvalidArgumentException::class,
'Between $values must be a list with exactly two elements: [min, max]',
Expand All @@ -309,12 +315,6 @@ public static function provideExceptions(): iterable
'Between $values must be a list with exactly two elements: [min, max]',
fn (Builder $builder) => $builder->whereBetween('id', ['min' => 1, 'max' => 2]),
];

yield 'whereBetween array too short (nested)' => [
\InvalidArgumentException::class,
'Between $values must be a list with exactly two elements: [min, max]',
fn (Builder $builder) => $builder->whereBetween('id', [[1, 2]]),
];
}

/** @dataProvider getEloquentMethodsNotSupported */
Expand Down
0