Skip to content

Commit 95e3709

Browse files
committed
Clean up DateRangeFilter - broken pills, and missing test
1 parent e429a02 commit 95e3709

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Views/Filters/DateRangeFilter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ public function validate(array|string|null $values): array|bool
4040
return false;
4141
}
4242

43-
$startDate = $this->createCarbonDate($returnedValues['minDate']);
44-
$endDate = $this->createCarbonDate($returnedValues['maxDate']);
45-
46-
if (! ($startDate instanceof Carbon) || ! ($endDate instanceof Carbon)) {
43+
if (! (($startDate = $this->createCarbonDate($returnedValues['minDate'])) instanceof Carbon) || ! (($endDate = $this->createCarbonDate($returnedValues['maxDate'])) instanceof Carbon)) {
4744
return false;
4845
}
46+
4947
if ($startDate->gt($endDate)) {
5048
return false;
5149
}

tests/Unit/Views/Filters/DateRangeFilterTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,5 +453,10 @@ public function test_can_check_validation_rejects_invalid_values_array(): void
453453
public function test_can_check_validation_rejects_broken_values_array(): void
454454
{
455455
$this->assertFalse(self::$filterInstance->validate(['minDate' => 'asdf', 'maxDate' => '2020-02-02']));
456+
$this->assertFalse(self::$filterInstance->validate(['minDate' => '4121-31-31', 'maxDate' => '2020-02-02']));
457+
$this->assertFalse(self::$filterInstance->validate(['minDate' => '2020-02-02', 'maxDate' => 'asdf']));
458+
$this->assertFalse(self::$filterInstance->validate(['minDate' => '2020-02-02', 'maxDate' => '4121-31-31']));
459+
460+
456461
}
457462
}

0 commit comments

Comments
 (0)