@@ -24,7 +24,7 @@ public function testMissingTrailingSlash()
2424 $ coll = new RouteCollection ();
2525 $ coll ->add ('foo ' , new Route ('/foo/ ' ));
2626
27- $ matcher = $ this ->getUrlMatcher ($ coll );
27+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
2828 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->willReturn ([]);
2929 $ matcher ->match ('/foo ' );
3030 }
@@ -34,7 +34,7 @@ public function testExtraTrailingSlash()
3434 $ coll = new RouteCollection ();
3535 $ coll ->add ('foo ' , new Route ('/foo ' ));
3636
37- $ matcher = $ this ->getUrlMatcher ($ coll );
37+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
3838 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->willReturn ([]);
3939 $ matcher ->match ('/foo/ ' );
4040 }
@@ -58,7 +58,7 @@ public function testSchemeRedirectRedirectsToFirstScheme()
5858 $ coll = new RouteCollection ();
5959 $ coll ->add ('foo ' , new Route ('/foo ' , [], [], [], '' , ['FTP ' , 'HTTPS ' ]));
6060
61- $ matcher = $ this ->getUrlMatcher ($ coll );
61+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
6262 $ matcher
6363 ->expects ($ this ->once ())
6464 ->method ('redirect ' )
@@ -73,7 +73,7 @@ public function testNoSchemaRedirectIfOneOfMultipleSchemesMatches()
7373 $ coll = new RouteCollection ();
7474 $ coll ->add ('foo ' , new Route ('/foo ' , [], [], [], '' , ['https ' , 'http ' ]));
7575
76- $ matcher = $ this ->getUrlMatcher ($ coll );
76+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
7777 $ matcher
7878 ->expects ($ this ->never ())
7979 ->method ('redirect ' );
@@ -85,7 +85,7 @@ public function testSchemeRedirectWithParams()
8585 $ coll = new RouteCollection ();
8686 $ coll ->add ('foo ' , new Route ('/foo/{bar} ' , [], [], [], '' , ['https ' ]));
8787
88- $ matcher = $ this ->getUrlMatcher ($ coll );
88+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
8989 $ matcher
9090 ->expects ($ this ->once ())
9191 ->method ('redirect ' )
@@ -100,7 +100,7 @@ public function testSchemeRedirectForRoot()
100100 $ coll = new RouteCollection ();
101101 $ coll ->add ('foo ' , new Route ('/ ' , [], [], [], '' , ['https ' ]));
102102
103- $ matcher = $ this ->getUrlMatcher ($ coll );
103+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
104104 $ matcher
105105 ->expects ($ this ->once ())
106106 ->method ('redirect ' )
@@ -114,7 +114,7 @@ public function testSlashRedirectWithParams()
114114 $ coll = new RouteCollection ();
115115 $ coll ->add ('foo ' , new Route ('/foo/{bar}/ ' ));
116116
117- $ matcher = $ this ->getUrlMatcher ($ coll );
117+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
118118 $ matcher
119119 ->expects ($ this ->once ())
120120 ->method ('redirect ' )
@@ -129,7 +129,7 @@ public function testRedirectPreservesUrlEncoding()
129129 $ coll = new RouteCollection ();
130130 $ coll ->add ('foo ' , new Route ('/foo:bar/ ' ));
131131
132- $ matcher = $ this ->getUrlMatcher ($ coll );
132+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
133133 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo%3Abar/ ' )->willReturn ([]);
134134 $ matcher ->match ('/foo%3Abar ' );
135135 }
@@ -138,7 +138,7 @@ public function testSchemeRequirement()
138138 {
139139 $ coll = new RouteCollection ();
140140 $ coll ->add ('foo ' , new Route ('/foo ' , [], [], [], '' , ['https ' ]));
141- $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ());
141+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext (), true );
142142 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo ' , 'foo ' , 'https ' )->willReturn ([]);
143143 $ this ->assertSame (['_route ' => 'foo ' ], $ matcher ->match ('/foo ' ));
144144 }
@@ -149,15 +149,15 @@ public function testFallbackPage()
149149 $ coll ->add ('foo ' , new Route ('/foo/ ' ));
150150 $ coll ->add ('bar ' , new Route ('/{name} ' ));
151151
152- $ matcher = $ this ->getUrlMatcher ($ coll );
152+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
153153 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo/ ' , 'foo ' )->willReturn (['_route ' => 'foo ' ]);
154154 $ this ->assertSame (['_route ' => 'foo ' ], $ matcher ->match ('/foo ' ));
155155
156156 $ coll = new RouteCollection ();
157157 $ coll ->add ('foo ' , new Route ('/foo ' ));
158158 $ coll ->add ('bar ' , new Route ('/{name}/ ' ));
159159
160- $ matcher = $ this ->getUrlMatcher ($ coll );
160+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
161161 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo ' , 'foo ' )->willReturn (['_route ' => 'foo ' ]);
162162 $ this ->assertSame (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
163163 }
@@ -167,7 +167,7 @@ public function testMissingTrailingSlashAndScheme()
167167 $ coll = new RouteCollection ();
168168 $ coll ->add ('foo ' , (new Route ('/foo/ ' ))->setSchemes (['https ' ]));
169169
170- $ matcher = $ this ->getUrlMatcher ($ coll );
170+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
171171 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo/ ' , 'foo ' , 'https ' )->willReturn ([]);
172172 $ matcher ->match ('/foo ' );
173173 }
@@ -178,7 +178,7 @@ public function testSlashAndVerbPrecedenceWithRedirection()
178178 $ coll ->add ('a ' , new Route ('/api/customers/{customerId}/contactpersons ' , [], [], [], '' , [], ['post ' ]));
179179 $ coll ->add ('b ' , new Route ('/api/customers/{customerId}/contactpersons/ ' , [], [], [], '' , [], ['get ' ]));
180180
181- $ matcher = $ this ->getUrlMatcher ($ coll );
181+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
182182 $ expected = [
183183 '_route ' => 'b ' ,
184184 'customerId ' => '123 ' ,
@@ -194,7 +194,7 @@ public function testNonGreedyTrailingRequirement()
194194 $ coll = new RouteCollection ();
195195 $ coll ->add ('a ' , new Route ('/{a} ' , [], ['a ' => '\d+ ' ]));
196196
197- $ matcher = $ this ->getUrlMatcher ($ coll );
197+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
198198 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/123 ' )->willReturn ([]);
199199
200200 $ this ->assertEquals (['_route ' => 'a ' , 'a ' => '123 ' ], $ matcher ->match ('/123/ ' ));
@@ -205,14 +205,23 @@ public function testTrailingRequirementWithDefaultA()
205205 $ coll = new RouteCollection ();
206206 $ coll ->add ('a ' , new Route ('/fr-fr/{a} ' , ['a ' => 'aaa ' ], ['a ' => '.+ ' ]));
207207
208- $ matcher = $ this ->getUrlMatcher ($ coll );
208+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
209209 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/fr-fr ' )->willReturn ([]);
210210
211211 $ this ->assertEquals (['_route ' => 'a ' , 'a ' => 'aaa ' ], $ matcher ->match ('/fr-fr/ ' ));
212212 }
213213
214- protected function getUrlMatcher (RouteCollection $ routes , ?RequestContext $ context = null )
214+ protected function getUrlMatcher (RouteCollection $ routes , ?RequestContext $ context = null , bool $ mock = false )
215215 {
216+ if (!$ mock ) {
217+ return new class ($ routes , $ context ?? new RequestContext ()) extends RedirectableUrlMatcher {
218+ public function redirect (string $ path , string $ route , ?string $ scheme = null ): array
219+ {
220+ return [];
221+ }
222+ };
223+ }
224+
216225 return $ this ->getMockBuilder (RedirectableUrlMatcher::class)
217226 ->setConstructorArgs ([$ routes , $ context ?? new RequestContext ()])
218227 ->onlyMethods (['redirect ' ])
0 commit comments