I am able to mock text files of any size and images of any resolution.
But for my tests I need images of any resolution and simultaneously of any file size (e.g.: 800x600px and 100 MB) as well as other file formats like PDFs.
When I use LargFileContent
the mimetype becomes text/plain
.
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\content\LargeFileContent;
use Illuminate\Http\UploadedFile
function createImageUploadFile()
{
$root = vfsStream::setup(
sys_get_temp_dir()
);
$virtualFile = vfsStream::newFile('testFile.jpg')
->withContent(LargeFileContent::withMegabytes(100))
->at($root);
// This sets the right mimetype but overwrites the file size
// imagejpeg(
// imagecreate(800, 600),
// $virtualFile->url()
// );
return new UploadedFile(
$virtualFile->url(),
null,
//mime_content_type($file->url()),
'image/jpeg', // no impact, remains a text/plain
null,
null,
true
);
}
How can I generate any type of file (mimetype) of any size and images (png,jpg) of any dimensions and file sizes?