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

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

问题描述

尝试编写单元测试,我需要执行sql查询

Try write a unit test and i need do sql query

class UpdateThrowsTest extends TestCase
{

protected $bgame;
protected $game_id = 95;

public function setUp(){
    $game = new Game();
    $game = $game::find($this->game_id);
}
}

然后我在控制台中编写"phpunit"并尝试异常

and then i write "phpunit" in console and try exception

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

Call to a member function connection() on null.

推荐答案

在使用Laravel 6项目进行测试的过程中,如果有人跳到此错误.

If anyone bounce to this error during test with Laravel 6 project.

尝试检查扩展TestCase 是否使用了正确的TestCase.可能是由于Laravel 6 make:test使用错误的TestCase生成了测试.

Try to check if the extends TestCase is using the right TestCase. It could be due to Laravel 6 make:test generated test using the wrong TestCase.

更改

use PHPUnit\Framework\TestCase;

收件人

use Tests\TestCase;

问题应该解决.

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

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