对null Laravel 5.4的成员函数connection()的调用

问题描述 投票:0回答:1

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

class UpdateThrowsTest extends TestCase
{

protected $bgame;
protected $game_id = 95;

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

然后我在控制台中写“ phpunit”并尝试异常

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

laravel laravel-5.4
1个回答
0
投票

[如果有人在使用Laravel 6项目进行测试的过程中弹回该错误。

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

更改

use PHPUnit\Framework\TestCase;

收件人

use Tests\TestCase;

问题应解决。

© www.soinside.com 2019 - 2024. All rights reserved.