Created
September 14, 2012 21:14
-
-
Save beberlei/3724886 to your computer and use it in GitHub Desktop.
Doctrine Test Setup
This file contains hidden or 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 | |
// 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