|
13 | 13 | use Psr\Http\Message\ServerRequestInterface; |
14 | 14 | use Psr\Http\Message\StreamInterface; |
15 | 15 | use RuntimeException; |
| 16 | +use Whoops\Handler\JsonResponseHandler; |
16 | 17 | use Whoops\Handler\PrettyPageHandler; |
17 | 18 | use Whoops\Run; |
18 | 19 | use Whoops\RunInterface; |
@@ -111,4 +112,40 @@ public function testAddsRequestMetadataToWhoopsPrettyPageHandler() |
111 | 112 | $generator($error, $this->request->reveal(), $this->response->reveal()) |
112 | 113 | ); |
113 | 114 | } |
| 115 | + |
| 116 | + public function testJsonContentTypeResponseWithJsonResponseHandler() |
| 117 | + { |
| 118 | + $error = new RuntimeException(); |
| 119 | + |
| 120 | + $handler = $this->prophesize(JsonResponseHandler::class); |
| 121 | + |
| 122 | + if (method_exists(JsonResponseHandler::class, 'contentType')) { |
| 123 | + $handler->contentType()->willReturn('application/json'); |
| 124 | + } |
| 125 | + |
| 126 | + $this->whoops->getHandlers()->willReturn([$handler->reveal()]); |
| 127 | + $this->whoops->handleException($error)->willReturn('error'); |
| 128 | + |
| 129 | + $this->request->getAttribute('originalUri', false)->willReturn('https://example.com/foo'); |
| 130 | + $this->request->getAttribute('originalRequest', false)->will([$this->request, 'reveal']); |
| 131 | + $this->request->getMethod()->willReturn('POST'); |
| 132 | + $this->request->getServerParams()->willReturn(['SCRIPT_NAME' => __FILE__]); |
| 133 | + $this->request->getHeaders()->willReturn([]); |
| 134 | + $this->request->getCookieParams()->willReturn([]); |
| 135 | + $this->request->getAttributes()->willReturn([]); |
| 136 | + $this->request->getQueryParams()->willReturn([]); |
| 137 | + $this->request->getParsedBody()->willReturn([]); |
| 138 | + |
| 139 | + $this->response->withHeader('Content-Type', 'application/json')->will([$this->response, 'reveal']); |
| 140 | + $this->response->getBody()->will([$this->stream, 'reveal']); |
| 141 | + |
| 142 | + $this->stream->write('error')->shouldBeCalled(); |
| 143 | + |
| 144 | + $generator = new WhoopsErrorResponseGenerator($this->whoops->reveal()); |
| 145 | + |
| 146 | + $this->assertSame( |
| 147 | + $this->response->reveal(), |
| 148 | + $generator($error, $this->request->reveal(), $this->response->reveal()) |
| 149 | + ); |
| 150 | + } |
114 | 151 | } |
0 commit comments