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(); }); });