/** * @author Andreas Glaser */ public function testSetByPath() { $myArray = ['test' => 'Hello', 'index2' => ['index3' => ['index4' => 'XYZ', 'index5' => 'Something']]]; $this->assertEquals(['test' => 'Bye', 'index2' => ['index3' => ['index4' => 'XYZ', 'index5' => 'Something']]], ArrayHelper::setByPath($myArray, 'test', 'Bye')); $this->assertEquals(['test' => 'Hello', 'index2' => ['index3' => ['index4' => 'XYZ', 'index5' => 'Something', 'test' => 'Cheese']]], ArrayHelper::setByPath($myArray, 'index2.index3.test', 'Cheese')); $this->setExpectedException('\\RuntimeException', 'Array index "test" exists already and is not of type "array"'); $this->assertEquals(['test' => 'Hello', 'index2' => ['index3' => ['index4' => 'XYZ', 'index5' => 'Something', 'test' => 'Cheese']]], ArrayHelper::setByPath($myArray, 'test.abc.something', 'Cheese')); }