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,130 @@
<?php
namespace MintyPHP\Tests\Service\User;
use MintyPHP\Service\Settings\SettingsAppGateway;
use MintyPHP\Service\Settings\SettingsDefaultsGateway;
use MintyPHP\Service\Settings\SettingsUserLifecycleGateway;
use MintyPHP\Service\User\UserSettingsGateway;
use PHPUnit\Framework\TestCase;
class UserSettingsGatewayTest extends TestCase
{
public function testGetDefaultTenantIdDelegates(): void
{
$defaults = $this->createMock(SettingsDefaultsGateway::class);
$defaults->method('getDefaultTenantId')->willReturn(5);
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertSame(5, $gateway->getDefaultTenantId());
}
public function testGetDefaultTenantIdReturnsNullWhenUnset(): void
{
$defaults = $this->createMock(SettingsDefaultsGateway::class);
$defaults->method('getDefaultTenantId')->willReturn(null);
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertNull($gateway->getDefaultTenantId());
}
public function testGetDefaultRoleIdDelegates(): void
{
$defaults = $this->createMock(SettingsDefaultsGateway::class);
$defaults->method('getDefaultRoleId')->willReturn(12);
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertSame(12, $gateway->getDefaultRoleId());
}
public function testGetDefaultRoleIdReturnsNullWhenUnset(): void
{
$defaults = $this->createMock(SettingsDefaultsGateway::class);
$defaults->method('getDefaultRoleId')->willReturn(null);
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertNull($gateway->getDefaultRoleId());
}
public function testGetDefaultDepartmentIdDelegates(): void
{
$defaults = $this->createMock(SettingsDefaultsGateway::class);
$defaults->method('getDefaultDepartmentId')->willReturn(8);
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertSame(8, $gateway->getDefaultDepartmentId());
}
public function testGetAppThemeDelegates(): void
{
$app = $this->createMock(SettingsAppGateway::class);
$app->method('getAppTheme')->willReturn('dark');
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertSame('dark', $gateway->getAppTheme());
}
public function testGetAppThemeReturnsNullWhenUnset(): void
{
$app = $this->createMock(SettingsAppGateway::class);
$app->method('getAppTheme')->willReturn(null);
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertNull($gateway->getAppTheme());
}
public function testAppThemesDelegatesToListThemes(): void
{
$themes = ['light' => 'Light', 'dark' => 'Dark'];
$app = $this->createMock(SettingsAppGateway::class);
$app->method('listThemes')->willReturn($themes);
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertSame($themes, $gateway->appThemes());
}
public function testDefaultThemeDelegates(): void
{
$app = $this->createMock(SettingsAppGateway::class);
$app->method('resolveDefaultTheme')->willReturn('light');
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertSame('light', $gateway->defaultTheme());
}
public function testNormalizeThemeDelegates(): void
{
$app = $this->createMock(SettingsAppGateway::class);
$app->method('normalizeTheme')->willReturn('dark');
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertSame('dark', $gateway->normalizeTheme('DARK'));
}
public function testNormalizeThemeWithNullDelegates(): void
{
$app = $this->createMock(SettingsAppGateway::class);
$app->method('normalizeTheme')->willReturn('light');
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
$this->assertSame('light', $gateway->normalizeTheme(null));
}
public function testGetUserInactivityDeactivateDaysDelegates(): void
{
$lifecycle = $this->createMock(SettingsUserLifecycleGateway::class);
$lifecycle->method('getUserInactivityDeactivateDays')->willReturn(180);
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $this->createMock(SettingsAppGateway::class), $lifecycle);
$this->assertSame(180, $gateway->getUserInactivityDeactivateDays());
}
public function testGetUserInactivityDeleteDaysDelegates(): void
{
$lifecycle = $this->createMock(SettingsUserLifecycleGateway::class);
$lifecycle->method('getUserInactivityDeleteDays')->willReturn(365);
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $this->createMock(SettingsAppGateway::class), $lifecycle);
$this->assertSame(365, $gateway->getUserInactivityDeleteDays());
}
}