47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Application\Security\Models\ValueObjects\Entities;
|
||
|
|
|
||
|
|
use Application\Security\Models\ValueObjects\Entities\SecurityAuditLogEntryId;
|
||
|
|
use Ramsey\Uuid\Uuid;
|
||
|
|
use Ramsey\Uuid\UuidInterface;
|
||
|
|
use Shared\DDD\Model\EntityId;
|
||
|
|
use Shared\Helpers\Exceptions\InvalidUuidException;
|
||
|
|
|
||
|
|
covers(SecurityAuditLogEntryId::class);
|
||
|
|
|
||
|
|
describe('SecurityAuditLogEntryId Value Object Instantiation', function (): void {
|
||
|
|
it('accepts valid UUIDv7 identifier and converts to datetime', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$uuid7 = Uuid::uuid7();
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$entryId = new SecurityAuditLogEntryId($uuid7);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($entryId)->toBeInstanceOf(EntityId::class)
|
||
|
|
->and($entryId->identifier)->toBe($uuid7)
|
||
|
|
->and($entryId->value)->toBe($uuid7->toString())
|
||
|
|
->and($entryId->toDateTime())->toBeInstanceOf(\DateTimeInterface::class)
|
||
|
|
->and($entryId->toDateTime()->getTimestamp())->toBeLessThanOrEqual(time());
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('SecurityAuditLogEntryId Value Object Validation Rules', function (): void {
|
||
|
|
it('throws InvalidUuidException when given a non-v7 UUID identifier', function (UuidInterface $nonV7Uuid): void {
|
||
|
|
// GIVEN
|
||
|
|
$input = $nonV7Uuid;
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$execution = fn () => new SecurityAuditLogEntryId($input);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($execution)->toThrow(InvalidUuidException::class);
|
||
|
|
})->with([
|
||
|
|
fn () => Uuid::uuid4(),
|
||
|
|
fn () => Uuid::uuid1(),
|
||
|
|
]);
|
||
|
|
});
|