45 lines
1.8 KiB
PHP
45 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Security\Models\Entities;
|
|
|
|
use Application\Security\Models\Entities\SecurityAuditLogEntry;
|
|
use Application\Security\Models\ValueObjects\Entities\SecurityAuditLogDetails;
|
|
use Application\Security\Models\ValueObjects\Entities\SecurityAuditLogEntryId;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Shared\DDD\Model\Entity;
|
|
use Shared\DDD\Model\HasTimestampIdentifier;
|
|
|
|
covers(SecurityAuditLogEntry::class);
|
|
|
|
describe('SecurityAuditLogEntry Entity', function (): void {
|
|
it('creates an audit log entry with timestamp derived from ID', function (): void {
|
|
// GIVEN
|
|
$entryId = new SecurityAuditLogEntryId(Uuid::uuid7());
|
|
$clientId = Uuid::uuid7();
|
|
$clientIdentifier = 'arcadia_id_' . str_repeat('a', 32);
|
|
$eventType = 'client.secret_rotated';
|
|
$details = new SecurityAuditLogDetails(['reason' => 'Scheduled rotation']);
|
|
|
|
// WHEN
|
|
$entry = new SecurityAuditLogEntry(
|
|
id: $entryId,
|
|
clientId: $clientId,
|
|
clientIdentifier: $clientIdentifier,
|
|
eventType: $eventType,
|
|
details: $details,
|
|
);
|
|
|
|
// THEN
|
|
expect($entry)->toBeInstanceOf(Entity::class)
|
|
->and($entry)->toBeInstanceOf(HasTimestampIdentifier::class)
|
|
->and($entry->id())->toBe($entryId)
|
|
->and($entry->clientId)->toBe($clientId)
|
|
->and($entry->clientIdentifier)->toBe($clientIdentifier)
|
|
->and($entry->eventType)->toBe($eventType)
|
|
->and($entry->details)->toBe($details)
|
|
->and($entry->createdAt())->toBeInstanceOf(\DateTimeInterface::class)
|
|
->and($entry->createdAt()->getTimestamp())->toBe($entryId->toDateTime()->getTimestamp());
|
|
});
|
|
});
|