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

87 lines
2.9 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 {
beforeEach(function (): void {
$this->maxPerCustomer = 3;
$this->minMaxPerCustomer = 1;
$this->zeroMaxPerCustomer = 0;
$this->cooldownDays = 30;
$this->minCooldownDays = 1;
$this->zeroCooldownDays = 0;
});
it('creates print rules with both fields set', function (): void {
// GIVEN / WHEN
$printRules = new PrintRules(
maxPerCustomer: $this->maxPerCustomer,
cooldownDays: $this->cooldownDays
);
// THEN
expect($printRules)->toBeInstanceOf(PrintRules::class)
->and($printRules->maxPerCustomer)->toBe($this->maxPerCustomer)
->and($printRules->cooldownDays)->toBe($this->cooldownDays);
});
it('creates print rules with only maxPerCustomer set', function (): void {
// GIVEN / WHEN
$printRules = new PrintRules(
maxPerCustomer: $this->maxPerCustomer
);
// THEN
expect($printRules->maxPerCustomer)->toBe($this->maxPerCustomer)
->and($printRules->cooldownDays)->toBeNull();
});
it('creates print rules with only cooldownDays set', function (): void {
// GIVEN / WHEN
$printRules = new PrintRules(
cooldownDays: $this->cooldownDays
);
// THEN
expect($printRules->maxPerCustomer)->toBeNull()
->and($printRules->cooldownDays)->toBe($this->cooldownDays);
});
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 {
// GIVEN / WHEN
$printRules = new PrintRules(
maxPerCustomer: $this->minMaxPerCustomer,
cooldownDays: $this->minCooldownDays
);
// THEN
expect($printRules->maxPerCustomer)->toBe($this->minMaxPerCustomer)
->and($printRules->cooldownDays)->toBe($this->minCooldownDays);
});
it('rejects a maxPerCustomer equal to zero', function (): void {
// GIVEN / WHEN / THEN
expect(fn (): PrintRules => new PrintRules(
maxPerCustomer: $this->zeroMaxPerCustomer
))->toThrow(\InvalidArgumentException::class, 'Max per customer must be greater than 0.');
});
it('rejects a cooldownDays equal to zero', function (): void {
// GIVEN / WHEN / THEN
expect(fn (): PrintRules => new PrintRules(
cooldownDays: $this->zeroCooldownDays
))->toThrow(\InvalidArgumentException::class, 'Cooldown days must be greater than 0.');
});
});