【问题标题】:Storage fake with factory laravel使用工厂 laravel 存储假货
【发布时间】:2019-10-07 08:24:39
【问题描述】:

我正在尝试在删除中使用存储假,但我不知道如何使用工厂模拟上传文件。我的测试:

 $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)
];

});

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:
    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']);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-24
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多