laravel - 使用工厂 laravel 存储假货
问题描述
我正在尝试在删除中使用存储假,但我不知道如何使用工厂模拟上传文件。我的测试:
$actualCategory = factory(Category::class)->create();
$this->json(
'DELETE',
'/api/category/' . $actualCategory->id
)->assertStatus(200)
->assertJsonStructure([
'success',
'data' => [
'id',
'name',
'image_code',
'updated_at',
'deleted_at',
'created_at'
]
]);
$this->assertSoftDeleted('categories', [
'id' => $actualCategory->id,
'name' => $actualCategory->name
]);
Storage::disk('categories')->assertMissing($actualCategory->image_code);
如果我对此发表评论-> json 仍在工作,而不是删除照片
我的工厂是:
$factory->define(Category::class, function (Faker $faker) {
return [
'name' => "Category {$faker->firstName}",
'image_code' => $faker->image('/tmp', 300, 300)
];
});
解决方案
class ExampleTest extends TestCase
{
public function testAlbumUpload()
{
Storage::fake('photos');
$response = $this->json('POST', '/photos', [
UploadedFile::fake()->image('photo1.jpg'),
UploadedFile::fake()->image('photo2.jpg')
]);
// Assert one or more files were stored...
Storage::disk('photos')->assertExists('photo1.jpg');
Storage::disk('photos')->assertExists(['photo1.jpg', 'photo2.jpg']);
// Assert one or more files were not stored...
Storage::disk('photos')->assertMissing('missing.jpg');
Storage::disk('photos')->assertMissing(['missing.jpg', 'non-existing.jpg']);
}
}
推荐阅读
- javascript - adobe photoshop UXP插件中的全局状态,如redux
- sas - 基于另一个数组的 SAS 数组变量名
- heroku - Heroku 机器人在它应该 24/7 运行时出现故障
- spring-data-jpa - Spring结合派生查询方法和criteriabuilder
- c++ - 返回具有指针成员的类类型对象的问题
- docker - 配置本地 Docker 容器并从另一个网络远程连接到它
- java - 使用 jcodec 生成包含多个图像的视频
- javascript - 防止在引导模式打开时触发按键事件侦听器
- web - 开发项目的管道或工作流
- java - SonarQube 显示 0% 的代码覆盖率,但 JaCoCo 报告是正确的