/
DoctrineOrmTestCase.php
58 lines (49 loc) · 1.71 KB
/
DoctrineOrmTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* This file is part of the GenemuFormBundle package.
*
* (c) Olivier Chauvel <olivier@generation-multiple.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Genemu\Bundle\FormBundle\Tests;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Cache\ArrayCache;
/**
* @author Olivier Chauvel <olivier@generation-multiple.com>
*/
abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Doctrine\\Common\\Version')) {
$this->markTestSkipped('Doctrine is not available.');
}
}
/**
* @return EntityManager
*/
public static function createTestEntityManager($paths = array())
{
if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
self::markTestSkipped('This test requires SQLite support in your environment');
}
$config = new Configuration();
$config->setAutoGenerateProxyClasses(true);
$config->setProxyDir(\sys_get_temp_dir());
$config->setProxyNamespace('GenemuFormBundleTests\Doctrine');
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
$config->setQueryCacheImpl(new ArrayCache());
$config->setMetadataCacheImpl(new ArrayCache());
$params = array(
'driver' => 'pdo_sqlite',
'dbname' => 'test',
'memory' => true,
);
return EntityManager::create($params, $config);
}
}