Skip to content
Permalink
Browse files

Fix reason phrase not getting set by statusCode()

Setting a statuscode with the mutable interface should set the reason
phrase.
  • Loading branch information...
markstory committed Jan 1, 2017
1 parent d6a720b commit ea7c52b91fcc00430ba441a291c125bca2301fac
Showing with 19 additions and 5 deletions.
  1. +5 −3 src/Http/Response.php
  2. +14 −2 tests/TestCase/Network/ResponseTest.php
@@ -402,9 +402,9 @@ class Response implements ResponseInterface
/**
* Reason Phrase
*
* @var string|null
* @var string
*/
protected $_reasonPhrase = null;
protected $_reasonPhrase = 'OK';
/**
* Stream mode options.
@@ -877,7 +877,9 @@ public function statusCode($code = null)
if (!isset($this->_statusCodes[$code])) {
throw new InvalidArgumentException('Unknown status code');
}
if (isset($this->_statusCodes[$code])) {
$this->_reasonPhrase = $this->_statusCodes[$code];
}
$this->_status = $code;
$this->_setContentType();
@@ -130,18 +130,30 @@ public function testWithCharset()
/**
* Tests the statusCode method
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testStatusCode()
{
$response = new Response();
$this->assertEquals(200, $response->statusCode());
$response->statusCode(404);
$this->assertEquals(404, $response->getStatusCode(), 'Sets shared state.');
$this->assertEquals(404, $response->statusCode());
$this->assertEquals('Not Found', $response->getReasonPhrase());
$this->assertEquals(500, $response->statusCode(500));
}
//Throws exception
/**
* Test invalid status codes
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testStatusCodeInvalid()
{
$response = new Response();
$response->statusCode(1001);
}

0 comments on commit ea7c52b

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