File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -1885,6 +1885,23 @@ public function getUri()
1885
1885
return $ this ->uri ;
1886
1886
}
1887
1887
1888
+ /**
1889
+ * Return an instance with the specified uri
1890
+ *
1891
+ * *Warning* Replacing the Uri will not update the `base`, `webroot`,
1892
+ * and `url` attributes.
1893
+ *
1894
+ * @param \Psr\Http\Message\UriInterface $uri The new request uri
1895
+ * @return static
1896
+ */
1897
+ public function withUri (UriInterface $ uri )
1898
+ {
1899
+ $ new = clone $ this ;
1900
+ $ new ->uri = $ uri ;
1901
+
1902
+ return $ new ;
1903
+ }
1904
+
1888
1905
/**
1889
1906
* Array access read implementation
1890
1907
*
Original file line number Diff line number Diff line change @@ -2697,6 +2697,40 @@ public function testWithBody()
2697
2697
$ this ->assertSame ($ body , $ new ->getBody ());
2698
2698
}
2699
2699
2700
+ /**
2701
+ * Test getUri
2702
+ *
2703
+ * @return void
2704
+ */
2705
+ public function testGetUri ()
2706
+ {
2707
+ $ request = new Request (['url ' => 'articles/view/3 ' ]);
2708
+ $ this ->assertEquals ('articles/view/3 ' , $ request ->url );
2709
+
2710
+ $ result = $ request ->getUri ();
2711
+ $ this ->assertInstanceOf ('Psr\Http\Message\UriInterface ' , $ result );
2712
+ $ this ->assertEquals ('/articles/view/3 ' , $ result ->getPath ());
2713
+ }
2714
+
2715
+ /**
2716
+ * Test withUri
2717
+ *
2718
+ * @return void
2719
+ */
2720
+ public function testWithUri ()
2721
+ {
2722
+ $ request = new Request ([
2723
+ 'url ' => 'articles/view/3 '
2724
+ ]);
2725
+ $ uri = $ this ->getMockBuilder ('Psr\Http\Message\UriInterface ' )->getMock ();
2726
+ $ new = $ request ->withUri ($ uri );
2727
+ $ this ->assertNotSame ($ new , $ request );
2728
+ $ this ->assertNotSame ($ uri , $ request ->getUri ());
2729
+ $ this ->assertSame ($ uri , $ new ->getUri ());
2730
+ $ this ->assertSame ('articles/view/3 ' , $ new ->url );
2731
+ $ this ->assertSame ('articles/view/3 ' , $ request ->url );
2732
+ }
2733
+
2700
2734
/**
2701
2735
* Test is('requested') and isRequested()
2702
2736
*
You can’t perform that action at this time.
0 commit comments