diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index dbec9ee890ed..2c0d7a08dbd3 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\View\View; use Illuminate\Support\Traits\Macroable; use PHPUnit\Framework\Assert as PHPUnit; +use Symfony\Component\HttpFoundation\StreamedResponse; use Illuminate\Foundation\Testing\Constraints\SeeInOrder; /** @@ -27,6 +28,13 @@ class TestResponse */ public $baseResponse; + /** + * The streamed content of the response. + * + * @var string + */ + protected $streamedContent; + /** * Create a new test response instance. * @@ -949,6 +957,28 @@ public function dump() dd($content); } + /** + * Get the streamed content from the response. + * + * @return string + */ + public function getStreamedContent() + { + if (! is_null($this->streamedContent)) { + return $this->streamedContent; + } + + if (! $this->baseResponse instanceof StreamedResponse) { + PHPUnit::fail('The response is not a streamed response.'); + } + + ob_start(); + + $this->sendContent(); + + return $this->streamedContent = ob_get_clean(); + } + /** * Dynamically access base response parameters. *