57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Campaign;
|
|
|
|
use Domain\Models\ValueObjects\Campaign\CampaignCoupon;
|
|
use Domain\Models\ValueObjects\Campaign\CampaignCouponArray;
|
|
use Domain\Models\ValueObjects\Coupon\CouponCode;
|
|
use Domain\Models\ValueObjects\PrintRules;
|
|
|
|
covers(CampaignCouponArray::class);
|
|
|
|
describe('campaign coupon array', function (): void {
|
|
$coupon = new CampaignCoupon(
|
|
new CouponCode('AAA01'),
|
|
new PrintRules(maxPerCustomer: 3),
|
|
);
|
|
|
|
it('creates an array with valid coupons', function () use ($coupon): void {
|
|
// GIVEN
|
|
$coupons = [$coupon, $coupon];
|
|
|
|
// WHEN
|
|
$array = new CampaignCouponArray($coupons);
|
|
|
|
// THEN
|
|
expect($array->value)->toBe($coupons);
|
|
});
|
|
|
|
it('rejects an empty array', function (): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): CampaignCouponArray => new CampaignCouponArray([]);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Coupons requires at least one CampaignCoupon.');
|
|
});
|
|
|
|
it('rejects a non-coupon element', function (): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): CampaignCouponArray => new CampaignCouponArray(['PC1']);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Coupons must be CampaignCoupon instances.');
|
|
});
|
|
|
|
it('rejects a non-coupon element mixed with valid coupons', function () use ($coupon): void {
|
|
// GIVEN
|
|
$coupons = [$coupon, 'PC1'];
|
|
|
|
// WHEN
|
|
$action = fn (): CampaignCouponArray => new CampaignCouponArray($coupons);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Coupons must be CampaignCoupon instances.');
|
|
});
|
|
});
|