Yii2 fixtures not unloading, not loading with dependencies -
unloading issue
i'm trying create fixtures in yii2 able fill tables test data. i'm not using codeception yet. i'm following yii2 guide on fixtures. first table user table:
namespace tests\unit\fixtures; use yii\test\activefixture; /** * user fixture */ class userfixture extends activefixture { public $modelclass = 'common\models\user'; }
this 1 works when ssh vagrant , load fixture, entries still there after unload. according terminal output fixture unloaded. missing here? should work out of box or should create own unload function?
edit: did adding user fixture:
public function unload(){ parent::unload(); $this->resettable(); }
i expect present in unload anyhow, have read (very slow) discussion in link posted below. don't know if parent::unload() line necessary, worked without line, baseactivefixture defines , empties $this->data , $this->_models.
depends issue
my second fixture depends on user fixture:
namespace tests\unit\fixtures; use yii\test\activefixture; /** * user libraries fixture */ class userlibrariesfixture extends activefixture { public $modelclass = 'common\models\userlibraries'; // dependencies public $depends = [ 'tests\unit\fixtures\userfixture', ]; }
this 1 loads correctly according terminal, userlibraries table remains empty. doesn't load dependencies, don't know if should will.
i've kept data files simple possible , correct data appears in user table. added data required fields userlibraries table, don't know if issue. there log file can check entries regarding fixtures?
edit: userlibraries fixture able create data in user table (but not userlibraries table), disabling foreign key check works fixtures dependencies. makes me think there error in data file userlibraries. check need log file.
edit2: fixture loading issue solution
the fixtures not load because of underscore in table names. table names userlibraries , user_libraries result in model, controller , view files identical file names when created gii. camelcase name table able load fixtures.
unloading fixtures question "under discussion" (see here). mysql workaround (i commented there) , should added each fixture model has dependant table:
<?php namespace tests\codeception\common\fixtures; use yii\test\activefixture; class variationfixture extends activefixture { public $modelclass = 'common\models\variation'; public function beforeload() { parent::beforeload(); $this->db->createcommand()->setsql('set foreign_key_checks = 0')->execute(); } public function afterload() { parent::afterload(); $this->db->createcommand()->setsql('set foreign_key_checks = 1')->execute(); } }
as loading, using codeception can use /tests/codeception/common/_support/fixturehelper::fixtures()
define fixtures want loaded before each test case:
public function fixtures() { return [ 'user' => [ 'class' => userfixture::classname(), 'datafile' => '@tests/codeception/common/fixtures/data/init_login.php', ], 'room' => [ 'class' => roomfixture::classname(), 'datafile' => '@tests/codeception/common/fixtures/company/data/room.php', ], ... ]; }
Comments
Post a Comment