mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 14:25:00 +00:00
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:
@@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user