Try using the create method on the fake to set the size instead of the image method:
UploadedFile::fake()->create('image.jpg', 4096); //kb
I am testing file uploads and using this code just to see the effect of the size method:
use Illuminate\Http\UploadedFile;
use Illuminate\Http\Testing\File;
use Illuminate\Support\Facades\Storage;
class CreateProductTest extends TestCase
{
/** @test */
public function a_test_for_file_uploads()
{
Storage::fake('public');
// size is 91 all the time
dd(File::image('new-image.jpg')->size(500));
// size is 91
dd(UploadedFile::fake()->image('123.jpg')->size(500));
// size is 3008
dd(File::image('new-image.jpg', 2000, 500)->size(100));
}
.
.
.
.
For both FIle and UploadedFile the size() method is not working and it keeps giving me the size of 91. However when I add dimensions to the image for example 1500x1000, the size increases. So only increasing dimensions will increase the size of the image and not the size method.
Please advice
I have found that this is only adding a sizeToRoport value as a fake so that the app just sees it as a file at that size and the actual file is a 91 byte file.
In most cases when dealing with testing files, this will work just fine but if you want to assert the size of the file when it is stored (testing image optimization for example) then you need to use something like this and have an actual file with that size to reference in the tests.
Please or to participate in this conversation.