From 17fdb9b378531727ef4aca941fcdf94b5cb096f1 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Wed, 27 Dec 2023 18:21:31 +0800 Subject: [PATCH] + Add unit test case for solution->pickAppFromSchema. --- module/solution/model.php | 13 ++++----- .../solution/test/model/pickappfromschema.php | 28 +++++++++++++++++++ module/solution/test/solution.class.php | 15 ++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100755 module/solution/test/model/pickappfromschema.php diff --git a/module/solution/model.php b/module/solution/model.php index 713b92196a..ea14885413 100644 --- a/module/solution/model.php +++ b/module/solution/model.php @@ -88,27 +88,26 @@ class solutionModel extends model } /** - * 按类别和图表从架构信息中选择应用程序。 - * Pick App from schema info by category and chart. + * 按类别和应用从配置信息中获取应用信息。 + * Pick App from schema info by category and app. * * @param object $schema * @param string $category - * @param string $chart + * @param string $app * @param object $cloudSolution * @access public * @return object|null */ - public function pickAppFromSchema(object $schema, string $category, string $chart, object $cloudSolution): object|null + public function pickAppFromSchema(object $schema, string $category, string $app, object $cloudSolution): object|null { $categoryList = helper::arrayColumn($schema->category, null, 'name'); $appGroup = zget($categoryList, $category, array()); foreach($appGroup->choices as $appInSchema) { + if($appInSchema->name != $app) continue; - if($appInSchema->name != $chart) continue; - - $appInfo = zget($cloudSolution->apps, $chart); + $appInfo = zget($cloudSolution->apps, $app); $appInfo->version = $appInSchema->version; $appInfo->app_version = $appInSchema->app_version; $appInfo->status = 'waiting'; diff --git a/module/solution/test/model/pickappfromschema.php b/module/solution/test/model/pickappfromschema.php new file mode 100755 index 0000000000..81dc399a95 --- /dev/null +++ b/module/solution/test/model/pickappfromschema.php @@ -0,0 +1,28 @@ +#!/usr/bin/env php +pickAppFromSchema(); +timeout=0 +cid=1 + +- 类别和应用不对应 @0 +- 类别和应用对应 + - 属性id @58 + - 属性alias @GitLab + - 属性status @waiting + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/solution.class.php'; + +zdTable('user')->gen(5); +zdTable('solution')->config('solution')->gen(0); +zdTable('instance')->config('instance')->gen(0); + +$solutionModel = new solutionTest(); +r($solutionModel->pickAppFromSchemaTest('git', 'gitee')) && p() && e('0'); // 类别和应用不对应 + +r($solutionModel->pickAppFromSchemaTest('git', 'gitlab')) && p('id,alias,status') && e('58,GitLab,waiting'); // 类别和应用对应 \ No newline at end of file diff --git a/module/solution/test/solution.class.php b/module/solution/test/solution.class.php index 9420fd33b9..57c3a66d4f 100644 --- a/module/solution/test/solution.class.php +++ b/module/solution/test/solution.class.php @@ -12,6 +12,7 @@ declare(strict_types=1); */ class solutionTest { + private $objectModel; public function __construct() { su('admin'); @@ -118,4 +119,18 @@ class solutionTest foreach($postData as $key => $value) $app->post->set($key, ''); return $solution; } + + /** + * Test pickAppFromSchema method. + * + * @param string $category + * @param string $application + * @access public + * @return object|null + */ + public function pickAppFromSchemaTest(string $category, string $application): object|null + { + list($cloudSolution, $components) = $this->initCreateData(); + return $this->objectModel->pickAppFromSchema($components, $category, $application, $cloudSolution); + } }