agent foundation

This commit is contained in:
2026-03-06 00:44:52 +01:00
parent 9819cba733
commit 9a08f96c11
199 changed files with 8522 additions and 1880 deletions

View File

@@ -2,11 +2,12 @@
namespace MintyPHP\Tests\Service\Audit;
use MintyPHP\Http\SessionStore;
use MintyPHP\Http\RequestContext;
use MintyPHP\Repository\Audit\SystemAuditLogRepository;
use MintyPHP\Service\Audit\SystemAuditRedactionService;
use MintyPHP\Service\Audit\SystemAuditService;
use MintyPHP\Service\Settings\SettingGateway;
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
use PHPUnit\Framework\TestCase;
class SystemAuditServiceTest extends TestCase
@@ -14,6 +15,7 @@ class SystemAuditServiceTest extends TestCase
protected function tearDown(): void
{
RequestContext::resetForTests();
$_SESSION = [];
}
public function testRecordReturnsNullWhenDisabled(): void
@@ -21,10 +23,10 @@ class SystemAuditServiceTest extends TestCase
$repo = $this->createMock(SystemAuditLogRepository::class);
$repo->expects($this->never())->method('create');
$settings = $this->createMock(SettingGateway::class);
$settings = $this->createMock(SettingsSystemAuditGateway::class);
$settings->expects($this->once())->method('isSystemAuditEnabled')->willReturn(false);
$service = new SystemAuditService($repo, new SystemAuditRedactionService(), $settings);
$service = new SystemAuditService($repo, new SystemAuditRedactionService(), $settings, new SessionStore());
$this->assertNull($service->record('admin.users.update', 'success'));
}
@@ -39,10 +41,10 @@ class SystemAuditServiceTest extends TestCase
$repo = $this->createMock(SystemAuditLogRepository::class);
$repo->expects($this->once())->method('create')->willReturn(5);
$settings = $this->createMock(SettingGateway::class);
$settings = $this->createMock(SettingsSystemAuditGateway::class);
$settings->method('isSystemAuditEnabled')->willReturn(true);
$service = new SystemAuditService($repo, new SystemAuditRedactionService(), $settings);
$service = new SystemAuditService($repo, new SystemAuditRedactionService(), $settings, new SessionStore());
$id = $service->record('admin.users.update', 'success', [
'target_type' => 'user',
@@ -59,10 +61,10 @@ class SystemAuditServiceTest extends TestCase
$repo = $this->createMock(SystemAuditLogRepository::class);
$repo->method('create')->willThrowException(new \RuntimeException('db down'));
$settings = $this->createMock(SettingGateway::class);
$settings = $this->createMock(SettingsSystemAuditGateway::class);
$settings->method('isSystemAuditEnabled')->willReturn(true);
$service = new SystemAuditService($repo, new SystemAuditRedactionService(), $settings);
$service = new SystemAuditService($repo, new SystemAuditRedactionService(), $settings, new SessionStore());
$this->assertNull($service->record('admin.users.update', 'success'));
}
@@ -72,10 +74,10 @@ class SystemAuditServiceTest extends TestCase
$repo = $this->createMock(SystemAuditLogRepository::class);
$repo->expects($this->once())->method('purgeOlderThanDays')->with(120)->willReturn(3);
$settings = $this->createMock(SettingGateway::class);
$settings = $this->createMock(SettingsSystemAuditGateway::class);
$settings->method('getSystemAuditRetentionDays')->willReturn(120);
$service = new SystemAuditService($repo, new SystemAuditRedactionService(), $settings);
$service = new SystemAuditService($repo, new SystemAuditRedactionService(), $settings, new SessionStore());
$this->assertSame(3, $service->purgeExpired());
}