2
2
3
3
namespace Symfony \Cmf \Bundle \RoutingBundle \Tests \Document ;
4
4
5
- use Symfony \Cmf \Bundle \RoutingBundle \Tests \BaseTestCase ;
6
5
use Symfony \Cmf \Bundle \RoutingBundle \Document \RouteProvider ;
7
6
8
- class RouteProviderTest extends BaseTestCase
7
+ class RouteProviderTest extends \PHPUnit_Framework_Testcase
9
8
{
9
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
10
+ private $ route ;
11
+
12
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
13
+ private $ route2 ;
14
+
15
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
16
+ private $ objectManager ;
17
+
18
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
19
+ private $ objectManager2 ;
20
+
21
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
22
+ private $ managerRegistry ;
23
+
24
+ public function setUp ()
25
+ {
26
+ $ this ->route = $ this ->getMockBuilder ('Symfony\Component\Routing\Route ' )
27
+ ->disableOriginalConstructor ()
28
+ ->getMock ()
29
+ ;
30
+ $ this ->route2 = $ this ->getMockBuilder ('Symfony\Component\Routing\Route ' )
31
+ ->disableOriginalConstructor ()
32
+ ->getMock ();
33
+ $ this ->objectManager = $ this ->getMock ('Doctrine\Common\Persistence\ObjectManager ' );
34
+ $ this ->objectManager2 = $ this ->getMock ('Doctrine\Common\Persistence\ObjectManager ' );
35
+ $ this ->managerRegistry = $ this ->getMock ('Doctrine\Common\Persistence\ManagerRegistry ' );
36
+ }
37
+
10
38
public function testGetRouteCollectionForRequest ()
11
39
{
12
40
$ this ->markTestIncomplete ();
13
41
}
14
42
15
43
public function testGetRouteByName ()
16
44
{
17
- $ managerRegistry = $ this ->getManagerRegistry (
18
- array (
19
- 'default ' => $ this ->getObjectManager (
20
- array ('test-route ' => $ this ->getRoute ('/cms/routes/test-route ' ))
21
- )
22
- )
23
- );
24
- $ routeProvider = new RouteProvider ($ managerRegistry );
45
+ $ this ->route
46
+ ->expects ($ this ->any ())
47
+ ->method ('getPath ' )
48
+ ->will ($ this ->returnValue ('/cms/routes/test-route ' ));
49
+
50
+ $ this ->objectManager
51
+ ->expects ($ this ->any ())
52
+ ->method ('find ' )
53
+ ->with (null , '/cms/routes/test-route ' )
54
+ ->will ($ this ->returnValue ($ this ->route ))
55
+ ;
56
+
57
+ $ this ->managerRegistry
58
+ ->expects ($ this ->any ())
59
+ ->method ('getManager ' )
60
+ ->will ($ this ->returnValue ($ this ->objectManager ))
61
+ ;
62
+
63
+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
25
64
$ routeProvider ->setManagerName ('default ' );
26
65
27
- $ foundRoute = $ routeProvider ->getRouteByName ('test-route ' );
66
+ $ foundRoute = $ routeProvider ->getRouteByName ('/cms/routes/ test-route ' );
28
67
29
68
$ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ foundRoute );
30
69
$ this ->assertEquals ('/cms/routes/test-route ' , $ foundRoute ->getPath ());
@@ -41,38 +80,55 @@ public function testGetRoutesByNames()
41
80
*/
42
81
public function testChangingDocumentManager ()
43
82
{
44
- $ managerRegistry = $ this ->getManagerRegistry (
45
- array (
46
- 'default ' => $ this ->getObjectManager (
47
- array ('test-route ' => $ this ->getRoute ('/cms/routes/test-route ' ))
48
- ),
49
- 'new_manager ' => $ this ->getObjectManager (
50
- array ('test-route ' => $ this ->getRoute ('/cms/routes/new-route ' ))
51
- )
52
- )
83
+ $ this ->route
84
+ ->expects ($ this ->any ())
85
+ ->method ('getPath ' )
86
+ ->will ($ this ->returnValue ('/cms/routes/test-route ' ));
87
+
88
+ $ this ->route2
89
+ ->expects ($ this ->any ())
90
+ ->method ('getPath ' )
91
+ ->will ($ this ->returnValue ('/cms/routes/new-route ' ));
92
+
93
+ $ this ->objectManager
94
+ ->expects ($ this ->any ())
95
+ ->method ('find ' )
96
+ ->with (null , '/cms/routes/test-route ' )
97
+ ->will ($ this ->returnValue ($ this ->route ))
98
+ ;
99
+
100
+ $ this ->objectManager2
101
+ ->expects ($ this ->any ())
102
+ ->method ('find ' )
103
+ ->with (null , '/cms/routes/test-route ' )
104
+ ->will ($ this ->returnValue ($ this ->route2 ))
105
+ ;
106
+
107
+ $ objectManagers = array (
108
+ 'default ' => $ this ->objectManager ,
109
+ 'new_manager ' => $ this ->objectManager2
53
110
);
54
- $ routeProvider = new RouteProvider ($ managerRegistry );
111
+ $ this ->managerRegistry
112
+ ->expects ($ this ->any ())
113
+ ->method ('getManager ' )
114
+ ->will (
115
+ $ this ->returnCallback (
116
+ function ($ name ) use ($ objectManagers ) {
117
+ return $ objectManagers [$ name ];
118
+ }
119
+ )
120
+ );
121
+
122
+ $ routeProvider = new RouteProvider ($ this ->managerRegistry );
55
123
56
124
$ routeProvider ->setManagerName ('default ' );
57
- $ foundRoute = $ routeProvider ->getRouteByName ('test-route ' );
125
+ $ foundRoute = $ routeProvider ->getRouteByName ('/cms/routes/ test-route ' );
58
126
$ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ foundRoute );
59
127
$ this ->assertEquals ('/cms/routes/test-route ' , $ foundRoute ->getPath ());
60
128
61
129
$ routeProvider ->setManagerName ('new_manager ' );
62
- $ newFoundRoute = $ routeProvider ->getRouteByName ('test-route ' );
130
+ $ newFoundRoute = $ routeProvider ->getRouteByName ('/cms/routes/ test-route ' );
63
131
$ this ->assertInstanceOf ('Symfony\Component\Routing\Route ' , $ newFoundRoute );
64
132
$ this ->assertEquals ('/cms/routes/new-route ' , $ newFoundRoute ->getPath ());
65
133
}
66
-
67
- /**
68
- * @param string $path
69
- * @return \PHPUnit_Framework_MockObject_MockObject
70
- */
71
- private function getRoute ($ path )
72
- {
73
- $ route = $ this ->getMockBuilder ('Symfony\Component\Routing\Route ' )->disableOriginalConstructor ()->getMock ();
74
- $ route ->expects ($ this ->any ())->method ('getPath ' )->will ($ this ->returnValue ($ path ));
75
-
76
- return $ route ;
77
- }
78
134
}
0 commit comments