+ [misc] Add unit tests for aiModel::isAssoc() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:06:08 +08:00
co-authored by Claude
parent ed7f2746e6
commit 3291ec79f0
2 changed files with 46 additions and 0 deletions
+19
View File
@@ -1043,4 +1043,23 @@ class aiTest
return $result;
}
/**
* Test isAssoc method.
*
* @param array $array
* @access public
* @return mixed
*/
public function isAssocTest($array = null)
{
/* Using reflection to call private static method */
$reflection = new ReflectionClass($this->objectModel);
$method = $reflection->getMethod('isAssoc');
$method->setAccessible(true);
$result = $method->invoke(null, $array);
if(dao::isError()) return dao::getError();
return $result;
}
}
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
/**
title=测试 aiModel::isAssoc();
timeout=0
cid=0
- 步骤1:索引数组 @0
- 步骤2:关联数组 @1
- 步骤3:空数组 @0
- 步骤4:混合键数组 @1
- 步骤5:非连续数字键 @1
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/ai.unittest.class.php';
$aiTest = new aiTest();
r($aiTest->isAssocTest(array(0, 1, 2))) && p() && e('0'); // 步骤1:索引数组
r($aiTest->isAssocTest(array('name' => 'test', 'id' => 1))) && p() && e('1'); // 步骤2:关联数组
r($aiTest->isAssocTest(array())) && p() && e('0'); // 步骤3:空数组
r($aiTest->isAssocTest(array(0 => 'a', 'key' => 'b'))) && p() && e('1'); // 步骤4:混合键数组
r($aiTest->isAssocTest(array(1 => 'first', 3 => 'third'))) && p() && e('1'); // 步骤5:非连续数字键