Are you sure your database.php config file has this key?
'default' => env('DB_CONNECTION', 'mysql'),
Also how do you run your phpunit?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a big and complex mysql-based schema and I want to use an in-memory sqlite database for testing using migrations for cleaning up as it's said here: https://laravel.com/docs/5.3/database-testing#using-migrations
The fact is that Laravel ignores the connection specified in the phpunit config and runs tests against the primay mysql database. It's not an options due to the slow speed.
Here is my connections section of the database.php config:
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
...
],
The default connection is mysql.
Here is the phpunit config:
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
As you can see it's supposed to override DB_CONNECTION with "testing" which is the in-memory sqlite.
I'm new to testing and totally confused. Now it seems I can't unit test what I want to - asserting on the results of a query builder which I (intentionally) can't mock. What do you guys think?
@bobbybouwmann @ohffs I've figured out the problem, I've been using config caching in my local environment and it's been preventing Laravel from using the phpunit config. The config:clear artisan command's helped. I've also changed the file cache driver to the array one for my local env.
Please or to participate in this conversation.