* Optimize api getStructByID function and finish unit test script.
This commit is contained in:
@@ -244,11 +244,11 @@ class apiModel extends model
|
||||
/**
|
||||
* Get a struct info.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return object
|
||||
* @return object|false
|
||||
*/
|
||||
public function getStructByID($id)
|
||||
public function getStructByID(int $id): object|false
|
||||
{
|
||||
$model = $this->dao->select('*')
|
||||
->from(TABLE_APISTRUCT)
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/api.class.php';
|
||||
su('admin');
|
||||
|
||||
zdTable('apistruct')->gen(10);
|
||||
|
||||
/**
|
||||
|
||||
title=测试 apiModel->getStructByID();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
获取刚创建的数据结构 >> struct
|
||||
- 获取数据结构ID为1的数据结构。
|
||||
- 属性id @1
|
||||
- 属性name @数据接口1
|
||||
- 属性type @formData
|
||||
- 获取数据结构ID为2的数据结构。
|
||||
- 属性id @2
|
||||
- 属性name @数据接口2
|
||||
- 属性type @json
|
||||
- 获取不存在的数据结构ID为22的数据结构。
|
||||
- 属性id @0
|
||||
- 属性name @0
|
||||
- 属性type @0
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$api = new apiTest();
|
||||
$tester->loadModel('api');
|
||||
|
||||
$normalStruct = new stdclass();
|
||||
$normalStruct->name = 'struct';
|
||||
$normalStruct->type = 'formData';
|
||||
$normalStruct->attribute = '[{"field":"field1","paramsType":"string","required":true,"desc":"desc","structType":"formData","sub":1,"key":"l2u5qy3jc1se6ghigll","children":[]}]';
|
||||
$normalStruct->desc = '';
|
||||
$normalStruct->addedBy = $tester->app->user->account;
|
||||
$normalStruct->addedDate = helper::now();
|
||||
|
||||
$struct = $api->createStructTest($normalStruct, false);
|
||||
r($api->getStructByIDTest($struct->id)) && p('name') && e('struct'); //获取刚创建的数据结构
|
||||
r($tester->api->getStructByID(1)) && p('id,name,type') && e('1,数据接口1,formData'); //获取数据结构ID为1的数据结构。
|
||||
r($tester->api->getStructByID(2)) && p('id,name,type') && e('2,数据接口2,json'); //获取数据结构ID为2的数据结构。
|
||||
r($tester->api->getStructByID(22)) && p('id,name,type') && e('0,0,0'); //获取不存在的数据结构ID为22的数据结构。
|
||||
|
||||
@@ -4,16 +4,26 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
su('admin');
|
||||
|
||||
zdTable('apistruct')->gen(10);
|
||||
|
||||
/**
|
||||
|
||||
title=测试 apiModel->getStructListByLibID();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取文档目录ID为1的数据结构列表。
|
||||
- 第0条的id属性 @1
|
||||
- 第0条的name属性 @数据接口1
|
||||
- 第0条的type属性 @formData
|
||||
- 获取文档目录ID为2的数据结构列表。
|
||||
- 第0条的id属性 @2
|
||||
- 第0条的name属性 @数据接口2
|
||||
- 第0条的type属性 @json
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('api');
|
||||
|
||||
r($tester->api->getStructListByLibID(1)) && p('0:id,name,type') && e('1,数据接口1,formData'); //获取文档目录ID为1的数据结构列表。
|
||||
r($tester->api->getStructListByLibID(2)) && p('0:id,name,type') && e('2,数据接口2,formData'); //获取文档目录ID为2的数据结构列表。
|
||||
r($tester->api->getStructListByLibID(2)) && p('0:id,name,type') && e('2,数据接口2,json'); //获取文档目录ID为2的数据结构列表。
|
||||
|
||||
Reference in New Issue
Block a user