* Test getByID function.

This commit is contained in:
daitingting
2023-12-27 03:27:14 +00:00
parent 21fef82f16
commit 5397c980d2
2 changed files with 57 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env php
<?php
/**
title=测试 zahostModel->getByID();
timeout=0
cid=1
- 查询 ID 为 1 的主机
- 属性id @1
- 属性name @宿主机1
- 属性type @zahost
- 查询 ID 为 2 不存在的主机 @0
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/zahost.class.php';
su('admin');
$host = zdTable('host');
$host->type->range('zahost');
$host->name->range('宿主机1');
$host->gen(1);
$zahost = new zahostTest();
$hostIDList = array('1', '2');
r($zahost->getByIDTest($hostIDList[0])) && p('id,name,type') && e('1,宿主机1,zahost'); //查询 ID 为 1 的主机
r($zahost->getByIDTest($hostIDList[1])) && p('') && e('0'); //查询 ID 为 2 不存在的主机
+25
View File
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
class zahostTest
{
public function __construct()
{
global $tester;
$this->objectModel = $tester->loadModel('zahost');
}
/**
* 测试根据编号获取主机信息。
* Get by id test.
*
* @param int $zahostID
* @access public
* @return array|object
*/
public function getByIDTest(int $zahostID): array|object
{
$zahost = $this->objectModel->getByID($zahostID);
if(dao::isError()) return dao::getError();
return $zahost;
}
}