VisualPHPUnit测试。不,它不是数组。VisualPHPUnit - 试图在获取对象的属性时获取非对象的属性
class TestGetChildren extends PHPUnit_Framework_TestCase
{
protected $objs;
protected function setUp()
{
$objs = array();
$i=0;
while ($i<20) {
$obj = (object) array (
'ID'=>$i,
'DIRID'=>0
);
if ($i>5) $obj->DIRID = $i-6;
if ($i>10) $obj->DIRID = 7;
$objs[] = $obj;
$i++;
}
$this->objs = $objs;
}
public function testGetChildren() {
$objs = $this->objs;
//var_dump($objs);
print_r(gettype($objs));
assert('array' == gettype($objs));
print_r($objs[19]->ID);
$vm = new FoldersPermissions($objs);
//$children = $vm->getChildren($vm->folders[0]);
foreach ($vm->folders as $obj) {
$children = $vm->getChildren($obj);
print_r($obj->ID."|".count($children)."\n");
// 0 is a special case, and 1 has 10 children
if (4 >= $obj->ID && 1 < $obj->ID) {
//print_r(($children));
$this->assertTrue(1 == count($children));
}
if (7 == $obj->ID){
$this->assertTrue(count($children) == 9);
}
}
}
}
此外,输出:
Debugging Output
19
所以它的实际工作。 什么?
而且,显然$ OBJ文件是不是数组...
编辑澄清: 我改变testGetChildren像这样:
public function testGetChildren() {
$objs = $this->objs;
//var_dump($objs);
print_r(gettype($objs));
assert('array' == gettype($objs));
,并得到这个作为响应:
NULL Warning:assert():断言失败
从您发布的代码$ objs * *是一个数组。 $ objs [19]是该数组的一个元素,这似乎是stdClass的一个对象。 – liquorvicar 2012-04-03 06:08:31
你会这么想,不是吗。显然它是一个NULL。奇怪的是,测试成功完成。 – Esa 2012-04-03 07:11:09