Add normalization and denormalization for RollingDate

Introduce methods to normalize and recreate RollingDate objects, ensuring consistent serialization and deserialization. Includes corresponding tests for both cases with and without a pivot date.
This commit is contained in:
2025-03-10 21:07:54 +01:00
parent 1751c65731
commit 2c91d2e10f
2 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Tests\Services\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class RollingDateTest extends TestCase
{
public function testNormalizationDenormalizationProcessWithoutPivotDate(): void
{
$date = new RollingDate(RollingDate::T_YEAR_PREVIOUS_START);
$actual = RollingDate::fromNormalized($date->normalize());
self::assertEquals(RollingDate::T_YEAR_PREVIOUS_START, $actual->getRoll());
self::assertNull($actual->getFixedDate());
self::assertEquals($date->getPivotDate()->getTimestamp(), $actual->getPivotDate()->getTimestamp());
}
public function testNormalizationDenormalizationProcessWithPivotDate(): void
{
$date = new RollingDate(RollingDate::T_FIXED_DATE, $pivot = new \DateTimeImmutable('now'));
$actual = RollingDate::fromNormalized($date->normalize());
self::assertEquals(RollingDate::T_FIXED_DATE, $actual->getRoll());
self::assertEquals($pivot, $actual->getFixedDate());
self::assertEquals($date->getPivotDate()->getTimestamp(), $actual->getPivotDate()->getTimestamp());
}
}