Laravel dusk not working .env.dusk.local

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 the user /register .

After I created a login test with the same email address but with a different password, this will not be a problem, because in .env.dusk.local it will be a different bank and will not be registered with anyone.

But when I run the php artisan dusk command, it takes information from the original .env and finishes erasing all entries from my default database.

I would like to know how to download information from my .env.dusk.local and use a 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 on github

+5
source share
1 answer

Instead of .env.dusk.local try .env.dusk

In addition, instead of using the mysql database, I would recommend using a temporary sqlite database, as it is created and destroyed during the tests.

you will need to have the sqilte configuration in your database.php file pointing to the actual .sqlite file that you have in your installation.

copy the sqlite configuration into database.php and then paste it, name it sqlite_dusk , maybe then to put db, put it as storage_path('dusk.sqlite') or something like that. Then create an empty dusk.sqlite file in the root of your storage folder.

Then in your .env.dusk install:

 DB_CONNECTION=sqlite_dusk 

Hope this helps!

0
source

Source: https://habr.com/ru/post/1265963/


All Articles