How to test file upload with laravel and phpunit?

前端 未结 6 1908
名媛妹妹
名媛妹妹 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:13

    Docs for CrawlerTrait.html#method_action reads:

    Parameters
    string $method
    string $action
    array $wildcards
    array $parameters
    array $cookies
    array $files
    array $server
    string $content

    So I assume the correct call should be

    $response = $this->action(
        'POST',
        'FileStorageController@store',
        [],
        $values,
        [],
        ['file' => $uploadedFile]
    );
    

    unless it requires non-empty wildcards and cookies.

提交回复
热议问题