【发布时间】:2016-01-21 18:23:59
【问题描述】:
我正在尝试在我的 laravel 控制器上运行此功能测试。我想测试图像处理,但这样做我想伪造图像上传。我该怎么做呢?我在网上找到了一些例子,但似乎没有一个对我有用。这是我所拥有的:
public function testResizeMethod()
{
$this->prepareCleanDB();
$this->_createAccessableCompany();
$local_file = __DIR__ . '/test-files/large-avatar.jpg';
$uploadedFile = new Symfony\Component\HttpFoundation\File\UploadedFile(
$local_file,
'large-avatar.jpg',
'image/jpeg',
null,
null,
true
);
$values = array(
'company_id' => $this->company->id
);
$response = $this->action(
'POST',
'FileStorageController@store',
$values,
['file' => $uploadedFile]
);
$readable_response = $this->getReadableResponseObject($response);
}
但是控制器没有通过这个检查:
elseif (!Input::hasFile('file'))
{
return Response::error('No file uploaded');
}
所以不知何故,文件没有正确传递。我该怎么办?
【问题讨论】:
-
我可以看到您已将其置于测试模式。上传的文件是否大于 php.ini 中设置的最大文件大小?
-
不,不是这样,上传限制是2mb,测试文件是300kb。