new PrintRules( maxPerCustomer: $maxPerCustomer, cooldownDays: $cooldownDays ); // THEN expect($printRules) ->toThrow(\DomainException::class, 'No more than one print rule.'); }); 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(\DomainException::class, 'PrintRules require at least a max per customer or a cooldown days.'); }); it('rejects a maxPerCustomer equal to zero', function () use ($zeroMaxPerCustomer): void { // GIVEN / WHEN / THEN expect(fn (): PrintRules => new PrintRules( maxPerCustomer: $zeroMaxPerCustomer ))->toThrow(\DomainException::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(\DomainException::class, 'Cooldown days must be greater than 30.'); }); it('rejects print rule when max per customer limit has reached', function () use ($maxPerCustomer, $minMaxPerCustomer): void { // GIVEN $printRules = new PrintRules( maxPerCustomer: $minMaxPerCustomer ); // WHEN $action = fn () => $printRules->hasPrintLimitNotReached($maxPerCustomer); // THEN expect($action)->toThrow(\DomainException::class, 'Maximum number of prints reached.'); }); it('rejects print rule when cooldown days period has expired', function () use ($cooldownDays, $minCooldownDays): void { // GIVEN $printRules = new PrintRules( cooldownDays: $cooldownDays ); // WHEN $action = fn () => $printRules->hasReprintPeriodExpired($minCooldownDays); // THEN expect($action)->toThrow(\DomainException::class, 'Reprint period has not expired.'); }); });