ldc-mesbr-app/tests/Unit/Domain/Models/ValueObjects/PeriodTest.php
2026-10-14 14:34:22 +02:00

44 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Domain\Models\ValueObjects\Period;
use DateTime;
covers(Period::class);
describe('period', function (): void {
$start = new DateTime('2026-01-01');
$end = new DateTime('2026-01-31');
it('creates a valid period', function () use ($start, $end): void {
// GIVEN / WHEN
$period = new Period($start, $end);
// THEN
expect($period)->toBeInstanceOf(Period::class)
->and($period->start)->toBe($start)
->and($period->end)->toBe($end);
});
it('accepts a period whose end equals its start', function (): void {
// GIVEN
$start = new DateTime('2026-01-01');
$end = new DateTime('2026-01-01');
// WHEN
$period = new Period($start, $end);
// THEN
expect($period->start)->toBe($start)
->and($period->end)->toBe($end);
});
it('throws when the end is before the start', function (): void {
// GIVEN / WHEN / THEN
expect(fn (): Period => new Period(new DateTime('2026-02-01'), new DateTime('2026-01-01')))
->toThrow(\DomainException::class, 'Period end date cannot be before its start date.');
});
});