Laravel PHPUnit在null上调用成员函数connection() [英] Laravel PHPUnit Call to a member function connection() on null

查看:63
本文介绍了Laravel PHPUnit在null上调用成员函数connection()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Laravel上的测试,并且由于此错误,我无法继续测试Eloquent:

I am learning testing on Laravel and I am unable to continue testing Eloquent by this error:

错误:在null上调用成员函数connection()

Error: Call to a member function connection() on null

这是我的代码:

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));
    }

我也在使用特征 use DatabaseTransactions;

该数据库已经在users表上创建了2条记录.我还需要配置其他内容吗,谢谢!

The database is already created with 2 records on users table. Do I need to config anything else, thanks!

推荐答案

替换

PHPUnit \ Framework \ TestCase

PHPUnit\Framework\TestCase

使用

Tests \ TestCase

Tests\TestCase

这篇关于Laravel PHPUnit在null上调用成员函数connection()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆