Ad

Using RefreshDatabase Shows The Driver Not Found Error

- 1 answer

I am Trying to write tests in laravel, i have been doing this for some time and it has been working well. With this new project, i am supposed to use TDD still and the Refresh Database. When i include use RefreshDatabase, i get an error that i have not been getting with the other projects i have been working on. What could be the problem.

code i am testing.

class ParentsTest extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function createParentTest(){
        $this->withoutExceptionHandling();
        $response = $this->post('/create-parent',[
            'fname' => 'Julius',
            'lname' => 'Ssemakula',
            'contact' => '256702913454'
        ]);
        $this->assertDatabaseHas('Parents', ['fname' => 'Julius']);
    }
}

the error I get is

1) Tests\Feature\ParentsTest::createParentTest Illuminate\Database\QueryException: could not find driver (SQL: PRAGMA foreign_keys = ON;)

Ad

Answer

You need to install the appropriate driver for the database you are using. If you are on Linux:

First find out which version of PHP you are running using php --version. I'll use php7.3 for demonstration purposes.

For MySQL:

sudo apt install php7.3-mysql

For SQLite:

sudo apt install php7.3-sqlite

For PostgreSQL:

sudo apt install php7.3-pgsql

After installing the appropriate drivers, your tests should work.

Ad
source: stackoverflow.com
Ad