|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Bundle\DoctrineBundle\Tests; |
|
|
13 |
|
|
|
14 |
use Symfony\Bundle\DoctrineBundle\Registry; |
|
|
15 |
|
|
|
16 |
class RegistryTest extends TestCase |
|
|
17 |
{ |
|
|
18 |
public function testGetDefaultConnectionName() |
|
|
19 |
{ |
|
|
20 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
21 |
$registry = new Registry($container, array(), array(), 'default', 'default'); |
|
|
22 |
|
|
|
23 |
$this->assertEquals('default', $registry->getDefaultConnectionName()); |
|
|
24 |
} |
|
|
25 |
|
|
|
26 |
public function testGetDefaultEntityManagerName() |
|
|
27 |
{ |
|
|
28 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
29 |
$registry = new Registry($container, array(), array(), 'default', 'default'); |
|
|
30 |
|
|
|
31 |
$this->assertEquals('default', $registry->getDefaultEntityManagerName()); |
|
|
32 |
} |
|
|
33 |
|
|
|
34 |
public function testGetDefaultConnection() |
|
|
35 |
{ |
|
|
36 |
$conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false); |
|
|
37 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
38 |
$container->expects($this->once()) |
|
|
39 |
->method('get') |
|
|
40 |
->with($this->equalTo('doctrine.dbal.default_connection')) |
|
|
41 |
->will($this->returnValue($conn)); |
|
|
42 |
|
|
|
43 |
$registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default'); |
|
|
44 |
|
|
|
45 |
$this->assertSame($conn, $registry->getConnection()); |
|
|
46 |
} |
|
|
47 |
|
|
|
48 |
public function testGetConnection() |
|
|
49 |
{ |
|
|
50 |
$conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false); |
|
|
51 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
52 |
$container->expects($this->once()) |
|
|
53 |
->method('get') |
|
|
54 |
->with($this->equalTo('doctrine.dbal.default_connection')) |
|
|
55 |
->will($this->returnValue($conn)); |
|
|
56 |
|
|
|
57 |
$registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default'); |
|
|
58 |
|
|
|
59 |
$this->assertSame($conn, $registry->getConnection('default')); |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
public function testGetUnknownConnection() |
|
|
63 |
{ |
|
|
64 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
65 |
$registry = new Registry($container, array(), array(), 'default', 'default'); |
|
|
66 |
|
|
|
67 |
$this->setExpectedException('InvalidArgumentException', 'Doctrine Connection named "default" does not exist.'); |
|
|
68 |
$registry->getConnection('default'); |
|
|
69 |
} |
|
|
70 |
|
|
|
71 |
public function testGetConnectionNames() |
|
|
72 |
{ |
|
|
73 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
74 |
$registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default'); |
|
|
75 |
|
|
|
76 |
$this->assertEquals(array('default' => 'doctrine.dbal.default_connection'), $registry->getConnectionNames()); |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
public function testGetDefaultEntityManager() |
|
|
80 |
{ |
|
|
81 |
$em = new \stdClass(); |
|
|
82 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
83 |
$container->expects($this->once()) |
|
|
84 |
->method('get') |
|
|
85 |
->with($this->equalTo('doctrine.orm.default_entity_manager')) |
|
|
86 |
->will($this->returnValue($em)); |
|
|
87 |
|
|
|
88 |
$registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default'); |
|
|
89 |
|
|
|
90 |
$this->assertSame($em, $registry->getEntityManager()); |
|
|
91 |
} |
|
|
92 |
|
|
|
93 |
public function testGetEntityManager() |
|
|
94 |
{ |
|
|
95 |
$em = new \stdClass(); |
|
|
96 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
97 |
$container->expects($this->once()) |
|
|
98 |
->method('get') |
|
|
99 |
->with($this->equalTo('doctrine.orm.default_entity_manager')) |
|
|
100 |
->will($this->returnValue($em)); |
|
|
101 |
|
|
|
102 |
$registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default'); |
|
|
103 |
|
|
|
104 |
$this->assertSame($em, $registry->getEntityManager('default')); |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
public function testGetUnknownEntityManager() |
|
|
108 |
{ |
|
|
109 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
110 |
$registry = new Registry($container, array(), array(), 'default', 'default'); |
|
|
111 |
|
|
|
112 |
$this->setExpectedException('InvalidArgumentException', 'Doctrine EntityManager named "default" does not exist.'); |
|
|
113 |
$registry->getEntityManager('default'); |
|
|
114 |
} |
|
|
115 |
|
|
|
116 |
public function testResetDefaultEntityManager() |
|
|
117 |
{ |
|
|
118 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
119 |
$container->expects($this->once()) |
|
|
120 |
->method('set') |
|
|
121 |
->with($this->equalTo('doctrine.orm.default_entity_manager'), $this->equalTo(null)); |
|
|
122 |
|
|
|
123 |
$registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default'); |
|
|
124 |
$registry->resetEntityManager(); |
|
|
125 |
} |
|
|
126 |
|
|
|
127 |
public function testResetEntityManager() |
|
|
128 |
{ |
|
|
129 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
130 |
$container->expects($this->once()) |
|
|
131 |
->method('set') |
|
|
132 |
->with($this->equalTo('doctrine.orm.default_entity_manager'), $this->equalTo(null)); |
|
|
133 |
|
|
|
134 |
$registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default'); |
|
|
135 |
$registry->resetEntityManager('default'); |
|
|
136 |
} |
|
|
137 |
|
|
|
138 |
public function testResetUnknownEntityManager() |
|
|
139 |
{ |
|
|
140 |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
|
141 |
$registry = new Registry($container, array(), array(), 'default', 'default'); |
|
|
142 |
|
|
|
143 |
$this->setExpectedException('InvalidArgumentException', 'Doctrine EntityManager named "default" does not exist.'); |
|
|
144 |
$registry->resetEntityManager('default'); |
|
|
145 |
} |
|
|
146 |
} |