48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?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');
|
|
});
|
|
|
|
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'
|
|
]);
|
|
});
|