forked from fa/breadcrumb-the-shire
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>
96 lines
3.7 KiB
PHP
96 lines
3.7 KiB
PHP
<?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));
|
|
}
|
|
}
|