File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -207,6 +207,18 @@ function withPath ($path) : static {
207207 return $ instance ;
208208 }
209209
210+ function withPathAdded (string $ addedPath ) : static {
211+ $ instance = clone $ this ;
212+ $ addedPath = Parse::parsePath ($ addedPath );
213+ if ($ instance ->path !== null ) {
214+ $ instance ->path = $ instance ->path ->concat ($ addedPath );
215+ } else {
216+ $ instance ->path = $ addedPath ;
217+ }
218+
219+ return $ instance ;
220+ }
221+
210222 /**
211223 * @throws InvalidArgumentException
212224 * @param string $scheme
Original file line number Diff line number Diff line change @@ -193,4 +193,20 @@ function provideSetterMethodsWithInvalidTypes () : \Generator {
193193 yield 'fragment ' => ['withFragment ' ];
194194 }
195195
196+ function testExpectsUriWithAddedPath () {
197+ $ uri = new Uri ('https://www.example.com/foo ' );
198+ $ uri = $ uri ->withPathAdded ('/bar ' );
199+
200+ $ this ->assertSame ('https://www.example.com/foo/bar ' , $ uri ->compose ());
201+ $ this ->assertSame ('/foo/bar ' , $ uri ->getPath ());
202+ }
203+
204+ function testExpectsUriWithAddedPathEvenIfPathWasEmptyBefore () {
205+ $ uri = new Uri ('https://www.example.com ' );
206+ $ uri = $ uri ->withPathAdded ('/foo/bar ' );
207+
208+ $ this ->assertSame ('https://www.example.com/foo/bar ' , $ uri ->compose ());
209+ $ this ->assertSame ('/foo/bar ' , $ uri ->getPath ());
210+ }
211+
196212}
You can’t perform that action at this time.
0 commit comments