In my Laravel app, I have a file upload that I validate using mimetypes. (We accept several kinds of graphics files, and using the actual mimetype was the only way to ensure we correctedly validated all possible variations of those files.)
I have a test that I want to cover this functionality:
$request = [
'files' => [
1 => [
'artwork' => UploadedFile::fake()->image('mockup1.jpg'),
]
]
];
$response = $this->put(route('fileUpdate', $this->order), $request);
$response->assertStatus(302)
->assertSessionHasErrors([
'files.*.artwork'
]);
The validation rule forbids .jpg files, so the test above expects a validation error. However, in the case above, the mimetype for the UploadedFile reads as "application/octet-stream", rather than "'image/jpeg".
For the purposes of testing, is there a way to set the mimetype of an UploadedFile fake?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire