Completed
Push — master ( 99a62a...bdb5af )
by Fabien
9s
created

RegistryTest::testResetDefaultEntityManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Doctrine Bundle
5
 *
6
 * The code was originally distributed inside the Symfony framework.
7
 *
8
 * (c) Fabien Potencier <[email protected]>
9
 * (c) Doctrine Project, Benjamin Eberlei <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Doctrine\Bundle\DoctrineBundle\Tests;
16
17
use Doctrine\Bundle\DoctrineBundle\Registry;
18
19
class RegistryTest extends TestCase
20
{
21 View Code Duplication
    public function testGetDefaultConnectionName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
24
        $registry = new Registry($container, array(), array(), 'default', 'default');
25
26
        $this->assertEquals('default', $registry->getDefaultConnectionName());
27
    }
28
29 View Code Duplication
    public function testGetDefaultEntityManagerName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
32
        $registry = new Registry($container, array(), array(), 'default', 'default');
33
34
        $this->assertEquals('default', $registry->getDefaultManagerName());
35
    }
36
37
    public function testGetDefaultConnection()
38
    {
39
        $conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
40
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
41
        $container->expects($this->once())
42
                  ->method('get')
43
                  ->with($this->equalTo('doctrine.dbal.default_connection'))
44
                  ->will($this->returnValue($conn));
45
46
        $registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default');
47
48
        $this->assertSame($conn, $registry->getConnection());
49
    }
50
51
    public function testGetConnection()
52
    {
53
        $conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
54
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
55
        $container->expects($this->once())
56
                  ->method('get')
57
                  ->with($this->equalTo('doctrine.dbal.default_connection'))
58
                  ->will($this->returnValue($conn));
59
60
        $registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default');
61
62
        $this->assertSame($conn, $registry->getConnection('default'));
63
    }
64
65 View Code Duplication
    public function testGetUnknownConnection()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
68
        $registry = new Registry($container, array(), array(), 'default', 'default');
69
70
        $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Connection named "default" does not exist.');
71
        $registry->getConnection('default');
72
    }
73
74
    public function testGetConnectionNames()
75
    {
76
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
77
        $registry = new Registry($container, array('default' => 'doctrine.dbal.default_connection'), array(), 'default', 'default');
78
79
        $this->assertEquals(array('default' => 'doctrine.dbal.default_connection'), $registry->getConnectionNames());
80
    }
81
82 View Code Duplication
    public function testGetDefaultEntityManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        $em = new \stdClass();
85
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
86
        $container->expects($this->once())
87
                  ->method('get')
88
                  ->with($this->equalTo('doctrine.orm.default_entity_manager'))
89
                  ->will($this->returnValue($em));
90
91
        $registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default');
92
93
        $this->assertSame($em, $registry->getManager());
94
    }
95
96 View Code Duplication
    public function testGetEntityManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        $em = new \stdClass();
99
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
100
        $container->expects($this->once())
101
                  ->method('get')
102
                  ->with($this->equalTo('doctrine.orm.default_entity_manager'))
103
                  ->will($this->returnValue($em));
104
105
        $registry = new Registry($container, array(), array('default' => 'doctrine.orm.default_entity_manager'), 'default', 'default');
106
107
        $this->assertSame($em, $registry->getManager('default'));
108
    }
109
110 View Code Duplication
    public function testGetUnknownEntityManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
113
        $registry = new Registry($container, array(), array(), 'default', 'default');
114
115
        $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Manager named "default" does not exist.');
116
        $registry->getManager('default');
117
    }
118
119 View Code Duplication
    public function testResetUnknownEntityManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
    {
121
        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
122
        $registry = new Registry($container, array(), array(), 'default', 'default');
123
124
        $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Manager named "default" does not exist.');
125
        $registry->resetManager('default');
126
    }
127
}
128