liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony
http://liip.ch
MIT License
641 stars 181 forks source link

WebTestCase::loadFixtureFiles with append=false using ODM fails #169

Open ReservedDeveloper opened 8 years ago

ReservedDeveloper commented 8 years ago

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!

lsmith77 commented 8 years ago

its easier to review if you just open a PR

ReservedDeveloper commented 8 years ago

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.

alexislefebvre commented 8 years ago

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

lsmith77 commented 8 years ago

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