49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Shared\ValueObjects;
|
|
|
|
use Shared\ValueObjects\Email;
|
|
|
|
covers(Email::class);
|
|
|
|
describe('Email Value Object Unit Tests', function (): void {
|
|
it('creates a valid normalized email', function (): void {
|
|
// GIVEN
|
|
$rawEmail = ' Admin.Security@Example.COM ';
|
|
|
|
// WHEN
|
|
$email = new Email($rawEmail);
|
|
|
|
// THEN
|
|
expect($email->value)->toBe('admin.security@example.com')
|
|
->and((string) $email)->toBe('admin.security@example.com');
|
|
});
|
|
|
|
it('rejects invalid email formats', function (string $invalid): void {
|
|
// GIVEN & WHEN & THEN
|
|
expect(fn () => new Email($invalid))
|
|
->toThrow(\InvalidArgumentException::class);
|
|
})->with([
|
|
'',
|
|
' ',
|
|
'not-an-email',
|
|
'@example.com',
|
|
'admin@',
|
|
'admin@.com',
|
|
'admin@com',
|
|
]);
|
|
|
|
it('correctly checks equality', function (): void {
|
|
// GIVEN
|
|
$email1 = new Email('test@example.com');
|
|
$email2 = new Email('TEST@EXAMPLE.COM');
|
|
$email3 = new Email('other@example.com');
|
|
|
|
// THEN
|
|
expect($email1->equals($email2))->toBeTrue()
|
|
->and($email1->equals($email3))->toBeFalse()
|
|
->and($email1->equals('test@example.com'))->toBeFalse();
|
|
});
|
|
});
|