toBeInstanceOf(Applicant::class) ->and($applicant->firstname)->toBe($firstname) ->and($applicant->lastname)->toBe($lastname) ->and($applicant->email)->toBe($email); }); it('rejects an empty or whitespace-only firstname', function (string $invalidFirstname) use ($lastname, $email): void { // WHEN $action = fn (): Applicant => new Applicant( $invalidFirstname, $lastname, $email, ); // THEN expect($action)->toThrow(\DomainException::class, 'Applicant firstname cannot be empty.'); })->with([ 'empty' => '', 'spaces' => ' ', ]); it('rejects a firstname that exceeds the maximum allowed length', function () use ($lastname, $email): void { // GIVEN $tooLongFirstname = str_repeat('a', 201); // WHEN $action = fn (): Applicant => new Applicant( $tooLongFirstname, $lastname, $email, ); // THEN expect($action)->toThrow(\DomainException::class, 'Applicant firstname exceeds the maximum allowed length.'); }); it('accepts a firstname of exactly the maximum length', function () use ($lastname, $email): void { // GIVEN $maxLengthFirstname = str_repeat('a', 200); // WHEN $applicant = new Applicant( $maxLengthFirstname, $lastname, $email, ); // THEN expect(mb_strlen($applicant->firstname))->toBe(200); }); it('rejects an empty or whitespace-only lastname', function (string $invalidLastname) use ($firstname, $email): void { // WHEN $action = fn (): Applicant => new Applicant( $firstname, $invalidLastname, $email, ); // THEN expect($action)->toThrow(\DomainException::class, 'Applicant lastname cannot be empty.'); })->with([ 'empty' => '', 'spaces' => ' ', ]); it('rejects a lastname that exceeds the maximum allowed length', function () use ($firstname, $email): void { // GIVEN $tooLongLastname = str_repeat('a', 201); // WHEN $action = fn (): Applicant => new Applicant( $firstname, $tooLongLastname, $email, ); // THEN expect($action)->toThrow(\DomainException::class, 'Applicant lastname exceeds the maximum allowed length.'); }); it('accepts a lastname of exactly the maximum length', function () use ($firstname, $email): void { // GIVEN $maxLengthLastname = str_repeat('a', 200); // WHEN $applicant = new Applicant( $firstname, $maxLengthLastname, $email, ); // THEN expect(mb_strlen($applicant->lastname))->toBe(200); }); });