EntityManagerTest.php 3.01 KB
Newer Older
romanb's avatar
romanb committed
1 2
<?php

3 4
namespace Doctrine\Tests\ORM;

5
require_once __DIR__ . '/../TestInit.php';
romanb's avatar
romanb committed
6

7
class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
romanb's avatar
romanb committed
8 9 10
{
    private $_em;

11 12
    function setUp()
    {
romanb's avatar
romanb committed
13 14 15 16
        parent::setUp();
        $this->_em = $this->_getTestEntityManager();
    }

romanb's avatar
romanb committed
17 18 19 20 21 22
    public function testSettingInvalidFlushModeThrowsException()
    {
        $prev = $this->_em->getFlushMode();
        try {
            $this->_em->setFlushMode('foobar');
            $this->fail("Setting invalid flushmode did not trigger exception.");
23
        } catch (\Doctrine\ORM\EntityManagerException $expected) {}
romanb's avatar
romanb committed
24
        $this->_em->setFlushMode($prev);
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    }

    public function testGetConnection()
    {
        $this->assertType('\Doctrine\DBAL\Connection', $this->_em->getConnection());
    }

    public function testGetMetadataFactory()
    {
        $this->assertType('\Doctrine\ORM\Mapping\ClassMetadataFactory', $this->_em->getMetadataFactory());
    }

    public function testGetConfiguration()
    {
        $this->assertType('\Doctrine\ORM\Configuration', $this->_em->getConfiguration());
    }

    public function testGetUnitOfWork()
    {
        $this->assertType('\Doctrine\ORM\UnitOfWork', $this->_em->getUnitOfWork());
    }

    public function testGetProxyFactory()
    {
        $this->assertType('\Doctrine\ORM\Proxy\ProxyFactory', $this->_em->getProxyFactory());
    }

    public function testGetEventManager()
    {
        $this->assertType('\Doctrine\Common\EventManager', $this->_em->getEventManager());
    }

    public function testGetDefaultFlushMode_OnCommit()
    {
        $this->assertEquals(\Doctrine\ORM\EntityManager::FLUSHMODE_COMMIT, $this->_em->getFlushMode());
    }

    public function testCreateNativeQuery()
    {
        $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
        $query = $this->_em->createNativeQuery('SELECT foo', $rsm);

        $this->assertSame('SELECT foo', $query->getSql());
    }

    public function testCreateQueryBuilder()
    {
        $this->assertType('\Doctrine\ORM\QueryBuilder', $this->_em->createQueryBuilder());
    }

    public function testCreateQuery_DqlIsOptional()
    {
        $this->assertType('\Doctrine\ORM\Query', $this->_em->createQuery());
    }

    public function testCreateQuery()
    {
        $q = $this->_em->createQuery('SELECT 1');
        $this->assertType('\Doctrine\ORM\Query', $q);
        $this->assertEquals('SELECT 1', $q->getDql());
    }

    static public function dataAffectedByErrorIfClosedException()
    {
        return array(
            array('flush'),
            array('persist'),
            array('remove'),
            array('merge'),
            array('refresh'),
            array('copy'),
        );
    }

    /**
     * @dataProvider dataAffectedByErrorIfClosedException
     * @param string $methodName
     */
    public function testAffectedByErrorIfClosedException($methodName)
    {
        $this->setExpectedException('Doctrine\ORM\EntityManagerException', 'Closed');

        $this->_em->close();
        $this->_em->$methodName(new \stdClass());
    }
romanb's avatar
romanb committed
110
}