@@ -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 }
@@ -56,7 +56,7 @@ public function testSchemeRedirectRedirectsToFirstScheme()
5656 $ coll = new RouteCollection ();
5757 $ coll ->add ('foo ' , new Route ('/foo ' , [], [], [], '' , ['FTP ' , 'HTTPS ' ]));
5858
59- $ matcher = $ this ->getUrlMatcher ($ coll );
59+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
6060 $ matcher
6161 ->expects ($ this ->once ())
6262 ->method ('redirect ' )
@@ -71,7 +71,7 @@ public function testNoSchemaRedirectIfOneOfMultipleSchemesMatches()
7171 $ coll = new RouteCollection ();
7272 $ coll ->add ('foo ' , new Route ('/foo ' , [], [], [], '' , ['https ' , 'http ' ]));
7373
74- $ matcher = $ this ->getUrlMatcher ($ coll );
74+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
7575 $ matcher
7676 ->expects ($ this ->never ())
7777 ->method ('redirect ' );
@@ -83,7 +83,7 @@ public function testSchemeRedirectWithParams()
8383 $ coll = new RouteCollection ();
8484 $ coll ->add ('foo ' , new Route ('/foo/{bar} ' , [], [], [], '' , ['https ' ]));
8585
86- $ matcher = $ this ->getUrlMatcher ($ coll );
86+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
8787 $ matcher
8888 ->expects ($ this ->once ())
8989 ->method ('redirect ' )
@@ -98,7 +98,7 @@ public function testSchemeRedirectForRoot()
9898 $ coll = new RouteCollection ();
9999 $ coll ->add ('foo ' , new Route ('/ ' , [], [], [], '' , ['https ' ]));
100100
101- $ matcher = $ this ->getUrlMatcher ($ coll );
101+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
102102 $ matcher
103103 ->expects ($ this ->once ())
104104 ->method ('redirect ' )
@@ -112,7 +112,7 @@ public function testSlashRedirectWithParams()
112112 $ coll = new RouteCollection ();
113113 $ coll ->add ('foo ' , new Route ('/foo/{bar}/ ' ));
114114
115- $ matcher = $ this ->getUrlMatcher ($ coll );
115+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
116116 $ matcher
117117 ->expects ($ this ->once ())
118118 ->method ('redirect ' )
@@ -127,7 +127,7 @@ public function testRedirectPreservesUrlEncoding()
127127 $ coll = new RouteCollection ();
128128 $ coll ->add ('foo ' , new Route ('/foo:bar/ ' ));
129129
130- $ matcher = $ this ->getUrlMatcher ($ coll );
130+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
131131 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo%3Abar/ ' )->willReturn ([]);
132132 $ matcher ->match ('/foo%3Abar ' );
133133 }
@@ -136,7 +136,7 @@ public function testSchemeRequirement()
136136 {
137137 $ coll = new RouteCollection ();
138138 $ coll ->add ('foo ' , new Route ('/foo ' , [], [], [], '' , ['https ' ]));
139- $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext ());
139+ $ matcher = $ this ->getUrlMatcher ($ coll , new RequestContext (), true );
140140 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo ' , 'foo ' , 'https ' )->willReturn ([]);
141141 $ this ->assertSame (['_route ' => 'foo ' ], $ matcher ->match ('/foo ' ));
142142 }
@@ -147,15 +147,15 @@ public function testFallbackPage()
147147 $ coll ->add ('foo ' , new Route ('/foo/ ' ));
148148 $ coll ->add ('bar ' , new Route ('/{name} ' ));
149149
150- $ matcher = $ this ->getUrlMatcher ($ coll );
150+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
151151 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo/ ' , 'foo ' )->willReturn (['_route ' => 'foo ' ]);
152152 $ this ->assertSame (['_route ' => 'foo ' ], $ matcher ->match ('/foo ' ));
153153
154154 $ coll = new RouteCollection ();
155155 $ coll ->add ('foo ' , new Route ('/foo ' ));
156156 $ coll ->add ('bar ' , new Route ('/{name}/ ' ));
157157
158- $ matcher = $ this ->getUrlMatcher ($ coll );
158+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
159159 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo ' , 'foo ' )->willReturn (['_route ' => 'foo ' ]);
160160 $ this ->assertSame (['_route ' => 'foo ' ], $ matcher ->match ('/foo/ ' ));
161161 }
@@ -165,7 +165,7 @@ public function testMissingTrailingSlashAndScheme()
165165 $ coll = new RouteCollection ();
166166 $ coll ->add ('foo ' , (new Route ('/foo/ ' ))->setSchemes (['https ' ]));
167167
168- $ matcher = $ this ->getUrlMatcher ($ coll );
168+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
169169 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/foo/ ' , 'foo ' , 'https ' )->willReturn ([]);
170170 $ matcher ->match ('/foo ' );
171171 }
@@ -176,7 +176,7 @@ public function testSlashAndVerbPrecedenceWithRedirection()
176176 $ coll ->add ('a ' , new Route ('/api/customers/{customerId}/contactpersons ' , [], [], [], '' , [], ['post ' ]));
177177 $ coll ->add ('b ' , new Route ('/api/customers/{customerId}/contactpersons/ ' , [], [], [], '' , [], ['get ' ]));
178178
179- $ matcher = $ this ->getUrlMatcher ($ coll );
179+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
180180 $ expected = [
181181 '_route ' => 'b ' ,
182182 'customerId ' => '123 ' ,
@@ -192,7 +192,7 @@ public function testNonGreedyTrailingRequirement()
192192 $ coll = new RouteCollection ();
193193 $ coll ->add ('a ' , new Route ('/{a} ' , [], ['a ' => '\d+ ' ]));
194194
195- $ matcher = $ this ->getUrlMatcher ($ coll );
195+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
196196 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/123 ' )->willReturn ([]);
197197
198198 $ this ->assertEquals (['_route ' => 'a ' , 'a ' => '123 ' ], $ matcher ->match ('/123/ ' ));
@@ -203,14 +203,23 @@ public function testTrailingRequirementWithDefaultA()
203203 $ coll = new RouteCollection ();
204204 $ coll ->add ('a ' , new Route ('/fr-fr/{a} ' , ['a ' => 'aaa ' ], ['a ' => '.+ ' ]));
205205
206- $ matcher = $ this ->getUrlMatcher ($ coll );
206+ $ matcher = $ this ->getUrlMatcher ($ coll, null , true );
207207 $ matcher ->expects ($ this ->once ())->method ('redirect ' )->with ('/fr-fr ' )->willReturn ([]);
208208
209209 $ this ->assertEquals (['_route ' => 'a ' , 'a ' => 'aaa ' ], $ matcher ->match ('/fr-fr/ ' ));
210210 }
211211
212- protected function getUrlMatcher (RouteCollection $ routes , ?RequestContext $ context = null )
212+ protected function getUrlMatcher (RouteCollection $ routes , ?RequestContext $ context = null , bool $ mock = false )
213213 {
214+ if (!$ mock ) {
215+ return new class ($ routes , $ context ?? new RequestContext ()) extends RedirectableUrlMatcher {
216+ public function redirect (string $ path , string $ route , ?string $ scheme = null ): array
217+ {
218+ return [];
219+ }
220+ };
221+ }
222+
214223 return $ this ->getMockBuilder (RedirectableUrlMatcher::class)
215224 ->setConstructorArgs ([$ routes , $ context ?? new RequestContext ()])
216225 ->onlyMethods (['redirect ' ])
0 commit comments