I just wanted to offer a slightly tidier approach if you want to clear the table of previous test data first, for example. if you run your tests in phpunit.
use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Loader; use Namespace\FakeBundle\DataFixtures\ORM\YourFixtures; public function setUp() { static::$kernel = static::createKernel(); static::$kernel->boot(); $this->em = static::$kernel->getContainer() ->get('doctrine') ->getManager() ; $loader = new Loader(); $loader->addFixture(new YourFixtures); $purger = new ORMPurger($this->em); $executor = new ORMExecutor($this->em, $purger); $executor->execute($loader->getFixtures()); parent::setUp(); }
This allows you to load fixtures (you can click on the method of adding accessories more) and clear the tables before loading them. Also note that MongoDB has the same option as MongoDBPurger and MongoDBExecutor. Hope this helps someone.
Peter Feb 17 '14 at 2:59 a.m. 2014-02-17 14:59
source share