Skip to content

Commit

Permalink
refactore: rename for from and to to before and after
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Apr 26, 2024
1 parent d3eecb0 commit e4afb03
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/Dto/Search/Query/Filter/RelativeDateRangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 . ']';
Expand Down
36 changes: 18 additions & 18 deletions test/Dto/Search/Query/Filter/RelativeDateRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RelativeDateRangeFilterTest extends TestCase
/**
* @return array<array{string, string}>
*/
public static function additionProviderForFromIntervals(): array
public static function additionProviderForBeforeIntervals(): array
{
return [
['P1D', 'sp_date_list:[NOW-1DAYS/DAY TO NOW/DAY+1DAY-1SECOND]'],
Expand All @@ -32,7 +32,7 @@ public static function additionProviderForFromIntervals(): array
/**
* @return array<array{string, string}>
*/
public static function additionProviderForToIntervals(): array
public static function additionProviderForAfterIntervals(): array
{
return [
['P1D', 'sp_date_list:[NOW/DAY TO NOW-1DAYS/DAY]'],
Expand All @@ -45,7 +45,7 @@ public static function additionProviderForToIntervals(): array
/**
* @return array<array{string, string, string}>
*/
public static function additionProviderForFromAndToIntervals(): array
public static function additionProviderForBeforeAndAfterIntervals(): array
{
return [
['P1D', 'P1D', 'sp_date_list:[NOW-1DAYS/DAY TO NOW-1DAYS/DAY]'],
Expand Down Expand Up @@ -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,
);

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit e4afb03

Please sign in to comment.