* [misc] Enhance unit tests for repoModel::getImportedProjects() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-25 09:16:31 +08:00
co-authored by Claude
parent 767b1a9307
commit ee3f8b4970
+38 -11
View File
@@ -1,23 +1,50 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
su('admin');
/**
title=测试 repoModel->getImportedProjects();
title=测试 repoModel::getImportedProjects();
timeout=0
cid=1
cid=0
- 查询已关联的版本库服务器ID为1的版本库列表属性1 @1
- 查询未关联的版本库服务器ID为2的版本库列表,结果应该为空属性1 @0
- 期望返回3个项目 @3
- 期望返回空数组 @0
- 期望返回空数组 @0
- 期望返回空数组 @0
- 期望返回空数组 @0
*/
zenData('repo')->loadYaml('repo')->gen(4);
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
$repo = $tester->loadModel('repo');
// 准备测试数据
$table = zenData('repo');
$table->id->range('1-10');
$table->product->range('1,2,1,2,1');
$table->name->range('repo1,repo2,repo3,repo4,repo5');
$table->serviceHost->range('1,1,2,3,1');
$table->serviceProject->range('100,200,300,400,500');
$table->deleted->range('0');
$table->gen(5);
r($repo->getImportedProjects(1)) && p('1') && e('1'); // 查询已关联的版本库服务器ID为1的版本库列表
r($repo->getImportedProjects(2)) && p('1') && e('0'); // 查询未关联的版本库服务器ID为2的版本库列表,结果应该为空
// 用户登录
su('admin');
// 创建测试实例
$repoTest = new repoTest();
// 测试步骤1:正常查询存在版本库的服务器ID为1
r(count($repoTest->getImportedProjectsTest(1))) && p() && e('3'); // 期望返回3个项目
// 测试步骤2:查询不存在版本库的服务器ID
r(count($repoTest->getImportedProjectsTest(999))) && p() && e('0'); // 期望返回空数组
// 测试步骤3:边界值测试服务器ID为0
r(count($repoTest->getImportedProjectsTest(0))) && p() && e('0'); // 期望返回空数组
// 测试步骤4:负数服务器ID测试
r(count($repoTest->getImportedProjectsTest(-1))) && p() && e('0'); // 期望返回空数组
// 测试步骤5:超大服务器ID测试
r(count($repoTest->getImportedProjectsTest(999999))) && p() && e('0'); // 期望返回空数组