ldc-boutique-cnc-sable/tests/Unit/Domain/Models/ValueObjects/MatriculeTest.php
2026-10-27 09:58:12 +01:00

70 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Domain\Models\ValueObjects\Matricule;
describe('Matricule', function () {
it('can instantiate and preserve leading zeros', function () {
// GIVEN
$value = '0111123';
// WHEN
$vo = new Matricule($value);
// THEN
expect($vo)->toBeInstanceOf(Matricule::class)
->and($vo->value)->toBe('0111123');
});
it('throws exception if it contains non-digit characters', function () {
// GIVEN
$value = 'AB01162';
// WHEN
$action = fn () => new Matricule($value);
// THEN
expect($action)->toThrow(\DomainException::class);
});
it('throws exception if it does not have exactly 7 digits', function () {
// GIVEN
$value = '12345';
// WHEN
$action = fn () => new Matricule($value);
// THEN
expect($action)->toThrow(\DomainException::class);
});
});
describe('Matricule methods', function (): void {
it('can be cast to string', function (): void {
// GIVEN
$vo = new Matricule('1234567');
// WHEN
$str = (string) $vo;
// THEN
expect($str)->toBe('1234567');
});
it('can equate', function (): void {
// GIVEN
$vo1 = new Matricule('1234567');
$vo2 = new Matricule('1234567');
$vo3 = new Matricule('7654321');
// WHEN
$eq1 = $vo1->equals($vo2);
$eq2 = $vo1->equals($vo3);
$eq3 = $vo1->equals('1234567');
// THEN
expect($eq1)->toBeTrue()
->and($eq2)->toBeFalse()
->and($eq3)->toBeFalse();
});
});