Laravel改造完整版传送门

在集成单元测试 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();
    256257if (! $instance) {258throw new RuntimeException('A facade root has not been set.');
    259}
    260261return $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

解决在单元测试中无法使用:RedisDBConfigRouteFacade 的问题。

参考地址:https://www.qs5.org/Post/702.html

Logo

鸿蒙生态一站式服务平台。

更多推荐