I'm new on Dusk
Well, configure using doc and tutorials
On my local development create a .env.dusk.local (I verified that app is on local environment with dd($this->app->environment())
.env.dusk.local
DB_CONNECTION=mysql_tests
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lowino_tests
DB_USERNAME=myname
DB_PASSWORD=mypassword
DB_DATABASE_TESTS=lowino_tests
in phpunit.xml
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="mysql_tests"/>
</php>
in config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'mysql_tests' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE_TESTS', 'lowino_tests'),
'username' => env('MYSQL_USER', env('DB_USERNAME', 'forge')),
'password' => env('MYSQL_PASSWORD', env('DB_PASSWORD', '')),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
in tests/Browser/RegisterTest.php
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class RegisterTest extends DuskTestCase
{
use DatabaseTransactions;
/**
* @group user
* @test
*/
function user_can_register()
{
//dd($this->app->environment());
//dd(env('DB_DATABASE'));
$this->browse(function ($browser) {
$browser->visit('/') //Go to the homepage
->clickLink('Register') //Click the Register link
->assertSee('Register') //Make sure the phrase in the argument is on the page
//Fill the form with these values
->value('#name', 'Joe')
->value('#email', '[email protected]')
->value('#password', '123456')
->value('#password-confirm', '123456')
->click('button[type="submit"]') //Click the submit button on the page
->assertPathIs('/home') //Make sure you are in the home page
//Make sure you see the phrase in the argument
->assertSee("You are logged in!");
});
// Make sure database has data
//
// ->assertDatabaseHas('users', ['name' => 'Joe']);
// Ver en la BD ??
}
First problem:
After run first test dusk --group=useron my database lowino (not test database, it's normal database) a new user Joe is created, instead on lowino_tests. Also I'm using use DatabaseTransactions
Why Dusk not uses lowino_tests and why not uses transactions?
What is wrong?