toBeInstanceOf(Email::class) ->and($email->value)->toBe('contact@example.com'); }); it('rejects an empty email', function (): void { // GIVEN $emailValue = ''; // WHEN $action = fn (): Email => new Email($emailValue); // THEN expect($action)->toThrow(\DomainException::class, 'Email cannot be empty.'); }); it('rejects invalid email formats', function (string $invalid): void { // GIVEN & WHEN & THEN expect(fn (): Email => new Email($invalid))->toThrow(\DomainException::class); })->with([ '', ' ', 'not-an-email', '@example.com', 'contact@', 'contact@.com', 'contact@com', str_repeat('a', 200) . '@example.fr' ]); });