Created
June 5, 2015 14:00
-
-
Save geerteltink/caa7e0512f02920b9fe6 to your computer and use it in GitHub Desktop.
Symfony 2 loading Doctrine DataFixtures in PHPunit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace UserBundle\Tests\Service; | |
use Doctrine\Common\DataFixtures\Executor\ORMExecutor; | |
use Doctrine\Common\DataFixtures\Loader as ORMLoader; | |
use Doctrine\Common\DataFixtures\Purger\ORMPurger; | |
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | |
use Symfony\Component\DependencyInjection\Container; | |
class DoctrineDataFixturesLoading extends KernelTestCase | |
{ | |
/** | |
* @var Container | |
*/ | |
private $container; | |
/** | |
* {@inheritDoc} | |
*/ | |
public function setUp() | |
{ | |
self::bootKernel(); | |
$this->container = static::$kernel->getContainer(); | |
// Load data fixtures | |
$em = $this->container->get('doctrine')->getManager(); | |
$loader = new ORMLoader(); | |
$loader->loadFromDirectory('src/AppBundle/DataFixtures/ORM/'); | |
$purger = new ORMPurger($em); | |
$executor = new ORMExecutor($em, $purger); | |
$executor->execute($loader->getFixtures()); | |
} | |
// Do some tests | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment