12
12
namespace Symfony \Component \Routing \Tests \Generator ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Psr \Log \LoggerInterface ;
16
+ use Symfony \Component \Routing \Exception \InvalidParameterException ;
17
+ use Symfony \Component \Routing \Exception \MissingMandatoryParametersException ;
18
+ use Symfony \Component \Routing \Exception \RouteNotFoundException ;
15
19
use Symfony \Component \Routing \Generator \UrlGenerator ;
16
20
use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
17
21
use Symfony \Component \Routing \RequestContext ;
@@ -78,7 +82,7 @@ public function testRelativeUrlWithNullParameter()
78
82
79
83
public function testRelativeUrlWithNullParameterButNotOptional ()
80
84
{
81
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
85
+ $ this ->expectException (InvalidParameterException::class);
82
86
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing/{foo}/bar ' , ['foo ' => null ]));
83
87
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
84
88
// Generating path "/testing//bar" would be wrong as matching this route would fail.
@@ -264,14 +268,14 @@ public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl()
264
268
265
269
public function testGenerateWithoutRoutes ()
266
270
{
267
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ RouteNotFoundException::class);
271
+ $ this ->expectException (RouteNotFoundException::class);
268
272
$ routes = $ this ->getRoutes ('foo ' , new Route ('/testing/{foo} ' ));
269
273
$ this ->getGenerator ($ routes )->generate ('test ' , [], UrlGeneratorInterface::ABSOLUTE_URL );
270
274
}
271
275
272
276
public function testGenerateWithInvalidLocale ()
273
277
{
274
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ RouteNotFoundException::class);
278
+ $ this ->expectException (RouteNotFoundException::class);
275
279
$ routes = new RouteCollection ();
276
280
277
281
$ route = new Route ('' );
@@ -293,21 +297,21 @@ public function testGenerateWithInvalidLocale()
293
297
294
298
public function testGenerateForRouteWithoutMandatoryParameter ()
295
299
{
296
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ MissingMandatoryParametersException::class);
300
+ $ this ->expectException (MissingMandatoryParametersException::class);
297
301
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing/{foo} ' ));
298
302
$ this ->getGenerator ($ routes )->generate ('test ' , [], UrlGeneratorInterface::ABSOLUTE_URL );
299
303
}
300
304
301
305
public function testGenerateForRouteWithInvalidOptionalParameter ()
302
306
{
303
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
307
+ $ this ->expectException (InvalidParameterException::class);
304
308
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing/{foo} ' , ['foo ' => '1 ' ], ['foo ' => 'd+ ' ]));
305
309
$ this ->getGenerator ($ routes )->generate ('test ' , ['foo ' => 'bar ' ], UrlGeneratorInterface::ABSOLUTE_URL );
306
310
}
307
311
308
312
public function testGenerateForRouteWithInvalidParameter ()
309
313
{
310
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
314
+ $ this ->expectException (InvalidParameterException::class);
311
315
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing/{foo} ' , [], ['foo ' => '1|2 ' ]));
312
316
$ this ->getGenerator ($ routes )->generate ('test ' , ['foo ' => '0 ' ], UrlGeneratorInterface::ABSOLUTE_URL );
313
317
}
@@ -323,7 +327,7 @@ public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
323
327
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger ()
324
328
{
325
329
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing/{foo} ' , ['foo ' => '1 ' ], ['foo ' => 'd+ ' ]));
326
- $ logger = $ this ->getMockBuilder (\ Psr \ Log \ LoggerInterface::class)-> getMock ( );
330
+ $ logger = $ this ->createMock ( LoggerInterface::class);
327
331
$ logger ->expects ($ this ->once ())
328
332
->method ('error ' );
329
333
$ generator = $ this ->getGenerator ($ routes , [], $ logger );
@@ -341,21 +345,21 @@ public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsC
341
345
342
346
public function testGenerateForRouteWithInvalidMandatoryParameter ()
343
347
{
344
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
348
+ $ this ->expectException (InvalidParameterException::class);
345
349
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing/{foo} ' , [], ['foo ' => 'd+ ' ]));
346
350
$ this ->getGenerator ($ routes )->generate ('test ' , ['foo ' => 'bar ' ], UrlGeneratorInterface::ABSOLUTE_URL );
347
351
}
348
352
349
353
public function testGenerateForRouteWithInvalidUtf8Parameter ()
350
354
{
351
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
355
+ $ this ->expectException (InvalidParameterException::class);
352
356
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing/{foo} ' , [], ['foo ' => '\pL+ ' ], ['utf8 ' => true ]));
353
357
$ this ->getGenerator ($ routes )->generate ('test ' , ['foo ' => 'abc123 ' ], UrlGeneratorInterface::ABSOLUTE_URL );
354
358
}
355
359
356
360
public function testRequiredParamAndEmptyPassed ()
357
361
{
358
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
362
+ $ this ->expectException (InvalidParameterException::class);
359
363
$ routes = $ this ->getRoutes ('test ' , new Route ('/{slug} ' , [], ['slug ' => '.+ ' ]));
360
364
$ this ->getGenerator ($ routes )->generate ('test ' , ['slug ' => '' ]);
361
365
}
@@ -476,7 +480,7 @@ public function testAdjacentVariables()
476
480
477
481
// The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything
478
482
// and following optional variables like _format could never match.
479
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
483
+ $ this ->expectException (InvalidParameterException::class);
480
484
$ generator ->generate ('test ' , ['x ' => 'do.t ' , 'y ' => '123 ' , 'z ' => 'bar ' , '_format ' => 'xml ' ]);
481
485
}
482
486
@@ -517,7 +521,7 @@ public function testImportantVariable()
517
521
518
522
public function testImportantVariableWithNoDefault ()
519
523
{
520
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ MissingMandatoryParametersException::class);
524
+ $ this ->expectException (MissingMandatoryParametersException::class);
521
525
$ routes = $ this ->getRoutes ('test ' , new Route ('/{page}.{!_format} ' ));
522
526
$ generator = $ this ->getGenerator ($ routes );
523
527
@@ -526,14 +530,14 @@ public function testImportantVariableWithNoDefault()
526
530
527
531
public function testDefaultRequirementOfVariableDisallowsSlash ()
528
532
{
529
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
533
+ $ this ->expectException (InvalidParameterException::class);
530
534
$ routes = $ this ->getRoutes ('test ' , new Route ('/{page}.{_format} ' ));
531
535
$ this ->getGenerator ($ routes )->generate ('test ' , ['page ' => 'index ' , '_format ' => 'sl/ash ' ]);
532
536
}
533
537
534
538
public function testDefaultRequirementOfVariableDisallowsNextSeparator ()
535
539
{
536
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
540
+ $ this ->expectException (InvalidParameterException::class);
537
541
$ routes = $ this ->getRoutes ('test ' , new Route ('/{page}.{_format} ' ));
538
542
$ this ->getGenerator ($ routes )->generate ('test ' , ['page ' => 'do.t ' , '_format ' => 'html ' ]);
539
543
}
@@ -561,21 +565,21 @@ public function testWithHostSameAsContextAndAbsolute()
561
565
562
566
public function testUrlWithInvalidParameterInHost ()
563
567
{
564
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
568
+ $ this ->expectException (InvalidParameterException::class);
565
569
$ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , [], ['foo ' => 'bar ' ], [], '{foo}.example.com ' ));
566
570
$ this ->getGenerator ($ routes )->generate ('test ' , ['foo ' => 'baz ' ], UrlGeneratorInterface::ABSOLUTE_PATH );
567
571
}
568
572
569
573
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue ()
570
574
{
571
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
575
+ $ this ->expectException (InvalidParameterException::class);
572
576
$ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , ['foo ' => 'bar ' ], ['foo ' => 'bar ' ], [], '{foo}.example.com ' ));
573
577
$ this ->getGenerator ($ routes )->generate ('test ' , ['foo ' => 'baz ' ], UrlGeneratorInterface::ABSOLUTE_PATH );
574
578
}
575
579
576
580
public function testUrlWithInvalidParameterEqualsDefaultValueInHost ()
577
581
{
578
- $ this ->expectException (\ Symfony \ Component \ Routing \ Exception \ InvalidParameterException::class);
582
+ $ this ->expectException (InvalidParameterException::class);
579
583
$ routes = $ this ->getRoutes ('test ' , new Route ('/ ' , ['foo ' => 'baz ' ], ['foo ' => 'bar ' ], [], '{foo}.example.com ' ));
580
584
$ this ->getGenerator ($ routes )->generate ('test ' , ['foo ' => 'baz ' ], UrlGeneratorInterface::ABSOLUTE_PATH );
581
585
}
0 commit comments