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

Commit c2caef4

Browse files
committed
Merge branch 'hotfix/476'
Close #476
2 parents cb9b006 + 19f34d7 commit c2caef4

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ All notable changes to this project will be documented in this file, in reverse
2525

2626
### Fixed
2727

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

3032
## 2.0.2 - 2017-03-13
3133

src/Middleware/WhoopsErrorResponseGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Whoops\Handler\PrettyPageHandler;
1515
use Whoops\Run;
1616
use Whoops\RunInterface;
17+
use Zend\Stratigility\Utils;
1718

1819
class WhoopsErrorResponseGenerator
1920
{
@@ -70,6 +71,8 @@ public function __invoke($e, ServerRequestInterface $request, ResponseInterface
7071
}
7172
}
7273

74+
$response = $response->withStatus(Utils::getStatusCode($e, $response));
75+
7376
$response
7477
->getBody()
7578
->write($this->whoops->handleException($e));

test/Middleware/WhoopsErrorResponseGeneratorTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace ZendTest\Expressive\Middleware;
99

10+
use Fig\Http\Message\StatusCodeInterface as StatusCode;
1011
use PHPUnit\Framework\TestCase;
1112
use Prophecy\Prophecy\ObjectProphecy;
1213
use Psr\Http\Message\ResponseInterface;
@@ -58,7 +59,9 @@ public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
5859
$this->request->getAttribute('originalUri', false)->shouldNotBeCalled();
5960
$this->request->getAttribute('originalRequest', false)->shouldNotBeCalled();
6061

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

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

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

7376
public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
7477
{
75-
$error = new RuntimeException();
78+
$error = new RuntimeException('STATUS_INTERNAL_SERVER_ERROR', StatusCode::STATUS_INTERNAL_SERVER_ERROR);
7679

7780
$handler = $this->prophesize(PrettyPageHandler::class);
7881
$handler
@@ -101,6 +104,8 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
101104
$this->request->getQueryParams()->willReturn([]);
102105
$this->request->getParsedBody()->willReturn([]);
103106

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

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

116121
public function testJsonContentTypeResponseWithJsonResponseHandler()
117122
{
118-
$error = new RuntimeException();
123+
$error = new RuntimeException('STATUS_NOT_IMPLEMENTED', StatusCode::STATUS_NOT_IMPLEMENTED);
119124

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

@@ -137,6 +142,8 @@ public function testJsonContentTypeResponseWithJsonResponseHandler()
137142
$this->request->getParsedBody()->willReturn([]);
138143

139144
$this->response->withHeader('Content-Type', 'application/json')->will([$this->response, 'reveal']);
145+
$this->response->withStatus(StatusCode::STATUS_NOT_IMPLEMENTED)->will([$this->response, 'reveal']);
146+
$this->response->getStatusCode()->willReturn(StatusCode::STATUS_NOT_IMPLEMENTED);
140147
$this->response->getBody()->will([$this->stream, 'reveal']);
141148

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

0 commit comments

Comments
 (0)