first commit

This commit is contained in:
julien
2026-03-20 22:13:41 +01:00
commit 41f8b3afb4
323 changed files with 27222 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Tests\AuditLog;
use Netig\Netslim\AuditLog\Application\AuditLogApplicationService;
use Netig\Netslim\AuditLog\Infrastructure\PdoAuditLogRepository;
use PDO;
use PHPUnit\Framework\TestCase;
final class AuditLogServiceTest extends TestCase
{
private PDO $db;
private AuditLogApplicationService $service;
protected function setUp(): void
{
$this->db = new PDO('sqlite::memory:', options: [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
$this->db->exec('CREATE TABLE audit_log (id INTEGER PRIMARY KEY AUTOINCREMENT, action TEXT NOT NULL, resource_type TEXT NOT NULL, resource_id TEXT NOT NULL, actor_user_id INTEGER DEFAULT NULL, context_json TEXT DEFAULT NULL, created_at TEXT NOT NULL)');
$this->service = new AuditLogApplicationService(new PdoAuditLogRepository($this->db));
}
public function testRecordsAndReadsAuditEntries(): void
{
$this->service->record('taxonomy.created', 'taxon', '12', 7, ['name' => 'PHP']);
$entries = $this->service->listRecent();
self::assertCount(1, $entries);
self::assertSame('taxonomy.created', $entries[0]->action);
self::assertSame('taxon', $entries[0]->resourceType);
self::assertSame('12', $entries[0]->resourceId);
self::assertSame(['name' => 'PHP'], $entries[0]->context);
}
}