test(EntityId): add unit tests for EntityId instantiation
Includes tests for valid UUID and handling of empty string.
This commit is contained in:
parent
52d0e6f0fd
commit
ccba793b4c
1 changed files with 36 additions and 0 deletions
36
tests/Unit/Shared/DDD/EntityIdTest.php
Normal file
36
tests/Unit/Shared/DDD/EntityIdTest.php
Normal 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);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue