LoginSignup
1
1

More than 5 years have passed since last update.

ModelのFixtureを任意のテストケースのみ実行する

Last updated at Posted at 2015-06-06

CakePHPでPHPUnitを使っているときに毎回テストケース実行時にFixtureが実行されると、実行時間が長くなり非効率です。
そこで以下の手順でFixtureを任意のタイミングで実行することが可能です。

1.autoFixturesプロパティをfalseにする

CakeTestCase::$autoFixturesがtrueになっていると、CakeTestCase::setUpメソッドで毎回Fixtureの読み込みを行うので、これをfalseにします。

SampleFixture.php
public $autoFixtures = false;

2.Fixtureを読み込みたいタイミングでloadFixturesメソッドを実行

Fixtureを読み込みたいタイミングでテストメソッド内でCakeTestCase::loadFixturesメソッドを実行します。

SampleFixture.php
function testMethod_任意のタイミングでFixture実行 () {
    $this->loadFixtures('fixtureA', 'fixtureB');
}

参考

1
1
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
1