* Refactor holidayModel::updateProjectRealDuration, and modify its unit test.
This commit is contained in:
@@ -324,6 +324,7 @@ class holidayModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试更新项目实际工期。
|
||||
* Update project real duration.
|
||||
*
|
||||
* @param string $beginDate
|
||||
@@ -331,7 +332,7 @@ class holidayModel extends model
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateProjectRealDuration($beginDate, $endDate)
|
||||
public function updateProjectRealDuration(string $beginDate, string $endDate): void
|
||||
{
|
||||
$updateProjectList = $this->dao->select('id, realBegan, realEnd')
|
||||
->from(TABLE_PROJECT)
|
||||
@@ -339,7 +340,7 @@ class holidayModel extends model
|
||||
->andWhere('type')->ne('program')
|
||||
->andwhere('realBegan', true)->between($beginDate, $endDate)
|
||||
->orWhere('realEnd')->between($beginDate, $endDate)
|
||||
->orWhere("(realBegan < '$beginDate' AND realEnd > '$endDate')")
|
||||
->orWhere("(realBegan < '{$beginDate}' AND realEnd > '{$endDate}')")
|
||||
->markRight(1)
|
||||
->fetchAll();
|
||||
|
||||
|
||||
@@ -256,6 +256,7 @@ class holidayTest
|
||||
*
|
||||
* @param int $testProjectID
|
||||
* @param int $holidayID
|
||||
* @param bool $updateDuration
|
||||
* @access public
|
||||
* @return int|array
|
||||
*/
|
||||
@@ -280,17 +281,20 @@ class holidayTest
|
||||
* Test updateProjectRealDuration method.
|
||||
*
|
||||
* @param int $testProjectID
|
||||
* @param object $holiday
|
||||
* @param int $holiday
|
||||
* @param bool $updateDuration
|
||||
* @access public
|
||||
* @return int
|
||||
* @return int|array
|
||||
*/
|
||||
public function updateProjectRealDurationTest($testProjectID, $holidayID)
|
||||
public function updateProjectRealDurationTest(int $testProjectID, int $holidayID, bool $updateDuration): int|array
|
||||
{
|
||||
global $tester;
|
||||
|
||||
$holiday = $tester->dao->select('*')->from(TABLE_HOLIDAY)->where('id')->eq($holidayID)->fetch();
|
||||
|
||||
$this->objectModel->updateProjectRealDuration($holiday->begin, $holiday->end);
|
||||
if($updateDuration)
|
||||
{
|
||||
$holiday = $tester->dao->select('*')->from(TABLE_HOLIDAY)->where('id')->eq($holidayID)->fetch();
|
||||
$this->objectModel->updateProjectRealDuration($holiday->begin, $holiday->end);
|
||||
}
|
||||
|
||||
$project = $tester->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($testProjectID)->fetch();
|
||||
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/holiday.class.php';
|
||||
include dirname(__FILE__, 2) . '/project.class.php';
|
||||
|
||||
zdTable('holiday')->gen(10);
|
||||
zdTable('project')->config('execution')->gen(5);
|
||||
zdTable('user')->gen(1);
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
@@ -11,40 +16,22 @@ title=测试 holidayModel->updateProjectRealDuration();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
测试新插入holiday1时项目的realDuration字段 >> 29
|
||||
测试新插入holiday3时项目的realDuration字段 >> 29
|
||||
测试新插入holiday99时项目的realDuration字段 >> 29
|
||||
测试新插入holiday100时项目的realDuration字段 >> 29
|
||||
|
||||
*/
|
||||
|
||||
$project = new Project();
|
||||
|
||||
$insertNewProject = array(
|
||||
'parent' => 1,
|
||||
'name' => '用于测试holiday的项目',
|
||||
'budget' => '',
|
||||
'budgetUnit' => 'CNY',
|
||||
'begin' => '2022-03-07',
|
||||
'end' => '2022-03-10',
|
||||
'realBegan' => '2022-04-01',
|
||||
'realEnd' => '2022-05-01',
|
||||
'desc' => '测试项目描述',
|
||||
'acl' => 'private',
|
||||
'whitelist' => '',
|
||||
'PM' => '',
|
||||
'products' => array(1),
|
||||
);
|
||||
|
||||
$newProject = $project->create($insertNewProject);
|
||||
$newProjectID = $newProject->id;
|
||||
|
||||
$holidayIDList = array('1', '3', '99', '100');
|
||||
$holidayIdList = array(10, 5, 1);
|
||||
$projectIdList = array(11, 61, 101);
|
||||
$updateDuration = array(true, false);
|
||||
|
||||
$holiday = new holidayTest();
|
||||
|
||||
r($holiday->updateProjectRealDurationTest($newProjectID, $holidayIDList[0])) && p() && e('29'); //测试新插入holiday1时项目的realDuration字段
|
||||
r($holiday->updateProjectRealDurationTest($newProjectID, $holidayIDList[1])) && p() && e('29'); //测试新插入holiday3时项目的realDuration字段
|
||||
r($holiday->updateProjectRealDurationTest($newProjectID, $holidayIDList[2])) && p() && e('29'); //测试新插入holiday99时项目的realDuration字段
|
||||
r($holiday->updateProjectRealDurationTest($newProjectID, $holidayIDList[3])) && p() && e('29'); //测试新插入holiday100时项目的realDuration字段
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[0], $holidayIdList[0], $updateDuration[0])) && p() && e('0'); //测试插入id为 10 的节假日时迭代 11 项目的实际工期
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[1], $holidayIdList[0], $updateDuration[1])) && p() && e('0'); //测试插入id为 10 的节假日时迭代 60 项目的实际工期
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[2], $holidayIdList[0], $updateDuration[1])) && p() && e('5'); //测试插入id为 10 的节假日时迭代 101 项目的实际工期
|
||||
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[0], $holidayIdList[1], $updateDuration[0])) && p() && e('0'); //测试插入id为 5 的节假日时迭代 11 项目的实际工期
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[1], $holidayIdList[1], $updateDuration[1])) && p() && e('6'); //测试插入id为 5 的节假日时迭代 60 项目的实际工期
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[2], $holidayIdList[1], $updateDuration[1])) && p() && e('5'); //测试插入id为 5 的节假日时迭代 101 项目的实际工期
|
||||
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[0], $holidayIdList[2], $updateDuration[0])) && p() && e('0'); //测试插入id为 5 的节假日时迭代 11 项目的实际工期
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[1], $holidayIdList[2], $updateDuration[1])) && p() && e('6'); //测试插入id为 5 的节假日时迭代 60 项目的实际工期
|
||||
r($holiday->updateProjectRealDurationTest($projectIdList[2], $holidayIdList[2], $updateDuration[1])) && p() && e('5'); //测试插入id为 5 的节假日时迭代 101 项目的实际工期
|
||||
|
||||
@@ -39,6 +39,16 @@ fields:
|
||||
type: timestamp
|
||||
format: "YY/MM/DD"
|
||||
postfix: "\t"
|
||||
- field: realBegan
|
||||
range: "(-6w)-(+1w):5D"
|
||||
type: timestamp
|
||||
format: "YY/MM/DD"
|
||||
postfix: "\t"
|
||||
- field: realEnd
|
||||
range: "(-5w)-(+2w):5D"
|
||||
type: timestamp
|
||||
format: "YY/MM/DD"
|
||||
postfix: "\t"
|
||||
- field: grade
|
||||
range: 1{4},1{5},1{6},2{6},1{6},1{5}
|
||||
- field: parent
|
||||
|
||||
Reference in New Issue
Block a user