/** * @author Andreas Glaser */ public function testGetByPath() { $testArray = ['index1' => 'Hey There', 'index2' => 'This is great', 'index3' => ['index4' => 'Cooool', 'index5' => new \stdClass(), 'abc' => ['great']]]; $this->assertEquals('Hey There', ArrayHelper::getByPath($testArray, 'index1')); $this->assertInstanceOf('\\stdClass', ArrayHelper::getByPath($testArray, 'index3.index5')); $this->assertEquals('great', ArrayHelper::getByPath($testArray, 'index3.abc.0')); $this->assertEquals('great', ArrayHelper::getByPath($testArray, 'index3:abc:0', false, null, ':')); $this->assertNull(ArrayHelper::getByPath($testArray, 'wrong-index')); $this->assertFalse(ArrayHelper::getByPath($testArray, 'wrong-index', false, false)); $this->setExpectedException('\\RuntimeException', 'Array index "wrong-key" does not exist'); ArrayHelper::getByPath($testArray, 'wrong-key', true); }