2026-09-22 13:01:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
|
|
|
|
|
|
use Domain\Models\ValueObjects\PrintRules;
|
|
|
|
|
|
|
|
|
|
covers(PrintRules::class);
|
|
|
|
|
|
|
|
|
|
describe('print rules', function (): void {
|
2026-10-12 17:08:07 +02:00
|
|
|
$maxPerCustomer = 3;
|
|
|
|
|
$minMaxPerCustomer = 1;
|
|
|
|
|
$zeroMaxPerCustomer = 0;
|
|
|
|
|
$cooldownDays = 30;
|
|
|
|
|
$minCooldownDays = 1;
|
|
|
|
|
$zeroCooldownDays = 0;
|
|
|
|
|
|
|
|
|
|
it('creates print rules with both fields set', function () use ($maxPerCustomer, $cooldownDays): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN
|
|
|
|
|
$printRules = new PrintRules(
|
2026-10-12 17:08:07 +02:00
|
|
|
maxPerCustomer: $maxPerCustomer,
|
|
|
|
|
cooldownDays: $cooldownDays
|
2026-10-01 12:04:26 +02:00
|
|
|
);
|
2026-09-22 13:01:30 +02:00
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($printRules)->toBeInstanceOf(PrintRules::class)
|
2026-10-12 17:08:07 +02:00
|
|
|
->and($printRules->maxPerCustomer)->toBe($maxPerCustomer)
|
|
|
|
|
->and($printRules->cooldownDays)->toBe($cooldownDays);
|
2026-09-22 13:01:30 +02:00
|
|
|
});
|
|
|
|
|
|
2026-10-12 17:08:07 +02:00
|
|
|
it('creates print rules with only maxPerCustomer set', function () use ($maxPerCustomer): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN
|
|
|
|
|
$printRules = new PrintRules(
|
2026-10-12 17:08:07 +02:00
|
|
|
maxPerCustomer: $maxPerCustomer
|
2026-10-01 12:04:26 +02:00
|
|
|
);
|
2026-09-22 13:01:30 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-10-12 17:08:07 +02:00
|
|
|
expect($printRules->maxPerCustomer)->toBe($maxPerCustomer)
|
2026-09-22 13:01:30 +02:00
|
|
|
->and($printRules->cooldownDays)->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
2026-10-12 17:08:07 +02:00
|
|
|
it('creates print rules with only cooldownDays set', function () use ($cooldownDays): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN
|
|
|
|
|
$printRules = new PrintRules(
|
2026-10-12 17:08:07 +02:00
|
|
|
cooldownDays: $cooldownDays
|
2026-10-01 12:04:26 +02:00
|
|
|
);
|
2026-09-22 13:01:30 +02:00
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($printRules->maxPerCustomer)->toBeNull()
|
2026-10-12 17:08:07 +02:00
|
|
|
->and($printRules->cooldownDays)->toBe($cooldownDays);
|
2026-09-22 13:01:30 +02:00
|
|
|
});
|
|
|
|
|
|
2026-09-25 09:44:57 +02:00
|
|
|
it('rejects print rules without any field set', function (): void {
|
|
|
|
|
// WHEN / THEN
|
|
|
|
|
expect(fn (): PrintRules => new PrintRules())
|
|
|
|
|
->toThrow(\InvalidArgumentException::class, 'PrintRules require at least a max per customer or a cooldown days.');
|
|
|
|
|
});
|
|
|
|
|
|
2026-10-12 17:08:07 +02:00
|
|
|
it('accepts the minimum value of 1 for both fields', function () use ($minMaxPerCustomer, $minCooldownDays): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN
|
|
|
|
|
$printRules = new PrintRules(
|
2026-10-12 17:08:07 +02:00
|
|
|
maxPerCustomer: $minMaxPerCustomer,
|
|
|
|
|
cooldownDays: $minCooldownDays
|
2026-10-01 12:04:26 +02:00
|
|
|
);
|
2026-09-22 13:01:30 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-10-12 17:08:07 +02:00
|
|
|
expect($printRules->maxPerCustomer)->toBe($minMaxPerCustomer)
|
|
|
|
|
->and($printRules->cooldownDays)->toBe($minCooldownDays);
|
2026-09-25 09:44:57 +02:00
|
|
|
});
|
|
|
|
|
|
2026-10-12 17:08:07 +02:00
|
|
|
it('rejects a maxPerCustomer equal to zero', function () use ($zeroMaxPerCustomer): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN / THEN
|
|
|
|
|
expect(fn (): PrintRules => new PrintRules(
|
2026-10-12 17:08:07 +02:00
|
|
|
maxPerCustomer: $zeroMaxPerCustomer
|
2026-10-01 12:04:26 +02:00
|
|
|
))->toThrow(\InvalidArgumentException::class, 'Max per customer must be greater than 0.');
|
2026-09-25 09:44:57 +02:00
|
|
|
});
|
|
|
|
|
|
2026-10-12 17:08:07 +02:00
|
|
|
it('rejects a cooldownDays equal to zero', function () use ($zeroCooldownDays): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN / THEN
|
|
|
|
|
expect(fn (): PrintRules => new PrintRules(
|
2026-10-12 17:08:07 +02:00
|
|
|
cooldownDays: $zeroCooldownDays
|
2026-10-01 12:04:26 +02:00
|
|
|
))->toThrow(\InvalidArgumentException::class, 'Cooldown days must be greater than 0.');
|
2026-09-22 13:01:30 +02:00
|
|
|
});
|
|
|
|
|
});
|