EntityManagerMock.php 3.16 KB
Newer Older
1
<?php
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 *  $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.doctrine-project.org>.
 */
21

22
namespace Doctrine\Tests\Mocks;
23

24
use Doctrine\ORM\Proxy\ProxyFactory;
25

26 27 28
/**
 * Special EntityManager mock used for testing purposes.
 */
29
class EntityManagerMock extends \Doctrine\ORM\EntityManager
30
{
31
    private $_uowMock;
32
    private $_proxyFactoryMock;
33 34 35 36 37 38 39 40
    private $_idGenerators = array();

    /**
     * @override
     */
    public function getUnitOfWork()
    {
        return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
41
    }
42 43
    
    /* Mock API */
44

45 46 47 48 49
    /**
     * Sets a (mock) UnitOfWork that will be returned when getUnitOfWork() is called.
     *
     * @param <type> $uow
     */
50 51 52 53
    public function setUnitOfWork($uow)
    {
        $this->_uowMock = $uow;
    }
54 55 56 57 58 59 60 61 62 63

    public function setProxyFactory($proxyFactory)
    {
        $this->_proxyFactoryMock = $proxyFactory;
    }

    public function getProxyFactory()
    {
        return isset($this->_proxyFactoryMock) ? $this->_proxyFactoryMock : parent::getProxyFactory();
    }
romanb's avatar
romanb committed
64 65
    
    /**
66
     * Mock factory method to create an EntityManager.
romanb's avatar
romanb committed
67 68 69 70 71
     *
     * @param unknown_type $conn
     * @param unknown_type $name
     * @param Doctrine_Configuration $config
     * @param Doctrine_EventManager $eventManager
72
     * @return Doctrine\ORM\EntityManager
romanb's avatar
romanb committed
73
     */
74 75
    public static function create($conn, \Doctrine\ORM\Configuration $config = null,
            \Doctrine\Common\EventManager $eventManager = null)
romanb's avatar
romanb committed
76 77
    {
        if (is_null($config)) {
78
            $config = new \Doctrine\ORM\Configuration();
79 80
            $config->setProxyDir(__DIR__ . '/../Proxies');
            $config->setProxyNamespace('Doctrine\Tests\Proxies');
romanb's avatar
romanb committed
81 82
        }
        if (is_null($eventManager)) {
83
            $eventManager = new \Doctrine\Common\EventManager();
romanb's avatar
romanb committed
84 85
        }
        
86
        return new EntityManagerMock($conn, $config, $eventManager);   
romanb's avatar
romanb committed
87
    }
88
/*
89 90 91 92
    public function setIdGenerator($className, $generator)
    {
        $this->_idGenerators[$className] = $generator;
    }
93
*/
94
    /** @override */
95
/*    public function getIdGenerator($className)
96
    {
97

98 99 100
        if (isset($this->_idGenerators[$className])) {
            return $this->_idGenerators[$className];
        }
101
                
102 103
        return parent::getIdGenerator($className);
    }
104
 */
105
}