LiipFunctionalTestBundle icon indicating copy to clipboard operation
LiipFunctionalTestBundle copied to clipboard

WebTestCase::loadFixtureFiles with append=false using ODM fails

Open ReservedDeveloper opened this issue 9 years ago • 4 comments

When attempting to use \Liip\FunctionalTestBundle\Test\WebTestCase::loadFixtureFiles() passing in append=false, I encountered an error. I believe it has to do with detection of the DB platform as shown in L382-L394.

My workaround, presently, is as follows:

    /**
     * @inheritDoc
     */
    public function loadFixtureFiles(array $paths = [], $append = false, $omName = null, $registryName = 'doctrine')
    {
        $om = $this->getObjectManager($omName, $registryName);

        if ($append == false && ($om instanceof DocumentManager)) {
            $sm = $om->getSchemaManager();

            $sm->dropDatabases();
            $sm->createDatabases();
        }

        parent::loadFixtureFiles($paths, true, $omName, $registryName);
    }

Not sure if that would be the ideal approach, or if there's a better platform agnostic way of determining which class methods need to be called for a reset. Just wanted to call it out for a future release!

ReservedDeveloper avatar Sep 23 '15 17:09 ReservedDeveloper

its easier to review if you just open a PR

lsmith77 avatar Sep 24 '15 12:09 lsmith77

The snag here is that you can't necessarily take the above mentioned approach for the method, since this bundle doesn't have concrete dependencies on doctrine/mongodb-odm.

You could do a method_exists($om, 'getSchemaManager') or is_a($om, 'Doctrine\ODM\MongoDB\DocumentManager') check, but both approaches feel super brittle, so I'm not sure what would be the best tactic here without requiring any further dependencies.

ReservedDeveloper avatar Nov 25 '15 22:11 ReservedDeveloper

@ReservedDeveloper can't we use something like if ('ODM' === $type) { for detecting ODM?

alexislefebvre avatar Feb 10 '16 13:02 alexislefebvre

@alexislefebvre no .. the type will be specific to the ODM .. but we can check for 'ORM' !== $type

lsmith77 avatar Feb 10 '16 14:02 lsmith77