@@ -123,14 +123,16 @@ public function testDumpWithSimpleLocalizedRoutes()
123
123
124
124
public function testDumpWithRouteNotFoundLocalizedRoutes ()
125
125
{
126
- $ this ->expectException (RouteNotFoundException::class);
127
- $ this ->expectExceptionMessage ('Unable to generate a URL for the named route "test" as such rou
8000
te does not exist. ' );
128
126
$ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' )->setRequirement ('_locale ' , 'en ' ));
129
127
130
128
$ code = $ this ->generatorDumper ->dump ();
131
129
file_put_contents ($ this ->testTmpFilepath , $ code );
132
130
133
131
$ projectUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ('/app.php ' ), null , 'pl_PL ' );
132
+
133
+ $ this ->expectException (RouteNotFoundException::class);
134
+ $ this ->expectExceptionMessage ('Unable to generate a URL for the named route "test" as such route does not exist. ' );
135
+
134
136
$ projectUrlGenerator ->generate ('test ' );
135
137
}
136
138
@@ -183,22 +185,25 @@ public function testDumpWithTooManyRoutes()
183
185
184
186
public function testDumpWithoutRoutes ()
185
187
{
186
- $ this ->expectException (\InvalidArgumentException::class);
187
188
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
188
189
189
190
$ projectUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ('/app.php ' ));
190
191
192
+ $ this ->expectException (\InvalidArgumentException::class);
193
+
191
194
$ projectUrlGenerator ->generate ('Test ' , []);
192
195
}
193
196
194
197
public function testGenerateNonExistingRoute ()
195
198
{
196
- $ this ->expectException (RouteNotFoundException::class);
197
199
$ this ->routeCollection ->add ('Test ' , new Route ('/test ' ));
198
200
199
201
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
200
202
201
203
$ projectUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ());
204
+
205
+ $ this ->expectException (RouteNotFoundException::class);
206
+
202
207
$ projectUrlGenerator ->generate ('NonExisting ' , []);
203
208
}
204
209
@@ -287,66 +292,72 @@ public function testAliases()
287
292
288
293
public function testTargetAliasNotExisting ()
289
294
{
290
- $ this ->expectException (RouteNotFoundException::class);
291
-
292
- $ this ->routeCollection ->addAlias ('a ' , 'not-existing ' );
295
+ $ this ->routeCollection ->add ('not-existing ' , new Route ('/not-existing ' ));
296
+ $ this ->routeCollection ->addAlias ('alias ' , 'not-existing ' );
293
297
294
298
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
295
299
296
- $ compiledUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ());
300
+ $ compiledRoutes = require $ this ->testTmpFilepath ;
301
+ unset($ compiledRoutes ['alias ' ]);
297
302
303
+ $ this ->expectException (RouteNotFoundException::class);
304
+
305
+ $ compiledUrlGenerator = new CompiledUrlGenerator ($ compiledRoutes , new RequestContext ());
298
306
$ compiledUrlGenerator ->generate ('a ' );
299
307
}
300
308
301
309
public function testTargetAliasWithNamePrefixNotExisting ()
302
310
{
303
- $ this ->expectException (RouteNotFoundException::class);
304
-
305
311
$ subCollection = new RouteCollection ();
306
- $ subCollection ->addAlias ('a ' , 'not-existing ' );
312
+ $ subCollection ->add ('not-existing ' , new Route ('/not-existing ' ));
313
+ $ subCollection ->addAlias ('alias ' , 'not-existing ' );
307
314
$ subCollection ->addNamePrefix ('sub_ ' );
308
315
309
316
$ this ->routeCollection ->addCollection ($ subCollection );
310
317
311
318
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
312
319
313
- $ compiledUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ());
320
+ $ compiledRoutes = require $ this ->testTmpFilepath ;
321
+ unset($ compiledRoutes ['sub_alias ' ]);
314
322
315
- $ compiledUrlGenerator ->generate ('sub_a ' );
323
+ $ this ->expectException (RouteNotFoundException::class);
324
+
325
+ $ compiledUrlGenerator = new CompiledUrlGenerator ($ compiledRoutes , new RequestContext ());
326
+ $ compiledUrlGenerator ->generate ('sub_alias ' );
316
327
}
317
328
318
329
public function testCircularReferenceShouldThrowAnException ()
319
330
{
320
- $ this ->expectException (RouteCircularReferenceException::class);
321
- $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> a -> b". ' );
322
-
323
331
$ this ->routeCollection ->addAlias ('a ' , 'b ' );
324
332
$ this ->routeCollection ->addAlias ('b ' , 'a ' );
325
333
334
+ $ this ->expectException (RouteCircularReferenceException::class);
335
+ $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> a -> b". ' );
336
+
326
337
$ this ->generatorDumper ->dump ();
327
338
}
328
339
329
340
public function testDeepCircularReferenceShouldThrowAnException ()
330
341
{
331
- $ this ->expectException (RouteCircularReferenceException::class);
332
- $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> c -> b". ' );
333
-
334
342
$ this ->routeCollection ->addAlias ('a ' , 'b ' );
335
343
$ this ->routeCollection ->addAlias ('b ' , 'c ' );
336
344
$ this ->routeCollection ->addAlias ('c ' , 'b ' );
337
345
346
+ $ this ->expectException (RouteCircularReferenceException::class);
347
+ $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> c -> b". ' );
348
+
338
349
$ this ->generatorDumper ->dump ();
339
350
}
340
351
341
352
public function testIndirectCircularReferenceShouldThrowAnException ()
342
353
{
343
- $ this ->expectException (RouteCircularReferenceException::class);
344
- $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> c -> a -> b". ' );
345
-
346
354
$ this ->routeCollection ->addAlias ('a ' , 'b ' );
347
355
$ this ->routeCollection ->addAlias ('b ' , 'c ' );
348
356
$ this ->routeCollection ->addAlias ('c ' , 'a ' );
349
357
358
+ $ this ->expectException (RouteCircularReferenceException::class);
359
+ $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> c -> a -> b". ' );
360
+
350
361
$ this ->generatorDumper ->dump ();
351
362
}
352
363
0 commit comments