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 · 12 comments
Closed

Doctrine cleanup: true not working #5326

ThomasLandauer opened this issue Jan 7, 2019 · 12 comments
Labels

Comments

@ThomasLandauer
Copy link
Member

@ThomasLandauer 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
Copy link
Member

@Naktibalda 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

@ThomasLandauer
Copy link
Member Author

@ThomasLandauer 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
Copy link

@demyan112rv 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
Copy link
Member

@Naktibalda Naktibalda commented Jan 9, 2019

Probably it was caused by #5250

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

@joelmedeiros
Copy link
Contributor

@joelmedeiros 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
Copy link
Member Author

@ThomasLandauer ThomasLandauer commented Jan 14, 2019

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

@ThomasLandauer
Copy link
Member Author

@ThomasLandauer 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
Copy link
Member

@Naktibalda Naktibalda commented Feb 10, 2019

2.5.4 will break your workaround.

@joelmedeiros
Copy link
Contributor

@joelmedeiros 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
* 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
Copy link
Member

@Naktibalda 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
Copy link
Member Author

@ThomasLandauer 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! :-)

@adlarge
Copy link

@adlarge adlarge commented Mar 22, 2019

Hi, i also have this issue with codeception 2.5.1 or 2.5.x-dev, if i look at my queries log i have a COMMIT then a ROLLBACK, so nothing is rollback. I'm just doing a flush.

This is my conf file :

actor: ApiTester
modules:
    enabled:
        - REST:
            depends: Symfony
            part: Json
            url: 'http://localhost'
        - Doctrine2:
            depends: Symfony
            cleanup: true
        - \App\Tests\Helper\Api
        - Asserts
        - Symfony:
            app_path: 'src'
            environment: 'test'
            debug: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants