Laravel DatabaseTransactions,DatabaseMigrations在测试时不起作用 [英] Laravel DatabaseTransactions, DatabaseMigrations have no effect when testing

查看:84
本文介绍了Laravel DatabaseTransactions,DatabaseMigrations在测试时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下测试课程

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ProvidersTest extends TestCase
{
    use DatabaseMigrations;

    /**
     * @var \Orka\Entities\User
     */
    protected $user;

    public function setUp()
    {
        parent::setUp();
        $user = factory(\Orka\Entities\User::class)->create();
        $this->user = $user;
    }

    /**
     * @test
     */
    public function it_shows_no_connected_providers()
    {
        $this
            ->actingAs($this->user)
            ->visit('/teams/1/providers')
            ->see('You have not connected a provider yet.')
        ;
    }
}

运行此代码时,我收到一条错误消息,告诉我表不存在,使它正常工作的唯一方法是在setUp()方法中调用$this->runDatabaseMigrations();,但据我所知我不需要要做到这一点.我在DatabaseTransactions中也遇到类似的问题.

When running this code I get an error telling me tables do no exist, the only way I can get it to work is to call $this->runDatabaseMigrations(); in the setUp() method, but as far as I know I should not need to do that. I have similar issues with DatabaseTransactions.

Laravel 5.1.23

Laravel 5.1.23

关于为什么发生这种情况的任何想法,因为文档中说应该自动触发.

Any ideas on why this is happening as the docs say that it should be triggered automatically.

推荐答案

此问题应已解决:

This should have been fixed: https://laracasts.com/discuss/channels/testing/databasetransactions-databasemigrations-have-no-effect?page=0#reply-112955 (see the last comment by Jeffrey)

这篇关于Laravel DatabaseTransactions,DatabaseMigrations在测试时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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