65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\Entities;
|
|
|
|
use Domain\Models\Entities\Actor;
|
|
use Domain\Models\ValueObjects\Actor\ActorDisplayName;
|
|
use Domain\Models\ValueObjects\Actor\ActorId;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
covers(Actor::class);
|
|
|
|
describe('actor', function (): void {
|
|
$displayName = new ActorDisplayName('John Doe');
|
|
|
|
it('hydrates an actor', function () use ($displayName): void {
|
|
// GIVEN
|
|
$id = ActorId::generate();
|
|
|
|
// 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 () use ($displayName): void {
|
|
// GIVEN
|
|
$updatedAt = new \DateTimeImmutable('2026-06-15 12:00:00', new \DateTimeZone('UTC'));
|
|
|
|
// WHEN
|
|
$actor = Actor::hydrate(
|
|
ActorId::generate(),
|
|
$displayName,
|
|
$updatedAt,
|
|
);
|
|
|
|
// THEN
|
|
expect($actor->updatedAt)->toBe($updatedAt)
|
|
->and($actor->updatedAt())->toBe($updatedAt);
|
|
});
|
|
|
|
it('returns the creation date extracted from the id', function () use ($displayName): void {
|
|
// GIVEN
|
|
$expected = new \DateTimeImmutable('2024-06-15 12:34:56.789000', new \DateTimeZone('UTC'));
|
|
$id = new ActorId(Uuid::uuid7($expected));
|
|
$actor = Actor::hydrate(
|
|
$id,
|
|
$displayName,
|
|
);
|
|
|
|
// 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'));
|
|
});
|
|
});
|