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

unloadFixtures() should run after db transaction #4497

Merged
merged 1 commit into from Sep 28, 2017
Merged

unloadFixtures() should run after db transaction #4497

merged 1 commit into from Sep 28, 2017

Conversation

devonliu02
Copy link
Contributor

No description provided.

@DavertMik
Copy link
Member

Makes sense... But makes a little sense to do both in transaction :)

@devonliu02
Copy link
Contributor Author

Fixtures were loaded before transaction (if transaction is on ), then if we unload fixtures before transaction rollback, the delete SQL in unloadFixture will be rollback too. so it is useless for cleanup configuration.

@devonliu02
Copy link
Contributor Author

Do you mean all fixtures operation should be done in transaction? @DavertMik

@DavertMik
Copy link
Member

DavertMik commented Sep 11, 2017

Not sure. As for me - yes, inside transaction. But maybe Yii community have another opinion

@samdark what you think?

$this->transaction->rollBack();
$this->debugSection('Database', 'Transaction cancelled; all changes reverted.');
}

if ($this->config['cleanup']) {
foreach ($this->loadedFixtures as $fixture) {
$fixture->unloadFixtures();
Copy link
Member

Choose a reason for hiding this comment

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

ok but fixtures are cleaned up by rolled back transaction...
and this call may throw an exception...

@samdark
Copy link
Collaborator

samdark commented Sep 13, 2017

I don't understand the change. Currently there are two options:

  1. Wrap everything with a transaction so no cleanup actually needed: transaction reverts data from fixtures by itself.
  2. Not using transaction but cleaning up manually with unloadFixtures().

Why should we use both?

@devonliu02
Copy link
Contributor Author

the problem here is that fixtures were loaded before the transaction, and transaction will not reverts them.

@samdark
Copy link
Collaborator

samdark commented Sep 13, 2017

Would this change fix loading fixtures before transaction?

@devonliu02
Copy link
Contributor Author

devonliu02 commented Sep 16, 2017

Maybe I didn't make that clear, or I misunderstood the configuration.

I want that fixtures will be unloaded after each test, and transaction on too.

Let's see the problem step by step,

  1. before test (_before)
    1. load fixtures
    2. begin transaction
  2. test run
  3. after test (_after)
    1. unload fixtures
    2. rollback transaction

Now, we can see that fixtures are not really be unloaded because the transaction has been rollback.
In this case, the fixtures will be loaded again before next test run.

@samdark
Copy link
Collaborator

samdark commented Sep 18, 2017

As far as I remember, sequence was meant to be:

  1. before test (_before)
    1. begin transaction
    2. load fixtures
  2. test run
  3. after test (_after)
    3. rollback transaction
    4. unload fixtures in case transactions aren't enabled

Is is different?

@devonliu02
Copy link
Contributor Author

@samdark
Copy link
Collaborator

samdark commented Sep 19, 2017

Indeed. @DavertMik need your input on original intentions...

@DavertMik
Copy link
Member

Sorry, you are right. I missed the execution order in _before. Looks like it changed after I looked into it last time. Yes, we need to merge it

@DavertMik DavertMik merged commit 949f5ba into Codeception:2.3 Sep 28, 2017
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

4 participants