From 912c082aa13c0d5a07a1b4ebf58a6c44a5f4e6aa Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 8 Sep 2025 03:53:02 +0800 Subject: [PATCH] + [misc] Add unit tests for cronModel::restartCron() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/cron/test/lib/cron.unittest.class.php | 24 ++++++++++++ module/cron/test/model/restartcron.php | 39 ++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 module/cron/test/model/restartcron.php diff --git a/module/cron/test/lib/cron.unittest.class.php b/module/cron/test/lib/cron.unittest.class.php index 880253ca96..5dc8cbe09f 100755 --- a/module/cron/test/lib/cron.unittest.class.php +++ b/module/cron/test/lib/cron.unittest.class.php @@ -230,4 +230,28 @@ class cronTest return $execId; } + + /** + * Restart cron test. + * + * @param mixed $execId + * @access public + * @return array + */ + public function restartCronTest($execId) + { + $this->objectModel->restartCron($execId); + + if(dao::isError()) return dao::getError(); + + // Get updated execId in config + $configAfter = $this->objectModel->dao->select('value')->from(TABLE_CONFIG) + ->where('owner')->eq('system') + ->andWhere('module')->eq('cron') + ->andWhere('section')->eq('scheduler') + ->andWhere('`key`')->eq('execId') + ->fetch('value'); + + return array('configAfter' => $configAfter); + } } diff --git a/module/cron/test/model/restartcron.php b/module/cron/test/model/restartcron.php new file mode 100755 index 0000000000..e6635f00cc --- /dev/null +++ b/module/cron/test/model/restartcron.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +dbh->exec("INSERT IGNORE INTO zt_config (owner, module, section, `key`, value) VALUES ('system', 'cron', 'scheduler', 'execId', '1000')"); +$tester->dbh->exec("INSERT IGNORE INTO zt_queue (cron, type, command, status, createdDate) VALUES (1, 'cron', 'test command', 'wait', '$oldWeekDate')"); +$tester->dbh->exec("INSERT IGNORE INTO zt_queue (cron, type, command, status, createdDate) VALUES (2, 'cron', 'test command', 'done', '$oldWeekDate')"); + +// 3. 用户登录 +su('admin'); + +// 4. 创建测试实例 +$cronTest = new cronTest(); + +// 5. 强制要求:必须包含至少5个测试步骤 +r($cronTest->restartCronTest(2001)) && p('configAfter') && e('2001'); // 步骤1:正常执行ID +r($cronTest->restartCronTest('3002')) && p('configAfter') && e('3002'); // 步骤2:字符串执行ID +r($cronTest->restartCronTest('')) && p('configAfter') && e('~~'); // 步骤3:空执行ID +r($cronTest->restartCronTest(-100)) && p('configAfter') && e('-100'); // 步骤4:负数执行ID +r($cronTest->restartCronTest(0)) && p('configAfter') && e('0'); // 步骤5:零执行ID \ No newline at end of file