2013-09-10 11:42:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Bridge\Doctrine\Test;
|
|
|
|
|
|
|
|
use Doctrine\Common\Annotations\AnnotationReader;
|
2016-10-24 10:16:47 +01:00
|
|
|
use Doctrine\Common\Cache\ArrayCache;
|
|
|
|
use Doctrine\ORM\Configuration;
|
2013-09-10 11:42:12 +01:00
|
|
|
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
|
|
|
|
use Doctrine\ORM\EntityManager;
|
2017-02-08 07:24:27 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2013-09-10 11:42:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides utility functions needed in tests.
|
|
|
|
*
|
|
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
|
|
*/
|
|
|
|
class DoctrineTestHelper
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns an entity manager for testing.
|
|
|
|
*
|
2016-10-24 10:16:47 +01:00
|
|
|
* @param Configuration|null $config
|
|
|
|
*
|
2013-09-10 11:42:12 +01:00
|
|
|
* @return EntityManager
|
|
|
|
*/
|
2016-10-24 10:16:47 +01:00
|
|
|
public static function createTestEntityManager(Configuration $config = null)
|
2013-09-10 11:42:12 +01:00
|
|
|
{
|
2015-10-08 10:41:54 +01:00
|
|
|
if (!extension_loaded('pdo_sqlite')) {
|
2017-02-08 07:24:27 +00:00
|
|
|
TestCase::markTestSkipped('Extension pdo_sqlite is required.');
|
2013-09-10 11:42:12 +01:00
|
|
|
}
|
|
|
|
|
2016-10-24 10:16:47 +01:00
|
|
|
if (null === $config) {
|
|
|
|
$config = self::createTestConfiguration();
|
|
|
|
}
|
2013-09-10 11:42:12 +01:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'driver' => 'pdo_sqlite',
|
|
|
|
'memory' => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
return EntityManager::create($params, $config);
|
|
|
|
}
|
|
|
|
|
2016-10-24 10:16:47 +01:00
|
|
|
/**
|
|
|
|
* @return Configuration
|
|
|
|
*/
|
|
|
|
public static function createTestConfiguration()
|
|
|
|
{
|
|
|
|
$config = new Configuration();
|
|
|
|
$config->setEntityNamespaces(array('SymfonyTestsDoctrine' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'));
|
|
|
|
$config->setAutoGenerateProxyClasses(true);
|
|
|
|
$config->setProxyDir(\sys_get_temp_dir());
|
|
|
|
$config->setProxyNamespace('SymfonyTests\Doctrine');
|
|
|
|
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader()));
|
|
|
|
$config->setQueryCacheImpl(new ArrayCache());
|
|
|
|
$config->setMetadataCacheImpl(new ArrayCache());
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2013-09-10 11:42:12 +01:00
|
|
|
/**
|
|
|
|
* This class cannot be instantiated.
|
|
|
|
*/
|
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|