ldc-arcadia-api/tests/Unit/Domain/Models/ValueObjects/Employees/SiRhMatriculeTest.php

75 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain;
use Domain\Models\ValueObjects\Employees\SiRhMatricule;
covers(SiRhMatricule::class);
describe('SiRhMatricule Value Object Instantiation', function (): void {
it('instantiates successfully with a valid 7-digit matricule', function (): void {
// GIVEN
$validMatricule = '0115590';
// WHEN
$matricule = new SiRhMatricule($validMatricule);
// THEN
expect($matricule->value)
->toBe('0115590')
->and((string) $matricule)->toBe('0115590');
});
it('instantiates successfully with a valid 8-digit matricule', function (): void {
// GIVEN
$validMatricule = '01155902';
// WHEN
$matricule = new SiRhMatricule($validMatricule);
// THEN
expect($matricule->value)
->toBe('01155902')
->and((string) $matricule)->toBe('01155902');
});
it('supports equality check with another SiRhMatricule instance', function (): void {
// GIVEN
$firstId = new SiRhMatricule('01155902');
$sameId = new SiRhMatricule('01155902');
$differentId = new SiRhMatricule('01155901');
// WHEN & THEN
expect($firstId->equals($sameId))
->toBeTrue()
->and($firstId->equals($differentId))
->toBeFalse();
});
it('can be converted to a string representation', function (): void {
// GIVEN
$matricule = new SiRhMatricule('01155902');
// WHEN
$stringRepresentation = (string) $matricule;
// THEN
expect($stringRepresentation)->toBe('01155902');
});
});
describe('SiRhMatricule Value Object Domain Rules', function (): void {
it('throws a DomainException when given an invalid matricule pattern', function (string $invalidMatricule): void {
expect(fn () => new SiRhMatricule($invalidMatricule))
->toThrow(\DomainException::class);
})->with([
'too short' => '12345',
'too long' => '123456789',
'comment with hash' => '# s996008',
'alphanumeric d prefix' => 'd05600013',
'alphanumeric P prefix' => 'P99900029',
'empty string' => '',
]);
});