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 $firstname): void { // WHEN $action = fn (): Applicant => new Applicant($firstname, 'Doe', new Email('john.doe@example.com')); // 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 (): void { // GIVEN $firstname = str_repeat('a', 201); // WHEN $action = fn (): Applicant => new Applicant($firstname, 'Doe', new Email('john.doe@example.com')); // THEN expect($action)->toThrow(\DomainException::class, 'Applicant firstname exceeds the maximum allowed length.'); }); it('accepts a firstname of exactly the maximum length', function (): void { // GIVEN $firstname = str_repeat('a', 200); // WHEN $applicant = new Applicant($firstname, 'Doe', new Email('john.doe@example.com')); // THEN expect(mb_strlen($applicant->firstname))->toBe(200); }); it('rejects an empty or whitespace-only lastname', function (string $lastname): void { // WHEN $action = fn (): Applicant => new Applicant('John', $lastname, new Email('john.doe@example.com')); // 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 (): void { // GIVEN $lastname = str_repeat('a', 201); // WHEN $action = fn (): Applicant => new Applicant('John', $lastname, new Email('john.doe@example.com')); // THEN expect($action)->toThrow(\DomainException::class, 'Applicant lastname exceeds the maximum allowed length.'); }); it('accepts a lastname of exactly the maximum length', function (): void { // GIVEN $lastname = str_repeat('a', 200); // WHEN $applicant = new Applicant('John', $lastname, new Email('john.doe@example.com')); // THEN expect(mb_strlen($applicant->lastname))->toBe(200); }); });