69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\PrintableCoupon;
|
|
|
|
use Domain\Models\ValueObjects\Campaign\CampaignCode;
|
|
use Domain\Models\ValueObjects\Coupon\CouponCode;
|
|
use Domain\Models\ValueObjects\CrmHashcode;
|
|
use Domain\Models\ValueObjects\PrintableCoupon\PrintableCouponCode;
|
|
use Domain\Models\ValueObjects\PrintableCoupon\UnprintedCoupon;
|
|
use Domain\Models\ValueObjects\PrintableCoupon\UnprintedReason;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
covers(UnprintedCoupon::class);
|
|
|
|
describe('unprinted coupon', function (): void {
|
|
$printableCode = PrintableCouponCode::generate();
|
|
$couponCode = new CouponCode('AAA01');
|
|
$campaignCode = CampaignCode::generate();
|
|
$customer = new CrmHashcode(Uuid::uuid4());
|
|
|
|
it('keeps all the given values', function () use ($printableCode, $couponCode, $campaignCode, $customer): void {
|
|
// GIVEN
|
|
$reason = new UnprintedReason('Coupon expired before printing.');
|
|
|
|
// WHEN
|
|
$unprinted = new UnprintedCoupon($printableCode, $couponCode, $campaignCode, $customer, $reason);
|
|
|
|
// THEN
|
|
expect($unprinted->printableCode)->toBe($printableCode)
|
|
->and($unprinted->couponCode)->toBe($couponCode)
|
|
->and($unprinted->campaignCode)->toBe($campaignCode)
|
|
->and($unprinted->customer)->toBe($customer)
|
|
->and($unprinted->unprintedReason)->toBe($reason);
|
|
});
|
|
|
|
it('keeps the reason as given without trimming it', function () use ($printableCode, $couponCode, $campaignCode, $customer): void {
|
|
// GIVEN
|
|
$reason = new UnprintedReason(' Printer failure ');
|
|
|
|
// WHEN
|
|
$unprinted = new UnprintedCoupon($printableCode, $couponCode, $campaignCode, $customer, $reason);
|
|
|
|
// THEN
|
|
expect($unprinted->unprintedReason)->toBe($reason);
|
|
});
|
|
|
|
it('rejects an empty reason', function (string $invalidReason) use ($printableCode, $couponCode, $campaignCode, $customer): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): UnprintedCoupon => new UnprintedCoupon(
|
|
$printableCode,
|
|
$couponCode,
|
|
$campaignCode,
|
|
$customer,
|
|
new UnprintedReason($invalidReason),
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Unprinted reason cannot be empty.');
|
|
})->with([
|
|
'empty' => '',
|
|
'spaces' => ' ',
|
|
'tab' => "\t",
|
|
'new lines' => "\n\r\n",
|
|
'mixed spaces' => " \t\n ",
|
|
'unicode spaces' => "\u{00A0}\u{2003}",
|
|
]);
|
|
});
|