关于laravel单元测试中的refreshDatabase特征

问题描述 投票:0回答:1

我的迁移位于两个不同的默认位置(database/migrations/tables/)和(database/migrations/foreign/),我想使用 RefreshDatabase 特征,但它使用默认迁移位置。

我如何在设置或某处指定或覆盖此迁移的“路径”选项?

我发现做到这一点的唯一方法是重写“refreshInMemoryDatabase”和“refreshTestDatabase”方法,但我正在以更好的方式思考。 谁能帮我这个技巧!

laravel unit-testing phpunit in-memory-database
1个回答
0
投票

通过指定

refreshTestDatabase
覆盖
--path=/app/database/migrations/tests
方法。

protected function refreshTestDatabase()
{
    if (! RefreshDatabaseState::$migrated) {
        $this->artisan('migrate:fresh --path=/app/database/migrations/tests`.
', $this->migrateFreshUsing());

        $this->app[Kernel::class]->setArtisan(null);

        RefreshDatabaseState::$migrated = true;
    }

    $this->beginDatabaseTransaction();
}

© www.soinside.com 2019 - 2024. All rights reserved.