Skip to content

Commit e4dee68

Browse files
committed
Revert "Remove test that wasn't reverted properly."
This reverts commit 288a307.
1 parent 1482be1 commit e4dee68

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ public function testHandleException()
147147
$this->assertContains('was not found', '' . $result->getBody());
148148
}
149149

150+
/**
151+
* Test rendering an error page holds onto the original request.
152+
*
153+
* @return void
154+
*/
155+
public function testHandleExceptionPreserveRequest()
156+
{
157+
$request = ServerRequestFactory::fromGlobals();
158+
$request = $request->withHeader('Accept', 'application/json');
159+
160+
$response = new Response();
161+
$middleware = new ErrorHandlerMiddleware();
162+
$next = function ($req, $res) {
163+
throw new \Cake\Http\Exception\NotFoundException('whoops');
164+
};
165+
$result = $middleware($request, $response, $next);
166+
$this->assertInstanceOf('Cake\Http\Response', $result);
167+
$this->assertNotSame($result, $response);
168+
$this->assertEquals(404, $result->getStatusCode());
169+
$this->assertContains('"message": "whoops"', '' . $result->getBody());
170+
$this->assertEquals('application/json; charset=UTF-8', $result->getHeaderLine('Content-type'));
171+
}
172+
150173
/**
151174
* Test handling PHP 7's Error instance.
152175
*

0 commit comments

Comments
 (0)