Laravel 5 Reseeding the Database for Unit Testing Between Tests

蓝咒 提交于 2019-12-05 08:10:45

Just run this:

    $this->artisan('migrate:refresh', [
        '--seed' => '1'
    ]);

To avoid changes to the database persisting between tests add use DatabaseTransactions to your tests that hit the database.

Why not create your own command like db:reset. This command either truncate all your tables or drop/create schema and then migrate.

In your test you then use: $this->call('db:reset') in between your tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!