Skip to content
Advertisement

Laravel 6 PHPUnit Testing – could not find driver (SQL: PRAGMA foreign_keys = ON;)

I’m started to write tests in Laravel. My application works, I can login, run migrations, but when I’m trying to test the login, I’m getting the following error:

could not find driver (SQL: PRAGMA foreign_keys = ON;)

My DB is in Postgres, and my test is as follows:

/** @test */
public function user_login_ok()
{
    $response = $this->json('POST', '/api/login', [
       'email' => 'test@test.com',
       'password' => 'test'
    ]);

    $this->assertEquals(200, $response->getStatusCode());
}

I’m not worried (for now) if my test is good enough or even right, but to solve this error.

Advertisement

Answer

Do you have a testing environment specific .env file? Do you have php section environment configuration in your phpunit.xml file?

If either of these has configuration for your database connection, they should be reviewed to make sure they are configured correctly.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement