From 3fbdb39a252ebbaea3bde58b9d3749b88162d85b Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 8 Sep 2025 06:07:39 +0800 Subject: [PATCH] + [misc] Add unit tests for dimensionModel::__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 --- .../test/lib/dimension.unittest.class.php | 46 +++++++++++++++++++ module/dimension/test/model/__construct.php | 33 +++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 module/dimension/test/lib/dimension.unittest.class.php create mode 100755 module/dimension/test/model/__construct.php diff --git a/module/dimension/test/lib/dimension.unittest.class.php b/module/dimension/test/lib/dimension.unittest.class.php new file mode 100644 index 0000000000..c66d510eea --- /dev/null +++ b/module/dimension/test/lib/dimension.unittest.class.php @@ -0,0 +1,46 @@ +objectModel = $tester->loadModel('dimension'); + } + + /** + * Test __construct method. + * + * @param string $testType + * @access public + * @return object + */ + public function __constructTest(string $testType = 'normal'): object + { + $result = new stdClass(); + $dimensionModel = $this->objectModel; + + switch($testType) { + case 'parentConstructor': + $result->result = property_exists($dimensionModel, 'app') && !empty($dimensionModel->app); + break; + case 'dao': + $result->result = property_exists($dimensionModel, 'dao') && !empty($dimensionModel->dao); + break; + case 'modelInstance': + $result->result = $dimensionModel instanceof dimensionModel; + break; + case 'modelExists': + $result->result = !empty($dimensionModel); + break; + case 'className': + $result->result = get_class($dimensionModel); + break; + default: + $result->result = 'normal'; + break; + } + + return $result; + } +} \ No newline at end of file diff --git a/module/dimension/test/model/__construct.php b/module/dimension/test/model/__construct.php new file mode 100755 index 0000000000..54b1556e7e --- /dev/null +++ b/module/dimension/test/model/__construct.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +__constructTest('normal')) && p('result') && e('normal'); // 步骤1:正常构造函数调用 +r($dimensionTest->__constructTest('modelExists')) && p('result') && e('1'); // 步骤2:模型实例存在 +r($dimensionTest->__constructTest('modelInstance')) && p('result') && e('1'); // 步骤3:实例类型验证 +r($dimensionTest->__constructTest('className')) && p('result') && e('dimensionModel'); // 步骤4:类名验证 +r($dimensionTest->__constructTest('parentConstructor')) && p('result') && e('1'); // 步骤5:父类构造函数调用 \ No newline at end of file