尝试编写单元测试,我需要执行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 6项目进行测试的过程中弹回该错误。
尝试检查extends TestCase是否使用了正确的TestCase。这可能是由于Laravel 6 make:test使用错误的TestCase生成的测试。
更改
use PHPUnit\Framework\TestCase;
收件人
use Tests\TestCase;
问题应解决。