public function testAddSimilarTokens() { $container = $this->makeSimilarTokensContainer(); $data = $container->getData(); $itemIancestors = array('ii' => 1, 'i' => array('iii' => 1)); $itemI = new ContainerItem(); $itemI->setValue('i'); $itemI->setPopularity(1); $itemI->setAncestors($itemIancestors); $etalon = array('i' => $itemI); $this->assertEquals($etalon, $data); }
/** * @dataProvider notIntegerDataProvider * @expectedException \InvalidArgumentException */ public function testSetPopularityFails($value) { $item = new ContainerItem(); $item->setPopularity($value); }
/** * @param array $letters * @param string $token * @param $namespace * @param bool $createIfNotExists * @return array|ContainerItem * @TODO Split this method */ protected function &getFinalDestination(array $letters, $token, $namespace, $createIfNotExists = false) { $destination =& $this->getCurrentNamespaceData($namespace); foreach ($letters as $letter) { if ($destination instanceof ContainerItem) { $destination =& $destination->getAncestors(); } $letter = mb_strtolower($letter); if (!isset($destination[$letter])) { $destination[$letter] = array(); } if (is_integer($destination[$letter])) { continue; } $destination =& $destination[$letter]; if ($createIfNotExists && is_array($destination) && key($destination) == $letter && is_integer($popularity = current($destination))) { $destination = new ContainerItem(); $destination->setValue($letter); $destination->setPopularity($popularity); $destination =& $destination->getAncestors(); } } if ($destination instanceof ContainerItem) { if (!$createIfNotExists) { $result = array($destination); return $result; } $destination =& $destination->getAncestors(); } if ($createIfNotExists && !isset($destination[$token])) { $destination[$token] = 0; } return $destination; }