@@ -269,23 +269,72 @@ public function testRedirectSetsDefaultCodeAndLocationHeader()
269269 $ this ->assertSame (302 , $ response ->getStatusCode ());
270270 }
271271
272- public function testRedirectSetsCode ()
273- {
274- $ response = new Response (new App ());
272+ /**
273+ * @dataProvider provideForRedirect
274+ */
275+ public function testRedirect (
276+ string $ server ,
277+ string $ protocol ,
278+ string $ method ,
279+ ?int $ code ,
280+ int $ expectedCode
281+ ) {
282+ $ _SERVER ['SERVER_SOFTWARE ' ] = $ server ;
283+ $ _SERVER ['SERVER_PROTOCOL ' ] = $ protocol ;
284+ $ _SERVER ['REQUEST_METHOD ' ] = $ method ;
275285
276- $ response ->redirect ('example.com ' , 'auto ' , 307 );
286+ $ response = new Response (new App ());
287+ $ response ->redirect ('example.com ' , 'auto ' , $ code );
277288
278289 $ this ->assertTrue ($ response ->hasHeader ('location ' ));
279290 $ this ->assertSame ('example.com ' , $ response ->getHeaderLine ('Location ' ));
280- $ this ->assertSame (307 , $ response ->getStatusCode ());
291+ $ this ->assertSame ($ expectedCode , $ response ->getStatusCode ());
281292 }
282293
283- public function testRedirectWithIIS ()
294+ public function provideForRedirect ()
284295 {
296+ yield from [
297+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'GET ' , null , 307 ],
298+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'GET ' , 307 , 307 ],
299+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'GET ' , 302 , 307 ],
300+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'POST ' , null , 303 ],
301+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'POST ' , 307 , 303 ],
302+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'POST ' , 302 , 303 ],
303+ ];
304+ }
305+
306+ /**
307+ * @dataProvider provideForRedirectWithIIS
308+ */
309+ public function testRedirectWithIIS (
310+ string $ protocol ,
311+ string $ method ,
312+ ?int $ code ,
313+ int $ expectedCode
314+ ) {
285315 $ _SERVER ['SERVER_SOFTWARE ' ] = 'Microsoft-IIS ' ;
286- $ response = new Response (new App ());
287- $ response ->redirect ('example.com ' , 'auto ' , 307 );
316+ $ _SERVER ['SERVER_PROTOCOL ' ] = 'HTTP/1.1 ' ;
317+ $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
318+
319+ $ response = new Response (new App ());
320+ $ response ->redirect ('example.com ' , 'auto ' , $ code );
321+
288322 $ this ->assertSame ('0;url=example.com ' , $ response ->getHeaderLine ('Refresh ' ));
323+ $ this ->assertSame ($ expectedCode , $ response ->getStatusCode ());
324+
325+ unset($ _SERVER ['SERVER_SOFTWARE ' ]);
326+ }
327+
328+ public function provideForRedirectWithIIS ()
329+ {
330+ yield from [
331+ ['HTTP/1.1 ' , 'GET ' , null , 302 ],
332+ ['HTTP/1.1 ' , 'GET ' , 307 , 307 ],
333+ ['HTTP/1.1 ' , 'GET ' , 302 , 302 ],
334+ ['HTTP/1.1 ' , 'POST ' , null , 302 ],
335+ ['HTTP/1.1 ' , 'POST ' , 307 , 307 ],
336+ ['HTTP/1.1 ' , 'POST ' , 302 , 302 ],
337+ ];
289338 }
290339
291340 public function testSetCookieFails ()
0 commit comments