mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
File类改进支持单元测试
This commit is contained in:
@@ -22,14 +22,17 @@ class File extends SplFileObject
|
||||
private $error = '';
|
||||
// 文件上传命名规则
|
||||
protected $rule = 'date';
|
||||
// 单元测试
|
||||
protected $isTest;
|
||||
|
||||
// 上传文件信息
|
||||
protected $info;
|
||||
|
||||
public function __construct($filename, $info = [])
|
||||
public function __construct($filename, $info = [],$isTest=false)
|
||||
{
|
||||
parent::__construct($filename);
|
||||
$this->info = $info;
|
||||
$this->info = $info;
|
||||
$this->isTest = $isTest;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +91,9 @@ class File extends SplFileObject
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
if($this->isTest){
|
||||
return is_file($this->getRealPath());
|
||||
}
|
||||
return is_uploaded_file($this->getRealPath());
|
||||
}
|
||||
|
||||
@@ -122,7 +128,9 @@ class File extends SplFileObject
|
||||
}
|
||||
|
||||
/* 移动文件 */
|
||||
if (!move_uploaded_file($this->getRealPath(), $path . $savename)) {
|
||||
if($this->isTest){
|
||||
rename($this->getRealPath(),$path.$savename);
|
||||
} elseif (!move_uploaded_file($this->getRealPath(), $path . $savename)) {
|
||||
$this->error = '文件上传保存错误!';
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -241,11 +241,19 @@ class Input
|
||||
if (empty($val['tmp_name'])) {
|
||||
continue;
|
||||
}
|
||||
$item[$key] = new File($val['tmp_name'], $val);
|
||||
if($val instanceof File){
|
||||
$item[$key] = $val;
|
||||
}else{
|
||||
$item[$key] = new File($val['tmp_name'], $val);
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
} elseif (isset($array[$name])) {
|
||||
return new File($array[$name]['tmp_name'], $array[$name]);
|
||||
if($array[$name] instanceof File){
|
||||
return $array[$name];
|
||||
}else{
|
||||
return new File($array[$name]['tmp_name'], $array[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user