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/627'
Browse files Browse the repository at this point in the history
Close #627
Fixes #626
  • Loading branch information
weierophinney committed Jul 25, 2018
2 parents 424a5bd + af84c3a commit c6db5b1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 3.0.3 - TBD
## 3.0.3 - 2018-07-25

### Added

Expand All @@ -22,7 +22,10 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#627](https://github.com/zendframework/zend-expressive/pull/627) fixes an issue in the Whoops response generator; previously, if an error or
exception occurred in an `ErrorHandler` listener or prior to handling the pipeline,
Whoops would fail to intercept, resulting in an empty response with status 200. With
the patch, it properly intercepts and displays the errors.

## 3.0.2 - 2018-04-10

Expand Down
1 change: 0 additions & 1 deletion src/Container/WhoopsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function __invoke(ContainerInterface $container) : Whoops
$config = $config['whoops'] ?? [];

$whoops = new Whoops();
$whoops->writeToOutput(false);
$whoops->allowQuit(false);
$whoops->pushHandler($container->get('Zend\Expressive\WhoopsPageHandler'));
$this->registerJsonHandler($whoops, $config);
Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/WhoopsErrorResponseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ public function __invoke(

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

$sendOutputFlag = $this->whoops->writeToOutput();
$this->whoops->writeToOutput(false);
$response
->getBody()
->write($this->whoops->handleException($e));
$this->whoops->writeToOutput($sendOutputFlag);

return $response;
}
Expand Down
12 changes: 12 additions & 0 deletions test/Middleware/WhoopsErrorResponseGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ public function setUp()
public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
{
$error = new RuntimeException();
$sendOutputFlag = true;

$this->whoops->getHandlers()->willReturn([]);
$this->whoops->handleException($error)->willReturn('WHOOPS');
$this->whoops->writeToOutput()->willReturn($sendOutputFlag);
$this->whoops->writeToOutput(false)->shouldBeCalled();
$this->whoops->writeToOutput($sendOutputFlag)->shouldBeCalled();

// Could do more assertions here, but these will be sufficent for
// ensuring that the method for injecting metadata is never called.
Expand All @@ -83,6 +87,7 @@ public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
{
$error = new RuntimeException('STATUS_INTERNAL_SERVER_ERROR', StatusCode::STATUS_INTERNAL_SERVER_ERROR);
$sendOutputFlag = true;

$handler = $this->prophesize(PrettyPageHandler::class);
$handler
Expand All @@ -100,6 +105,9 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()

$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
$this->whoops->handleException($error)->willReturn('WHOOPS');
$this->whoops->writeToOutput()->willReturn($sendOutputFlag);
$this->whoops->writeToOutput(false)->shouldBeCalled();
$this->whoops->writeToOutput($sendOutputFlag)->shouldBeCalled();

$this->request->getAttribute('originalUri', false)->willReturn('https://example.com/foo');
$this->request->getAttribute('originalRequest', false)->will([$this->request, 'reveal']);
Expand Down Expand Up @@ -128,6 +136,7 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
public function testJsonContentTypeResponseWithJsonResponseHandler()
{
$error = new RuntimeException('STATUS_NOT_IMPLEMENTED', StatusCode::STATUS_NOT_IMPLEMENTED);
$sendOutput = true;

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

Expand All @@ -137,6 +146,9 @@ public function testJsonContentTypeResponseWithJsonResponseHandler()

$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
$this->whoops->handleException($error)->willReturn('error');
$this->whoops->writeToOutput()->willReturn($sendOutput);
$this->whoops->writeToOutput(false)->shouldBeCalled();
$this->whoops->writeToOutput($sendOutput)->shouldBeCalled();

$this->request->getAttribute('originalUri', false)->willReturn('https://example.com/foo');
$this->request->getAttribute('originalRequest', false)->will([$this->request, 'reveal']);
Expand Down

0 comments on commit c6db5b1

Please sign in to comment.