OrmTestCase.php 1.29 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

namespace Doctrine\Tests;

/**
 * Base testcase class for all ORM testcases.
 */
class OrmTestCase extends DoctrineTestCase
{
10 11 12
    /** The metadata cache that is shared between all ORM tests (except functional tests). */
    private static $_metadataCacheImpl = null;

13 14 15 16 17
    /**
     * Creates an EntityManager for testing purposes.
     *
     * @return Doctrine\ORM\EntityManager
     */
18
    protected function _getTestEntityManager($conn = null, $conf = null, $eventManager = null)
19
    {
20
        $config = new \Doctrine\ORM\Configuration();
21
        $config->setMetadataCacheImpl(self::getSharedMetadataCacheImpl());
22
        $eventManager = new \Doctrine\Common\EventManager();
23 24
        if (is_null($conn)) {
            $conn = array(
25 26 27 28
                'driverClass' => 'Doctrine\Tests\Mocks\DriverMock',
                'wrapperClass' => 'Doctrine\Tests\Mocks\ConnectionMock',
                'user' => 'john',
                'password' => 'wayne'
29 30 31
            );
        }
        return \Doctrine\ORM\EntityManager::create($conn, $config, $eventManager);
32
    }
33 34 35 36 37 38 39 40

    private static function getSharedMetadataCacheImpl()
    {
        if (is_null(self::$_metadataCacheImpl)) {
            self::$_metadataCacheImpl = new \Doctrine\ORM\Cache\ArrayCache;
        }
        return self::$_metadataCacheImpl;
    }
41
}