Skip to content

Commit

Permalink
Fix reason phrase not getting set by statusCode()
Browse files Browse the repository at this point in the history
Setting a statuscode with the mutable interface should set the reason
phrase.
  • Loading branch information
markstory committed Jan 1, 2017
1 parent d6a720b commit ea7c52b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/Http/Response.php
Expand Up @@ -402,9 +402,9 @@ class Response implements ResponseInterface
/** /**
* Reason Phrase * Reason Phrase
* *
* @var string|null * @var string
*/ */
protected $_reasonPhrase = null; protected $_reasonPhrase = 'OK';


/** /**
* Stream mode options. * Stream mode options.
Expand Down Expand Up @@ -877,7 +877,9 @@ public function statusCode($code = null)
if (!isset($this->_statusCodes[$code])) { if (!isset($this->_statusCodes[$code])) {
throw new InvalidArgumentException('Unknown status code'); throw new InvalidArgumentException('Unknown status code');
} }

if (isset($this->_statusCodes[$code])) {
$this->_reasonPhrase = $this->_statusCodes[$code];
}
$this->_status = $code; $this->_status = $code;
$this->_setContentType(); $this->_setContentType();


Expand Down
16 changes: 14 additions & 2 deletions tests/TestCase/Network/ResponseTest.php
Expand Up @@ -130,18 +130,30 @@ public function testWithCharset()
/** /**
* Tests the statusCode method * Tests the statusCode method
* *
* @expectedException \InvalidArgumentException
* @return void * @return void
*/ */
public function testStatusCode() public function testStatusCode()
{ {
$response = new Response(); $response = new Response();
$this->assertEquals(200, $response->statusCode()); $this->assertEquals(200, $response->statusCode());

$response->statusCode(404); $response->statusCode(404);
$this->assertEquals(404, $response->getStatusCode(), 'Sets shared state.');
$this->assertEquals(404, $response->statusCode()); $this->assertEquals(404, $response->statusCode());
$this->assertEquals('Not Found', $response->getReasonPhrase());

$this->assertEquals(500, $response->statusCode(500)); $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); $response->statusCode(1001);
} }


Expand Down

0 comments on commit ea7c52b

Please sign in to comment.