Zini

phpunit file upload: size 0 (zero)

Posted 7 months ago by Zini

My test makes a post request:

// FileUploadTest.php
$this->post(
    'uri',
    ['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.

Reply to

Use Markdown with GitHub-flavored code blocks.