/** * testSetByPath * * @return void * * @covers \Windwalker\Utilities\ArrayHelper::setByPath */ public function testSetByPath() { $data = array(); // One level $return = ArrayHelper::setByPath($data, 'flower', 'sakura'); $this->assertEquals('sakura', $data['flower']); $this->assertTrue($return); // Multi-level ArrayHelper::setByPath($data, 'foo.bar', 'test'); $this->assertEquals('test', $data['foo']['bar']); // Separator ArrayHelper::setByPath($data, 'foo/bar', 'play', '/'); $this->assertEquals('play', $data['foo']['bar']); // Type ArrayHelper::setByPath($data, 'cloud/fly', 'bird', '/', 'stdClass'); $this->assertEquals('bird', $data['cloud']->fly); // False $return = ArrayHelper::setByPath($data, '', 'goo'); $this->assertFalse($return); // Fix path ArrayHelper::setByPath($data, 'double..separators', 'value'); $this->assertEquals('value', $data['double']['separators']); $this->assertExpectedException(function () { ArrayHelper::setByPath($data, 'a.b', 'c', '.', 'Non\\Exists\\Class'); }, new \InvalidArgumentException(), 'Type or class: Non\\Exists\\Class not exists'); }