Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to a member function connection() on null Laravel 5.4

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);
}
}

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

Call to a member function connection() on null.

like image 844
Viktor Avatar asked Dec 01 '22 11:12

Viktor


1 Answers

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

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.

Change

use PHPUnit\Framework\TestCase;

To

use Tests\TestCase;

The problem should solve.

like image 166
Larry Mckuydee Avatar answered Dec 05 '22 18:12

Larry Mckuydee