VisualPHPUnit test.
No, it’s not an array.
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);
}
}
}
}
Also, output:
Debugging Output
19
So it actually works.
What?
Also, apparently $objs is not an array…
edit to clarify:
I altered testGetChildren like so:
public function testGetChildren() {
$objs = $this->objs;
//var_dump($objs);
print_r(gettype($objs));
assert('array' == gettype($objs));
and got this as a response:
NULL Warning: assert(): Assertion failed
Okay, I know the reason for the error is because the function testGetChildren has – ignoring case – the same name as the class.
So, probably it interprets the function as the constructor, which messes up the class it inherits.