Laravel - HTTP Tests - Testing File Uploads

The Illuminate\Http\UploadedFile class provides a fake method which may be used to generate dummy files or images for testing. This, combined with the Storage facade's fake method, greatly simplifies the testing of file uploads. For example, you may combine these two features to easily test an avatar upload form:

    
    image('avatar.jpg');
    
            $response = $this->post('/avatar', [
                'avatar' => $file,
            ]);
    
            Storage::disk('avatars')->assertExists($file->hashName());
        }
    }
	

If you would like to assert that a given file does not exist, you may use the assertMissing method provided by the Storage facade:

    
    Storage::fake('avatars');
    
    // ...
    
    Storage::disk('avatars')->assertMissing('missing.jpg');