0

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;)

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Tengo todas las extensiones instaladas para PDO y aun me da error, lo extraño es que la base de datos que estoy usando es postgresql pero con las pruebas unitarias me da error con sqlite
Es posible que esté utilizando funciones que no están disponibles en SQLite. (Google Translated)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.