I would like to test restful API test for file uploading.
I try to run:
$I->sendPOST($this->endpoint, $postData, ['file' => 'example.jpg']);
[PHPUnit_Framework_ExceptionWrapper] An uploaded file must be an array or an instance of UploadedFile.
After testing it seems to make it work we need to use
UploadedFile object as file.
$path = codecept_data_dir(); $filename = 'example-image.jpg'; // copy original test file to have at the same place after test copy($path . 'example.jpg', $path . $filename); $mime = 'image/jpeg'; $uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile($path . $filename, $filename, $mime, filesize($path . $filename)); $I->sendPOST($this->endpoint, $postData, ['file' => $uploadedFile]);