Laravel7 - 写单元测试时,提示 A facade root has not been set。
在集成单元测试 tests/Unit 时遇到如下报错:RuntimeException: A facade root has not been set./vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:258254▕{255▕$instance = static::getFacadeRoot();256▕257▕
·
在集成单元测试 tests/Unit 时遇到如下报错:
RuntimeException: A facade root has not been set.
/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:258
254▕ {
255▕ $instance = static::getFacadeRoot();
256▕
257▕ if (! $instance) {
➜ 258▕ throw new RuntimeException('A facade root has not been set.');
259▕ }
260▕
261▕ return $instance->$method(...$args);
262▕ }
修改 use PHPUnit\Framework\TestCase;
为 use Tests\TestCase;
或者 use CreatesApplication
这个 trait
原因见原帖:Laravel 6/7 testing: A facade root has not been set
解决在单元测试中无法使用:Redis
,DB
,Config
,Route
等 Facade
的问题。
参考地址:https://www.qs5.org/Post/702.html
更多推荐
已为社区贡献1条内容
所有评论(0)