sample-php-laravel
sample-php-laravel copied to clipboard
Error when running PHPUnit and test case with migrations
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?
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?
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?