test(EntityId): add unit tests for EntityId instantiation

Includes tests for valid UUID and handling of empty string.
This commit is contained in:
Jérémy Munsch 2026-08-13 12:47:18 +02:00
parent 52d0e6f0fd
commit ccba793b4c
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4

View file

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Shared\DDD;
use Shared\DDD\EntityId;
covers(EntityId::class);
describe('EntityId', function (): void {
it('can be instantiated with a valid UUID string', function (): void {
// GIVEN
$validUuid = '550e8400-e29b-41d4-a716-446655440000';
// WHEN
$entityId = new readonly class ($validUuid) extends EntityId
{
};
// THEN
expect($entityId->value)
->toBe($validUuid)
->and((string) $entityId)->toBe($validUuid);
});
it('throws a DomainException when instantiated with an empty string', function (): void {
// GIVEN
$invalidUuid = '';
// WHEN & THEN
expect(fn () => new readonly class ($invalidUuid) extends EntityId
{
})->toThrow(\DomainException::class);
});
});