Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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' => '[email protected]',
       '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.

like image 853
Bruno Albuquerque Avatar asked Jan 26 '23 08:01

Bruno Albuquerque


2 Answers

You may need to enable extension for pdo_sqlite in your php.ini file that is being used by phpunit.

like image 84
Alaa mohammed Avatar answered Jan 27 '23 22:01

Alaa mohammed


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.

like image 36
Bryan Avatar answered Jan 27 '23 22:01

Bryan