I use Dusk for a simple login test.
I created the .env.dusk file so that the test uses an alternative database and does not delete the data registered on the platform.
.Env archive
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;
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 deletes all the data from the database used in the application.
How can I solve this problem?
source
share