106 lines
3.4 KiB
PHP
106 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Coupon;
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponProcessingCode;
|
|
use Domain\Models\ValueObjects\Coupon\CouponProcessingCodeArray;
|
|
use Shared\Enums\Country;
|
|
|
|
covers(CouponProcessingCodeArray::class);
|
|
|
|
describe('coupon processing code array', function (): void {
|
|
$franceCode = new CouponProcessingCode('ABC1234567890', Country::FRANCE);
|
|
$beneluxCode = new CouponProcessingCode('XYZ0987654321', Country::BENELUX);
|
|
|
|
it('creates an array containing a France processing code', function () use ($franceCode): void {
|
|
// GIVEN
|
|
$processingCodes = [$franceCode];
|
|
|
|
// WHEN
|
|
$array = new CouponProcessingCodeArray($processingCodes);
|
|
|
|
// THEN
|
|
expect($array->value)->toBe($processingCodes);
|
|
});
|
|
|
|
it('accepts additional countries next to France', function () use ($franceCode, $beneluxCode): void {
|
|
// GIVEN
|
|
$processingCodes = [$beneluxCode, $franceCode];
|
|
|
|
// WHEN
|
|
$array = new CouponProcessingCodeArray($processingCodes);
|
|
|
|
// THEN
|
|
expect($array->value)->toBe($processingCodes);
|
|
});
|
|
|
|
it('rejects an empty array', function (): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): CouponProcessingCodeArray => new CouponProcessingCodeArray([]);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(
|
|
\DomainException::class,
|
|
'ProcessingCodes requires at least one CouponProcessingCode.',
|
|
);
|
|
});
|
|
|
|
|
|
it('rejects two legal informations for the same country', function () use ($franceCode): void {
|
|
// GIVEN
|
|
$informations = [
|
|
$franceCode,
|
|
new CouponProcessingCode('XYZ0987654321', Country::FRANCE),
|
|
];
|
|
|
|
// WHEN
|
|
$action = fn (): CouponProcessingCodeArray => new CouponProcessingCodeArray($informations);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(
|
|
\DomainException::class,
|
|
'Only one CouponProcessingCode is allowed per country, duplicate for FRANCE.',
|
|
);
|
|
});
|
|
|
|
it('rejects a non processing code element', function (): void {
|
|
// GIVEN / WHEN
|
|
$action = fn (): CouponProcessingCodeArray => new CouponProcessingCodeArray(['ABC1234567890']);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(
|
|
\DomainException::class,
|
|
'Value of CouponProcessingCodeArray must be CouponProcessingCode instances.',
|
|
);
|
|
});
|
|
|
|
it('rejects a non processing code element mixed with valid ones', function () use ($franceCode): void {
|
|
// GIVEN
|
|
$processingCodes = [$franceCode, 'ABC1234567890'];
|
|
|
|
// WHEN
|
|
$action = fn (): CouponProcessingCodeArray => new CouponProcessingCodeArray($processingCodes);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(
|
|
\DomainException::class,
|
|
'Value of CouponProcessingCodeArray must be CouponProcessingCode instances.',
|
|
);
|
|
});
|
|
|
|
it('rejects an array without France processing code', function () use ($beneluxCode): void {
|
|
// GIVEN
|
|
$processingCodes = [$beneluxCode];
|
|
|
|
// WHEN
|
|
$action = fn (): CouponProcessingCodeArray => new CouponProcessingCodeArray($processingCodes);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(
|
|
\DomainException::class,
|
|
'CouponProcessingCodes requires a CouponProcessingCode for France.',
|
|
);
|
|
});
|
|
});
|