Skip to content

Commit

Permalink
Implement withUri() and tests for getUri() as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 13, 2016
1 parent dd584fe commit bc19b3a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Network/Request.php
Expand Up @@ -1885,6 +1885,23 @@ public function getUri()
return $this->uri;
}

/**
* Return an instance with the specified uri
*
* *Warning* Replacing the Uri will not update the `base`, `webroot`,
* and `url` attributes.
*
* @param \Psr\Http\Message\UriInterface $uri The new request uri
* @return static
*/
public function withUri(UriInterface $uri)
{
$new = clone $this;
$new->uri = $uri;

return $new;
}

/**
* Array access read implementation
*
Expand Down
34 changes: 34 additions & 0 deletions tests/TestCase/Network/RequestTest.php
Expand Up @@ -2697,6 +2697,40 @@ public function testWithBody()
$this->assertSame($body, $new->getBody());
}

/**
* Test getUri
*
* @return void
*/
public function testGetUri()
{
$request = new Request(['url' => 'articles/view/3']);
$this->assertEquals('articles/view/3', $request->url);

$result = $request->getUri();
$this->assertInstanceOf('Psr\Http\Message\UriInterface', $result);
$this->assertEquals('/articles/view/3', $result->getPath());
}

/**
* Test withUri
*
* @return void
*/
public function testWithUri()
{
$request = new Request([
'url' => 'articles/view/3'
]);
$uri = $this->getMockBuilder('Psr\Http\Message\UriInterface')->getMock();
$new = $request->withUri($uri);
$this->assertNotSame($new, $request);
$this->assertNotSame($uri, $request->getUri());
$this->assertSame($uri, $new->getUri());
$this->assertSame('articles/view/3', $new->url);
$this->assertSame('articles/view/3', $request->url);
}

/**
* Test is('requested') and isRequested()
*
Expand Down

0 comments on commit bc19b3a

Please sign in to comment.