I am trying to set up Dusk to use a specific SQLite DB for testing but I cannot get Dusk to use the values in my Dusk specific .env file(s).
I created .env.dusk.local and .env.dusk.testing (I know that I only actually need 1 of the .env.dusk.* files but I am using both just to try to get the darn thing working) and set DB_CONNECTION=sqlite in both of those env's. I even tried adding $app['config']->set('database.default','sqlite'); to the CreatesApplication trait.
Even still, Dusk will only talk to the DB that I have configured in my .env .
I confirmed that Dusk is still using the original .env values by updating my DB_CONNECTION in .env to a test value (foo) and then I immediately saw DB errors in the screenshots. I reset the test DB_CONNECTION value in .env back to my development db (pgsql) and the Dusk test passed. Next, I tried changing the DB_CONNECTION value in .env.dusk.local and .env.dusk.testing to a test value (again using foo) but I did not see any DB errors in the screenshots (foo is not a real connection).
So far, the only techniques that work are:
-
Manually setting DB_CONNECTION to sqlite in .env and then manually changing it back to pgsql after the tests. (not really an acceptable workflow).
-
setting 'default' => 'sqlite' in config/database.php. (also not an acceptable workflow)
I noticed another issue after trying option 2 where Laravel was complaining about a missing sessions table even though I had set SESSION_DRIVER=array in both of the .env.dusk.* files. This also seems to confirm that Dusk is ignoring the .env.dusk.* files.
The docs indicate that Dusk will back up .env and then copy .env.dusk.{environment} to .env. This does appear to be happening as I can see the .env contents changing by running tail on .env wile running php artisan dusk. No idea why the application won't use the values in my .env.dusk.local or .env.dusk.testing.
Here are my configs:
from config/database.php
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('bookme.sqlite')),
'prefix' => '',
],
from .env.dusk.local and .env.dusk.testing (same contents for both)
APP_ENV=local
APP_KEY=base64:REDACTED
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=https://bookme.justinc.dev
DB_CONNECTION=sqlite
BROADCAST_DRIVER=log
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
from Tests\CreatesApplication trait
<?php
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
trait CreatesApplication
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$app['config']->set('database.default','sqlite');
return $app;
}
}
I've read of others having a similar issues across these forums, Stack Overflow and Github but none of the suggestions seem to fix this issue.
Is there a trick to getting Dusk to use the values from .env.dusk.local (assuming app env is local)? If there is no trick, can anyone see where I am going wrong?
I really appreciate any help!