Skip to content
Permalink
Browse files

Implement withUri() and tests for getUri() as well.

  • Loading branch information...
markstory committed Sep 12, 2016
1 parent dd584fe commit bc19b3a2dcf19e066b802c569aa6a3123a9139de
Showing with 51 additions and 0 deletions.
  1. +17 −0 src/Network/Request.php
  2. +34 −0 tests/TestCase/Network/RequestTest.php
@@ -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
*
@@ -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()
*

0 comments on commit bc19b3a

Please sign in to comment.
You can’t perform that action at this time.