Files
saasshop/tests/Feature/ConfigAutoloadFromSystemConfigsTest.php

34 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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'));
}
}