Codeception / module-yii2

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

Fixtures are not loaded when cleanup = false #11

Closed wapmorgan closed 2 years ago

wapmorgan commented 4 years ago

If I set cleanup to false (to speed-up testing), this method does not load fixtures:

private function loadFixtures($test)
    {
        $this->debugSection('Fixtures', 'Loading fixtures');
        if (empty($this->loadedFixtures)
            && method_exists($test, $this->_getConfig('fixturesMethod'))
        ) {
            $connectionWatcher = new Yii2Connector\ConnectionWatcher();
            $connectionWatcher->start();
            $this->haveFixtures(call_user_func([$test, $this->_getConfig('fixturesMethod')]));
            $connectionWatcher->stop();
            $connectionWatcher->closeAll();
        }
        $this->debugSection('Fixtures', 'Done');
    }

I think that $this->loadedFixtures is not empty after first fixtures loading in earlier test, and when codeception goes to another test, it does not load fixtures for it.

wapmorgan commented 3 years ago

I think, expected behavior for loading fixtures with cleanap = false is:

  1. Load all fixtures from test case in the beggining of test case
  2. Skip unloading fixtures in the end of test case
  3. Reload fixtures (if previously tests loaded one fixture of declared in current test case)
samdark commented 3 years ago

@wapmorgan yes, your proposed behavior is better than current one, I think.

samdark commented 3 years ago

Want to implement the change?

SamMousa commented 2 years ago

This seems to have been an attempt to make loadFixtures idempotent. Which isn't needed...

Edit: I'm hesitant to change this though, since the property is public anyone could depend on this behavior. To be honest, I'm not using fixtures in my code and don't really see their benefit; but that also means that I have little experience with this part of the code.

Seeing as this has been open for almost 2 years I'm gonna go ahead and close it.