Story 1.7 - Implémente un système complet d'audit trail pour tracer toutes les actions sensibles (authentification, modifications de données, exports) avec immuabilité garantie par PostgreSQL. Fonctionnalités principales: - Table audit_log append-only avec contraintes PostgreSQL (RULE) - AuditLogger centralisé avec injection automatique du contexte - Correlation ID pour traçabilité distribuée (HTTP + async) - Handlers pour événements d'authentification - Commande d'archivage des logs anciens - Pas de PII dans les logs (emails/IPs hashés) Infrastructure: - Middlewares Messenger pour propagation du Correlation ID - HTTP middleware pour génération/propagation du Correlation ID - Support multi-tenant avec TenantResolver
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Shared\Domain;
|
|
|
|
use App\Shared\Domain\CorrelationId;
|
|
use InvalidArgumentException;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
final class CorrelationIdTest extends TestCase
|
|
{
|
|
public function testGenerateCreatesValidUuid(): void
|
|
{
|
|
$correlationId = CorrelationId::generate();
|
|
|
|
$this->assertTrue(Uuid::isValid($correlationId->value()));
|
|
}
|
|
|
|
public function testFromStringCreatesCorrelationIdFromValidUuid(): void
|
|
{
|
|
$uuid = '550e8400-e29b-41d4-a716-446655440000';
|
|
$correlationId = CorrelationId::fromString($uuid);
|
|
|
|
$this->assertSame($uuid, $correlationId->value());
|
|
}
|
|
|
|
public function testValueReturnsUuidString(): void
|
|
{
|
|
$uuid = '550e8400-e29b-41d4-a716-446655440000';
|
|
$correlationId = CorrelationId::fromString($uuid);
|
|
|
|
$this->assertSame($uuid, $correlationId->value());
|
|
}
|
|
|
|
public function testToStringReturnsUuidString(): void
|
|
{
|
|
$uuid = '550e8400-e29b-41d4-a716-446655440000';
|
|
$correlationId = CorrelationId::fromString($uuid);
|
|
|
|
$this->assertSame($uuid, (string) $correlationId);
|
|
}
|
|
|
|
public function testGenerateCreatesDifferentIdsEachTime(): void
|
|
{
|
|
$id1 = CorrelationId::generate();
|
|
$id2 = CorrelationId::generate();
|
|
|
|
$this->assertNotSame($id1->value(), $id2->value());
|
|
}
|
|
|
|
public function testFromStringRejectsInvalidUuid(): void
|
|
{
|
|
$this->expectException(InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Invalid correlation ID format');
|
|
|
|
CorrelationId::fromString('not-a-valid-uuid');
|
|
}
|
|
|
|
public function testFromStringRejectsEmptyString(): void
|
|
{
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
CorrelationId::fromString('');
|
|
}
|
|
}
|