Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InitDbFixture object cannot be overridden during FixturesStore initialization #88

Merged
merged 1 commit into from Jun 16, 2023

Conversation

PoohOka
Copy link
Contributor

@PoohOka PoohOka commented Jun 15, 2023

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.

Screenshot 2023-06-15 at 16 58 15

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

return [
    InitDbFixture::class
];

to

return [
    'initDbFixture' => [
        'class' => InitDbFixture::class,
    ],
];

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'
        ]
    ];
}

Copy link
Member

@Arhell Arhell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samdark samdark merged commit 70ad754 into Codeception:master Jun 16, 2023
3 checks passed
@samdark
Copy link
Collaborator

samdark commented Jun 16, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants