i think this makes sense because your test at that point is VIEWING your site as if you would.. and when you do, your data doesnt end up in the test db rather in prod db.. you are not supposed to use dusk for production.. only your local/staging.. and for that i think this is fine..
Oct 26, 2018
5
Level 1
Dusk unexpectedly accessing two databases in same test
My dusk test is accessing two different databases.
I'd like it to only access one.
Any help would be appreciated!
Details:
I have two databases: one for testing (test_db) and one for production (prod_db).
My .env file specifies DB_DATABASE=prod_db.
My .env.dusk.local file specifies DB_DATABASE=test_db.
I call php artisan dusk --env=dusk.local for this test.
When my test calls factory(User::class)->create(), the record is entered into the test_db.
But when the same test then calls $browser->visit('/login') and types and submits email and password, it is searching prod_db.
Any ideas what might be going on?
My test class:
<?php
namespace Tests\Browser;
use App\User;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ExampleTest extends DuskTestCase
{
use DatabaseMigrations;
public function testBasicExample()
{
$this->browse(function (Browser $browser) {
$user = factory(User::class)->create([
'name' => 'Amy Ames',
'email' => '[email protected]',
'password' => \Hash::make('password')
]);
// THIS PASSES
$this->assertDatabaseHas('users', ['email' => $user->email]);
// THIS PRINTS "test_db", AS SPECIFIED IN .env.dusk.local
echo "\n" . env('DB_DATABASE') . "\n";
// THIS FAILS WATING FOR LOCATION.
// ERROR MESSAGE ON SCREENSHOT =
// "These credentials do not match our records."
// $browser->visit('/login')
// ->type('email', '[email protected]')
// ->type('password', 'password')
// ->click('@login-submit')
// ->waitForLocation('/dashboard')
// ->assertSee('Amy Ames')
// ->assertSee("Dashboard works!");
// THIS PASSES, BUT THE USER John Doe IS IN MY "prod_db" DATABASE, AS
// SPECIFIED IN .env
$browser->visit('/login')
->type('email', '[email protected]')
->type('password', 'password')
->click('@login-submit')
->waitForLocation('/dashboard')
->assertSee('John Doe')
->assertSee("Dashboard works!");
});
}
}
Please or to participate in this conversation.