@@ -104,14 +104,16 @@ public function testDumpWithSimpleLocalizedRoutes()
104
104
105
105
public function testDumpWithRouteNotFoundLocalizedRoutes ()
106
106
{
107
- $ this ->expectException (RouteNotFoundException::class);
108
- $ this ->expectExceptionMessage ('Unable to generate a URL for the named route "test" as such route does not exist. ' );
109
107
$ this ->routeCollection ->add ('test.en ' , (new Route ('/testing/is/fun ' ))->setDefault ('_locale ' , 'en ' )->setDefault ('_canonical_route ' , 'test ' )->setRequirement ('_locale ' , 'en ' ));
110
108
111
109
$ code = $ this ->generatorDumper ->dump ();
112
110
file_put_contents ($ this ->testTmpFilepath , $ code );
113
111
114
112
$ projectUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ('/app.php ' ), null , 'pl_PL ' );
113
+
114
+ $ this ->expectException (RouteNotFoundException::class);
115
+ $ this ->expectExceptionMessage ('Unable to generate a URL for the named route "test" as such route does not exist. ' );
116
+
115
117
$ projectUrlGenerator ->generate ('test ' );
116
118
}
117
119
@@ -163,22 +165,25 @@ public function testDumpWithTooManyRoutes()
163
165
164
166
public function testDumpWithoutRoutes ()
165
167
{
166
- $ this ->expectException (\InvalidArgumentException::class);
167
168
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
168
169
169
170
$ projectUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ('/app.php ' ));
170
171
172
+ $ this ->expectException (\InvalidArgumentException::class);
173
+
171
174
$ projectUrlGenerator ->generate ('Test ' , []);
172
175
}
173
176
174
177
public function testGenerateNonExistingRoute ()
175
178
{
176
- $ this ->expectException (RouteNotFoundException::class);
177
179
$ this ->routeCollection ->add ('Test ' , new Route ('/test ' ));
178
180
179
181
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
180
182
181
183
$ projectUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ());
184
+
185
+ $ this ->expectException (RouteNotFoundException::class);
186
+
182
187
$ projectUrlGenerator ->generate ('NonExisting ' , []);
183
188
}
184
189
@@ -267,66 +272,72 @@ public function testAliases()
267
272
268
273
public function testTargetAliasNotExisting ()
269
274
{
270
- $ this ->expectException (RouteNotFoundException::class);
271
-
272
- $ this ->routeCollection ->addAlias ('a ' , 'not-existing ' );
275
+ $ this ->routeCollection ->add ('not-existing ' , new Route ('/not-existing ' ));
276
+ $ this ->routeCollection ->addAlias ('alias ' , 'not-existing ' );
273
277
274
278
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
275
279
276
- $ compiledUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ());
280
+ $ compiledRoutes = require $ this ->testTmpFilepath ;
281
+ unset($ compiledRoutes ['alias ' ]);
277
282
283
+ $ this ->expectException (RouteNotFoundException::class);
284
+
285
+ $ compiledUrlGenerator = new CompiledUrlGenerator ($ compiledRoutes , new RequestContext ());
278
286
$ compiledUrlGenerator ->generate ('a ' );
279
287
}
280
288
281
289
public function testTargetAliasWithNamePrefixNotExisting ()
282
290
{
283
- $ this ->expectException (RouteNotFoundException::class);
284
-
285
291
$ subCollection = new RouteCollection ();
286
- $ subCollection ->addAlias ('a ' , 'not-existing ' );
292
+ $ subCollection ->add ('not-existing ' , new Route ('/not-existing ' ));
293
+ $ subCollection ->addAlias ('alias ' , 'not-existing ' );
287
294
$ subCollection ->addNamePrefix ('sub_ ' );
288
295
289
296
$ this ->routeCollection ->addCollection ($ subCollection );
290
297
291
298
file_put_contents ($ this ->testTmpFilepath , $ this ->generatorDumper ->dump ());
292
299
293
- $ compiledUrlGenerator = new CompiledUrlGenerator (require $ this ->testTmpFilepath , new RequestContext ());
300
+ $ compiledRoutes = require $ this ->testTmpFilepath ;
301
+ unset($ compiledRoutes ['sub_alias ' ]);
294
302
295
- $ compiledUrlGenerator ->generate ('sub_a ' );
303
+ $ this ->expectException (RouteNotFoundException::class);
304
+
305
+ $ compiledUrlGenerator = new CompiledUrlGenerator ($ compiledRoutes , new RequestContext ());
306
+ $ compiledUrlGenerator ->generate ('sub_alias ' );
296
307
}
297
308
298
309
public function testCircularReferenceShouldThrowAnException ()
299
310
{
300
- $ this ->expectException (RouteCircularReferenceException::class);
301
- $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> a -> b". ' );
302
-
303
311
$ this ->routeCollection ->addAlias ('a ' , 'b ' );
304
312
$ this ->routeCollection ->addAlias ('b ' , 'a ' );
305
313
314
+ $ this ->expectException (RouteCircularReferenceException::class);
315
+ $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> a -> b". ' );
316
+
306
317
$ this ->generatorDumper ->dump ();
307
318
}
308
319
309
320
public function testDeepCircularReferenceShouldThrowAnException ()
310
321
{
311
- $ this ->expectException (RouteCircularReferenceException::class);
312
- $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> c -> b". ' );
313
-
314
322
$ this ->routeCollection ->addAlias ('a ' , 'b ' );
315
323
$ this ->routeCollection ->addAlias ('b ' , 'c ' );
316
324
$ this ->routeCollection ->addAlias ('c ' , 'b ' );
317
325
326
+ $ this ->expectException (RouteCircularReferenceException::class);
327
+ $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> c -> b". ' );
328
+
318
329
$ this ->generatorDumper ->dump ();
319
330
}
320
331
321
332
public function testIndirectCircularReferenceShouldThrowAnException ()
322
333
{
323
- $ this ->expectException (RouteCircularReferenceException::class);
324
- $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> c -> a -> b". ' );
325
-
326
334
$ this ->routeCollection ->addAlias ('a ' , 'b ' );
327
335
$ this ->routeCollection ->addAlias ('b ' , 'c ' );
328
336
$ this ->routeCollection ->addAlias ('c ' , 'a ' );
329
337
338
+ $ this ->expectException (RouteCircularReferenceException::class);
339
+ $ this ->expectExceptionMessage ('Circular reference detected for route "b", path: "b -> c -> a -> b". ' );
340
+
330
341
$ this ->generatorDumper ->dump ();
331
342
}
332
343
0 commit comments