refactor(config): remove runtime config files and centralize route/bootstrap
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace MintyPHP\Tests\Service\Settings;
|
||||
|
||||
use MintyPHP\Service\Settings\SettingCacheService;
|
||||
use MintyPHP\Service\Settings\SettingKeys;
|
||||
use MintyPHP\Service\Settings\SettingsMetadataGateway;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SettingCacheServiceTest extends TestCase
|
||||
@@ -31,6 +33,42 @@ class SettingCacheServiceTest extends TestCase
|
||||
$this->assertNull($service->get('app_locale'));
|
||||
}
|
||||
|
||||
public function testDefaultFilePathUsesStorageRuntimeSettingsFile(): void
|
||||
{
|
||||
$service = new SettingCacheService();
|
||||
|
||||
$this->assertStringEndsWith('/storage/runtime/settings.php', $service->filePath());
|
||||
}
|
||||
|
||||
public function testColdStartHydratesHotPathKeysFromDatabaseAndWritesCacheFile(): void
|
||||
{
|
||||
$file = $this->tempFilePath();
|
||||
|
||||
$metadataGateway = $this->createMock(SettingsMetadataGateway::class);
|
||||
$metadataGateway->expects($this->exactly(6))
|
||||
->method('getValue')
|
||||
->willReturnCallback(static function (string $key): ?string {
|
||||
return match ($key) {
|
||||
SettingKeys::APP_TITLE_KEY => 'Demo App',
|
||||
SettingKeys::APP_LOCALE_KEY => 'de',
|
||||
SettingKeys::APP_THEME_KEY => 'dark',
|
||||
SettingKeys::APP_THEME_USER_KEY => '1',
|
||||
SettingKeys::APP_REGISTRATION_KEY => '0',
|
||||
SettingKeys::APP_PRIMARY_COLOR_KEY => '#112233',
|
||||
default => null,
|
||||
};
|
||||
});
|
||||
|
||||
$service = new SettingCacheService($file, $metadataGateway);
|
||||
$this->assertSame('Demo App', $service->get('app_title'));
|
||||
$this->assertFileExists($file);
|
||||
|
||||
/** @var array<string, string> $cache */
|
||||
$cache = include $file;
|
||||
$this->assertSame('de', $cache[SettingKeys::APP_LOCALE_KEY] ?? null);
|
||||
$this->assertSame('#112233', $cache[SettingKeys::APP_PRIMARY_COLOR_KEY] ?? null);
|
||||
}
|
||||
|
||||
private function tempFilePath(): string
|
||||
{
|
||||
$dir = sys_get_temp_dir() . '/mintyphp_settings_cache_test_' . bin2hex(random_bytes(6));
|
||||
|
||||
Reference in New Issue
Block a user