/** * Tests PFXUtils::initNestedArrays(). */ public function testInitNestedArrays() { $expected = array('foo' => array('bar' => null)); $nestedArrays = array(); PFXUtils::initNestedArrays(array('foo', 'bar'), $nestedArrays); $this->assertEquals($expected, $nestedArrays); // We can add a key to an existing array $expected['bar'] = array('baz' => null); PFXUtils::initNestedArrays(array('bar', 'baz'), $nestedArrays); $this->assertEquals($expected, $nestedArrays); /* The addition can be done deeper, and with an arbitrary deepest element. */ $expected['foo']['baz'] = array('zab' => new stdClass()); PFXUtils::initNestedArrays(array('baz', 'zab'), $expected['foo'], new stdClass()); /* It can also be used to initialize a single element although that's silly. */ $nestedArrays = array(); $expected = array(0 => array('foo' => 'bar', 'baz' => array(1, 2, 3))); PFXUtils::initNestedArrays(array(0), $nestedArrays, array('foo' => 'bar', 'baz' => array(1, 2, 3))); $this->assertEquals($expected, $nestedArrays); }