Skip to content

Commit

Permalink
Request: added withUrl()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 13, 2019
1 parent d0dd0bd commit e126517
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public function __construct(UrlScript $url, array $post = null, array $files = n
}


/**
* @return static
*/
public function withUrl(UrlScript $url)
{
$dolly = clone $this;
$dolly->url = $url;
return $dolly;
}


/**
* Returns URL object.
*/
Expand Down
24 changes: 24 additions & 0 deletions tests/Http/Request.manipulation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

use Nette\Http;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


test(function () {
$url = new Http\UrlScript('http://nette.org/?arg=hello');
$request = new Http\Request($url);

Assert::same($url, $request->getUrl());
Assert::same('hello', $request->getQuery('arg'));

$url2 = new Http\UrlScript('http://nette.org/?arg=another');
$request = $request->withUrl($url2);

Assert::same($url2, $request->getUrl());
Assert::same('another', $request->getQuery('arg'));
});

0 comments on commit e126517

Please sign in to comment.