@@ -283,6 +283,55 @@ public function testCreateWithRequestUri()
283
283
$ this ->assertEquals ('http://test.com/foo ' , $ request ->getUri ());
284
284
}
285
285
286
+ /**
287
+ * @dataProvider getRequestUriData
288
+ */
289
+ public function testGetRequestUri ($ serverRequestUri , $ expected , $ message )
290
+ {
291
+ $ request = new Request ();
292
+ $ request ->server ->add (array (
293
+ 'REQUEST_URI ' => $ serverRequestUri ,
294
+
295
+ // For having http://test.com
296
+ 'SERVER_NAME ' => 'test.com ' ,
297
+ 'SERVER_PORT ' => 80 ,
298
+ ));
299
+
300
+ $ this ->assertSame ($ expected , $ request ->getRequestUri (), $ message );
301
+ $ this ->assertSame ($ expected , $ request ->server ->get ('REQUEST_URI ' ), 'Normalize the request URI. ' );
302
+ }
303
+
304
+ public function getRequestUriData ()
305
+ {
306
+ $ message = 'Do not modify the path. ' ;
307
+ yield array ('/foo ' , '/foo ' , $ message );
308
+ yield array ('//bar/foo ' , '//bar/foo ' , $ message );
309
+ yield array ('///bar/foo ' , '///bar/foo ' , $ message );
310
+
311
+ $ message = 'Handle when the scheme, host are on REQUEST_URI. ' ;
312
+ yield array ('http://test.com/foo?bar=baz ' , '/foo?bar=baz ' , $ message );
313
+
314
+ $ message = 'Handle when the scheme, host and port are on REQUEST_URI. ' ;
315
+ yield array ('http://test.com:80/foo ' , '/foo ' , $ message );
316
+ yield array ('https://test.com:8080/foo ' , '/foo ' , $ message );
317
+ yield array ('https://test.com:443/foo ' , '/foo ' , $ message );
318
+
319
+ $ message = 'Fragment should not be included in the URI ' ;
320
+ yield array ('http://test.com/foo#bar ' , '/foo ' , $ message );
321
+ yield array ('/foo#bar ' , '/foo ' , $ message );
322
+ }
323
+
324
+ public function testGetRequestUriWithoutRequiredHeader ()
325
+ {
326
+ $ expected = '' ;
327
+
328
+ $ request = new Request ();
329
+
330
+ $ message = 'Fallback to empty URI when headers are missing. ' ;
331
+ $ this ->assertSame ($ expected , $ request ->getRequestUri (), $ message );
332
+ $ this ->assertSame ($ expected , $ request ->server ->get ('REQUEST_URI ' ), 'Normalize the request URI. ' );
333
+ }
334
+
286
335
public function testCreateCheckPrecedence ()
287
336
{
288
337
// server is used by default
0 commit comments