-
Notifications
You must be signed in to change notification settings - Fork 195
Add response status code for the Whoops error handler #476
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,8 +142,8 @@ public function testJsonContentTypeResponseWithJsonResponseHandler() | |
$this->request->getParsedBody()->willReturn([]); | ||
|
||
$this->response->withHeader('Content-Type', 'application/json')->will([$this->response, 'reveal']); | ||
$this->response->withStatus(StatusCode::STATUS_INTERNAL_SERVER_ERROR)->will([$this->response, 'reveal']); | ||
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_INTERNAL_SERVER_ERROR); | ||
$this->response->withStatus(StatusCode::STATUS_IM_A_TEAPOT)->will([$this->response, 'reveal']); | ||
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_IM_A_TEAPOT); | ||
$this->response->getBody()->will([$this->stream, 'reveal']); | ||
|
||
$this->stream->write('error')->shouldBeCalled(); | ||
|
@@ -155,4 +155,25 @@ public function testJsonContentTypeResponseWithJsonResponseHandler() | |
$generator($error, $this->request->reveal(), $this->response->reveal()) | ||
); | ||
} | ||
|
||
public function testNonErrorStatusCodeIsSetTo500() | ||
{ | ||
$error = new RuntimeException(); | ||
|
||
$this->whoops->getHandlers()->willReturn([]); | ||
$this->whoops->handleException($error)->willReturn('WHOOPS'); | ||
|
||
$this->response->withStatus(StatusCode::STATUS_INTERNAL_SERVER_ERROR)->will([$this->response, 'reveal']); | ||
$this->response->getBody()->will([$this->stream, 'reveal']); | ||
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_MOVED_PERMANENTLY); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait... shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's deliberately an error code below 400 to make sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm, it doesn't make sense since the default error code is 0. So it's already converted and tested in the previous tests. |
||
|
||
$this->stream->write('WHOOPS')->shouldBeCalled(); | ||
|
||
$generator = new WhoopsErrorResponseGenerator($this->whoops->reveal()); | ||
|
||
$this->assertSame( | ||
$this->response->reveal(), | ||
$generator($error, $this->request->reveal(), $this->response->reveal()) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand this change.
$error
here is a simpleRuntimeException
, so I'd expect an internal server error. Or are you redefining the$error
somehow?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have misunderstood that... or you wanted to see changes to the default
RunTimeException
error code.