@@ -273,7 +273,7 @@ public function testMultipleMiddleware()
273273 return $ request ->str ."bazQux " ;
274274 })->setStr ('foobar ' )->jsonify ()->uppercase ();
275275
276- $ this ->assertResponse ("GET " , "/foo " , '{"body":"FOOBARBAZQUX"} ' );
276+ $ this ->assertResponse ("GET " , "/foo " , '{"body":"FOOBARBAZQUX"} ' , 200 , ' application/json ' );
277277 }
278278
279279 /**
@@ -310,6 +310,41 @@ public function testRouteGroup()
310310 $ this ->assertResponse ("GET " , "/group/hello " , 'IM IN GROUP ' );
311311 }
312312
313+ /**
314+ * @runInSeparateProcess
315+ * @preserveGlobalState enabled
316+ */
317+ public function testResponseJson ()
318+ {
319+ $ this ->app ->get ('/anything.json ' , function () {
320+ return [
321+ 'message ' => 'hello '
322+ ];
323+ });
324+
325+ $ this ->assertResponse ("GET " , "/anything.json " , '{"message":"hello"} ' , 200 , 'application/json ' );
326+ }
327+
328+ /**
329+ * @runInSeparateProcess
330+ * @preserveGlobalState enabled
331+ */
332+ public function testMiddlewareKeepResponseToJson ()
333+ {
334+ $ this ->app ->middleware ('uppercase ' , function ($ req , $ res , $ next ) {
335+ $ next ();
336+ return strtoupper ($ res ->body );
337+ });
338+
339+ $ this ->app ->get ('/anything.json ' , function () {
340+ return [
341+ 'message ' => 'hello '
342+ ];
343+ })->uppercase ();
344+
345+ $ this ->assertResponse ("GET " , "/anything.json " , '{"MESSAGE":"HELLO"} ' , 200 , 'application/json ' );
346+ }
347+
313348 /**
314349 * @runInSeparateProcess
315350 * @preserveGlobalState enabled
@@ -427,12 +462,14 @@ protected function runAndGetResponse($method, $path)
427462 return [$ response , $ rendered ];
428463 }
429464
430- protected function assertResponse ($ method , $ path , $ assert_body , $ assert_status = 200 )
465+ protected function assertResponse ($ method , $ path , $ assert_body , $ assert_status = 200 , $ assert_content_type = ' text/html ' )
431466 {
467+ $ at = $ method .' ' .$ path .' => ' .$ assert_body ;
432468 list ($ response , $ rendered ) = $ this ->runAndGetResponse ($ method , $ path );
433469
434- $ this ->assertEquals ($ rendered , $ assert_body );
435- $ this ->assertEquals ($ response ->getStatus (), $ assert_status );
470+ $ this ->assertEquals ($ rendered , $ assert_body , $ at );
471+ $ this ->assertEquals ($ response ->getStatus (), $ assert_status , $ at );
472+ $ this ->assertEquals ($ response ->getContentType (), $ assert_content_type , $ at );
436473 }
437474
438475}
0 commit comments