File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
tests/TestCase/Error/Middleware Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,29 @@ public function testHandleException()
147
147
$ this ->assertContains ('was not found ' , '' . $ result ->getBody ());
148
148
}
149
149
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
+
150
173
/**
151
174
* Test handling PHP 7's Error instance.
152
175
*
You can’t perform that action at this time.
0 commit comments