toBeInstanceOf(Matricule::class) ->and($vo->value)->toBe($value); })->with([ '7 digits with leading zero' => '0111123', '8 digits with leading zero' => '01111234', ]); it('throws exception if it contains non-digit characters', function (string $value) { // WHEN $action = fn () => new Matricule($value); // THEN expect($action)->toThrow(\DomainException::class); })->with([ '7 chars with letters' => 'AB01162', '8 chars with letters' => 'AB011623', ]); it('throws exception if length is not 7 or 8 digits', function (string $value) { // WHEN $action = fn () => new Matricule($value); // THEN expect($action)->toThrow(\DomainException::class); })->with([ 'too short (6 digits)' => '123456', 'too short (5 digits)' => '12345', 'too long (9 digits)' => '123456789', ]); }); describe('Matricule methods', function (): void { it('can be cast to string', function (string $value): void { // GIVEN $vo = new Matricule($value); // WHEN $str = (string) $vo; // THEN expect($str)->toBe($value); })->with([ '7 digits' => '1234567', '8 digits' => '12345678', ]); it('can equate', function (): void { // GIVEN $vo1 = new Matricule('1234567'); $vo2 = new Matricule('1234567'); $vo3 = new Matricule('12345678'); // WHEN $eq1 = $vo1->equals($vo2); $eq2 = $vo1->equals($vo3); $eq3 = $vo1->equals('1234567'); // THEN expect($eq1)->toBeTrue() ->and($eq2)->toBeFalse() ->and($eq3)->toBeFalse(); }); });