@@ -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,69 @@ 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
+ * @expectedDeprecation The "Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper" class is deprecated since Symfony 4.3, use "CompiledUrlGeneratorDumper" instead.
195
+ */
196
+ public function testDefaultLocaleIsPassedToNotCompiledGeneratorCacheClass ()
197
+ {
198
+ $ this ->loader ->expects ($ this ->once ())
199
+ ->method ('load ' )->with ('routing.yml ' , null )
200
+ ->willReturn (new RouteCollection ());
201
+
202
+ $ router = new Router ($ this ->loader , 'routing.yml ' , [
203
+ 'cache_dir ' => $ this ->cacheDir ,
204
+ 'generator_class ' => 'Symfony\Component\Routing\Generator\UrlGenerator ' ,
205
+ ], null , null , 'hr ' );
206
+
207
+ $ generator = $ router ->getGenerator ();
208
+
209
+ $ this ->assertInstanceOf ('Symfony\Component\Routing\Generator\UrlGeneratorInterface ' , $ generator );
210
+
211
+ $ p = new \ReflectionProperty ($ generator , 'defaultLocale ' );
212
+ $ p ->setAccessible (true );
213
+
214
+ $ this ->assertSame ('hr ' , $ p ->getValue ($ generator ));
215
+ }
135
216
}
0 commit comments