Laravel 5.3 TestCase上传文件返回null

时间:2016-10-26 03:14:56

标签: php laravel laravel-5 phpunit laravel-5.3

我是phpunit和laravel testcase的新手。我想测试上传文件并添加数据库路径。但是当我运行代码时,文件为空。以下是代码:

测试用例:

$file = new UploadedFile( 
        base_path(). "/public/upload/test.txt",
        'test.txt',
        'text/plain',
        502,
        null,
        true
    );
$posted = [];

电话:

$response = $this->call('POST', 'upload', $posted,[],['file' => $file]);

$response = $this->action( 
    'POST',
    'classname@upload',
    [],
    $posted,
    [],
    ['file' => $file]
);

控制器:

function upload(Request $request){
   dd($request->file());
}

结果:

[]

0 个答案:

没有答案