File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed 
src/Illuminate/Http/Client Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 33namespace  Illuminate \Http \Client ;
44
55use  ArrayAccess ;
6+ use  GuzzleHttp \Psr7 \StreamWrapper ;
67use  Illuminate \Support \Collection ;
78use  Illuminate \Support \Traits \Macroable ;
89use  LogicException ;
@@ -104,6 +105,18 @@ public function collect($key = null)
104105        return  Collection::make ($ this json ($ key
105106    }
106107
108+     /** 
109+      * Get the body of the response as a PHP resource. 
110+      * 
111+      * @return resource 
112+      * 
113+      * @throws \InvalidArgumentException 
114+      */ 
115+     public  function  resource ()
116+     {
117+         return  StreamWrapper::getResource ($ this response ->getBody ());
118+     }
119+ 
107120    /** 
108121     * Get a header from the response. 
109122     * 
Original file line number Diff line number Diff line change @@ -327,6 +327,18 @@ public function testResponseObjectAsObject()
327327        $ this assertSame ('bar ' , $ responseobject ()->result ->foo );
328328    }
329329
330+     public  function  testResponseCanBeReturnedAsResource ()
331+     {
332+         $ this factory ->fake ([
333+             '* '  => ['result '  => ['foo '  => 'bar ' ]],
334+         ]);
335+ 
336+         $ response$ this factory ->get ('http://foo.com/api ' );
337+ 
338+         $ this assertIsResource ($ responseresource ());
339+         $ this assertSame ('{"result":{"foo":"bar"}} ' , stream_get_contents ($ responseresource ()));
340+     }
341+ 
330342    public  function  testResponseCanBeReturnedAsCollection ()
331343    {
332344        $ this factory ->fake ([
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments