ldc-mesbr-app/tests/Unit/Domain/Models/Entities/ActorTest.php

55 lines
1.7 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\Entities;
use Domain\Models\Entities\Actor;
2026-09-23 15:31:51 +02:00
use Domain\Models\ValueObjects\Actor\ActorDisplayName;
use Domain\Models\ValueObjects\Actor\ActorId;
use Ramsey\Uuid\Uuid;
covers(Actor::class);
describe('actor', function (): void {
it('hydrates an actor', function (): void {
// GIVEN
$id = ActorId::generate();
2026-09-23 15:31:51 +02:00
$displayName = new ActorDisplayName('John Doe');
// WHEN
$actor = Actor::hydrate($id, $displayName);
// THEN
expect($actor->id())->toBe($id)
->and($actor->displayName)->toBe($displayName)
->and($actor->updatedAt)->toBeNull()
->and($actor->updatedAt())->toBeNull();
});
it('hydrates an actor with an explicit updatedAt date', function (): void {
// GIVEN
$updatedAt = new \DateTimeImmutable('2026-06-15 12:00:00', new \DateTimeZone('UTC'));
// WHEN
2026-09-23 15:31:51 +02:00
$actor = Actor::hydrate(ActorId::generate(), new ActorDisplayName('John Doe'), $updatedAt);
// THEN
expect($actor->updatedAt)->toBe($updatedAt)
->and($actor->updatedAt())->toBe($updatedAt);
});
it('returns the creation date extracted from the id', function (): void {
// GIVEN
$expected = new \DateTimeImmutable('2024-06-15 12:34:56.789000', new \DateTimeZone('UTC'));
$id = new ActorId(Uuid::uuid7($expected));
2026-09-23 15:31:51 +02:00
$actor = Actor::hydrate($id, new ActorDisplayName('John Doe'));
// WHEN
$result = $actor->createdAt();
// THEN
expect($result->format('Y-m-d H:i:s.v'))->toBe($expected->format('Y-m-d H:i:s.v'));
});
});