test: add 92 tests for 12 untested gateway and service classes

Cover Settings gateways (Session, LoginPersistence, SystemAudit, Smtp,
FrontendTelemetry, Metadata, App), Auth gateways (ExternalIdentity,
Tenant), DirectorySettings, UserSettings, and HotkeyService.
Gateway test coverage rises from 25% to 52%, overall service/gateway
coverage from 58.6% to 70.7%.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 20:46:20 +02:00
parent ea0b31ba67
commit 98afac24b1
12 changed files with 1221 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
<?php
namespace MintyPHP\Tests\Service\Settings;
use MintyPHP\Repository\Settings\SettingRepositoryInterface;
use MintyPHP\Service\Settings\SettingsMetadataGateway;
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
use PHPUnit\Framework\TestCase;
class SettingsSystemAuditGatewayTest extends TestCase
{
public function testIsSystemAuditEnabledReturnsTrueByDefault(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->method('getValue')->willReturn(null);
$gateway = new SettingsSystemAuditGateway(new SettingsMetadataGateway($settings));
$this->assertTrue($gateway->isSystemAuditEnabled());
}
public function testIsSystemAuditEnabledReturnsFalseWhenDisabled(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->method('getValue')->willReturnCallback(static function (string $key): ?string {
return match ($key) {
'system_audit_enabled' => '0',
default => null,
};
});
$gateway = new SettingsSystemAuditGateway(new SettingsMetadataGateway($settings));
$this->assertFalse($gateway->isSystemAuditEnabled());
}
public function testGetSystemAuditRetentionDaysDefaultsTo365(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->method('getValue')->willReturn(null);
$gateway = new SettingsSystemAuditGateway(new SettingsMetadataGateway($settings));
$this->assertSame(365, $gateway->getSystemAuditRetentionDays());
}
public function testGetSystemAuditRetentionDaysReturnsValidValue(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->method('getValue')->willReturnCallback(static function (string $key): ?string {
return match ($key) {
'system_audit_retention_days' => '180',
default => null,
};
});
$gateway = new SettingsSystemAuditGateway(new SettingsMetadataGateway($settings));
$this->assertSame(180, $gateway->getSystemAuditRetentionDays());
}
public function testGetSystemAuditRetentionDaysClampsToMinimum(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->method('getValue')->willReturnCallback(static function (string $key): ?string {
return match ($key) {
'system_audit_retention_days' => '10',
default => null,
};
});
$gateway = new SettingsSystemAuditGateway(new SettingsMetadataGateway($settings));
$this->assertSame(365, $gateway->getSystemAuditRetentionDays());
}
public function testGetSystemAuditRetentionDaysClampsToMaximum(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->method('getValue')->willReturnCallback(static function (string $key): ?string {
return match ($key) {
'system_audit_retention_days' => '2000',
default => null,
};
});
$gateway = new SettingsSystemAuditGateway(new SettingsMetadataGateway($settings));
$this->assertSame(365, $gateway->getSystemAuditRetentionDays());
}
public function testSetSystemAuditRetentionDaysRejectsBelowRange(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->method('getValue')->willReturn(null);
$settings->expects($this->never())->method('set');
$gateway = new SettingsSystemAuditGateway(new SettingsMetadataGateway($settings));
$this->assertFalse($gateway->setSystemAuditRetentionDays(10));
}
}