use*_*959 5 php tdd phpunit unit-testing file
我试图用PHPUnit和vfsStream测试move_uploaded_file和is_uploaded_file.他们总是回归虚假.
public function testShouldUploadAZipFileAndMoveIt()
{
$_FILES = array('fieldName' => array(
'name' => 'file.zip',
'type' => 'application/zip',
'tmp_name' => 'vfs://root/file.zip',
'error' => 0,
'size' => 0,
));
vfsStream::setup();
$vfsStreamFile = vfsStream::newFile('file.zip');
vfsStreamWrapper::getRoot()
->addChild($vfsStreamFile);
$vfsStreamDirectory = vfsStream::newDirectory('/destination');
vfsStreamWrapper::getRoot()
->addChild($vfsStreamDirectory);
$fileUpload = new File_Upload();
$fileUpload->upload(
vfsStream::url('root/file.zip'),
vfsStream::url('root/destination/file.zip')
);
$this->assertFileExists(vfsStream::url('root/destination/file.zip'));
}
Run Code Online (Sandbox Code Playgroud)
可能吗?我怎么做?我可以使用PHP代码发布没有表单的vfsStreamFile(或任何数据)吗?谢谢.
不move_uploaded_file,is_uploaded_file是专门为处理上传的文件而设计的。它们包括额外的安全检查,以确保文件在上传完成和控制脚本访问文件之间的时间内未被篡改。
注意:从脚本内更改文件被视为篡改。
| 归档时间: |
|
| 查看次数: |
1697 次 |
| 最近记录: |