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