Support the ongoing development of Laravel.io →
Laravel Testing

I am testing that a file is remove after a response download as below:

UploadedFile::fake()
    ->create('test-file.xlsx')
    ->storeAs("{$dataset->id}", 'test-excel-file.xlsx'.,'datasets');

$this->get(route('datasets.export', ['dataset' => $dataset->id, 'hash' => 'test-excel-file']))
    ->assertHeader('Content-Type', 'excel.mime'))
    ->assertHeader('Content-Disposition', "attachment; filename=downloadFileName");

Storage::disk('datasets')->assertMissing("{$dataset->id}/test-excel-file.xlsx");

the code for the response is the following:

    return response()->download(
        $dataset->filePath(),
        'downloadFileName',
        [
            'Content-Type' => 'excel.mime',
            'Cache-Control' => 'cache, must-revalidate',
        ]
    )->deleteFileAfterSend(true);

i am getting this error:

Tests\Feature\SendExportGeneratedEmailTest::it_downloads_the_dataset_file
Found unexpected file at path [1/test-excel-file.xlsx].
Failed asserting that true is false.

Every assertion works except the assertMissing. The file is not being deleted, but when tested in the browser it works

hope anyone can help

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.