* Refactor upgradeModel::isError, and add its unit test.
This commit is contained in:
@@ -2108,12 +2108,13 @@ class upgradeModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否出现错误。
|
||||
* Judge any error occurs.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isError()
|
||||
public function isError(): bool
|
||||
{
|
||||
return !empty(static::$errors);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
|
||||
title=测试 upgradeModel->isError();
|
||||
cid=1
|
||||
|
||||
- 测试 static::$errors 为 errors 时,是否有报错 @1
|
||||
- 测试 static::$errors 为 emptyErrors 时,是否有报错 @0
|
||||
|
||||
**/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/upgrade.class.php';
|
||||
|
||||
zdTable('user')->config('user')->gen(5);
|
||||
|
||||
su('admin');
|
||||
|
||||
$upgrade = new upgradeTest();
|
||||
|
||||
$errors = array('error1', 'error2', 'error3');
|
||||
$emptyErrors = array();
|
||||
r($upgrade->isErrorTest($errors)) && p() && e('1'); // 测试 static::$errors 为 errors 时,是否有报错
|
||||
r($upgrade->isErrorTest($emptyErrors)) && p() && e('0'); // 测试 static::$errors 为 emptyErrors 时,是否有报错
|
||||
@@ -191,4 +191,18 @@ class upgradeTest
|
||||
$groupPrivs = $tester->dao->select('count(1) as count')->from(TABLE_GROUPPRIV)->fetch('count');
|
||||
return "groups:{$groups},groupPrivs:{$groupPrivs}";
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试判断是否出现错误。
|
||||
* Test judge any error occurs.
|
||||
*
|
||||
* @param array $errors
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isErrorTest(array $errors): bool
|
||||
{
|
||||
$this->objectModel::$errors = $errors;
|
||||
return $this->objectModel->isError();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user