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