2026-08-13 12:47:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Shared\DDD;
|
|
|
|
|
|
2026-08-17 10:31:28 +02:00
|
|
|
use Shared\DDD\Model\EntityId;
|
2026-08-13 12:47:18 +02:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
2026-08-20 09:45:54 +02:00
|
|
|
|
|
|
|
|
it('correctly compares equality for identical and distinct instances', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$classA1 = new DummyEntityIdA('uuid-1');
|
|
|
|
|
$classA2 = new DummyEntityIdA('uuid-1');
|
|
|
|
|
$classA3 = new DummyEntityIdA('uuid-2');
|
|
|
|
|
$classB = new DummyEntityIdB('uuid-1');
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect($classA1->equals($classA2))->toBeTrue()
|
|
|
|
|
->and($classA1->equals($classA3))->toBeFalse()
|
|
|
|
|
->and($classA1->equals($classB))->toBeFalse()
|
|
|
|
|
->and($classB->equals($classA1))->toBeFalse()
|
|
|
|
|
->and($classA1->equals('uuid-1'))->toBeFalse()
|
|
|
|
|
->and($classA1->equals(null))->toBeFalse();
|
|
|
|
|
});
|
2026-08-13 12:47:18 +02:00
|
|
|
});
|