feat(config): autoload system_configs into config() for governance

This commit is contained in:
萝卜
2026-03-14 03:21:51 +00:00
parent 301ce565cd
commit e9fba11785
2 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
namespace Tests\Feature;
use App\Models\SystemConfig;
use App\Providers\AppServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ConfigAutoloadFromSystemConfigsTest extends TestCase
{
use RefreshDatabase;
public function test_system_configs_autoload_injected_into_config(): void
{
// 写入 DB 后,手动触发一次 AppServiceProvider::boot()
// 以模拟“请求启动时自动注入 config()”的行为。
SystemConfig::query()->create([
'config_key' => 'saasshop.amounts.tolerance',
'config_name' => '金额容差(元)',
'config_value' => '0.05',
'value_type' => 'number',
'autoload' => true,
'group' => 'saasshop',
'remark' => '用于测试:从 DB 自动注入到 config()',
]);
// 重新执行 provider 的 boot测试环境中应用在插入前已启动因此需要手动触发
(new AppServiceProvider($this->app))->boot();
$this->assertSame(0.05, config('saasshop.amounts.tolerance'));
}
}