8000 [DoctrineBundle] added tests for registry · renegare/symfony@2a5449d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a5449d

Browse files
beberleifabpot
authored andcommitted
[DoctrineBundle] added tests for registry
1 parent 879242c commit 2a5449d

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 \PHPUnit_Framework_TestCase
17+
{
18+
public function setUp()
19+
{
20+
if (!class_exists('Doctrine\ORM\Version')) {
21+
$this->markTestSkipped('Doctrine is required for this test to run.');
22+
}
23+
}
24+
25+
public function testGetDefaultConnectionName()
26+
{
27+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
28+
$registry = new Registry($container, array(), array(), 'default', 'default');
29+
30+
$this->assertEquals('default', $registry->getDefaultConnectionName());
31+
}
32+
33+
public function testGetDefaultEntityManagerName()
34+
{
35+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
36+
$registry = new Registry($container, array(), array(), 'default', 'default');
37+
38+
$this->assertEquals('default', $registry->getDefaultEntityManagerName());
39+
}
40+
41+
public function testGetDefaultConnection()
42+
{
43+
$conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
44+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
45+
$container->expects($this->once())
46+
->method('get')
47+
->with($this->equalTo('doctrine.dbal.default_connection'))
48+
->will($this->returnValue($conn));
49+
50+
$registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default');
51+
52+
$this->assertSame($conn, $registry->getConnection());
53+
}
54+
55+
public function testGetConnection()
56+
{
57+
$conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
58+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
59+
$container->expects($this->once())
60+
->method('get')
61+
->with($this->equalTo('doctrine.dbal.default_connection'))
62+
->will($this->returnValue($conn));
63+
64+
$registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default');
65+
66+
$this->assertSame($conn, $registry->getConnection('default'));
67+
}
68+
69+
public function testGetUnknownConnection()
70+
{
71+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
72+
$registry = new Registry($container, array(), array(), 'default', 'default');
73+
74+
$this->setExpectedException('InvalidArgumentException', 'Doctrine Connection named "default" does not exist.');
75+
$registry->getConnection('default');
76+
}
77+
78+
public function testGetConnectionNames()
79+
{
80+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
81+
$registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default');
82+
83+
$this->assertEquals(array('default' => 'doctrine.dbal.default_connection'), $registry->getConnectionNames());
84+
}
85+
86+
public function testGetDefaultEntityManager()
87+
{
88+
$em = new \stdClass();
89+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
90+
$container->expects($this->once())
91+
->method('get')
92+
->with($this->equalTo('doctrine.orm.default_entity_manager'))
93+
->will($this->returnValue($em));
94+
95+
$registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default');
96+
97+
$this->assertSame($em, $registry->getEntityManager());
98+
}
99+
100+
public function testGetEntityManager()
101+
{
102+
$em = new \stdClass();
103+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
104+
$container->expects($this->once())
105+
->method('get')
106+
->with($this->equalTo('doctrine.orm.default_entity_manager'))
107+
->will($this->returnValue($em));
108+
109+
$registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default');
110+
111+
$this->assertSame($em, $registry->getEntityManager('default'));
112+
}
113+
114+
public function testGetUnknownEntityManager()
115+
{
116+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
117+
$registry = new Registry($container, array(), array(), 'default', 'default');
118+
119+
$this->setExpectedException('InvalidArgumentException', 'Doctrine EntityManager named "default" does not exist.');
120+
$registry->getEntityManager('default');
121+
}
122+
123+
public function testResetDefaultEntityManager()
124+
{
125+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
126+
$container->expects($this->once())
127+
->method('set')
128+
->with($this->equalTo('doctrine.orm.default_entity_manager'), $this->equalTo(null));
129+
130+
$registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default');
131+
$registry->resetEntityManager();
132+
}
133+
134+
public function testResetEntityManager()
135+
{
136+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
137+
$container->expects($this->once())
138+
->method('set')
139+
->with($this->equalTo('doctrine.orm.default_entity_manager'), $this->equalTo(null));
140+
141+
$registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default');
142+
$registry->resetEntityManager('default');
143+
}
144+
145+
public function testResetUnknownEntityManager()
146+
{
147+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
148+
$registry = new Registry($container, array(), array(), 'default', 'default');
149+
150+
$this->setExpectedException('InvalidArgumentException', 'Doctrine EntityManager named "default" does not exist.');
151+
$registry->resetEntityManager('default');
152+
}
153+
}

0 commit comments

Comments
 (0)
0