I have an application and I want to use Laravel Dusk.
I created a file named .env.dusk.local
with a database for tests and a file named .env
with my default database.
I ran the php artisan command and created a user by /register
.
After I created a login test with the same email but with a different password, this would not be a problem because in .env.dusk.local
it would be a different bank and would not have any users registered.
But when I run the php artisan dusk command it takes the information from the original .env
and ends up erasing all records from my default database.
I would like to know how to load the information from my .env.dusk.local
and use my test database.
.env default
APP_ENV=local
APP_KEY=base64:K8otIkxJk0rFsZYSEq1hwBuaxQX3QI3Bb7ZmemJRIWg=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost:8000
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_dusk
DB_USERNAME=root
DB_PASSWORD=123456
.env.dusk.local
APP_ENV=local
APP_KEY=base64:K8otIkxJk0rFsZYSEq1hwBuaxQX3QI3Bb7ZmemJRIWg=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost:8000
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_dusk_test
DB_USERNAME=root
DB_PASSWORD=123456
Mu function for testLogin
namespace Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\App;
use Tests\DuskTestCase;
class LoginTest extends DuskTestCase
{
use DatabaseMigrations;
/**
* A Dusk test example.
*
* @return void
*/
public function testLogin()
{
$user = factory(\App\User::class)->create(['email' => 'lucas@example.com']);
$this->browse(function ($browser) use ($user) {
$browser->visit('/login')
->type('email', $user->email)
->type('password', 'secret')
->press('Login')
->assertPathIs('/home');
});
}
}
Here is this project in github