2026-09-22 12:45:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Coupon;
|
|
|
|
|
|
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponDiffusion;
|
2026-09-25 09:44:57 +02:00
|
|
|
use Domain\Models\ValueObjects\Period;
|
2026-09-25 11:20:51 +02:00
|
|
|
use DateTime;
|
2026-09-22 12:45:08 +02:00
|
|
|
|
|
|
|
|
covers(CouponDiffusion::class);
|
|
|
|
|
|
|
|
|
|
describe('coupon diffusion', function (): void {
|
2026-09-25 09:44:57 +02:00
|
|
|
it('creates a valid coupon diffusion with one period', function (): void {
|
2026-09-22 12:45:08 +02:00
|
|
|
// GIVEN
|
2026-09-25 09:44:57 +02:00
|
|
|
$periods = [
|
|
|
|
|
new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01')),
|
|
|
|
|
];
|
2026-09-22 12:45:08 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$couponDiffusion = new CouponDiffusion($periods);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($couponDiffusion->periods)->toBe($periods);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-25 09:44:57 +02:00
|
|
|
it('creates a valid coupon diffusion with several periods', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$periods = [
|
|
|
|
|
new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01')),
|
|
|
|
|
new Period(new DateTime('2026-03-01'), new DateTime('2026-04-01')),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$couponDiffusion = new CouponDiffusion($periods);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($couponDiffusion->periods)->toBe($periods);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects a coupon diffusion without period', function (): void {
|
2026-09-22 12:45:08 +02:00
|
|
|
// GIVEN
|
|
|
|
|
$periods = [];
|
|
|
|
|
|
|
|
|
|
// GIVEN / THEN
|
|
|
|
|
expect(fn (): CouponDiffusion => new CouponDiffusion($periods))->toThrow(\DomainException::class);
|
|
|
|
|
});
|
2026-09-25 09:44:57 +02:00
|
|
|
|
|
|
|
|
it('rejects a coupon diffusion with a non-period element', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$periods = ['2026-08-25', '2026-10-31'];
|
|
|
|
|
|
|
|
|
|
// WHEN / THEN
|
|
|
|
|
expect(fn (): CouponDiffusion => new CouponDiffusion($periods))
|
|
|
|
|
->toThrow(\DomainException::class, 'CouponDiffusion periods must be Period instances.');
|
|
|
|
|
});
|
2026-09-22 12:45:08 +02:00
|
|
|
});
|