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

Doctrine `cleanup: true` not working #5326

Closed
ThomasLandauer opened this Issue Jan 7, 2019 · 11 comments

Comments

Projects
None yet
4 participants
@ThomasLandauer
Copy link
Contributor

ThomasLandauer commented Jan 7, 2019

What are you trying to achieve?

Rollback the transcation.

What do you get instead?

Changes are kept in the database.

Provide console output if related. Use -vvv mode for more details.

The output does start with:

Scenario --
[Database] Transaction started
[Database] Transaction started

But this is not shown at the end of the output (no matter if the test passes or not):

[Database] Transaction cancelled; all changes reverted.

Details

  • Codeception version: 2.5.2
  • Symfony version: 4.2.1
  • PHP Version: 7.2.10
  • Suite configuration:
actor: FunctionalTester
modules:
    enabled:
        - Symfony:
            app_path: 'src'
            environment: 'test'
        - Doctrine2:
            depends: Symfony
            cleanup: true
        - REST:
            depends: Symfony
        - Asserts
        - \App\Tests\Helper\Functional
@Naktibalda

This comment has been minimized.

Copy link
Member

Naktibalda commented Jan 7, 2019

Does your application code commit?
Doctrine2 module only rolls back if there is an active transaction.

https://github.com/Codeception/Codeception/blob/2.5.2/src/Codeception/Module/Doctrine2.php#L170

@Naktibalda Naktibalda added the Doctrine label Jan 7, 2019

@ThomasLandauer

This comment has been minimized.

Copy link
Contributor Author

ThomasLandauer commented Jan 7, 2019

I don't know. I just do what I'm always doing: $entityManager->flush();

I have another app with Symfony 3 and Codeception 2.5.1 and there it works as expected.

How can I determine if the transaction is still active in the last line of the test? Is there anything I can codecept_debug()?

@demyan112rv

This comment has been minimized.

Copy link

demyan112rv commented Jan 8, 2019

I had the same problem with Codeception version 2.5.2
After a rollback to version 2.5.1, everything worked.
I use Phinx as migration tool and my config look like this:

modules:
    enabled:
        - Db:
            dsn: 'mysql:host=...'
            user: '...'
            password: '...'
            cleanup: true
            populate: true
            populator: 'db-migrations:rollback && db-migrations:run'
@Naktibalda

This comment has been minimized.

Copy link
Member

Naktibalda commented Jan 9, 2019

Probably it was caused by #5250

@joelmedeiros Do you see what could be causing this issue?

@joelmedeiros

This comment has been minimized.

Copy link
Contributor

joelmedeiros commented Jan 11, 2019

Probably it was caused by #5250

@joelmedeiros Do you see what could be causing this issue?

I'll take a look

@ThomasLandauer

This comment has been minimized.

Copy link
Contributor Author

ThomasLandauer commented Jan 14, 2019

A downgrade to 2.5.1 "fixed" it for me too.

@ThomasLandauer

This comment has been minimized.

Copy link
Contributor Author

ThomasLandauer commented Feb 10, 2019

Still not working in 2.5.3 - workaround is to add this to your composer.json:

    "conflict": {
        "codeception/codeception": "2.5.2 || 2.5.3"
    },
@Naktibalda

This comment has been minimized.

Copy link
Member

Naktibalda commented Feb 10, 2019

2.5.4 will break your workaround.

@joelmedeiros

This comment has been minimized.

Copy link
Contributor

joelmedeiros commented Feb 11, 2019

I finally found the solution in this PR, please check if it can correct all issues, it have worked to me.

Naktibalda added a commit that referenced this issue Feb 15, 2019

[Doctrine] Fixed cleanup issue #5326
* Reloading module on reconfigure to persist new configs.

* Making cleanup property work after on reconfigure

* hotfix - do not persist data on database when cleanup config is set.

* Update Doctrine2.php

correcting merge failure
@Naktibalda

This comment has been minimized.

Copy link
Member

Naktibalda commented Feb 15, 2019

@ThomasLandauer Please test this change by setting codeception version to 2.5.x-dev in composer.json, running composer update and then running your tests.

I plan to release 2.5.4 next week and it will probably be the last release of 2.5 branch.

@ThomasLandauer

This comment has been minimized.

Copy link
Contributor Author

ThomasLandauer commented Feb 17, 2019

I first removed this from conflict: "codeception/codeception": "2.5.2 || 2.5.3", and I got codeception 2.5.3. Result: Some failures on first run, even more on second run.

Then I entered 2.5.x-dev, and I got codeception 2.5.x-dev 7f685c3. Result: All green in three runs.

=> Looks good! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.