public function testGetMaxKeyLength() { $testArray = array('foo' => 'hello', 'maximum' => 'not', 'this is serious business' => 'yeah', 'a' => 'b'); $testArray2 = array('a' => 'b', 'ab' => 'eeee', 'aaaaa' => 'hello', 'rock' => "n'roll"); $testArray3 = array('aaaa' => 'b', "[32mlol[0m" => 'no'); $this->integer(Vivian\Util::getMaxKeyLength($testArray))->isEqualTo(24)->integer(Vivian\Util::getMaxKeyLength($testArray2))->isEqualTo(5)->integer(Vivian\Util::getMaxKeyLength($testArray3))->isEqualTo(4); }
/** * Render a structure of type 'array' * * @param array $array * @param Structure $structure * * @return string */ private static function buildArray(array $array, Structure $structure) { $maxKeyLength = Util::getMaxKeyLength($array); $maxValueLength = Util::getMaxValueLength($array); $drawBorders = $structure->getBorder() ? true : false; $insertTab = $structure->getTab() ? true : false; if ($drawBorders) { $firstLine = self::printBorder($structure->getBorder(), $maxKeyLength, $maxValueLength); if ($insertTab) { $firstLine = $structure->getTab() . $firstLine; } } else { $firstLine = ''; } $lines = ''; foreach ($array as $key => $value) { $lines .= self::printStructureLine($key, $value, $structure, $maxKeyLength, $maxValueLength); } $lastLine = $firstLine; $result = $firstLine . $lines . $lastLine; return $result; }