Codeception / module-yii2

Codeception module for Yii2 framework
MIT License
16 stars 36 forks source link

Update Yii2 module: use Fixtures store owner #20

Closed wapmorgan closed 2 years ago

wapmorgan commented 3 years ago

Suggestion to fix #11 - Load fixtures by each test case separately.

Shortly: load fixtures and save owner of store. This is used when cleanup: false and fixtures is loaded in _fixtures method (not by calling haveFixtures()) and when different test cases load different fixtures

SamMousa commented 3 years ago

Also, $loadedFixtures is public, so changing its structure is a break in BC.

In general I'm not sure of this is the right solution; for me not cleaning up fixtures means my test environment is no longer consistent, combined with random test order this will lead to brittle tests where the causes of failures cannot be easily identified. I always thought it was more of a debug option used for manual inspection in case something went wrong and needed detailed analysis.

That said, if the conclusion is that we want to support this case then we should at least make it clear to everyone that this breaks backwards compatibility, I'm not sure how many people use fixtures I tend to prefer helper functions on actors instead. They mean I can run my tests inside transactions and dependencies are more explicit:

public function testSoftDelete(FunctionalTester $I) 
{
    $project = $I->haveProject();
    $project->delete();
    $I->assertFalse(Project::find()->andWhere(['id' => $project->id])->exists());
    $I->assertFalse(Project::find()->withDeletedRecords()->andWhere(['id' => $project->id])->exists());
}

But that's a whole other discussion =/

SamMousa commented 3 years ago

Why does FixturesStore know about its owner? The public getter is never used, so the owner shouldn't even be passed in...

samdark commented 2 years ago

@wapmorgan what is the plan with this PR?

samdark commented 2 years ago

OK :) Thanks anyway.