Created
September 27, 2019 19:31
-
-
Save michaelbunch/f4b5c1949512bc52ec8d1339044c5737 to your computer and use it in GitHub Desktop.
Laravel test helper for creating a temporary file upload with contents.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\Helpers; | |
class UploadedFileTestHelper | |
{ | |
/** | |
* Create a fake file upload with the contents | |
* | |
* @param mixed $contents The contents of the temporary file | |
* @return UploadedFile | |
*/ | |
public function makeRequestFile($contents, $kilobytes = 2) | |
{ | |
$tempFile = tmpfile(); | |
fwrite($tempFile, $json); | |
fseek($tempFile, 0); | |
return UploadedFile::createFromBase( | |
tap(new \Illuminate\Http\Testing\File('request,json', $tempFile), function ($file) uses ($kilobytes) { | |
$file->sizeToReport = $kilobytes * 1024; | |
}) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment