From 1d537cfdd285c3bfbb418b4d85ecbab5c65c4345 Mon Sep 17 00:00:00 2001 From: liugang Date: Tue, 9 Sep 2025 01:59:05 +0800 Subject: [PATCH] + [misc] Add unit tests for mrModel::__construct() 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/mr/test/lib/mr.unittest.class.php | 25 ++++++++++ module/mr/test/model/construct.php | 62 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100755 module/mr/test/model/construct.php diff --git a/module/mr/test/lib/mr.unittest.class.php b/module/mr/test/lib/mr.unittest.class.php index bba3f63da5..883e7c034b 100755 --- a/module/mr/test/lib/mr.unittest.class.php +++ b/module/mr/test/lib/mr.unittest.class.php @@ -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(); + } + } } diff --git a/module/mr/test/model/construct.php b/module/mr/test/model/construct.php new file mode 100755 index 0000000000..8184542d3e --- /dev/null +++ b/module/mr/test/model/construct.php @@ -0,0 +1,62 @@ +#!/usr/bin/env php +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'); \ No newline at end of file