/** * @author Andreas Glaser */ public function testExistByPath() { $myArray = ['test' => 'Hello', 'index2' => ['index3' => ['index4' => 'XYZ', 'index5' => 'Something']]]; // test positive results $this->assertTrue(ArrayHelper::existsByPath($myArray, 'test')); $this->assertTrue(ArrayHelper::existsByPath($myArray, 'index2')); $this->assertTrue(ArrayHelper::existsByPath($myArray, 'index2.index3')); $this->assertTrue(ArrayHelper::existsByPath($myArray, 'index2.index3.index4')); $this->assertTrue(ArrayHelper::existsByPath($myArray, 'index2.index3.index5')); // test negative results $this->assertFalse(ArrayHelper::existsByPath($myArray, 'wrong-key')); $this->assertFalse(ArrayHelper::existsByPath($myArray, 'test.wrong-key')); $this->assertFalse(ArrayHelper::existsByPath($myArray, 'index2.wrong-key')); $this->assertFalse(ArrayHelper::existsByPath($myArray, 'index2.index3.wrong-key')); $this->assertFalse(ArrayHelper::existsByPath($myArray, 'index2.index3.wrong-key')); // test delimiter $this->assertTrue(ArrayHelper::existsByPath($myArray, 'test', ':')); $this->assertTrue(ArrayHelper::existsByPath($myArray, 'index2', ':')); $this->assertTrue(ArrayHelper::existsByPath($myArray, 'index2:index3', ':')); $this->assertTrue(ArrayHelper::existsByPath($myArray, 'index2:index3:index4', ':')); $this->assertTrue(ArrayHelper::existsByPath($myArray, 'index2:index3:index5', ':')); }