61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Coupon;
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponMovement;
|
|
use Domain\Models\ValueObjects\Coupon\CouponMovementArray;
|
|
|
|
covers(CouponMovementArray::class);
|
|
|
|
describe('coupon movement array', function (): void {
|
|
$couponMovement = new CouponMovement(100);
|
|
|
|
it('creates an array with valid coupon movements', function () use ($couponMovement): void {
|
|
// GIVEN
|
|
$couponMovements = [$couponMovement, $couponMovement];
|
|
|
|
// WHEN
|
|
$array = new CouponMovementArray($couponMovements);
|
|
|
|
// THEN
|
|
expect($array->value)->toBe($couponMovements);
|
|
});
|
|
|
|
it('rejects an empty array', function (): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): CouponMovementArray => new CouponMovementArray([]);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(
|
|
\DomainException::class,
|
|
'CouponMovementArray requires at least one CouponMovement.',
|
|
);
|
|
});
|
|
|
|
it('rejects a non coupon movement element', function (): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): CouponMovementArray => new CouponMovementArray(['movement']);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(
|
|
\DomainException::class,
|
|
'Value of CouponMovementArray must be CouponMovement instances.',
|
|
);
|
|
});
|
|
|
|
it('rejects a non coupon movement element mixed with valid ones', function () use ($couponMovement): void {
|
|
// GIVEN
|
|
$couponMovements = [$couponMovement, 'movement'];
|
|
|
|
// WHEN
|
|
$action = fn (): CouponMovementArray => new CouponMovementArray($couponMovements);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(
|
|
\DomainException::class,
|
|
'Value of CouponMovementArray must be CouponMovement instances.',
|
|
);
|
|
});
|
|
});
|