I save fixtures in tests/codeception/common/fixtures and tests/codeception/common/unit/fixtures I think in common/fixtures I must put "global fixtures" and in common/unit/fixtures I must put fixtures, which use in common/unit tests. Is it true? But where I must put fixtures for functional and accept test? In their directory is not fixture directory…
When I use command
./yii fixture User
it find fixture in tests/codeception/common/unit/test. Why? I think for more logic, it must finds fixtures in "global fixtures directory" Am I wrong?
Why does yii not unload fixtures after test? I use related fixtures (and tables)(GoogleKeywordFixture -> GoogleGroupFixture) in first test. In second I use only GoogleGroupFixture. In second test yii try reload(unloadFixtures(‘GoogleKeywordFixture’), loadFixtures(‘GoogleKeywordFixture’)) , but it finished with error, because GoogleKeywordFixture referrers to GoogleKeywordFixture(from prev test). How to resolve this problem?
I believe this is correct though the semantic for "global fixtures" means fixtures that need to be loaded before any others. Such as the initDb fixture. I prefer to call fixtures that can be used across different test suits "general purpose fixtures" to avoid ambiguity.
This might be because unit is the default namespace for the fixture. You can specify a different namespace with
I have two tables(and Models). GoogleGroup(id, name) and BadKeyword(id, name, group_id). Field BadKeyword.group_id - foreign key to GoogleGroup.id.
When I have created BadKeywordFixtures I set depends
class BadKeywordsFixture extends ActiveFixture
{
public $depends = [
'tests\codeception\common\fixtures\GoogleGroupsFixture',
];
public $modelClass = 'common\modules\bidmanager\models\costnoatification\BadKeywords';
public $dataFile = '@tests/codeception/common/fixtures/data/init_bad_keywords.php';
}
I have two tests. First test use GoogleGroupFixtures and BadKeywordFixtures.Second test use only GoogleGroupFixtures
I’m willing to bet your issue is because you have integrity constraints on your database (such as using innoDb tables with foreign keys in MYSQL). The tables need to be dropped in a specific order and yii is failing to do so.
You are extending DbTestCase which means it should work, which I find odd… maybe try adding the fixture to the globalFixtures() method of your Test class to see if that works.
Is there perhaps a pivot table that needs to be dropped as well? And that yii wouldn’t find from your fixture/AR definitions ?
Also:
Because BadKeywordsFixture depends on GoogleGroupsFixture you don’t have to define the groups fixture in your test class. It doesn’t hurt to have it there as Yii2 handles the fact that it’s a dependency of BadKeywords but it isn’t necessary:
class BadKeywordsTest extends DbTestCase
{
.........
public function fixtures()
{
return [
'badKeywords' => [
'class' => BadKeywordsFixture::className(),
],
'campaigns' => [
'class' => GoogleCampaignsFixture::className(),
],
];
}
.......
}