@@ -49,7 +49,7 @@ class ProviderBasedGeneratorTest extends TestCase
49
49
*/
50
50
private $ context ;
51
51
52
- public function setUp ()
52
+ public function setUp (): void
53
53
{
54
54
$ this ->routeDocument = $ this ->createMock (Route::class);
55
55
$ this ->routeCompiled = $ this ->createMock (CompiledRoute::class);
@@ -59,58 +59,79 @@ public function setUp()
59
59
$ this ->generator = new TestableProviderBasedGenerator ($ this ->provider );
60
60
}
61
61
62
- public function testGenerateFromName ()
62
+ public function testGenerateFromName (): void
63
63
{
64
64
$ name = 'foo/bar ' ;
65
65
66
66
$ this ->provider ->expects ($ this ->once ())
67
67
->method ('getRouteByName ' )
68
68
->with ($ name )
69
- ->will ($ this ->returnValue ( $ this -> routeDocument ) )
69
+ ->willReturn ($ this ->routeDocument )
70
70
;
71
71
$ this ->routeDocument ->expects ($ this ->once ())
72
72
->method ('compile ' )
73
- ->will ($ this ->returnValue ( $ this -> routeCompiled ) )
73
+ ->willReturn ($ this ->routeCompiled )
74
74
;
75
75
76
76
$ this ->assertEquals ('result_url ' , $ this ->generator ->generate ($ name ));
77
77
}
78
78
79
- public function testGenerateNotFound ()
79
+ public function testGenerateNotFound (): void
80
80
{
81
81
$ name = 'foo/bar ' ;
82
82
83
83
$ this ->provider ->expects ($ this ->once ())
84
84
->method ('getRouteByName ' )
85
85
->with ($ name )
86
- ->will ( $ this -> returnValue ( null ) )
86
+ ->willReturn ( null )
87
87
;
88
88
89
89
$ this ->expectException (RouteNotFoundException::class);
90
90
$ this ->generator ->generate ($ name );
91
91
}
92
92
93
- public function testGenerateFromRoute ()
93
+ public function testGenerateFromRoute (): void
94
94
{
95
95
$ this ->provider ->expects ($ this ->never ())
96
96
->method ('getRouteByName ' )
97
97
;
98
98
$ this ->routeDocument ->expects ($ this ->once ())
99
99
->method ('compile ' )
100
- ->will ($ this ->returnValue ($ this ->routeCompiled ))
100
+ ->willReturn ($ this ->routeCompiled )
101
+ ;
102
+
103
+ $ url = $ this ->generator ->generate (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME , [
104
+ RouteObjectInterface::ROUTE_OBJECT => $ this ->routeDocument ,
105
+ ]);
106
+ $ this ->assertEquals ('result_url ' , $ url );
107
+ }
108
+
109
+ /**
110
+ * @group legacy
111
+ *
112
+ * @expectedDeprecation Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`
113
+ */
114
+ public function testGenerateFromRouteLegacy (): void
115
+ {
116
+ $ this ->provider ->expects ($ this ->never ())
117
+ ->method ('getRouteByName ' )
118
+ ;
119
+ $ this ->routeDocument ->expects ($ this ->once ())
120
+ ->method ('compile ' )
121
+ ->willReturn ($ this ->routeCompiled )
101
122
;
102
123
103
124
$ this ->assertEquals ('result_url ' , $ this ->generator ->generate ($ this ->routeDocument ));
104
125
}
105
126
106
- public function testSupports ()
127
+ public function testSupports (): void
107
128
{
108
129
$ this ->assertTrue ($ this ->generator ->supports ('foo/bar ' ));
109
130
$ this ->assertTrue ($ this ->generator ->supports ($ this ->routeDocument ));
110
131
$ this ->assertFalse ($ this ->generator ->supports ($ this ));
111
132
}
112
133
113
- public function testGetRouteDebugMessage ()
134
+ public function testGetRouteDebugMessage (): void
114
135
{
115
136
$ this ->assertContains ('/some/key ' , $ this ->generator ->getRouteDebugMessage (new RouteObject ()));
116
137
$ this ->assertContains ('/de/test ' , $ this ->generator ->getRouteDebugMessage (new Route ('/de/test ' )));
@@ -121,7 +142,7 @@ public function testGetRouteDebugMessage()
121
142
/**
122
143
* Tests the generate method with passing in a route object into generate().
123
144
*/
124
- public function testGenerateByRoute ()
145
+ public function testGenerateByRoute (): void
125
146
{
126
147
$ this ->generator = new ProviderBasedGenerator ($ this ->provider );
127
148
@@ -137,7 +158,10 @@ public function testGenerateByRoute()
137
158
$ this ->generator ->setContext ($ context );
138
159
139
160
$ this ->expectException (InvalidParameterException::class);
140
- $ this ->generator ->generate ($ route , ['number ' => 'string ' ]);
161
+ $ this ->generator ->generate (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME , [
162
+ RouteObjectInterface::ROUTE_OBJECT => $ route ,
163
+ 'number ' => 'string ' ,
164
+ ]);
141
165
}
142
166
}
143
167
@@ -154,13 +178,13 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
154
178
155
179
class RouteObject implements RouteObjectInterface
156
180
{
157
- public function getRouteKey ()
181
+ public function getRouteKey (): string
158
182
{
159
183
return '/some/key ' ;
160
184
}
161
185
162
- public function getContent ()
186
+ public function getContent (): ? object
163
187
{
164
- return ;
188
+ return null ;
165
189
}
166
190
}
0 commit comments