1111
1212namespace Symfony \Component \Routing \Tests \Matcher ;
1313
14- use PHPUnit \Framework \TestCase ;
1514use Symfony \Component \Routing \Route ;
1615use Symfony \Component \Routing \RouteCollection ;
1716use Symfony \Component \Routing \RequestContext ;
1817
19- class RedirectableUrlMatcherTest extends TestCase
18+ class RedirectableUrlMatcherTest extends UrlMatcherTest
2019{
2120 public function testRedirectWhenNoSlash ()
2221 {
2322 $ coll = new RouteCollection ();
2423 $ coll ->add ('foo ' , new Route ('/foo/ ' ));
2524
26- $ matcher = $ this ->getMockForAbstractClass ( ' Symfony\Component\Routing\Matcher\RedirectableUrlMatcher ' , array ( $ coll, new RequestContext ()) );
27- $ matcher ->expects ($ this ->once ())->method ('redirect ' );
25+ $ matcher = $ this ->getUrlMatcher ( $ coll );
26+ $ matcher ->expects ($ this ->once ())->method ('redirect ' )-> will ( $ this -> returnValue ( array ())) ;
2827 $ matcher ->match ('/foo ' );
2928 }
3029
@@ -38,7 +37,7 @@ public function testRedirectWhenNoSlashForNonSafeMethod()
3837
3938 $ context = new RequestContext ();
4039 $ context ->setMethod ('POST ' );
41- $ matcher = $ this ->getMockForAbstractClass ( ' Symfony\Component\Routing\Matcher\RedirectableUrlMatcher ' , array ( $ coll , $ context) );
40+ $ matcher = $ this ->getUrlMatcher ( $ coll , $ context );
4241 $ matcher ->match ('/foo ' );
4342 }
4443
@@ -47,7 +46,7 @@ public function testSchemeRedirectRedirectsToFirstScheme()
4746 $ coll = new RouteCollection ();
4847 $ coll ->add ('foo ' , new Route ('/foo ' , array (), array (), array (), '' , array ('FTP ' , 'HTTPS ' )));
4948
50- $ matcher = $ this ->getMockForAbstractClass ( ' Symfony\Component\Routing\Matcher\RedirectableUrlMatcher ' , array ( $ coll, new RequestContext ()) );
49+ $ matcher = $ this ->getUrlMatcher ( $ coll );
5150 $ matcher
5251 ->expects ($ this ->once ())
5352 ->method ('redirect ' )
@@ -62,11 +61,10 @@ public function testNoSchemaRedirectIfOnOfMultipleSchemesMatches()
6261 $ coll = new RouteCollection ();
6362 $ coll ->add ('foo ' , new Route ('/foo ' , array (), array (), array (), '' , array ('https ' , 'http ' )));
6463
65- $ matcher = $ this ->getMockForAbstractClass ( ' Symfony\Component\Routing\Matcher\RedirectableUrlMatcher ' , array ( $ coll, new RequestContext ()) );
64+ $ matcher = $ this ->getUrlMatcher ( $ coll );
6665 $ matcher
6766 ->expects ($ this ->never ())
68- ->method ('redirect ' )
69- ;
67+ ->method ('redirect ' );
7068 $ matcher ->match ('/foo ' );
7169 }
7270
@@ -75,8 +73,22 @@ public function testRedirectPreservesUrlEncoding()
7573 $ coll = new RouteCollection ();
7674 $ coll ->add ('foo ' , new Route ('/foo:bar/ ' ));
7775
78- $ matcher = $ this ->getMockForAbstractClass ( ' Symfony\Component\Routing\Matcher\RedirectableUrlMatcher ' , array ( $ coll, new RequestContext ()) );
79- $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo%3Abar/ ' );
76+ $ matcher = $ this ->getUrlMatcher ( $ coll );
77+ $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo%3Abar/ ' )-> willReturn ( array ()) ;
8078 $ matcher ->match ('/foo%3Abar ' );
8179 }
80+
81+ public function testSchemeRequirement ()
82+ {
83+ $ coll = new RouteCollection ();
84+ $ coll ->add ('foo ' , new Route ('/foo ' , array (), array (), array (), '' , array ('https ' )));
85+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ());
86+ $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo ' , 'foo ' , 'https ' )->willReturn (array ('_route ' => 'foo ' ));
87+ $ this ->assertSame (array ('_route ' => 'foo ' ), $ matcher ->match ('/foo ' ));
88+ }
89+
90+ protected function getUrlMatcher (RouteCollection $ routes , RequestContext $ context = null )
91+ {
92+ return $ this ->getMockForAbstractClass ('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher ' , array ($ routes , $ context ?: new RequestContext ()));
93+ }
8294}
0 commit comments