Skip to content

Instantly share code, notes, and snippets.

@beberlei
Created September 14, 2012 21:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beberlei/3724886 to your computer and use it in GitHub Desktop.
Save beberlei/3724886 to your computer and use it in GitHub Desktop.
Doctrine Test Setup
<?php
// tests/MyProject/Tests/DoctrineTestCase.php
namespace MyProject\Tests;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\EntityManager;
class DoctrineTestCase extends \PHPUnit_Framework_TestCase
{
protected $em;
protected function createEntityManagerConfiguration()
{
$config = new \Doctrine\ORM\Configuration();
// your config here matching your applications config
// or grab the configuration object from framework somehow.
return $config;
}
public function setUp()
{
$config = $this->createEntityManagerConfiguration();
$this->em = EnityManager::create(array('driver' => 'pdo_sqlite', 'memory' => true), $config);
$schemaTool = new SchemaTool($this->em);
$schemaTool->createSchema($this->em->getMetadataFactory()->getAllMetadata());
}
public function testSomething()
{
$query = $this->em->createQuery('....');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment