ldc-mesbr-app/tests/Unit/Domain/Models/ValueObjects/PrintRulesTest.php
2026-10-02 12:47:27 +02:00

72 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Domain\Models\ValueObjects\PrintRules;
covers(PrintRules::class);
describe('print rules', function (): void {
it('creates print rules with both fields set', function (): void {
// WHEN
$printRules = new PrintRules(maxPerCustomer: 3, cooldownDays: 30);
// THEN
expect($printRules)->toBeInstanceOf(PrintRules::class)
->and($printRules->maxPerCustomer)->toBe(3)
->and($printRules->cooldownDays)->toBe(30);
});
it('creates print rules with only maxPerCustomer set', function (): void {
// WHEN
$printRules = new PrintRules(maxPerCustomer: 5);
// THEN
expect($printRules->maxPerCustomer)->toBe(5)
->and($printRules->cooldownDays)->toBeNull();
});
it('creates print rules with only cooldownDays set', function (): void {
// WHEN
$printRules = new PrintRules(cooldownDays: 45);
// THEN
expect($printRules->maxPerCustomer)->toBeNull()
->and($printRules->cooldownDays)->toBe(45);
});
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.');
});
it('accepts the minimum value of 1 for both fields', function (): void {
// WHEN
$printRules = new PrintRules(maxPerCustomer: 1, cooldownDays: 1);
// THEN
expect($printRules->maxPerCustomer)->toBe(1)
->and($printRules->cooldownDays)->toBe(1);
});
it('rejects a maxPerCustomer equal to zero', function (): void {
// GIVEN
$maxPerCustomer = 0;
// WHEN / THEN
expect(fn (): PrintRules => new PrintRules(maxPerCustomer: $maxPerCustomer))
->toThrow(\InvalidArgumentException::class, 'Max per customer must be greater than 0.');
});
it('rejects a cooldownDays equal to zero', function (): void {
// GIVEN
$cooldownDays = 0;
// WHEN / THEN
expect(fn (): PrintRules => new PrintRules(cooldownDays: $cooldownDays))
->toThrow(\InvalidArgumentException::class, 'Cooldown days must be greater than 0.');
});
});