Laravel PHPUnit调用null上的成员函数connection()
我正在学习在Laravel上进行测试,由于这个错误,我无法继续进行雄辩的测试: 错误:调用null上的成员函数connection() 这是我的代码:Laravel PHPUnit调用null上的成员函数connection(),laravel,phpunit,Laravel,Phpunit,我正在学习在Laravel上进行测试,由于这个错误,我无法继续进行雄辩的测试: 错误:调用null上的成员函数connection() 这是我的代码: public function test_users_can_follow_each_other() { $this->userOne = User::find(1); $this->userTwo = User::find(2); $this->userOne->f
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));
}
我还使用traituse DatabaseTransactions代码>
已在users表上创建了具有2条记录的数据库。我还需要配置什么吗,谢谢 更换
PHPUnit\Framework\TestCase
与
测试\测试用例替换
PHPUnit\Framework\TestCase
与
Tests\TestCase如何创建您提到的这两个记录?如果您运行测试,它通常会被清除,您需要为每个测试设置数据库(记录)$这->userTwo=factory(User::class)->create();但是我得到了这个错误:InvalidArgumentException:无法找到名为[default][App\User]的工厂。是的,这就是为一个特定测试设置数据库的方式。因此,在代码中添加这两行。同时将其更改为工厂(App\User::class,2)->create()
。我仍然收到相同的错误:InvalidArgumentException:无法找到名为[default][App\User]的工厂。这是什么Laravel版本?如何创建您提到的这两个记录?如果您运行测试,它通常会被清除,您需要为每个测试设置数据库(记录)$这->userTwo=factory(User::class)->create();但是我得到了这个错误:InvalidArgumentException:无法找到名为[default][App\User]的工厂。是的,这就是为一个特定测试设置数据库的方式。因此,在代码中添加这两行。同时将其更改为工厂(App\User::class,2)->create()
。我仍然收到相同的错误:InvalidArgumentException:无法找到名为[default][App\User]的工厂。这是什么Laravel版本?