Laravel: Unable to pass browser validation using the RefreshDatabase property

My test will fail if I use the RefreshDatabase property.

Without the trait test, the test passes, but the data remains in the database.

I use:

  • Laravel 5.5 (new)
  • Laradock: nginx mysql selenium

Tests run from the laradock workspace.

This is a test, simple, from the official documentation .

<?php

namespace Tests\Browser;

use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class LoginTest extends DuskTestCase
{
    use RefreshDatabase;

    /**
     * A Dusk test example.
     *
     * @return void
     */
    public function testLogin()
    {
        $user = factory(User::class)->create();

        // dump('wait...');
        // sleep(15);
        // dump('go!');

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

dump/sleep/dump- it's just to see if the user has been created in the database. Is not!

The result php artisan duskis:

There was 1 failure:

1) Tests\Browser\LoginTest::testLogin
Failed asserting that '/login' matches PCRE pattern "/^\/home/u".

/var/www/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:53
/var/www/tests/Browser/LoginTest.php:32
/var/www/vendor/laravel/dusk/src/TestCase.php:92
/var/www/tests/Browser/LoginTest.php:34

Note:
Text approval "These credentials do not match our records." will be true, so I believe that the user was never created.

+4
source
2

, sqlite/pgsql/whateversql. , - $app['config']... \Tests\CreatesApplication::createApplication.

, artisan config:clear artisan serve. phpunit.dusk.xml, .env.dusk.{env}, dusk.

0

DatabaseMigrations RefreshDatabase.

-1

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


All Articles