我是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());
}
结果:
[]