title: Test a streamed response
body: <p>I have the following route:</p>
  
  <pre><code>Route::get('echo',function (Request $req) {
      return response()-&gt;stream(function () use ($req) {
          echo json_encode($req-&gt;all());
      }, 200, [
          'Content-Type' =&gt; 'application/json'
      ]);
  })-&gt;name('echo');
  </code></pre>
  
  <p>For the sake of simplicity lets assume it's a simple echo response. In reality it's a very large file. The outcome in either case is the same. </p>
  
  <p>Now I want to test this route to see whether I indeed can see that json content so I've tried this:</p>
  
  <pre><code>public function testBasicTest()
  {
  
      $response = $this-&gt;get(route('echo', [
          "content"=&gt;"some content"
      ]));
      $response-&gt;assertSeeText("some content"); //Doesn't work
      $response-&gt;assertJson( [
          "content"=&gt;"some content"
      ]); //Neither does this
  }
  </code></pre>
  
  <p>I've inspected it a bit further and it appears to be because (a) the response is wrapped around a <code>TestResponse</code> (b) the response content is never streamed and (c) even if the response content were to be forcibly streamed via <code>$response-&gt;baseResponse-&gt;sendContent()</code> the actual content is echoed and not actually captured by the <code>TestResponse</code> </p>
  
  <p>In addition calling <code>$response-&gt;getContent()</code> does not work because it seems to directly call the <code>StreamedResponse::getContent()</code> which is hard-coded to return <code>false</code>. </p>
  
  <p>I have managed to have some limited success using:</p>
  
  <pre><code>ob_start();
  $response-&gt;sendContent();
  $result = ob_get_clean();
  </code></pre>
  
  <p>however this looks like a very sloppy thing to do in a unit test. </p>
  
  <p>Has anyone else encountered this before? Is it possible to test the contents of a streamed response?</p>