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', 2048) . '@example.fr' ]); it('considers two emails with the same value as equal', function (): void { // GIVEN $first = new Email('contact@example.fr'); $second = new Email('contact@example.fr'); // WHEN $result = $first->equals($second); // THEN expect($result)->toBeTrue(); }); it('considers an email as not equal to', function (mixed $invalid): void { // GIVEN $email = new Email('contact-1@example.fr'); // WHEN $result = $email->equals($invalid); // THEN expect($result)->toBeFalse(); // GIVEN })->with([ 'different email' => new Email('contact-2@example.fr'), 'non-email value' => new stdClass(), ]); });