There is an issue configuring component properties when the user does not use Yii2 default values during Codeception tests. The problem caused by using anonymous array value to register InitDbFixture [yii\test\InitDbFixture] component rather than using key-pair component registering.
The following attachment occurred from changing Yii default database component from db to something else.
Solution
During FixturesStore [Codeception\Lib\Connector\Yii2\FixturesStore] initialization, its globalFixtures() has InitDbFixture component registering as anonymous fixture value resulting to Yii unable to merge the fixtures array in FixtureTrait [yii\test\FixtureTrait::getFixtures()].
This allows the user to override component InitDbFixture default values via _fixtures() in test case.
Result
Example of application using otherDbComponent to be main database component than Yii default db.
// in a Cest file
public function _fixtures()
{
return [
// This will be merged and overridden during initialization
'initDbFixture' => [
'class' => \yii\test\InitDbFixture::class,
'db' => 'otherDbComponent',
],
'user' => [
'class' => UserFixture::class,
'db' => 'otherDbComponent',
'dataFile' => codecept_data_dir() . 'login_data.php'
]
];
}
Issue
There is an issue configuring component properties when the user does not use Yii2 default values during Codeception tests. The problem caused by using anonymous array value to register InitDbFixture [yii\test\InitDbFixture] component rather than using key-pair component registering.
The following attachment occurred from changing Yii default database component from
db
to something else.Solution
During FixturesStore [Codeception\Lib\Connector\Yii2\FixturesStore] initialization, its
globalFixtures()
has InitDbFixture component registering as anonymous fixture value resulting to Yii unable to merge the fixtures array in FixtureTrait [yii\test\FixtureTrait::getFixtures()].By changing its registration from the following
to
This allows the user to override component InitDbFixture default values via
_fixtures()
in test case.Result
Example of application using
otherDbComponent
to be main database component than Yii defaultdb
.