public function testGetData() { $path = 'section1/section11'; $apiTree = new SectionDefinition('section11'); $apiTree->addVariable(new VariableDefinition('acme.item1', 'string')); $subSection1 = new SectionDefinition('sub_section1'); $apiTree->addSubSection($subSection1); $subSection1->addVariable(new VariableDefinition('acme.item2', 'integer')); $subSection11 = new SectionDefinition('sub_section11'); $subSection1->addSubSection($subSection11); $subSection11->addVariable(new VariableDefinition('acme.item2', 'integer')); $subSection11->addVariable(new VariableDefinition('acme.item3', 'array')); $this->configProvider->expects($this->once())->method('getApiTree')->with($path)->will($this->returnValue($apiTree)); $this->configManager->expects($this->any())->method('get')->will($this->returnValueMap([['acme.item1', false, false, 'val1'], ['acme.item2', false, false, 123], ['acme.item3', false, false, ['val1' => 1, 'val2' => true]]])); $datetime = new \DateTime('now', new \DateTimeZone('UTC')); $this->configManager->expects($this->any())->method('getInfo')->will($this->returnValue(['createdAt' => $datetime, 'updatedAt' => $datetime])); $this->assertSame([['key' => 'acme.item1', 'type' => 'string', 'value' => 'val1', 'createdAt' => $datetime, 'updatedAt' => $datetime], ['key' => 'acme.item2', 'type' => 'integer', 'value' => 123, 'createdAt' => $datetime, 'updatedAt' => $datetime], ['key' => 'acme.item3', 'type' => 'array', 'value' => ['val1' => 1, 'val2' => true], 'createdAt' => $datetime, 'updatedAt' => $datetime]], $this->manager->getData($path)); }
/** * @param string $sectionName * @param array $tree * * @return SectionDefinition */ protected function buildApiTree($sectionName, array $tree) { $section = new SectionDefinition($sectionName); foreach ($tree as $key => $val) { if ($key === 'section') { continue; } if (!empty($val['section'])) { $section->addSubSection($this->buildApiTree($key, $val)); } else { $section->addVariable(new VariableDefinition($key, $val['type'])); } } return $section; }