ldc-mesbr-app/tests/Unit/Shared/Models/ValueObjects/EmailTest.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2026-07-24 17:19:56 +02:00
<?php
declare(strict_types=1);
namespace Tests\Unit\Shared\Models\ValueObjects;
use Shared\Models\ValueObjects\Email;
covers(Email::class);
describe('email', function (): void {
it('creates a valid email', function (): void {
// GIVEN
$emailValue = ' Contact@Example.COM ';
// WHEN
$email = new Email($emailValue);
// THEN
expect($email)->toBeInstanceOf(Email::class)
->and($email->value)->toBe('contact@example.com');
2026-07-24 17:19:56 +02:00
});
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.');
2026-07-24 17:19:56 +02:00
});
it('rejects invalid email formats', function (string $invalid): void {
// GIVEN & WHEN & THEN
expect(fn (): Email => new Email($invalid))->toThrow(\DomainException::class);
2026-07-24 17:19:56 +02:00
})->with([
'',
' ',
'not-an-email',
'@example.com',
'contact@',
'contact@.com',
'contact@com',
str_repeat('a', 200) . '@example.fr'
2026-07-24 17:19:56 +02:00
]);
});