gpt4 book ai didi

Laravel 6/7 测试 : A facade root has not been set

转载 作者:行者123 更新时间:2023-12-02 00:00:02 25 4
gpt4 key购买 nike

我正在尝试为我的 Laravel 7 应用程序编写一些测试。但我一直面临 A facade root has not been set. 错误。

<?php

namespace Tests\Feature;

use Illuminate\Support\Facades\Config;
use PHPUnit\Framework\TestCase;

class AddressListenerRepositoryTest extends TestCase
{
public function testCreate()
{
Config::set('x', 'address_listeners'); // Cause of "A facade root has not been set" error
}
}

谁能解释一下这个错误的原因?

最佳答案

您应该使用 use Test\TestCase; 而不是 PHPUnit\Framework\TestCase

测试需要调用 createApplication 方法,它位于 Test\TestCase 中,该方法将触发内核,因此每个对象和类都会被引导。然后您可以使用容器、外观、请求、响应和所有这些东西。

关于Laravel 6/7 测试 : A facade root has not been set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61969956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com