Might not be the issue - but I usually use a '.env.dusk' file (no '.local' at the end). Also - you can't use the RefreshDatabase trait - you need to use the DatabaseMigrations one. Because your test is now separate from your actual 'app' (as the browser is different process) it'll get very messy.
Dusk configuration; I’m doing something wrong
It’s the weekend. I shouldn’t be working, but I am!
I’m trying to get some Dusk tests running, but having issues with environments.
I’ve read the documentation and created a .env.dusk.local file with the following:
DB_CONNECTION=dusk
I’ve added a dusk connection to my config/database.php file:
'dusk' => [
'driver' => 'sqlite',
'database' => database_path('dusk.sqlite'),
'prefix' => '',
],
In my test, I’ve imported and using the DatabaseMigrations trait. This is what one of my test cases looks like:
public function testUserWithActiveRentalCanWatchVideo()
{
$video = $this->createPublishedVideo();
$user = factory(User::class)->create();
$rental = factory(Rental::class)->states('active')->create([
'user_id' => $user->getKey(),
'video_id' => $video->getKey(),
]);
$this->browse(function (Browser $browser) use ($video, $user) {
$url = route('channel.video.show', [
$video->channel,
$video,
]);
$browser->loginAs($user)
->visit($url)
->assertVisible('video');
});
}
It seems to create the records in the right database (the SQLite database at database/dusk.sqlite) but when Dusk invokes my application, my application seems to still be using the actual database connection (sqlite). I tested this by adding die(env('DB_CONNECTION')) to the top of my public/index.php file and reviewing the error screen-shot, and it says sqlite rather than the expected dusk.
How do I make Dusk use the database connection configured in my .env.dusk.local file when running tests? From the documentation, it’s my understand Dusk would back up my actual .env file, replace it with .env.dusk.local, and then put my .env file back after Dusk finished running. Is there something I’ve missed, or something else I need to do?
Yes, unfortunately...
Please or to participate in this conversation.