Temporary Doctrine2 fixtures for testing with phpunit
You can use Doctrine DataFixture and put this code in your setUp method of a unit test class:
$loader = new Doctrine\Common\DataFixtures\Loader;$loader->loadFromDirectory('/path/to/MyDataFixtures');$purger = new Doctrine\Common\DataFixtures\Purger\ORMPurger($em);$executor = new Doctrine\Common\DataFixtures\Executor\ORMExecutor($em, $purger);$executor->execute($loader->getFixtures());
You can refer to the docs to see how create DataFixture classes.
Here is a good example of how to do it: Symfony 2 + Doctrine 2 + PHPUnit 3.5: Serialization of closure exception
PS: I assume you have a working $em (EntityManager) in this example.