@@ -299,13 +299,15 @@ public function testAssertCookieExpired()
299299
300300 public function testGetJSON ()
301301 {
302- $ this ->getTestResponse (['foo ' => 'bar ' ]);
303- $ formatter = Services::format ()->getFormatter ('application/json ' );
302+ $ data = ['foo ' => 'bar ' ];
303+ $ this ->getTestResponse ('' );
304+ $ this ->response ->setJSON ($ data , true );
304305
305- $ this ->assertSame ($ formatter ->format (['foo ' => 'bar ' ]), $ this ->testResponse ->getJSON ());
306+ $ formatter = Services::format ()->getFormatter ('application/json ' );
307+ $ this ->assertSame ($ formatter ->format ($ data ), $ this ->testResponse ->getJSON ());
306308 }
307309
308- public function testEmptyJSON ()
310+ public function testGetJSONEmptyJSON ()
309311 {
310312 $ this ->getTestResponse ('<h1>Hello World</h1> ' );
311313 $ this ->response ->setJSON ('' , true );
@@ -314,7 +316,7 @@ public function testEmptyJSON()
314316 $ this ->assertSame ('"" ' , $ this ->testResponse ->getJSON ());
315317 }
316318
317- public function testFalseJSON ()
319+ public function testGetJSONFalseJSON ()
318320 {
319321 $ this ->getTestResponse ('<h1>Hello World</h1> ' );
320322 $ this ->response ->setJSON (false , true );
@@ -323,7 +325,7 @@ public function testFalseJSON()
323325 $ this ->assertSame ('false ' , $ this ->testResponse ->getJSON ());
324326 }
325327
326- public function testTrueJSON ()
328+ public function testGetJSONTrueJSON ()
327329 {
328330 $ this ->getTestResponse ('<h1>Hello World</h1> ' );
329331 $ this ->response ->setJSON (true , true );
@@ -332,7 +334,7 @@ public function testTrueJSON()
332334 $ this ->assertSame ('true ' , $ this ->testResponse ->getJSON ());
333335 }
334336
335- public function testInvalidJSON ()
337+ public function testGetJSONInvalidJSON ()
336338 {
337339 $ tmp = ' test " case ' ;
338340 $ this ->getTestResponse ('<h1>Hello World</h1> ' );
@@ -344,30 +346,36 @@ public function testInvalidJSON()
344346
345347 public function testGetXML ()
346348 {
347- $ this ->getTestResponse (['foo ' => 'bar ' ]);
348- $ formatter = Services::format ()->getFormatter ('application/xml ' );
349+ $ data = ['foo ' => 'bar ' ];
350+ $ this ->getTestResponse ('' );
351+ $ this ->response ->setXML ($ data );
349352
350- $ this ->assertSame ($ formatter ->format (['foo ' => 'bar ' ]), $ this ->testResponse ->getXML ());
353+ $ formatter = Services::format ()->getFormatter ('application/xml ' );
354+ $ this ->assertSame ($ formatter ->format ($ data ), $ this ->testResponse ->getXML ());
351355 }
352356
353- public function testJsonFragment ()
357+ public function testAssertJSONFragment ()
354358 {
355- $ this -> getTestResponse ( [
359+ $ data = [
356360 'config ' => [
357361 'key-a ' ,
358362 'key-b ' ,
359363 ],
360- ]);
364+ ];
365+ $ this ->getTestResponse ('' );
366+ $ this ->response ->setJSON ($ data , true );
361367
362368 $ this ->testResponse ->assertJSONFragment (['config ' => ['key-a ' ]]);
363369 $ this ->testResponse ->assertJSONFragment (['config ' => ['key-a ' ]], true );
364370 }
365371
366372 public function testAssertJSONFragmentFollowingAssertArraySubset ()
367373 {
368- $ this -> getTestResponse ( [
374+ $ data = [
369375 'config ' => '124 ' ,
370- ]);
376+ ];
377+ $ this ->getTestResponse ('' );
378+ $ this ->response ->setJSON ($ data , true );
371379
372380 $ this ->testResponse ->assertJSONFragment (['config ' => 124 ]); // must fail on strict
373381 $ this ->testResponse ->assertJSONFragment (['config ' => '124 ' ], true );
@@ -383,36 +391,50 @@ public function testAssertJSONFragmentFailsGracefullyWhenNotGivenJson()
383391 $ this ->testResponse ->assertJSONFragment (['foo ' => 'bar ' ]);
384392 }
385393
386- public function testJsonExact ()
394+ public function testAssertJsonExactArray ()
387395 {
388396 $ data = [
389397 'config ' => [
390398 'key-a ' ,
391399 'key-b ' ,
392400 ],
393401 ];
402+ $ this ->getTestResponse ('' );
403+ $ this ->response ->setJSON ($ data , true );
404+
405+ $ this ->testResponse ->assertJSONExact ($ data );
406+ }
394407
395- $ this ->getTestResponse ($ data );
408+ public function testAssertJsonExactObject ()
409+ {
410+ $ data = (object ) [
411+ 'config ' => [
412+ 'key-a ' ,
413+ 'key-b ' ,
414+ ],
415+ ];
416+ $ this ->getTestResponse ('' );
417+ $ this ->response ->setJSON ($ data , true );
396418
397419 $ this ->testResponse ->assertJSONExact ($ data );
398420 }
399421
400- public function testJsonExactString ()
422+ public function testAssertJsonExactString ()
401423 {
402424 $ data = [
403425 'config ' => [
404426 'key-a ' ,
405427 'key-b ' ,
406428 ],
407429 ];
430+ $ this ->getTestResponse ('' );
431+ $ this ->response ->setJSON ($ data , true );
408432
409- $ this ->getTestResponse ($ data );
410433 $ formatter = Services::format ()->getFormatter ('application/json ' );
411-
412434 $ this ->testResponse ->assertJSONExact ($ formatter ->format ($ data ));
413435 }
414436
415- protected function getTestResponse ($ body = null , array $ responseOptions = [], array $ headers = [])
437+ protected function getTestResponse (? string $ body = null , array $ responseOptions = [], array $ headers = [])
416438 {
417439 $ this ->response = new Response (new App ());
418440 $ this ->response ->setBody ($ body );
0 commit comments