92 lines
2.3 KiB
PHP
92 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Shared\Models\ValueObjects;
|
|
|
|
use DomainException;
|
|
use Shared\Models\ValueObjects\RCS;
|
|
use stdClass;
|
|
|
|
covers(RCS::class);
|
|
|
|
describe('RCS text', function (): void {
|
|
it('creates a valid RCS', function (): void {
|
|
// GIVEN
|
|
$rcsValue = 'RCS PARIS 111 222 333';
|
|
|
|
// WHEN
|
|
$rcs = new RCS($rcsValue);
|
|
|
|
// THEN
|
|
expect($rcs)->toBeInstanceOf(RCS::class)
|
|
->and($rcs->value())->toBe($rcsValue);
|
|
});
|
|
|
|
it('rejects an empty RCS text', function (): void {
|
|
// GIVEN
|
|
$rcsValue = '';
|
|
|
|
// WHEN
|
|
$action = fn (): RCS => new RCS($rcsValue);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(DomainException::class, 'RCS text cannot be empty.');
|
|
});
|
|
|
|
it('rejects invalid TCS text formats', function (string $invalid): void {
|
|
// GIVEN & WHEN & THEN
|
|
expect(fn (): RCS => new RCS($invalid))
|
|
->toThrow(DomainException::class);
|
|
})->with([
|
|
'',
|
|
' ',
|
|
'Paris',
|
|
'RCS PARIS',
|
|
'111 222 333',
|
|
'RCS PARIS 111',
|
|
'RCS PARIS 111 222',
|
|
'PARIS 111 222 333',
|
|
'RCS PARIS 1A1 2B2 3C3',
|
|
'RCS PARIS 1111 2222 3333',
|
|
]);
|
|
|
|
it('rejects an RCS text that exceeds the maximum allowed length', function (): void {
|
|
// GIVEN
|
|
$rcsValue = str_repeat('a', 2049);
|
|
|
|
// WHEN
|
|
$action = fn (): RCS => new RCS($rcsValue);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(DomainException::class, 'RCS text exceeds the maximum allowed length.');
|
|
});
|
|
|
|
it('considers two RCS texts to be equal if they have the same value', function (): void {
|
|
// GIVEN
|
|
$first = new RCS('RCS PARIS 111 222 333');
|
|
$second = new RCS('RCS PARIS 111 222 333');
|
|
|
|
// WHEN
|
|
$result = $first->equals($second);
|
|
|
|
// THEN
|
|
expect($result)->toBeTrue();
|
|
});
|
|
|
|
it('considers an RCS text as not equal to', function (mixed $invalid): void {
|
|
// GIVEN
|
|
$rcs = new RCS('RCS PARIS 111 222 333');
|
|
|
|
// WHEN
|
|
$result = $rcs->equals($invalid);
|
|
|
|
// THEN
|
|
expect($result)->toBeFalse();
|
|
|
|
// GIVEN
|
|
})->with([
|
|
'different rcs text' => new RCS('RCS NANTES 444 555 666'),
|
|
'non-rcs-text value' => new stdClass(),
|
|
]);
|
|
});
|