背景: 我创建了一个测试类,它在laravel 5.1中运行良好;但是在laravel 5.2中没有。这是因为文件的“test”参数丢失了。
我使用下面的代码创建文件请求:
$this->dataFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(
base_path('tests/files/datafiles/A.csv'), 'A.csv', 'text/csv', 13071, null, true
);
我使用$ this-> call()
发送$this->call('POST', '/uploadFile?token=' . $this->token, $params, [], ['file' => [$this->dataFile]], []);
我遇到的问题是,在接收端,“测试”参数来自于我们是假的:
[0] => Illuminate\Http\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => A.csv
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => text/csv
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 13071
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[pathName:SplFileInfo:private] => D:\tests/files/datafiles/A.csv
[fileName:SplFileInfo:private] => A.csv
)
答案 0 :(得分:1)
您应该使用:
\Illuminate\Http\UploadedFile
要创建上传的文件而不是:
\Symfony\Component\HttpFoundation\File\UploadedFile
有关详细信息,请参阅此答案: https://stackoverflow.com/a/37306881/1835484