public function testSetPath() { $this->assertEquals('root', ArrayUtil::setPath(null, array(), 'root')); $root = ArrayUtil::setPath(array(), array('name'), 'root'); $this->assertEquals(array('name' => 'root'), $root); $rootWithOneChild = ArrayUtil::setPath($root, array('children', 0, 'name'), 'zero'); $this->assertEquals(array('name' => 'root', 'children' => array(array('name' => 'zero'))), $rootWithOneChild); $object = (object) array('type' => 'object', 'name' => 'Bob'); $rootWithOneChildAndObject = ArrayUtil::setPath($rootWithOneChild, explode('.', 'other.object'), $object); $this->assertEquals($object, $rootWithOneChildAndObject['other']['object']); // Set a field in an object and assert that all copies of that object are the same $rootWithOneChildAndObject2 = ArrayUtil::setPath($rootWithOneChildAndObject, explode('.', 'other.object.location'), 'inside'); $this->assertEquals($rootWithOneChildAndObject, $rootWithOneChildAndObject2); $this->assertEquals($object, $rootWithOneChildAndObject2['other']['object']); $this->assertEquals('inside', ArrayUtil::getPath($rootWithOneChildAndObject2, explode('.', 'other.object.location'))); }