Laravel 5 Unit Test - Call to a member function connection() on null

前端 未结 7 1265
灰色年华
灰色年华 2020-12-31 06:53

I tried creating a unit test for the relationships between my User and Shop models, however when I run vendor\\\\bin\\\\phpunit this e

7条回答
  •  被撕碎了的回忆
    2020-12-31 07:38

    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.

提交回复
热议问题