zenstruck / foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html
MIT License
608 stars 63 forks source link

Database Resetter with Multiple mapper #563

Closed Didixdan closed 5 days ago

Didixdan commented 4 months ago

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 commented 4 months ago

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();
    }
}
nikophil commented 4 months ago

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 commented 5 days ago

closing stale issue