@@ -19,53 +19,97 @@ class ObjectRouteLoaderTest extends \PHPUnit_Framework_TestCase
19
19
{
20
20
public function testLoadCallsServiceAndReturnsCollection ()
21
21
{
22
- $ routeLoader = $ this ->getMock ('Symfony\Component\Routing\Loader\RouteLoaderInterface ' );
23
- $ serviceRouteLoader = new ObjectRouteLoaderForTest ();
24
-
25
- $ serviceRouteLoader ->loaderMap = array (
26
- 'my_route_provider_service ' => $ routeLoader ,
27
- );
22
+ $ loader = new ObjectRouteLoaderForTest ();
28
23
29
24
// create a basic collection that will be returned
30
- $ routes = new RouteCollection ();
31
- $ routes ->add ('foo ' , new Route ('/foo ' ));
25
+ $ collection = new RouteCollection ();
26
+ $ collection ->add ('foo ' , new Route ('/foo ' ));
32
27
33
- $ routeLoader
34
- ->expects ($ this ->any ())
35
- ->method ('getRouteCollection ' )
36
- // the loader itself is passed
37
- ->with ($ serviceRouteLoader )
38
- ->will ($ this ->returnValue ($ routes ));
28
+ // create some callable object
29
+ $ service = $ this ->getMockBuilder ('stdClass ' )
30
+ ->setMethods (array ('loadRoutes ' ))
31
+ ->getMock ();
32
+ $ service ->expects ($ this ->once ())
33
+ ->method ('loadRoutes ' )
34
+ ->with ($ loader )
35
+ ->will ($ this ->returnValue ($ collection ));
39
36
40
- $ actualRoutes = $ serviceRouteLoader ->load ('my_route_provider_service ' , 'service ' );
37
+ $ loader ->loaderMap = array (
38
+ 'my_route_provider_service ' => $ service ,
39
+ );
41
40
42
- $ this ->assertSame ($ routes , $ actualRoutes );
41
+ $ actualRoutes = $ loader ->load (
42
+ 'my_route_provider_service:loadRoutes ' ,
43
+ 'service '
44
+ );
45
+
46
+ $ this ->assertSame ($ collection , $ actualRoutes );
43
47
// the service file should be listed as a resource
44
48
$ this ->assertNotEmpty ($ actualRoutes ->getResources ());
45
49
}
46
50
47
51
/**
48
- * @expectedException \LogicException
52
+ * @expectedException \InvalidArgumentException
53
+ * @dataProvider getBadResourceStrings
49
54
*/
50
- public function testExceptionOnInterfaceNotImplemented ( )
55
+ public function testExceptionWithoutSyntax ( $ resourceString )
51
56
{
52
- // anything that doesn't implement the interface
53
- $ routeLoader = new \stdClass ();
57
+ $ loader = new ObjectRouteLoaderForTest ();
58
+ $ loader ->load ($ resourceString );
59
+ }
54
60
55
- $ serviceRouteLoader = new ObjectRouteLoaderForTest ();
56
- $ serviceRouteLoader ->loaderMap = array (
57
- 'any_service_name ' => $ routeLoader ,
61
+ public function getBadResourceStrings ()
62
+ {
63
+ return array (
64
+ array ('Foo ' ),
65
+ array ('Bar::baz ' ),
66
+ array ('Foo:Bar:baz ' ),
58
67
);
68
+ }
69
+
70
+ /**
71
+ * @expectedException \LogicException
72
+ */
73
+ public function testExceptionOnNoObjectReturned ()
74
+ {
75
+ $ loader = new ObjectRouteLoaderForTest ();
76
+ $ loader ->loaderMap = array ('my_service ' => 'NOT_AN_OBJECT ' );
77
+ $ loader ->load ('my_service:method ' );
78
+ }
79
+
80
+ /**
81
+ * @expectedException \BadMethodCallException
82
+ */
83
+ public function testExceptionOnBadMethod ()
84
+ {
85
+ $ loader = new ObjectRouteLoaderForTest ();
86
+ $ loader ->loaderMap = array ('my_service ' => new \stdClass ());
87
+ $ loader ->load ('my_service:method ' );
88
+ }
89
+
90
+ /**
91
+ * @expectedException \LogicException
92
+ */
93
+ public function testExceptionOnMethodNotReturningCollection ()
94
+ {
95
+ $ service = $ this ->getMockBuilder ('stdClass ' )
96
+ ->setMethods (array ('loadRoutes ' ))
97
+ ->getMock ();
98
+ $ service ->expects ($ this ->once ())
99
+ ->method ('loadRoutes ' )
100
+ ->will ($ this ->returnValue ('NOT_A_COLLECTION ' ));
59
101
60
- $ serviceRouteLoader ->load ('any_service_name ' , 'service ' );
102
+ $ loader = new ObjectRouteLoaderForTest ();
103
+ $ loader ->loaderMap = array ('my_service ' => $ service );
104
+ $ loader ->load ('my_service:loadRoutes ' );
61
105
}
62
106
}
63
107
64
108
class ObjectRouteLoaderForTest extends ObjectRouteLoader
65
109
{
66
110
public $ loaderMap = array ();
67
111
68
- protected function getRouteLoaderService ($ id )
112
+ protected function getServiceObject ($ id )
69
113
{
70
114
return isset ($ this ->loaderMap [$ id ]) ? $ this ->loaderMap [$ id ] : null ;
71
115
}
0 commit comments