Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/476'
Browse files Browse the repository at this point in the history
Close #476
  • Loading branch information
weierophinney committed Mar 28, 2017
2 parents cb9b006 + 19f34d7 commit c2caef4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#476](https://github.com/zendframework/zend-expressive/pull/476) fixes the
`WhoopsErrorResponseGenerator` to ensure it returns a proper error status
code, instead of using a `200 OK` status.

## 2.0.2 - 2017-03-13

Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/WhoopsErrorResponseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;
use Whoops\RunInterface;
use Zend\Stratigility\Utils;

class WhoopsErrorResponseGenerator
{
Expand Down Expand Up @@ -70,6 +71,8 @@ public function __invoke($e, ServerRequestInterface $request, ResponseInterface
}
}

$response = $response->withStatus(Utils::getStatusCode($e, $response));

$response
->getBody()
->write($this->whoops->handleException($e));
Expand Down
11 changes: 9 additions & 2 deletions test/Middleware/WhoopsErrorResponseGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace ZendTest\Expressive\Middleware;

use Fig\Http\Message\StatusCodeInterface as StatusCode;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -58,7 +59,9 @@ public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
$this->request->getAttribute('originalUri', false)->shouldNotBeCalled();
$this->request->getAttribute('originalRequest', false)->shouldNotBeCalled();

$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_INTERNAL_SERVER_ERROR);

$this->stream->write('WHOOPS')->shouldBeCalled();

Expand All @@ -72,7 +75,7 @@ public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()

public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
{
$error = new RuntimeException();
$error = new RuntimeException('STATUS_INTERNAL_SERVER_ERROR', StatusCode::STATUS_INTERNAL_SERVER_ERROR);

$handler = $this->prophesize(PrettyPageHandler::class);
$handler
Expand Down Expand Up @@ -101,6 +104,8 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
$this->request->getQueryParams()->willReturn([]);
$this->request->getParsedBody()->willReturn([]);

$this->response->withStatus(StatusCode::STATUS_INTERNAL_SERVER_ERROR)->will([$this->response, 'reveal']);
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_INTERNAL_SERVER_ERROR);
$this->response->getBody()->will([$this->stream, 'reveal']);

$this->stream->write('WHOOPS')->shouldBeCalled();
Expand All @@ -115,7 +120,7 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()

public function testJsonContentTypeResponseWithJsonResponseHandler()
{
$error = new RuntimeException();
$error = new RuntimeException('STATUS_NOT_IMPLEMENTED', StatusCode::STATUS_NOT_IMPLEMENTED);

$handler = $this->prophesize(JsonResponseHandler::class);

Expand All @@ -137,6 +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_NOT_IMPLEMENTED)->will([$this->response, 'reveal']);
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_NOT_IMPLEMENTED);
$this->response->getBody()->will([$this->stream, 'reveal']);

$this->stream->write('error')->shouldBeCalled();
Expand Down

0 comments on commit c2caef4

Please sign in to comment.