I have some unit tests that require several fixtures, and it can take about a second or two before each test to load them. They work, but the whole test suite takes forever. If understand correctly, the Yii2 module wraps each test in a transaction (https://codeception.com/docs/modules/Yii2#Config). So shouldn’t I be able to load the fixtures only once for each test suite and rely on transactions to undo any modifications that occurred in the test? How could I go about this? There does not seem to be any “_beforeSuite()” method in \Codeception\Test\Unit
. I tried setting a flag:
class MyModelTest extends \Codeception\Test\Unit
{
static $fixturesLoaded = false;
public function _before()
{
if (!self::$fixturesLoaded) {
$this->tester->haveFixtures([
MyModel::class,
]);
self::$fixturesLoaded = true;
}
}
But this does not work as the _before() method is apparently called inside the transaction so the fixtures don’t persist between tests.
My unit.suite.yaml
:
class_name: UnitTester
modules:
enabled:
- Yii2:
part: [orm, fixtures]
cleanup: false
transaction: true