diff --git a/module/compile/test/lib/compile.unittest.class.php b/module/compile/test/lib/compile.unittest.class.php index 4d3552ac22..4267949496 100755 --- a/module/compile/test/lib/compile.unittest.class.php +++ b/module/compile/test/lib/compile.unittest.class.php @@ -285,6 +285,31 @@ class compileTest return $result; } + /** + * Test updateJobLastSyncDate method. + * + * @param int $jobID + * @param string $date + * @access public + * @return bool + */ + public function updateJobLastSyncDateTest($jobID, $date) + { + global $tester; + + // 先检查job是否存在 + $job = $tester->dao->select('id')->from(TABLE_JOB)->where('id')->eq($jobID)->fetch(); + if(!$job) return false; + + $this->objectModel->updateJobLastSyncDate($jobID, $date); + + if(dao::isError()) return dao::getError(); + + // 返回更新后的lastSyncDate值进行验证 + $result = $tester->dao->select('lastSyncDate')->from(TABLE_JOB)->where('id')->eq($jobID)->fetch('lastSyncDate'); + return $result; + } + /** * 魔术方法,调用objectModel一些比较简单的方法。 * Magic method, call some simple methods of objectModel. diff --git a/module/compile/test/tao/updatejoblastsyncdate.php b/module/compile/test/tao/updatejoblastsyncdate.php index 8b0d880b68..e5f8d8c3e0 100755 --- a/module/compile/test/tao/updatejoblastsyncdate.php +++ b/module/compile/test/tao/updatejoblastsyncdate.php @@ -4,32 +4,42 @@ declare(strict_types=1); /** -title=测试 compileModel->updateJobLastSyncDate(). +title=测试 compileTao::updateJobLastSyncDate(); timeout=0 -cid=1 +cid=0 -- 将id为1的job的lastSyncDate更新为当前时间,检查是否更新成功 @1 -- 将id为1的job的lastSyncDate更新为一天后的时间,检查是否更新成功 @1 +- 执行compile模块的updateJobLastSyncDateTest方法,参数是1, $now @2025-01-15 10:30:00 +- 执行compile模块的updateJobLastSyncDateTest方法,参数是2, $futureDate @2025-12-31 23:59:59 +- 执行compile模块的updateJobLastSyncDateTest方法,参数是3, $pastDate @2024-01-01 00:00:00 +- 执行compile模块的updateJobLastSyncDateTest方法,参数是999, $now @0 +- 执行compile模块的updateJobLastSyncDateTest方法,参数是1, '0000-00-00 00:00:00' @0000-00-00 00:00:00 */ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/lib/compile.unittest.class.php'; -zenData('job')->gen(1); +// 准备测试数据:从YAML文件加载job表配置并生成测试数据 +zendata('job')->loadYaml('job_updatejoblastsyncdate', false, 2)->gen(3); + su('admin'); $compile = new compileTest(); -$now = date('Y-m-d H:i:s'); +// 测试步骤1:更新存在的job的lastSyncDate为当前时间 +$now = '2025-01-15 10:30:00'; +r($compile->updateJobLastSyncDateTest(1, $now)) && p() && e('2025-01-15 10:30:00'); -$compile->updateJobLastSyncDate(1, $now); +// 测试步骤2:更新存在的job的lastSyncDate为未来时间 +$futureDate = '2025-12-31 23:59:59'; +r($compile->updateJobLastSyncDateTest(2, $futureDate)) && p() && e('2025-12-31 23:59:59'); -$time = $tester->dao->select('lastSyncDate')->from(TABLE_JOB)->where('id')->eq(1)->fetch('lastSyncDate'); -r($time === $now) && p() && e(1); //将id为1的job的lastSyncDate更新为当前时间,检查是否更新成功 +// 测试步骤3:更新存在的job的lastSyncDate为历史时间 +$pastDate = '2024-01-01 00:00:00'; +r($compile->updateJobLastSyncDateTest(3, $pastDate)) && p() && e('2024-01-01 00:00:00'); -$date = date('Y-m-d H:i:s', strtotime('+1 day')); -$compile->updateJobLastSyncDate(1, $date); +// 测试步骤4:更新不存在的job的lastSyncDate +r($compile->updateJobLastSyncDateTest(999, $now)) && p() && e('0'); -$time = $tester->dao->select('lastSyncDate')->from(TABLE_JOB)->where('id')->eq(1)->fetch('lastSyncDate'); -r($time === $date) && p() && e(1); //将id为1的job的lastSyncDate更新为一天后的时间,检查是否更新成功 \ No newline at end of file +// 测试步骤5:更新job的lastSyncDate为NULL值 +r($compile->updateJobLastSyncDateTest(1, '0000-00-00 00:00:00')) && p() && e('0000-00-00 00:00:00'); \ No newline at end of file diff --git a/module/compile/test/tao/yaml/job_updatejoblastsyncdate.yaml b/module/compile/test/tao/yaml/job_updatejoblastsyncdate.yaml new file mode 100644 index 0000000000..ff5fb9e615 --- /dev/null +++ b/module/compile/test/tao/yaml/job_updatejoblastsyncdate.yaml @@ -0,0 +1,54 @@ +--- +title: job数据配置 +desc: 为updateJobLastSyncDate方法测试提供job表数据 +author: Claude +version: 1.0 + +fields: +- field: id + note: job ID + range: 1-3 + +- field: name + note: job名称 + range: job1,job2,job3 + +- field: repo + note: 代码库ID + range: 1{3} + +- field: product + note: 产品ID + range: 1{3} + +- field: frame + note: 框架类型 + range: jenkins{3} + +- field: engine + note: 引擎类型 + range: jenkins{3} + +- field: autoRun + note: 自动运行 + range: 1{3} + +- field: server + note: 服务器ID + range: 1{3} + +- field: pipeline + note: 流水线配置 + range: pipeline1,pipeline2,pipeline3 + +- field: triggerType + note: 触发类型 + range: tag{3} + +- field: lastSyncDate + note: 最后同步时间 + range: '~~{3}' + +- field: deleted + note: 删除状态 + range: 0{3} \ No newline at end of file