Laravel黄昏只能迁移一次 [英] Migrate only once with Laravel dusk
问题描述
根据根据数据库测试"文档我可以在每次测试后重置数据库(第一个选项).第二种选择是使用事务运行测试.对于我来说,这似乎是一种更好的方法,但是如果我要使用事务运行,则迁移不会运行.
According to the "Database Testing" documentation I can reset the database after each test (first option). Second option is to run test using Transactions. It seems a better approach to me, but if I want to run with transaction, the migration does not run.
对于所有测试过程,是否可以运行一次迁移?
Is there any way to run the migration once for all the test process?
换句话说,我要运行迁移,使用事务运行每个测试,然后回滚.我尝试使用文档中的内容,但我认为缺少某些内容.
In other words, I want to run the migration, run every tests with transaction, then rollback. I tried with what the documentation says, but I think something is missing.
推荐答案
今天解决了这一问题,将迁移与迁移结合起来似乎可以解决问题.我的测试快照如下:
Wrangled with this for a while today and running migrations in conjunction with migrations seems to do the trick. A snapshot of my test is as follows:
<?php
namespace Tests\Browser;
use App\User;
use Tests\DuskTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class DefaultTest extends DuskTestCase
{
use DatabaseMigrations, DatabaseTransactions;
/**
* A Dusk test example.
*
* @return void
*/
public function test_something()
{
//Add test stuff here
}
}
我在实际测试中有几个工厂,它们似乎经历了迁移,并且按预期在测试后销毁了数据.
I've got a couple of factories in my actual test and they seem to run through the migrations with the data destroyed after the test as expected.
这篇关于Laravel黄昏只能迁移一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!