/** * Test traverse, deep save, deep destroy */ public function testObjectTraverseACycle() { $a = new Object("TestObject"); $b = new Object("TestObject"); $c = new Object("TestObject"); $a->set("likes", array($b, "foo")); $b->set("likes", array($c, 42)); $c->set("likes", $a); $objects = array(); // collected objects $seen = array(); Object::traverse($a, $seen, function ($val) use(&$objects) { if ($val instanceof Object) { $objects[] = $val; } }); $this->assertEquals(3, count($seen)); $this->assertEquals(3, count($objects)); // now start from $c $objects = array(); // collected objects $seen = array(); Object::traverse($c, $seen, function ($val) use(&$objects) { if ($val instanceof Object) { $objects[] = $val; } }); $this->assertEquals(3, count($seen)); $this->assertEquals(3, count($objects)); }