lundi 27 mars 2017

How to create .env file for test with Laravel Dusk

I'm using Dusk to do a simple login test.

I created a .env.dusk file so that the test uses an alternate database and does not delete the data that was registered on the platform.

Archive .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_dusk
DB_USERNAME=root
DB_PASSWORD=123456

Archive .env.dusk

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_dusk_test
DB_USERNAME=root
DB_PASSWORD=123456

LoginTest.php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class LoginTest extends DuskTestCase
{
    use DatabaseMigrations;
    /**
     * A Dusk test example.
     *
     * @return void
     */
    public function testLogin()
    {
        $user = factory(\App\User::class)->create(['email' => 'example@example.com']);

        $this->browse(function ($browser) use ($user) {
            $browser->visit('/login')
                    ->type('email', $user->email)
                    ->type('password', 'secret')
                    ->press('Login')
                    ->assertPathIs('/home');
        });
    }
}

But when I run the tests it does not change the database and it deletes all data from the database used in the application.

How can I solve this problem?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mHRgTo
via IFTTT

Aucun commentaire:

Enregistrer un commentaire