使用phpunit.xml,.env.dusk.local和sqlite内存数据库使用Dusk设置Laravel 5.4 [英] Set up Laravel 5.4 with Dusk using phpunit.xml, .env.dusk.local, and an sqlite in-memory database

查看:149
本文介绍了使用phpunit.xml,.env.dusk.local和sqlite内存数据库使用Dusk设置Laravel 5.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切.我想知道如何使用内存中的SQLite数据库使用Dusk正确设置新的Laravel 5.4项目.

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"

  • 我创建了一个新的Laravel 5.4项目
  • 安装了黄昏并添加了服务提供商
  • 我正在使用 laravel docs 中的测试身份验证的测试.它已经包含了DatabaseMigrations特性
  • 我可以运行测试,第一个可以工作(导航到/login路由),但是第二个尝试登录的尝试却失败了.
  • 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.

我添加了一个.env.dusk.local其中包含

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');
        });
    }
}

我想念什么?

推荐答案

您不能.

要注意的重要一点是,对于这种端到端测试,Dusk将无法控制环境,因为它将打开一个单独的进程.内存中的SQLite将仅在Dusk进程下存在,并且击中应用程序的实际浏览器将不了解Dusk创建的数据库,从而无法在数据库中声明任何内容.

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

这篇关于使用phpunit.xml,.env.dusk.local和sqlite内存数据库使用Dusk设置Laravel 5.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆