sample-php-laravel icon indicating copy to clipboard operation
sample-php-laravel copied to clipboard

Error when running PHPUnit and test case with migrations

Open fpena opened this issue 7 years ago • 2 comments

When running PHPUnit and having a class extending from TestCase and using use RefreshDatabase; for migrations, it returns an error:

Example class:

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ExampleTest extends TestCase
{
    use RefreshDatabase;
    
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

Error:

Illuminate\Database\QueryException: could not find driver (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

Is there something to add to the config.yml file?

fpena avatar Feb 09 '18 23:02 fpena

You just need to install the driver for the database you're using in testing. What driver do you have configured for your tests to run?

ryanwohara avatar May 25 '18 21:05 ryanwohara

Same problem is there for me, in the pipeline config I install sqlite with sudo apt install -y libsqlite3-dev zlib1g-dev . Then, migration is successful, while the tests are failing due to error: could not find the driver (same as explained above). Could anyone solve the issue so far?

kristof-siket avatar Nov 21 '18 18:11 kristof-siket