EntityManagerMock::setProxyFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/*
3
 *  $Id$
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.doctrine-project.org>.
20
 */
21
22
namespace Admingenerator\GeneratorBundle\Tests\Mocks\Doctrine;
23
24
/**
25
 * Special EntityManager mock used for testing purposes.
26
 */
27
class EntityManagerMock extends \Doctrine\ORM\EntityManager
28
{
29
    private $_uowMock;
30
    private $_proxyFactoryMock;
31
    private $_idGenerators = array();
32
33
    /**
34
     * @override
35
     */
36
    public function getUnitOfWork()
37
    {
38
        return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
39
    }
40
41
    /* Mock API */
42
43
    /**
44
     * Sets a (mock) UnitOfWork that will be returned when getUnitOfWork() is called.
45
     *
46
     * @param \Doctrine\ORM\UnitOfWork $uow
47
     */
48
    public function setUnitOfWork($uow)
49
    {
50
        $this->_uowMock = $uow;
51
    }
52
53
    public function setProxyFactory($proxyFactory)
54
    {
55
        $this->_proxyFactoryMock = $proxyFactory;
56
    }
57
58
    public function getProxyFactory()
59
    {
60
        return isset($this->_proxyFactoryMock) ? $this->_proxyFactoryMock : parent::getProxyFactory();
61
    }
62
63
    /**
64
     * Mock factory method to create an EntityManager.
65
     *
66
     * @param  unknown_type               $conn
67
     * @param  \Doctrine\ORM\Configuration     $config
68
     * @param  \Doctrine\Common\EventManager      $eventManager
69
     * @return EntityManagerMock
70
     */
71
    public static function create($conn, \Doctrine\ORM\Configuration $config = null,
72
            \Doctrine\Common\EventManager $eventManager = null)
73
    {
74
        if (is_null($config)) {
75
            $config = new \Doctrine\ORM\Configuration();
76
            $config->setProxyDir(__DIR__ . '/../Proxies');
77
            $config->setProxyNamespace('Doctrine\Tests\Proxies');
78
            $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true));
79
        }
80
        if (is_null($eventManager)) {
81
            $eventManager = new \Doctrine\Common\EventManager();
82
        }
83
84
        return new EntityManagerMock($conn, $config, $eventManager);
85
    }
86
}
87