I make this simple test:
public function test_my_awesome_test()
{
$user = User::find(1);
$response = $this->actingAs($user)->get('/awesome/test');
$response->assertStatus(200);
}
But after run test it's display me error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'testing.users' doesn't exist (SQL: select * from
users
whereusers
.id
= 1 limit 1)
I had this same error if I needed to print some data from database. This tables exist and website works correctly. Who know where is problem?
CodePudding user response:
According to the Laravel documentation, Sail overrides the DB name you defined in the .env
file when you run the tests. You need to remove the following line from your phpunit.xml
file:
<env name="DB_DATABASE" value="testing"/>
CodePudding user response:
make .testing file in root of project and set database connection config like .env file in that . if you run a test , laravel use .testing instead of .env to read enviroment