* Refactor holidayModel::isWorkingDay, and modify its unit test.
This commit is contained in:
@@ -275,13 +275,14 @@ class holidayModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一天是否是工作日。
|
||||
* Judge if is working days.
|
||||
*
|
||||
* @param string $date
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isWorkingDay($date)
|
||||
public function isWorkingDay(string $date): bool
|
||||
{
|
||||
$record = $this->dao->select('*')->from(TABLE_HOLIDAY)
|
||||
->where('type')->eq('working')
|
||||
|
||||
@@ -233,19 +233,21 @@ class holidayTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Test isWorkingDay method.
|
||||
* 测试某天是否是工作日。
|
||||
* Test judge if is a working day.
|
||||
*
|
||||
* @param string $date
|
||||
* @param string $date
|
||||
* @access public
|
||||
* @return object
|
||||
* @return string|array
|
||||
*/
|
||||
public function isWorkingDayTest($date)
|
||||
public function isWorkingDayTest(string $date): string|array
|
||||
{
|
||||
$date = !empty($date) ? date('Y-m-d', strtotime($date)) : '0000-00-00';
|
||||
$objects = $this->objectModel->isWorkingDay($date);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
return $objects === true ? 'It is a working day' : 'It is not a working day';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/holiday.class.php';
|
||||
|
||||
zdTable('holiday')->gen(10);
|
||||
zdTable('user')->gen(1);
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
@@ -17,8 +22,8 @@ pid=1
|
||||
*/
|
||||
|
||||
$holiday = new holidayTest();
|
||||
$date = array('2022-03-01', '2022-04-09', '2002-2-2');
|
||||
$date = array('-1 month', '-1 month +3 day', '');
|
||||
|
||||
r($holiday->isWorkingDayTest($date[0])) && p() && e('0'); // 测试不是工作日
|
||||
r($holiday->isWorkingDayTest($date[1])) && p() && e('1'); // 测试是工作日
|
||||
r($holiday->isWorkingDayTest($date[2])) && p() && e('0'); // 测试日期格式不对
|
||||
r($holiday->isWorkingDayTest($date[0])) && p() && e('It is not a working day'); // 测试不是工作日
|
||||
r($holiday->isWorkingDayTest($date[1])) && p() && e('It is a working day'); // 测试是工作日
|
||||
r($holiday->isWorkingDayTest($date[2])) && p() && e('It is not a working day'); // 测试日期格式不对
|
||||
|
||||
Reference in New Issue
Block a user