private function listOfTreesToArray(DataTreeList $list) { $listName = $list->getName(); $result = [$listName => []]; foreach ($list->getChildren() as $child) { $result[$listName][] = $this->toArray($child); } return $result; }
public function testListFoTrees() { $list = new DataTreeList('list'); $list->addTree(new DataTreeElement('a', 'b')); $obtained = $this->sut->toStdObject($list); $this->assertEquals('b', $obtained->list[0]->a); $list->addTree(new DataTreeElement('a', 'b')); $obtained = $this->sut->toStdObject($list); $this->assertEquals('b', $obtained->list[1]->a); }
public function testListFoTrees() { $list = new DataTreeList('list'); $list->addTree(new DataTreeElement('a', 'b')); $obtained = $this->sut->toArray($list); $expected = ['list' => [0 => ['a' => 'b']]]; $this->assertEquals(serialize($expected), serialize($obtained)); $list->addTree(new DataTreeElement('a', 'b')); $obtained = $this->sut->toArray($list); $expected = ['list' => [0 => ['a' => 'b'], 1 => ['a' => 'b']]]; $this->assertEquals(serialize($expected), serialize($obtained)); }
public function testChildrenSameName() { $root = new DataTreeList(); $root->setName('root'); $el1 = new NodeElement('a', 'b'); $el2 = new NodeElement('a', 'b'); $root->addTree($el1); $root->addTree($el2); $expected = '{"root":[{"a":"b"},{"a":"b"}]}'; $obitained = $this->sut->buildContent($root); $this->assertEquals($expected, $obitained); }