What I've been trying is to use in-memory database while testing with Laravel Dusk.
Here we have a file, .env.dusk.local
, with the following values.
DB_CONNECTION=sqlite
DB_DATABASE=:memory:
Here is a snippet of a browser testing file.
class ViewOrderTest extends DuskTestCase
{
use DatabaseMigrations;
/** @test */
public function user_can_view_their_order()
{
$order = factory(Order::class)->create();
$this->browse(function (Browser $browser) use ($order) {
$browser->visit('/orders/' . $order->id);
$browser->assertSee('Order ABC'); //Order name
});
}
}
When php artisan dusk
is executed, Dusk starts browser testing.
However, Dusk seems to be accessing my local DB, because there is an order name on the testing browser which only exists in my local DB, while 'Order ABC' is expected to be displayed on the browser.
According to the doc, Laravel Dusk allows us to set the environmental variables.
To force Dusk to use its own environment file when running tests, create a .env.dusk.{environment} file in the root of your project. For example, if you will be initiating the dusk command from your local environment, you should create a .env.dusk.local file.
I don't feel that Dusk is accessing the seperate DB.
Any advice will be appreciated.