/** * Renders this node. * * @param string $target * @param string $title * @param string $charset * @param boolean $highlight * @param integer $lowUpperBound * @param integer $highLowerBound * @access public */ public function render($target, $title, $charset = 'ISO-8859-1', $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70) { if ($this->yui) { $template = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'file.html'); $yuiTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'yui_item.js'); } else { $template = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'file_no_yui.html'); } $i = 1; $lines = ''; $ignore = FALSE; foreach ($this->codeLines as $line) { if (strpos($line, '@codeCoverageIgnore') !== FALSE) { if (strpos($line, '@codeCoverageIgnoreStart') !== FALSE) { $ignore = TRUE; } else { if (strpos($line, '@codeCoverageIgnoreEnd') !== FALSE) { $ignore = FALSE; } } } $css = ''; if (!$ignore && isset($this->executedLines[$i])) { $count = ''; // Array: Line is executable and was executed. // count(Array) = Number of tests that hit this line. if (is_array($this->executedLines[$i])) { $color = 'lineCov'; $numTests = count($this->executedLines[$i]); $count = sprintf('%8d', $numTests); if ($this->yui) { $buffer = ''; foreach ($this->executedLines[$i] as $test) { if (!isset($test->__liHtml)) { $test->__liHtml = ''; if ($test instanceof PHPUnit_Framework_SelfDescribing) { $testName = $test->toString(); if ($test instanceof PHPUnit_Framework_TestCase) { switch ($test->getStatus()) { case PHPUnit_Runner_BaseTestRunner::STATUS_PASSED: $testCSS = ' class=\\"testPassed\\"'; break; case PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE: $testCSS = ' class=\\"testFailure\\"'; break; case PHPUnit_Runner_BaseTestRunner::STATUS_ERROR: $testCSS = ' class=\\"testError\\"'; break; case PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE: case PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED: $testCSS = ' class=\\"testIncomplete\\"'; break; default: $testCSS = ''; } } } $test->__liHtml .= sprintf('<li%s>%s</li>', $testCSS, $testName); } $buffer .= $test->__liHtml; } if ($numTests > 1) { $header = $numTests . ' tests cover'; } else { $header = '1 test covers'; } $header .= ' line ' . $i; $yuiTemplate->setVar(array('line' => $i, 'header' => $header, 'tests' => $buffer), FALSE); $this->yuiPanelJS .= $yuiTemplate->render(); } } else { if ($this->executedLines[$i] == -1) { $color = 'lineNoCov'; $count = sprintf('%8d', 0); } else { $color = 'lineDeadCode'; $count = ' '; } } $css = sprintf('<span class="%s"> %s : ', $color, $count); } $fillup = array_shift($this->codeLinesFillup); if ($fillup > 0) { $line .= str_repeat(' ', $fillup); } $lines .= sprintf('<span class="lineNum" id="container%d"><a name="%d"></a><a href="#%d" id="line%d">%8d</a> </span>%s%s%s' . "\n", $i, $i, $i, $i, $i, !empty($css) ? $css : ' : ', !$this->highlight ? htmlspecialchars($line) : $line, !empty($css) ? '</span>' : ''); $i++; } $items = ''; foreach ($this->classes as $className => $classData) { $numCalledClasses = $classData['executedLines'] > 0 ? 1 : 0; $calledClassesPercent = $numCalledClasses == 1 ? 100 : 0; $numCalledMethods = 0; $numMethods = count($classData['methods']); foreach ($classData['methods'] as $method) { if ($method['executedLines'] > 0) { $numCalledMethods++; } } $items .= $this->doRenderItem(array('name' => sprintf('<b><a href="#%d">%s</a></b>', $classData['startLine'], $className), 'numClasses' => 1, 'numCalledClasses' => $numCalledClasses, 'calledClassesPercent' => sprintf('%01.2f', $calledClassesPercent), 'numMethods' => $numMethods, 'numCalledMethods' => $numCalledMethods, 'calledMethodsPercent' => $this->calculatePercent($numCalledMethods, $numMethods), 'numExecutableLines' => $classData['executableLines'], 'numExecutedLines' => $classData['executedLines'], 'executedLinesPercent' => $this->calculatePercent($classData['executedLines'], $classData['executableLines'])), $lowUpperBound, $highLowerBound); foreach ($classData['methods'] as $methodName => $methodData) { $numCalledMethods = $methodData['executedLines'] > 0 ? 1 : 0; $calledMethodsPercent = $numCalledMethods == 1 ? 100 : 0; $items .= $this->doRenderItem(array('name' => sprintf(' <a href="#%d">%s</a>', $methodData['startLine'], PHPUnit_Util_Class::getMethodSignature(new ReflectionMethod($className, $methodName))), 'numClasses' => '', 'numCalledClasses' => '', 'calledClassesPercent' => '', 'numMethods' => 1, 'numCalledMethods' => $numCalledMethods, 'calledMethodsPercent' => sprintf('%01.2f', $calledMethodsPercent), 'numExecutableLines' => $methodData['executableLines'], 'numExecutedLines' => $methodData['executedLines'], 'executedLinesPercent' => $this->calculatePercent($methodData['executedLines'], $methodData['executableLines'])), $lowUpperBound, $highLowerBound, 'method_item.html'); } } $this->setTemplateVars($template, $title, $charset); $template->setVar(array('lines' => $lines, 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound, FALSE), 'items' => $items, 'yuiPanelJS' => $this->yuiPanelJS)); $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId()); $template->renderTo($target . $cleanId . '.html'); }