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