diff --git a/lib/core/config_repository.dart b/lib/core/config_repository.dart index 28e5067..8645041 100644 --- a/lib/core/config_repository.dart +++ b/lib/core/config_repository.dart @@ -66,6 +66,11 @@ class ConfigRepository { static ConfigRepository? _cachedConfig; + /// 设置缓存配置(仅用于测试) + static void setCachedConfig(ConfigRepository config) { + _cachedConfig = config; + } + /// 同步加载配置(用于向后兼容或必须同步的场景) /// 为默认配置路径启用缓存 static ConfigRepository loadSync([String? configPath]) { diff --git a/test/config_prefix_test.dart b/test/config_prefix_test.dart index 60c843e..f7047ee 100644 --- a/test/config_prefix_test.dart +++ b/test/config_prefix_test.dart @@ -79,8 +79,9 @@ generation: // Force a reload of the static config by accessing it. // This is a bit of a hack due to the static nature of SwaggerConfig and StringHelper. // A better approach would be to pass the config explicitly or mock the static dependencies. - ConfigRepository.loadSync(configFile - .path); // Ensure the config is loaded for the static accessor + // Load config and set it as cached so static accessors pick it up + final config = ConfigRepository.loadSync(configFile.path); + ConfigRepository.setCachedConfig(config); expect(StringHelper.generateClassName('User'), 'SUser'); expect(StringHelper.generateClassName('model'), 'SModel');