@@ -22,10 +22,26 @@ class RouterTest extends TestCase
22
22
23
23
private $ loader = null ;
24
24
25
+ private $ cacheDir ;
26
+
25
27
protected function setUp (): void
26
28
{
27
29
$ this ->loader = $ this ->getMockBuilder ('Symfony\Component\Config\Loader\LoaderInterface ' )->getMock ();
28
30
$ this ->router = new Router ($ this ->loader , 'routing.yml ' );
31
+
32
+ $ this ->cacheDir = sys_get_temp_dir ().\DIRECTORY_SEPARATOR .uniqid ('router_ ' , true );
33
+ }
34
+
35
+ protected function tearDown (): void
36
+ {
37
+ if (is_dir ($ this ->cacheDir )) {
38
+ array_map ('unlink ' , glob ($ this ->cacheDir .\DIRECTORY_SEPARATOR .'* ' ));
39
+ rmdir ($ this ->cacheDir );
40
+ }
41
+
42
+ $ this ->loader = null ;
43
+ $ this ->router = null ;
44
+ $ this ->cacheDir = null ;
29
45
}
30
46
31
47
public function testSetOptionsWithSupportedOptions ()
@@ -132,4 +148,68 @@ public function testMatchRequestWithRequestMatcherInterface()
132
148
133
149
$ this ->router ->matchRequest (Request::create ('/ ' ));
134
150
}
151
+
152
+ public function testDefaultLocaleIsPassedToGeneratorClass ()
153
+ {
154
+ $ this ->loader ->expects ($ this ->once ())
155
+ ->method ('load ' )->with ('routing.yml ' , null )
156
+ ->willReturn (new RouteCollection ());
157
+
158
+ $ router = new Router ($ this ->loader , 'routing.yml ' , [
159
+ 'cache_dir ' => null ,
160
+ ], null , null , 'hr ' );
161
+
162
+ $ generator = $ router ->getGenerator ();
163
+
164
+ $ this ->assertInstanceOf ('Symfony\Component\Routing\Generator\UrlGeneratorInterface ' , $ generator );
165
+
166
+ $ p = new \ReflectionProperty ($ generator , 'defaultLocale ' );
167
+ $ p ->setAccessible (true );
168
+
169
+ $ this ->assertSame ('hr ' , $ p ->getValue ($ generator ));
170
+ }
171
+
172
+ public function testDefaultLocaleIsPassedToCompiledGeneratorCacheClass ()
173
+ {
174
+ $ this ->loader ->expects ($ this ->once ())
175
+ ->method ('load ' )->with ('routing.yml ' , null )
176
+ ->willReturn (new RouteCollection ());
177
+
178
+ $ router = new Router ($ this ->loader , 'routing.yml ' , [
179
+ 'cache_dir ' => $ this ->cacheDir ,
180
+ ], null , null , 'hr ' );
181
+
182
+ $ generator = $ router ->getGenerator ();
183
+
184
+ $ this ->assertInstanceOf ('Symfony\Component\Routing\Generator\UrlGeneratorInterface ' , $ generator );
185
+
186
+ $ p = new \ReflectionProperty ($ generator , 'defaultLocale ' );
187
+ $ p ->setAccessible (true );
188
+
189
+ $ this ->assertSame ('hr ' , $ p ->getValue ($ generator ));
190
+ }
191
+
192
+ /**
193
+ * @group legacy
194
+ */
195
+ public function testDefaultLocaleIsPassedToNotCompiledGeneratorCacheClass ()
196
+ {
197
+ $ this ->loader ->expects ($ this ->once ())
198
+ ->method ('load ' )->with ('routing.yml ' , null )
199
+ ->willReturn (new RouteCollection ());
200
+
201
+ $ router = new Router ($ this ->loader , 'routing.yml ' , [
202
+ 'cache_dir ' => $ this ->cacheDir ,
203
+ 'generator_class ' => 'Symfony\Component\Routing\Generator\UrlGenerator ' ,
204
+ ], null , null , 'hr ' );
205
+
206
+ $ generator = $ router ->getGenerator ();
207
+
208
+ $ this ->assertInstanceOf ('Symfony\Component\Routing\Generator\UrlGeneratorInterface ' , $ generator );
209
+
210
+ $ p = new \ReflectionProperty ($ generator , 'defaultLocale ' );
211
+ $ p ->setAccessible (true );
212
+
213
+ $ this ->assertSame ('hr ' , $ p ->getValue ($ generator ));
214
+ }
135
215
}
0 commit comments