feat(config): autoload system_configs into config() for governance
This commit is contained in:
33
tests/Feature/ConfigAutoloadFromSystemConfigsTest.php
Normal file
33
tests/Feature/ConfigAutoloadFromSystemConfigsTest.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user