diff --git a/src/Dto/Search/Query/Filter/RelativeDateRangeFilter.php b/src/Dto/Search/Query/Filter/RelativeDateRangeFilter.php index c1ef7d8..37bc886 100644 --- a/src/Dto/Search/Query/Filter/RelativeDateRangeFilter.php +++ b/src/Dto/Search/Query/Filter/RelativeDateRangeFilter.php @@ -11,8 +11,8 @@ class RelativeDateRangeFilter extends Filter { public function __construct( private readonly ?\DateTime $base, - private readonly ?DateInterval $from, - private readonly ?DateInterval $to, + private readonly ?DateInterval $before, + private readonly ?DateInterval $after, ?string $key = null ) { parent::__construct( @@ -28,16 +28,16 @@ public function getQuery(): string private function toSolrDateRage(): string { - if ($this->from === null) { + if ($this->before === null) { $from = $this->getBaseInSolrSyntax() . "/DAY"; } else { - $from = $this->toSolrIntervalSyntax($this->from); + $from = $this->toSolrIntervalSyntax($this->before); } - if ($this->to === null) { + if ($this->after === null) { $to = $this->getBaseInSolrSyntax() . "/DAY+1DAY-1SECOND"; } else { - $to = $this->toSolrIntervalSyntax($this->to); + $to = $this->toSolrIntervalSyntax($this->after); } return '[' . $from . ' TO ' . $to . ']'; diff --git a/test/Dto/Search/Query/Filter/RelativeDateRangeFilterTest.php b/test/Dto/Search/Query/Filter/RelativeDateRangeFilterTest.php index 6696212..94f6f44 100644 --- a/test/Dto/Search/Query/Filter/RelativeDateRangeFilterTest.php +++ b/test/Dto/Search/Query/Filter/RelativeDateRangeFilterTest.php @@ -19,7 +19,7 @@ class RelativeDateRangeFilterTest extends TestCase /** * @return array */ - public static function additionProviderForFromIntervals(): array + public static function additionProviderForBeforeIntervals(): array { return [ ['P1D', 'sp_date_list:[NOW-1DAYS/DAY TO NOW/DAY+1DAY-1SECOND]'], @@ -32,7 +32,7 @@ public static function additionProviderForFromIntervals(): array /** * @return array */ - public static function additionProviderForToIntervals(): array + public static function additionProviderForAfterIntervals(): array { return [ ['P1D', 'sp_date_list:[NOW/DAY TO NOW-1DAYS/DAY]'], @@ -45,7 +45,7 @@ public static function additionProviderForToIntervals(): array /** * @return array */ - public static function additionProviderForFromAndToIntervals(): array + public static function additionProviderForBeforeAndAfterIntervals(): array { return [ ['P1D', 'P1D', 'sp_date_list:[NOW-1DAYS/DAY TO NOW-1DAYS/DAY]'], @@ -98,14 +98,14 @@ public static function additionProviderForInvalidIntervals(): array /** * @throws Exception */ - #[DataProvider('additionProviderForFromIntervals')] + #[DataProvider('additionProviderForBeforeIntervals')] public function testGetQueryWithFrom( - string $from, + string $before, string $expected ): void { $filter = new RelativeDateRangeFilter( null, - new DateInterval($from), + new DateInterval($before), null, ); @@ -119,15 +119,15 @@ public function testGetQueryWithFrom( /** * @throws Exception */ - #[DataProvider('additionProviderForToIntervals')] + #[DataProvider('additionProviderForAfterIntervals')] public function testGetQueryWithTo( - string $to, + string $after, string $expected ): void { $filter = new RelativeDateRangeFilter( null, null, - new DateInterval($to), + new DateInterval($after), ); $this->assertEquals( @@ -140,16 +140,16 @@ public function testGetQueryWithTo( /** * @throws Exception */ - #[DataProvider('additionProviderForFromAndToIntervals')] + #[DataProvider('additionProviderForBeforeAndAfterIntervals')] public function testGetQueryWithFromAndTo( - string $from, - string $to, + string $before, + string $after, string $expected ): void { $filter = new RelativeDateRangeFilter( null, - new DateInterval($from), - new DateInterval($to), + new DateInterval($before), + new DateInterval($after), ); $this->assertEquals( @@ -165,14 +165,14 @@ public function testGetQueryWithFromAndTo( #[DataProvider('additionProviderWithBase')] public function testGetQueryWithBase( DateTime $base, - ?string $from, - ?string $to, + ?string $before, + ?string $after, string $expected ): void { $filter = new RelativeDateRangeFilter( $base, - $from === null ? null : new DateInterval($from), - $to === null ? null : new DateInterval($to), + $before === null ? null : new DateInterval($before), + $after === null ? null : new DateInterval($after), ); $this->assertEquals(