How to test file upload with laravel and phpunit?

前端 未结 6 1896
名媛妹妹
名媛妹妹 2020-12-11 14:32

I\'m trying to run this functional test on my laravel controller. I would like to test image processing, but to do so I want to fake image uploading. How do I do this? I fou

6条回答
  •  借酒劲吻你
    2020-12-11 15:12

    With phpunit you can attach a file to a form by using attach() method.

    Example from lumen docs:

    public function testPhotoCanBeUploaded()
    {
        $this->visit('/upload')
             ->name('File Name', 'name')
             ->attach($absolutePathToFile, 'photo')
             ->press('Upload')
             ->see('Upload Successful!');
    }
    

提交回复
热议问题