Laravel 5 Unit Test - Call to a member function connection() on null
First of all, setUp()
is called before every test, so you shouldn't call it from within the constructor
Second of all, you should call the parent::setUp()
in your setUp()
to initialize the app instance.
One more reason
check if the test class is extending use Tests\TestCase; rather then use PHPUnit\Framework\TestCase;
Laravel ships with the later, but Tests\TestCase class take care of setting up the application, otherwise models wont be able to communicate with the database if they are extending PHPunit\Framework\TestCase.