Skip to content
Permalink
Browse files

Add withLocation()

Add an immutable variant of location().
  • Loading branch information...
markstory committed Nov 17, 2016
1 parent 72d3d29 commit 06f7a6bd6d9635ec7f46bd563c0d1d8c3d975e5b
Showing with 27 additions and 0 deletions.
  1. +11 −0 src/Network/Response.php
  2. +16 −0 tests/TestCase/Network/ResponseTest.php
@@ -722,6 +722,17 @@ public function location($url = null)
return null;
}
/**
* Return an instance with an updated location header
*
* @param string $url The location to redirect to.
* @return static A new response with the Location header set.
*/
public function withLocation($url)
{
return $this->withHeader('Location', $url);
}
/**
* Sets a header.
*
@@ -2110,6 +2110,22 @@ public function testLocation()
$this->assertEquals('http://example.org', $response->location(), 'Reading a location should return the value.');
}
/**
* Test the withLocation method.
*
* @return void
*/
public function testWithLocation()
{
$response = new Response();
$this->assertSame('', $response->getHeaderLine('Location'), 'No header should be set.');
$new = $response->withLocation('http://example.org');
$this->assertNotSame($new, $response);
$this->assertSame('', $response->getHeaderLine('Location'), 'No header should be set');
$this->assertSame('http://example.org', $new->getHeaderLine('Location'), 'Header should be set');
}
/**
* Test get protocol version.
*

0 comments on commit 06f7a6b

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