Laravel黄昏不起作用.env.dusk.local [英] Laravel dusk not working .env.dusk.local
问题描述
我有一个应用程序,我想使用Laravel Dusk.
I have an application and I want to use Laravel Dusk.
我创建了一个名为.env.dusk.local
的文件,其中包含用于测试的数据库,一个名为.env
的文件具有我的默认数据库.
I created a file named .env.dusk.local
with a database for tests and a file named .env
with my default database.
我运行了php artisan命令,并由/register
创建了一个用户.
I ran the php artisan command and created a user by /register
.
使用相同的电子邮件但使用不同的密码创建登录测试后,这将不是问题,因为在.env.dusk.local
中它将是另一家银行,并且没有任何用户注册.
After I created a login test with the same email but with a different password, this would not be a problem because in .env.dusk.local
it would be a different bank and would not have any users registered.
但是当我运行php artisan dusk命令时,它将从原始的.env
中获取信息,并最终从默认数据库中删除了所有记录.
But when I run the php artisan dusk command it takes the information from the original .env
and ends up erasing all records from my default database.
我想知道如何从.env.dusk.local
加载信息并使用测试数据库.
I would like to know how to load the information from my .env.dusk.local
and use my test database.
.env默认值
APP_ENV=local
APP_KEY=base64:K8otIkxJk0rFsZYSEq1hwBuaxQX3QI3Bb7ZmemJRIWg=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost:8000
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_dusk
DB_USERNAME=root
DB_PASSWORD=123456
.env.dusk.local
.env.dusk.local
APP_ENV=local
APP_KEY=base64:K8otIkxJk0rFsZYSEq1hwBuaxQX3QI3Bb7ZmemJRIWg=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost:8000
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_dusk_test
DB_USERNAME=root
DB_PASSWORD=123456
testLogin的Mu功能
Mu function for testLogin
namespace Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\App;
use Tests\DuskTestCase;
class LoginTest extends DuskTestCase
{
use DatabaseMigrations;
/**
* A Dusk test example.
*
* @return void
*/
public function testLogin()
{
$user = factory(\App\User::class)->create(['email' => 'lucas@example.com']);
$this->browse(function ($browser) use ($user) {
$browser->visit('/login')
->type('email', $user->email)
->type('password', 'secret')
->press('Login')
->assertPathIs('/home');
});
}
}
推荐答案
代替.env.dusk.local
尝试.env.dusk
我也不建议您使用mysql数据库,因为它会在测试期间创建和销毁,因此我建议您使用一个临时的sqlite数据库.
Also instead of using your mysql database I would recommend using a temporary sqlite db since it gets created and destroyed during tests.
您必须在database.php中有一个sqilte配置,该配置指向安装中具有的实际.sqlite文件
you will have to have a sqilte config in your database.php that points at an actual .sqlite file that you have in your installation
,因此将sqlite
配置复制到database.php
中,然后将其粘贴,将其命名为sqlite_dusk
,然后对于数据库的位置,将其放置为storage_path('dusk.sqlite')
或类似的名称.然后在storage
文件夹的根目录中创建一个空白的dusk.sqlite
文件.
so copy the sqlite
config in database.php
and then paste it, name it sqlite_dusk
maybe, then for the location of the db put it as storage_path('dusk.sqlite')
or something like that. Then create a blank dusk.sqlite
file in the root of your storage
folder.
然后在您的.env.dusk
集合中:
DB_CONNECTION=sqlite_dusk
希望有帮助!
这篇关于Laravel黄昏不起作用.env.dusk.local的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!