I just wanted to offer a slightly neater approach if you want to first purge your table of previous test data, e.g. if you are running 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 fixtures to be loaded, (you can push more into the add fixture method), and purge the tables before they are loaded.
Also note MongoDB has the same option using MongoDBPurger, and MongoDBExecutor.
Hope it helps someone