We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Imagine you are using streamed downloads in your Laravel controllers like this:
use App\Services\GitHub;
return response()->streamDownload(function () {
echo GitHub::api('repo')
->contents()
->readme('laravel', 'laravel')['contents'];
}, 'laravel-readme.md');
I was doing this in a project and I wanted to test it. I wanted to make sure that the response was streamed and that the content was correct.
The way I tested it was like this:
/** @test */
public function it_streams_the_download()
{
$user = User::factory()->create();
$response = $this->actingAs($user)
->get('/my-endpoint')
->assertOk();
$content = $response->streamedContent();
$this->assertEquals('The content of the file', $content);
}
Thanks for this article for the inspiration.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.