+ [misc] Add unit tests for mrModel::__construct() method

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:06:19 +08:00
co-authored by Claude
parent 5b03700798
commit 1d537cfdd2
2 changed files with 87 additions and 0 deletions
+25
View File
@@ -432,4 +432,29 @@ class mrTest
$MR = $this->objectModel->fetchByID($MRID);
return $this->objectModel->apiAcceptMR($MR);
}
/**
* Test __construct method.
*
* @param string $appName
* @param string $rawModule
* @access public
* @return mixed
*/
public function constructTest(string $appName = '', string $rawModule = 'mr')
{
global $app;
$originalRawModule = $app->rawModule ?? '';
try {
$app->rawModule = $rawModule;
$mrModel = new mrModel($appName);
$result = $mrModel->moduleName;
$app->rawModule = $originalRawModule;
return $result;
} catch (Exception $e) {
$app->rawModule = $originalRawModule;
return 'error: ' . $e->getMessage();
}
}
}
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/env php
<?php
/**
title=测试 mrModel::__construct();
timeout=0
cid=0
- 执行mrTest模块的constructTest方法,参数是'', 'mr' @mr
- 执行mrTest模块的constructTest方法,参数是'', 'mr' @mr
- 执行mrTest模块的constructTest方法,参数是'zentao', 'mr' @mr
- 执行mrTest模块的constructTest方法,参数是'', 'pullreq' @pullreq
- 执行mrTest模块的constructTest方法,参数是'zentao', 'pullreq' @pullreq
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
class mrConstructTest
{
public function __construct()
{
global $tester;
$this->objectModel = $tester->loadModel('mr');
}
/**
* Test __construct method.
*
* @param string $appName
* @param string $rawModule
* @access public
* @return mixed
*/
public function constructTest(string $appName = '', string $rawModule = 'mr')
{
global $app;
$originalRawModule = $app->rawModule ?? '';
try {
$app->rawModule = $rawModule;
$mrModel = new mrModel($appName);
$result = $mrModel->moduleName;
$app->rawModule = $originalRawModule;
return $result;
} catch (Exception $e) {
$app->rawModule = $originalRawModule;
return 'error: ' . $e->getMessage();
}
}
}
su('admin');
$mrTest = new mrConstructTest();
r($mrTest->constructTest('', 'mr')) && p() && e('mr');
r($mrTest->constructTest('', 'mr')) && p() && e('mr');
r($mrTest->constructTest('zentao', 'mr')) && p() && e('mr');
r($mrTest->constructTest('', 'pullreq')) && p() && e('pullreq');
r($mrTest->constructTest('zentao', 'pullreq')) && p() && e('pullreq');