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

Problem with dama and reset database #534

Open
nikophil opened this issue Dec 1, 2023 · 0 comments
Open

Problem with dama and reset database #534

nikophil opened this issue Dec 1, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@nikophil
Copy link
Member

nikophil commented Dec 1, 2023

there is a subtle bug with ResetDatabase and dama, and maybe zestruck\messenger-test.

Given this scenario:
1- test 1 (without reset trait) : because of the middleware, doctrine connection is initialized, and StaticDriver as well
2- test 2 (with reset trait) : all other connections are "killed" because of https://github.com/zenstruck/foundry/blob/1.x/src/Test/ORMDatabaseResetter.php#L110-L118
3- dama tries to open a transaction, but the connection does not exist anymore

and if i comment out the lines where we kill the other connections :
1- test 1 (without reset trait) : because of the middleware, doctrine connection is initialized, and StaticDriver as well
2- test 2 (with reset trait) : I have the following error :

RuntimeException: Error running "doctrine:database:drop": Could not drop database "opa-dev_test" for connection named default
An exception occurred while executing a query: SQLSTATE[55006]: Object in use: 7 ERROR:  database "opa-dev_test" is being accessed by other users

it sounds like the proper solution would be to run the reset database logic before the first test, not before the first test with the reset database trait

Maybe we could add a helper to use in bootstrap.php:

// tests/boostrap.php

DatabaseResetter::reset(); // by default uses KERNEL_CLASS env variable to instantiate the kernel

DatabaseResetter::reset(new MyKernel()); // pass your own kernel if doing something out of the ordinary
@nikophil nikophil added the bug Something isn't working label Dec 1, 2023
@nikophil nikophil mentioned this issue Dec 21, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant