thc1967's avatar

UploadedFile::fake()->image(...) Failing in Controller Validation

My controller validation:

$validations = [
    'name' => 'required|string|min:3|max:64|unique:'.$system->getTable(),
    'file_upload' => [
        'nullable',
        'image',
        'mimetypes:image/jpeg,image/png,image/gif',
        'max:60',
    ],
];

My PHPUnit test:

...
Storage::fake('logos');
...
$item = make(System::class);

$postData = collect($item->toArray())->merge([
    'file_upload' => $file = UploadedFile::fake()->image('logo.gif', 60, 30),
]);

$this->post(route('systems.store', $postData->toArray()));
...

The result: Two messages in my session error bag:

  • The file upload must be an image.

  • The file upload must be a file of type: image/jpeg, image/png, image/gif.

Even if I pare the validations back to just file, removing image and mime:..., it still fails. It's as if UploadedFile::fake() doesn't generate a file?

0 likes
0 replies

Please or to participate in this conversation.