@@ -387,6 +387,51 @@ public function testResponseObjectAsObject()
387387 $ this ->assertSame ('bar ' , $ response ->object ()->result ->foo );
388388 }
389389
390+ public function testResponseObjectIsTappable ()
391+ {
392+ $ bar = null ;
393+ $ this ->factory ->fake ([
394+ '* ' => ['result ' => ['foo ' => 'bar ' ]],
395+ ]);
396+
397+ $ this ->factory ->get ('http://foo.com/api ' )
398+ ->tap (function (Response $ response ) use (&$ bar ) {
399+ $ bar = $ response ['result ' ]['foo ' ];
400+ });
401+
402+ $ this ->assertSame ('bar ' , $ bar );
403+ }
404+
405+ public function testResponseObjectIsMacroable ()
406+ {
407+ Response::macro ('movieFields ' , function () {
408+ return $ this ->collect ()
409+ ->mapWithKeys (fn ($ field , $ key ) => [strtolower ($ key ) => $ field ])
410+ ->toArray ();
411+ });
412+
413+ $ response = $ this ->factory ->fake ([
414+ '* ' => [
415+ 'Title ' => 'The Godfather ' ,
416+ 'Year ' => 1972 ,
417+ 'Rated ' => 'R ' ,
418+ 'Runtime ' => '175 min ' ,
419+ 'Director ' => 'Francis Ford Coppola ' ,
420+ ],
421+ ]);
422+
423+ $ response = $ this ->factory ->get ('http://www.omdbapi.com/?apikey=test_api_key&i=test_imdb_id ' );
424+
425+ $ this ->assertIsArray ($ response ->movieFields ());
426+ $ this ->assertSame ([
427+ 'title ' => 'The Godfather ' ,
428+ 'year ' => 1972 ,
429+ 'rated ' => 'R ' ,
430+ 'runtime ' => '175 min ' ,
431+ 'director ' => 'Francis Ford Coppola ' ,
432+ ], $ response ->movieFields ());
433+ }
434+
390435 public function testResponseCanBeReturnedAsResource ()
391436 {
392437 $ this ->factory ->fake ([
0 commit comments