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

Commit 416101f

Browse files
committed
Fix issue #626
1 parent 491da1e commit 416101f

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Container/WhoopsFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public function __invoke(ContainerInterface $container) : Whoops
5353
$config = $config['whoops'] ?? [];
5454

5555
$whoops = new Whoops();
56-
$whoops->writeToOutput(false);
5756
$whoops->allowQuit(false);
5857
$whoops->pushHandler($container->get('Zend\Expressive\WhoopsPageHandler'));
5958
$this->registerJsonHandler($whoops, $config);

src/Middleware/WhoopsErrorResponseGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ public function __invoke(
7979

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

82+
$sendOutput = $this->whoops->writeToOutput();
83+
$this->whoops->writeToOutput(false);
8284
$response
8385
->getBody()
8486
->write($this->whoops->handleException($e));
87+
$this->whoops->writeToOutput($sendOutput);
8588

8689
return $response;
8790
}

test/Middleware/WhoopsErrorResponseGeneratorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ public function setUp()
5555
public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
5656
{
5757
$error = new RuntimeException();
58+
$sendOutput = true;
5859

5960
$this->whoops->getHandlers()->willReturn([]);
6061
$this->whoops->handleException($error)->willReturn('WHOOPS');
62+
$this->whoops->writeToOutput()->willReturn($sendOutput);
63+
$this->whoops->writeToOutput(false)->shouldBeCalled();
64+
$this->whoops->writeToOutput($sendOutput)->shouldBeCalled();
6165

6266
// Could do more assertions here, but these will be sufficent for
6367
// ensuring that the method for injecting metadata is never called.
@@ -81,6 +85,7 @@ public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
8185
public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
8286
{
8387
$error = new RuntimeException('STATUS_INTERNAL_SERVER_ERROR', StatusCode::STATUS_INTERNAL_SERVER_ERROR);
88+
$sendOutput = true;
8489

8590
$handler = $this->prophesize(PrettyPageHandler::class);
8691
$handler
@@ -98,6 +103,9 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
98103

99104
$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
100105
$this->whoops->handleException($error)->willReturn('WHOOPS');
106+
$this->whoops->writeToOutput()->willReturn($sendOutput);
107+
$this->whoops->writeToOutput(false)->shouldBeCalled();
108+
$this->whoops->writeToOutput($sendOutput)->shouldBeCalled();
101109

102110
$this->request->getAttribute('originalUri', false)->willReturn('https://example.com/foo');
103111
$this->request->getAttribute('originalRequest', false)->will([$this->request, 'reveal']);
@@ -126,6 +134,7 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler()
126134
public function testJsonContentTypeResponseWithJsonResponseHandler()
127135
{
128136
$error = new RuntimeException('STATUS_NOT_IMPLEMENTED', StatusCode::STATUS_NOT_IMPLEMENTED);
137+
$sendOutput = true;
129138

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

@@ -135,6 +144,9 @@ public function testJsonContentTypeResponseWithJsonResponseHandler()
135144

136145
$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
137146
$this->whoops->handleException($error)->willReturn('error');
147+
$this->whoops->writeToOutput()->willReturn($sendOutput);
148+
$this->whoops->writeToOutput(false)->shouldBeCalled();
149+
$this->whoops->writeToOutput($sendOutput)->shouldBeCalled();
138150

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

0 commit comments

Comments
 (0)