feat: default statistics filter to a rolling 12-month window
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\StatisticsFilterDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class StatisticsFilterDtoTest extends TestCase
|
||||
{
|
||||
public function testFreshDtoFallsBackToARollingTwelveMonthWindow(): void
|
||||
{
|
||||
$dto = new StatisticsFilterDto();
|
||||
|
||||
$expectedFrom = (new \DateTimeImmutable('today'))->modify('-12 months');
|
||||
|
||||
$this->assertSame(
|
||||
$expectedFrom->format('Y-m-d'),
|
||||
$dto->getEffectiveDateFrom()->format('Y-m-d'),
|
||||
);
|
||||
$this->assertSame(
|
||||
(new \DateTimeImmutable('today'))->format('Y-m-d'),
|
||||
$dto->getEffectiveDateTo()->format('Y-m-d'),
|
||||
);
|
||||
$this->assertTrue($dto->isUsingDefaultRange());
|
||||
$this->assertFalse($dto->isActive());
|
||||
}
|
||||
|
||||
public function testAPickedLowerBoundStopsTheFromFallbackButNotTheToFallback(): void
|
||||
{
|
||||
$from = new \DateTimeImmutable('2025-03-01');
|
||||
|
||||
$dto = (new StatisticsFilterDto())->setDateFrom($from);
|
||||
|
||||
$this->assertSame($from, $dto->getEffectiveDateFrom());
|
||||
$this->assertSame(
|
||||
(new \DateTimeImmutable('today'))->format('Y-m-d'),
|
||||
$dto->getEffectiveDateTo()->format('Y-m-d'),
|
||||
);
|
||||
$this->assertFalse($dto->isUsingDefaultRange());
|
||||
$this->assertTrue($dto->isActive());
|
||||
}
|
||||
|
||||
public function testBothBoundsPickedAreReturnedVerbatim(): void
|
||||
{
|
||||
$from = new \DateTimeImmutable('2025-01-01');
|
||||
$to = new \DateTimeImmutable('2025-06-30');
|
||||
|
||||
$dto = (new StatisticsFilterDto())
|
||||
->setDateFrom($from)
|
||||
->setDateTo($to)
|
||||
;
|
||||
|
||||
$this->assertSame($from, $dto->getEffectiveDateFrom());
|
||||
$this->assertSame($to, $dto->getEffectiveDateTo());
|
||||
$this->assertFalse($dto->isUsingDefaultRange());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user