* Modify holidayModel::updateTaskRealDuration, and modify its unit test.

This commit is contained in:
liumengyi
2023-12-05 08:48:40 +08:00
parent f76fc5fe81
commit 8dd9bd5e98
4 changed files with 64 additions and 10 deletions
+3 -2
View File
@@ -382,6 +382,7 @@ class holidayModel extends model
}
/**
* 更新任务的实际工期。
* Update task real duration.
*
* @param string $beginDate
@@ -389,7 +390,7 @@ class holidayModel extends model
* @access public
* @return void
*/
public function updateTaskRealDuration($beginDate, $endDate)
public function updateTaskRealDuration(string $beginDate, string $endDate): void
{
$updateTaskList = $this->dao->select('id, realStarted, finishedDate')
->from(TABLE_TASK)
@@ -401,7 +402,7 @@ class holidayModel extends model
foreach($updateTaskList as $task)
{
$realDuration = $this->getActualWorkingDays($task->realStarted, date('Y-m-d',strtotime($task->finishedDate)));
$realDuration = $this->getActualWorkingDays($task->realStarted, date('Y-m-d', $task->finishedDate ? strtotime($task->finishedDate) : time()));
$realDuration = count($realDuration);
$this->dao->update(TABLE_TASK)->set('realDuration')->eq($realDuration)->where('id')->eq($task->id)->exec();
+12 -8
View File
@@ -309,7 +309,7 @@ class holidayTest
* Test update task plan duration.
*
* @param int $testTaskID
* @param int $holiday
* @param int $holidayID
* @param bool $updateDuration
* @access public
* @return int|array
@@ -332,20 +332,24 @@ class holidayTest
}
/**
* Test updateTaskRealDuration method.
* 测试更新任务实际工期。
* Test update task real duration.
*
* @param int $testTaskID
* @param object $holiday
* @param int $holidayID
* @param bool $updateDuration
* @access public
* @return int
* @return int|array
*/
public function updateTaskRealDurationTest($testTaskID, $holidayID)
public function updateTaskRealDurationTest(int $testTaskID, int $holidayID, bool $updateDuration): int|array
{
global $tester;
$holiday = $tester->dao->select('*')->from(TABLE_HOLIDAY)->where('id')->eq($holidayID)->fetch();
$this->objectModel->updateTaskRealDuration($holiday->begin, $holiday->end);
if($updateDuration)
{
$holiday = $tester->dao->select('*')->from(TABLE_HOLIDAY)->where('id')->eq($holidayID)->fetch();
$this->objectModel->updateTaskRealDuration($holiday->begin, $holiday->end);
}
$task = $tester->dao->select('*')->from(TABLE_TASK)->where('id')->eq($testTaskID)->fetch();
+39
View File
@@ -0,0 +1,39 @@
#!/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('task')->config('task')->gen(10);
zdTable('user')->gen(1);
su('admin');
/**
title=测试 holidayModel->updateTaskRealDurationTest();
cid=1
pid=1
*/
$holiday = new holidayTest();
$holidayIdList = array(10, 5, 1);
$taskIdList = array(1, 2, 3);
$updateDuration = array(true, false);
$holiday = new holidayTest();
r($holiday->updateTaskRealDurationTest($taskIdList[0], $holidayIdList[0], $updateDuration[0])) && p() && e('1'); //测试插入id为 10 的节假日时任务 1 任务的计划工期
r($holiday->updateTaskRealDurationTest($taskIdList[1], $holidayIdList[0], $updateDuration[1])) && p() && e('1'); //测试插入id为 10 的节假日时任务 2 任务的计划工期
r($holiday->updateTaskRealDurationTest($taskIdList[2], $holidayIdList[0], $updateDuration[1])) && p() && e('6'); //测试插入id为 10 的节假日时任务 3 任务的计划工期
r($holiday->updateTaskRealDurationTest($taskIdList[0], $holidayIdList[1], $updateDuration[0])) && p() && e('1'); //测试插入id为 5 的节假日时任务 1 任务的计划工期
r($holiday->updateTaskRealDurationTest($taskIdList[1], $holidayIdList[1], $updateDuration[1])) && p() && e('5'); //测试插入id为 5 的节假日时任务 2 任务的计划工期
r($holiday->updateTaskRealDurationTest($taskIdList[2], $holidayIdList[1], $updateDuration[1])) && p() && e('6'); //测试插入id为 5 的节假日时任务 3 任务的计划工期
r($holiday->updateTaskRealDurationTest($taskIdList[0], $holidayIdList[2], $updateDuration[0])) && p() && e('6'); //测试插入id为 5 的节假日时任务 1 任务的计划工期
r($holiday->updateTaskRealDurationTest($taskIdList[1], $holidayIdList[2], $updateDuration[1])) && p() && e('5'); //测试插入id为 5 的节假日时任务 2 任务的计划工期
r($holiday->updateTaskRealDurationTest($taskIdList[2], $holidayIdList[2], $updateDuration[1])) && p() && e('6'); //测试插入id为 5 的节假日时任务 3 任务的计划工期
+10
View File
@@ -13,3 +13,13 @@ fields:
type: timestamp
format: "YY/MM/DD"
postfix: "\t"
- field: realStarted
range: "(-5w)-(+1w):5D"
type: timestamp
format: "YY/MM/DD"
postfix: "\t"
- field: finishedDate
range: "(-4w)-(+2w):5D"
type: timestamp
format: "YY/MM/DD"
postfix: "\t"