多資料庫連線的資料庫事務

DatabaseTransactions trait 允許資料庫在測試期間回滾所有更改。如果要回滾多個資料庫,則需要設定 $connectionsToTransact 屬性

use Illuminate\Foundation\Testing\DatabaseMigrations;

class ExampleTest extends TestCase
{
     use DatabaseTransactions;

     $connectionsToTransact =["mysql","sqlite"] //tell Laravel which database need to rollBack

    public function testExampleIndex()
    {
        $this->visit('/action/parameter')
         ->see('items');
    }
}