LoginSignup
1
4

More than 3 years have passed since last update.

Laravelで複数のデータベースを跨ぐテストを実施する際のトランザクションの設定

Last updated at Posted at 2019-10-02

背景

LaravelのPHPUnitで

use DatabaseTransactions;

を使用すると1つのデータベースへのトランザクションしか受け付けてくれない。
複数のデータベースを跨ぐトランザクションの設定を実施するには

connectionsToTransact

を使用する。

具体例


use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;

class HogeTest extends TestCase
{
    use DatabaseTransactions;

    protected $connectionsToTransact = ['mysql1', 'mysql2'];

参考

Multiple databases and testing

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4