11
11
12
12
namespace Symfony \Cmf \Component \Routing \Tests \Routing ;
13
13
14
+ use PHPUnit \Framework \MockObject \MockObject ;
14
15
use PHPUnit \Framework \TestCase ;
15
16
use Psr \Log \LoggerInterface ;
16
17
use Symfony \Cmf \Component \Routing \ChainRouter ;
@@ -35,7 +36,7 @@ class ChainRouterTest extends TestCase
35
36
private $ router ;
36
37
37
38
/**
38
- * @var RequestContext|\PHPUnit_Framework_MockObject_MockObject
39
+ * @var RequestContext|MockObject
39
40
*/
40
41
private $ context ;
41
42
@@ -84,7 +85,7 @@ public function testSortRouters()
84
85
{
85
86
list ($ low , $ medium , $ high ) = $ this ->createRouterMocks ();
86
87
// We're using a mock here and not $this->router because we need to ensure that the sorting operation is done only once.
87
- /** @var $router ChainRouter|\PHPUnit_Framework_MockObject_MockObject */
88
+ /** @var $router ChainRouter|MockObject */
88
89
$ router = $ this ->getMockBuilder (ChainRouter::class)
89
90
->disableOriginalConstructor ()
90
91
->setMethods (['sortRouters ' ])
@@ -121,7 +122,7 @@ public function testReSortRouters()
121
122
list ($ low , $ medium , $ high ) = $ this ->createRouterMocks ();
122
123
$ highest = clone $ high ;
123
124
// We're using a mock here and not $this->router because we need to ensure that the sorting operation is done only once.
124
- /** @var $router ChainRouter|\PHPUnit_Framework_MockObject_MockObject */
125
+ /** @var $router ChainRouter|MockObject */
125
126
$ router = $ this ->getMockBuilder (ChainRouter::class)
126
127
->disableOriginalConstructor ()
127
128
->setMethods (['sortRouters ' ])
@@ -302,7 +303,7 @@ public function testMatchWithRequestMatchers()
302
303
->with ($ this ->callback (function (Request $ r ) use ($ url ) {
303
304
return $ r ->getPathInfo () === $ url ;
304
305
}))
305
- ->will ($ this ->throwException (new \ Symfony \ Component \ Routing \ Exception \ ResourceNotFoundException ()))
306
+ ->will ($ this ->throwException (new ResourceNotFoundException ()))
306
307
;
307
308
$ low
308
309
->expects ($ this ->once ())
@@ -413,7 +414,7 @@ public function testMatchRequestAndNotAllowed()
413
414
->expects ($ this ->once ())
414
415
->method ('match ' )
415
416
->with ($ url )
416
- ->will ($ this ->throwException (new \ Symfony \ Component \ Routing \ Exception \ MethodNotAllowedException ([])))
417
+ ->will ($ this ->throwException (new MethodNotAllowedException ([])))
417
418
;
418
419
$ low
419
420
->expects ($ this ->once ())
@@ -428,9 +429,6 @@ public function testMatchRequestAndNotAllowed()
428
429
$ this ->assertEquals (['test ' ], $ result );
429
430
}
430
431
431
- /**
432
- * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
433
- */
434
432
public function testMatchNotFound ()
435
433
{
436
434
$ url = '/test ' ;
@@ -451,12 +449,10 @@ public function testMatchNotFound()
451
449
$ this ->router ->add ($ low , 10 );
452
450
$ this ->router ->add ($ high , 100 );
453
451
452
+ $ this ->expectException (ResourceNotFoundException::class);
454
453
$ this ->router ->match ('/test ' );
455
454
}
456
455
457
- /**
458
- * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
459
- */
460
456
public function testMatchRequestNotFound ()
461
457
{
462
458
$ url = '/test ' ;
@@ -477,14 +473,12 @@ public function testMatchRequestNotFound()
477
473
$ this ->router ->add ($ low , 10 );
478
474
$ this ->router ->add ($ high , 100 );
479
475
476
+ $ this ->expectException (ResourceNotFoundException::class);
480
477
$ this ->router ->matchRequest (Request::create ('/test ' ));
481
478
}
482
479
483
480
/**
484
481
* Call match on ChainRouter that has RequestMatcher in the chain.
485
- *
486
- * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
487
- * @expectedExceptionMessage None of the routers in the chain matched url '/test'
488
482
*/
489
483
public function testMatchWithRequestMatchersNotFound ()
490
484
{
@@ -502,13 +496,13 @@ public function testMatchWithRequestMatchersNotFound()
502
496
503
497
$ this ->router ->add ($ high , 20 );
504
498
499
+ $ this ->expectException (ResourceNotFoundException::class);
500
+ $ this ->expectExceptionMessage ('None of the routers in the chain matched url \'/test \'' );
505
501
$ this ->router ->match ($ url );
506
502
}
507
503
508
504
/**
509
505
* If any of the routers throws a not allowed exception and no other matches, we need to see this.
510
- *
511
- * @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException
512
506
*/
513
507
public function testMatchMethodNotAllowed ()
514
508
{
@@ -530,13 +524,12 @@ public function testMatchMethodNotAllowed()
530
524
$ this ->router ->add ($ low , 10 );
531
525
$ this ->router ->add ($ high , 100 );
532
526
527
+ $ this ->expectException (MethodNotAllowedException::class);
533
528
$ this ->router ->match ('/test ' );
534
529
}
535
530
536
531
/**
537
532
* If any of the routers throws a not allowed exception and no other matches, we need to see this.
538
- *
539
- * @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException
540
533
*/
541
534
public function testMatchRequestMethodNotAllowed ()
542
535
{
@@ -558,6 +551,7 @@ public function testMatchRequestMethodNotAllowed()
558
551
$ this ->router ->add ($ low , 10 );
559
552
$ this ->router ->add ($ high , 100 );
560
553
554
+ $ this ->expectException (MethodNotAllowedException::class);
561
555
$ this ->router ->matchRequest (Request::create ('/test ' ));
562
556
}
563
557
@@ -592,9 +586,6 @@ public function testGenerate()
592
586
$ this ->assertEquals ($ url , $ result );
593
587
}
594
588
595
- /**
596
- * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
597
- */
598
589
public function testGenerateNotFound ()
599
590
{
600
591
$ name = 'test ' ;
@@ -615,13 +606,12 @@ public function testGenerateNotFound()
615
606
$ this ->router ->add ($ low , 10 );
616
607
$ this ->router ->add ($ high , 100 );
617
608
609
+ $ this ->expectException (RouteNotFoundException::class);
618
610
$ this ->router ->generate ($ name , $ parameters );
619
611
}
620
612
621
613
/**
622
614
* Route is an object but no versatile generator around to do the debug message.
623
- *
624
- * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
625
615
*/
626
616
public function testGenerateObjectNotFound ()
627
617
{
@@ -637,13 +627,12 @@ public function testGenerateObjectNotFound()
637
627
638
628
$ this ->router ->add ($ defaultRouter , 200 );
639
629
630
+ $ this ->expectException (RouteNotFoundException::class);
640
631
$ this ->router ->generate ($ name , $ parameters );
641
632
}
642
633
643
634
/**
644
635
* A versatile router will generate the debug message.
645
- *
646
- * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
647
636
*/
648
637
public function testGenerateObjectNotFoundVersatile ()
649
638
{
@@ -669,6 +658,7 @@ public function testGenerateObjectNotFoundVersatile()
669
658
670
659
$ this ->router ->add ($ chainedRouter , 10 );
671
660
661
+ $ this ->expectException (RouteNotFoundException::class);
672
662
$ this ->router ->generate ($ name , $ parameters );
673
663
}
674
664
@@ -754,9 +744,6 @@ public function testRouteCollection()
754
744
$ this ->assertEquals (['high ' , 'low ' ], $ names );
755
745
}
756
746
757
- /**
758
- * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
759
- */
760
747
public function testSupport ()
761
748
{
762
749
$ router = $ this ->createMock (VersatileRouter::class);
@@ -774,11 +761,12 @@ public function testSupport()
774
761
775
762
$ this ->router ->add ($ router );
776
763
764
+ $ this ->expectException (RouteNotFoundException::class);
777
765
$ this ->router ->generate ('foobar ' );
778
766
}
779
767
780
768
/**
781
- * @return RouterInterface[]|\PHPUnit_Framework_MockObject_MockObject []
769
+ * @return RouterInterface[]|MockObject []
782
770
*/
783
771
protected function createRouterMocks ()
784
772
{
0 commit comments