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