phpunit file upload: size 0 (zero)

Posted 4 months ago by Zini

My test makes a post request:

// FileUploadTest.php
    ['file' => \Illuminate\Http\UploadedFile::fake()->image('file.jpg')->size(200)]

The controller detects the filesize:

// FileUploadController.php
if ($request->hasFile('file')) {
    \Log::debug('bytes: ' . \File::size($request->file));

When I upload a file manually, the correct size of the file would be logged. When I run a phpunit test, the size is always 0.

Any idea what is going on?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.