LoginTest.php
<?php
namespace Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
class LoginTest extends DuskTestCase
{
use DatabaseMigrations;
protected $user;
/**
* Init user
*
* @return void
*/
public function getUser()
{
if ($this->user) {
return;
}
$this->user = factory(\App\Models\User::class)->create([
'email' => '[email protected]',
]);
}
/**
* Test user login with error
*
* @return void
*/
public function testAUserReceivesErrorsForWrongLoginCredentials()
{
$this->getUser();
$this->browse(function(Browser $browser) {
$browser->visit(route('login'))
->type('email', $this->user->email)
->type('password', 'wrongPassword')
->click('button[type=submit]')
->pause(5000)
->assertVisible('.notification.is-danger');
});
}
/**
* Test user login
*
* @return void
*/
public function testUserCanSuccessfullyLogIn()
{
$this->getUser();
$this->browse(function (Browser $browser) {
$browser->visit(route('login'))
->type('email', $this->user->email)
->type('password', 'secret')
->click('button[type=submit]')
->pause(5000)
->assertRouteIs('profile', $this->user->username);
});
}
}
.env.dusk.local
APP_ENV=local
APP_KEY=RANDOM_STRING
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://site.dev
DB_CONNECTION=testing
database.php
'testing' => [
'driver' => 'sqlite',
'database' => storage_path('testing.sqlite'),
'prefix' => '',
],