foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Problem with dama and reset database

Open nikophil opened this issue 2 years ago • 0 comments

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 avatar Dec 01 '23 20:12 nikophil