48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Coupon;
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponQuantity;
|
|
|
|
covers(CouponQuantity::class);
|
|
|
|
describe('coupon quantity', function (): void {
|
|
beforeEach(function (): void {
|
|
$this->quantity = 10;
|
|
$this->zeroQuantity = 0;
|
|
$this->negativeQuantity = -1;
|
|
});
|
|
|
|
it('creates a valid coupon quantity', function (): void {
|
|
// GIVEN / WHEN
|
|
$couponQuantity = new CouponQuantity(
|
|
$this->quantity
|
|
);
|
|
|
|
// THEN
|
|
expect($couponQuantity)->toBeInstanceOf(CouponQuantity::class)
|
|
->and($couponQuantity->quantity)->toBe($this->quantity);
|
|
});
|
|
|
|
it('rejects a quantity of zero', function (): void {
|
|
// WHEN
|
|
$action = fn (): CouponQuantity => new CouponQuantity(
|
|
$this->zeroQuantity
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'CouponQuantity quantity must be positive.');
|
|
});
|
|
|
|
it('rejects a negative quantity', function (): void {
|
|
// WHEN
|
|
$action = fn (): CouponQuantity => new CouponQuantity(
|
|
$this->negativeQuantity
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'CouponQuantity quantity must be positive.');
|
|
});
|
|
});
|