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

Commit 694eae4

Browse files
committed
Merge pull request #627 from Moln/hotfix/enable-whoops-output
`WhoopsErrorResponseGenerator` change to restore the default output of Whoops
2 parents 424a5bd + 416101f commit 694eae4

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
@@ -57,9 +57,13 @@ public function setUp()
5757
public function testWritesResultsOfWhoopsExceptionsHandlingToResponse()
5858
{
5959
$error = new RuntimeException();
60+
$sendOutput = true;
6061

6162
$this->whoops->getHandlers()->willReturn([]);
6263
$this->whoops->handleException($error)->willReturn('WHOOPS');
64+
$this->whoops->writeToOutput()->willReturn($sendOutput);
65+
$this->whoops->writeToOutput(false)->shouldBeCalled();
66+
$this->whoops->writeToOutput($sendOutput)->shouldBeCalled();
6367

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

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

101106
$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
102107
$this->whoops->handleException($error)->willReturn('WHOOPS');
108+
$this->whoops->writeToOutput()->willReturn($sendOutput);
109+
$this->whoops->writeToOutput(false)->shouldBeCalled();
110+
$this->whoops->writeToOutput($sendOutput)->shouldBeCalled();
103111

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

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

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

138147
$this->whoops->getHandlers()->willReturn([$handler->reveal()]);
139148
$this->whoops->handleException($error)->willReturn('error');
149+
$this->whoops->writeToOutput()->willReturn($sendOutput);
150+
$this->whoops->writeToOutput(false)->shouldBeCalled();
151+
$this->whoops->writeToOutput($sendOutput)->shouldBeCalled();
140152

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

0 commit comments

Comments
 (0)