Set up Laravel 5.4 with Dusk using phpunit.xml, .env.dusk.local, and an sqlite in-memory database

笑着哭i 提交于 2019-12-01 16:05:11

问题


The title says it all. I would like to know how to properly set up a new Laravel 5.4 project with Dusk, using an in-memory SQLite database.

I can run the tests, but I get an error: "No such table: users"

  • I have created a new Laravel 5.4 project
  • Installed Dusk and added the Service Provider
  • I'm using the test from the laravel docs that tests authentication. It already includes the DatabaseMigrations trait
  • I can run the tests, and the first one works (navigating to the /login route) but the second where it tried to log in fails.

I have added a .env.dusk.local which contains

APP_ENV=local
APP_KEY=RANDOM_STRING_HERE
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://laravel54.dev

DB_CONNECTION=sqlite
DB_DATABASE=':memory:' // I've also tried just :memory: and also adding these details to the config/database.php file but to no avail

This is the test I am running (directly from the docs)

<?php

namespace Tests\Browser;

use App\User;
use Tests\DuskTestCase;
use Laravel\Dusk\Chrome;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class LoginTest extends DuskTestCase
{
    use DatabaseMigrations;

    public function test_login_page()
    {
        $user = factory(User::class)->create();

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

What am I missing?


回答1:


You cannot.

The important thing to note is that for this kind of end-to-end test, Dusk will not be able to control the environment as it will open a separate process. An in-memory SQLite would only exists under Dusk process and the real-browser hitting the application would have no knowledge of the database Dusk created, making it impossible to assert anything in the database.

https://github.com/laravel/dusk/issues/110

https://github.com/laravel/dusk/issues/73



来源:https://stackoverflow.com/questions/41908118/set-up-laravel-5-4-with-dusk-using-phpunit-xml-env-dusk-local-and-an-sqlite-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!