Skip to content

Commit efc3c0a

Browse files
committed
Request: added withUrl()
1 parent 5b5afae commit efc3c0a

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/Http/Request.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ public function __construct(UrlScript $url, array $post = null, array $files = n
7676
}
7777

7878

79+
/**
80+
* @return static
81+
*/
82+
public function withUrl(UrlScript $url)
83+
{
84+
$dolly = clone $this;
85+
$dolly->url = $url;
86+
return $dolly;
87+
}
88+
89+
7990
/**
8091
* Returns URL object.
8192
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Nette\Http;
6+
use Tester\Assert;
7+
8+
9+
require __DIR__ . '/../bootstrap.php';
10+
11+
12+
test(function () {
13+
$url = new Http\UrlScript('http://nette.org/?arg=hello');
14+
$request = new Http\Request($url);
15+
16+
Assert::same($url, $request->getUrl());
17+
Assert::same('hello', $request->getQuery('arg'));
18+
19+
$url2 = new Http\UrlScript('http://nette.org/?arg=another');
20+
$request = $request->withUrl($url2);
21+
22+
Assert::same($url2, $request->getUrl());
23+
Assert::same('another', $request->getQuery('arg'));
24+
});

tests/Http/UrlImmutable.manipulation.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test(function () {
5151
Assert::same('/', $url->getPath());
5252

5353
$url = $url->withHost('')->withPath('');
54-
Assert::same('http://?arg=value#anchor', $url->absoluteUrl);
54+
Assert::same('http:?arg=value#anchor', $url->absoluteUrl);
5555

5656
$url = $url->withPath('');
5757
Assert::same('', $url->getPath());

0 commit comments

Comments
 (0)