48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\RequestedCoupon;
|
|
|
|
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
|
|
|
|
covers(RequestedCouponQuantity::class);
|
|
|
|
describe('quantity', function (): void {
|
|
beforeEach(function (): void {
|
|
$this->value = 10;
|
|
$this->zeroValue = 0;
|
|
$this->negativeValue = -1;
|
|
});
|
|
|
|
it('creates a valid quantity', function (): void {
|
|
// GIVEN / WHEN
|
|
$quantity = new RequestedCouponQuantity(
|
|
$this->value
|
|
);
|
|
|
|
// THEN
|
|
expect($quantity)->toBeInstanceOf(RequestedCouponQuantity::class)
|
|
->and($quantity->value)->toBe($this->value);
|
|
});
|
|
|
|
it('rejects a quantity of zero', function (): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): RequestedCouponQuantity => new RequestedCouponQuantity(
|
|
$this->zeroValue
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Quantity should be more than 0.');
|
|
});
|
|
|
|
it('rejects a negative quantity', function (): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): RequestedCouponQuantity => new RequestedCouponQuantity(
|
|
$this->negativeValue
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Quantity should be more than 0.');
|
|
});
|
|
});
|