foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Database Resetter with Multiple mapper

Open Didixdan opened this issue 1 year ago • 2 comments

It seems like the Database Resetter does not work well when we have a ODM database and an ORM database.

When i write a functional test and i'm using ResetDatabase trait, the package call DatabaseResetter::resetDatabase which call createORMDatabaseResetter and reset it.

I know it does that because he attempt to create a test database, and got an access denied from the MySQL container (valid behavior because the functional test is only for ODM)

How can i tell Foundry to not reset the database of the ORM connection ? I've found nothing about that in all issues/PR.

Didixdan avatar Feb 20 '24 08:02 Didixdan

For those who wants to have this to work, here is a temporary trait until Foundry work as we want.


namespace App\Traits;

use Doctrine\ODM\MongoDB\DocumentManager;

/**
 * @method static bootKernel()
 */
trait ResetDatabaseODM
{
    public function setUp(): void
    {
        static::bootKernel();
        /** @var DocumentManager $documentManager */
        $documentManager = static::$kernel->getContainer()->get('doctrine_mongodb.odm.document_manager');

        $documentManager->getSchemaManager()->dropDatabases();
    }
}

Didixdan avatar Feb 21 '24 08:02 Didixdan

Hello,

you can list the connections/managers you want to reset, thanks to bundle configuration.

You can find an example in the docs here: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#database-reset

wouldn't it fix your case to pass it an empty array?

nikophil avatar Feb 22 '24 16:02 nikophil

closing stale issue

nikophil avatar Jun 23 '24 16:06 nikophil