【发布时间】:2021-04-22 18:12:46
【问题描述】:
有没有办法使用 Laravels Storage::fake() 方法模拟文件?
我使用https://laravel.com/docs/5.7/mocking#storage-fake 作为我的测试的基础,它适用于上传。但是我的下载测试很难看,因为我每次都必须先运行我的上传路线,并使用模拟上传UploadedFile::fake()->image('avatar.jpg')。有没有办法跳过那部分并模拟文件直接存在于假存储系统中?
public function testAvatarUpload()
{
Storage::fake('avatars');
// This is the call I would like to change into a mocked existing uploaded file
$uploadResponse = $this->json('POST', '/avatar', [
'avatar' => UploadedFile::fake()->image('avatar.jpg')
]);
// Download the first avatar
$response = $this->get('/download/avatar/1');
$response->assertStatus(200);
}
【问题讨论】:
标签: php laravel laravel-5.6