Laravel PHPUnit 在 null 上调用成员函数 connection()

0 phpunit laravel

我正在学习 Laravel 测试,但由于以下错误,我无法继续测试 Eloquent:

错误:对空值调用成员函数connection()

这是我的代码:

public function test_users_can_follow_each_other()
    {
        $this->userOne = User::find(1);
        $this->userTwo = User::find(2);
        $this->userOne->followedBy($this->userTwo->id);
        $this->assertTrue($this->userTwo->isFollowedBy($this->userOne->id));
    }
Run Code Online (Sandbox Code Playgroud)

我也在使用这个特质use DatabaseTransactions;

数据库已创建,用户表上有 2 条记录。还需要配置什么吗,谢谢!

小智 7

代替

PHPUnit\框架\测试用例

测试\测试用例