2026-10-12 17:08:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Coupon;
|
|
|
|
|
|
2026-10-13 15:41:21 +02:00
|
|
|
use Domain\Models\ValueObjects\ProcessingCode;
|
2026-10-12 17:08:07 +02:00
|
|
|
use Shared\Enums\Country;
|
|
|
|
|
|
2026-10-13 15:41:21 +02:00
|
|
|
covers(ProcessingCode::class);
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
describe('coupon processing code', function (): void {
|
2026-10-13 15:56:11 +02:00
|
|
|
$value = '5425003944130';
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
it('creates a valid processing code', function () use ($value): void {
|
|
|
|
|
// GIVEN / WHEN
|
2026-10-13 15:41:21 +02:00
|
|
|
$code = new ProcessingCode($value, Country::FRANCE);
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($code->value)->toBe($value)
|
|
|
|
|
->and($code->availableIn)->toBe(Country::FRANCE);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects an invalid value', function (string $invalidValue): void {
|
|
|
|
|
// GIVEN / WHEN
|
2026-10-13 15:41:21 +02:00
|
|
|
$action = fn (): ProcessingCode => new ProcessingCode($invalidValue, Country::FRANCE);
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-10-13 15:56:11 +02:00
|
|
|
expect($action)->toThrow(\DomainException::class, 'Processing Code must be exactly 13 numeric characters');
|
2026-10-12 17:08:07 +02:00
|
|
|
})->with([
|
|
|
|
|
'empty' => '',
|
2026-10-13 15:56:11 +02:00
|
|
|
'too short' => '542500394413',
|
|
|
|
|
'too long' => '54250039441301',
|
|
|
|
|
'with letters' => 'ABC1234567890',
|
|
|
|
|
'special char' => '542500394413!',
|
|
|
|
|
'with space' => '5425 03944130',
|
|
|
|
|
'trailing break' => "5425003944130\n",
|
2026-10-12 17:08:07 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
it('is equal to another processing code with the same value', function () use ($value): void {
|
|
|
|
|
// GIVEN
|
2026-10-13 15:41:21 +02:00
|
|
|
$code = new ProcessingCode($value, Country::FRANCE);
|
|
|
|
|
$other = new ProcessingCode($value, Country::FRANCE);
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
// WHEN / THEN
|
|
|
|
|
expect($code->equals($other))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignores the country when comparing', function () use ($value): void {
|
|
|
|
|
// GIVEN
|
2026-10-13 15:41:21 +02:00
|
|
|
$france = new ProcessingCode($value, Country::FRANCE);
|
|
|
|
|
$benelux = new ProcessingCode($value, Country::BENELUX);
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
// WHEN / THEN
|
|
|
|
|
expect($france->equals($benelux))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('is not equal to a processing code with a different value', function () use ($value): void {
|
|
|
|
|
// GIVEN
|
2026-10-13 15:41:21 +02:00
|
|
|
$code = new ProcessingCode($value, Country::FRANCE);
|
|
|
|
|
$other = new ProcessingCode('4006381333931', Country::FRANCE);
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
// WHEN / THEN
|
|
|
|
|
expect($code->equals($other))->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('is not equal to a value that is not a processing code', function () use ($value): void {
|
|
|
|
|
// GIVEN
|
2026-10-13 15:41:21 +02:00
|
|
|
$code = new ProcessingCode($value, Country::FRANCE);
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
// WHEN / THEN
|
|
|
|
|
expect($code->equals($value))->toBeFalse()
|
|
|
|
|
->and($code->equals(null))->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('is converted to its value as a string', function () use ($value): void {
|
|
|
|
|
// GIVEN
|
2026-10-13 15:41:21 +02:00
|
|
|
$code = new ProcessingCode($value, Country::FRANCE);
|
2026-10-12 17:08:07 +02:00
|
|
|
|
|
|
|
|
// WHEN / THEN
|
|
|
|
|
expect((string) $code)->toBe($value);
|
|
|
|
|
});
|
|
|
|
|
});
|