1
0
mirror of synced 2024-12-13 14:56:01 +03:00
doctrine2/tests/Doctrine/Tests/OrmTestCase.php

58 lines
2.0 KiB
PHP

<?php
namespace Doctrine\Tests;
/**
* Base testcase class for all ORM testcases.
*/
class OrmTestCase extends DoctrineTestCase
{
/** The metadata cache that is shared between all ORM tests (except functional tests). */
private static $_metadataCacheImpl = null;
/** The query cache that is shared between all ORM tests (except functional tests). */
private static $_queryCacheImpl = null;
/**
* Creates an EntityManager for testing purposes.
*
* NOTE: The created EntityManager will have its dependant DBAL parts completely
* mocked out using a DriverMock, ConnectionMock, etc. These mocks can then
* be configured in the tests to simulate the DBAL behavior that is desired
* for a particular test,
*
* @return Doctrine\ORM\EntityManager
*/
protected function _getTestEntityManager($conn = null, $conf = null, $eventManager = null)
{
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(self::getSharedMetadataCacheImpl());
$config->setQueryCacheImpl(self::getSharedQueryCacheImpl());
$eventManager = new \Doctrine\Common\EventManager();
if ($conn === null) {
$conn = array(
'driverClass' => 'Doctrine\Tests\Mocks\DriverMock',
'wrapperClass' => 'Doctrine\Tests\Mocks\ConnectionMock',
'user' => 'john',
'password' => 'wayne'
);
}
return \Doctrine\ORM\EntityManager::create($conn, $config, $eventManager);
}
private static function getSharedMetadataCacheImpl()
{
if (self::$_metadataCacheImpl === null) {
self::$_metadataCacheImpl = new \Doctrine\ORM\Cache\ArrayCache;
}
return self::$_metadataCacheImpl;
}
private static function getSharedQueryCacheImpl()
{
if (self::$_queryCacheImpl === null) {
self::$_queryCacheImpl = new \Doctrine\ORM\Cache\ArrayCache;
}
return self::$_queryCacheImpl;
}
}