Пример #1
0
 /**
  * Returns the cached result of date('D M j G:i:s T Y').
  *
  * @return string
  * @since  Method available since Release 3.0.1
  */
 public static function getDate()
 {
     if (self::$date == '') {
         self::$date = date('D M j G:i:s T Y');
     }
     return self::$date;
 }
Пример #2
0
 /**
  * Renders this node.
  *
  * @param $target string       	
  * @param $title string       	
  * @param $charset string       	
  * @param $lowUpperBound integer       	
  * @param $highLowerBound integer       	
  */
 public function render($target, $title, $charset = 'ISO-8859-1', $lowUpperBound = 35, $highLowerBound = 70)
 {
     if ($this->yui) {
         $template = new PHPCoverage_Util_Template(PHPCoverage_Util_Report::$templatePath . 'file.html');
         $yuiTemplate = new PHPCoverage_Util_Template(PHPCoverage_Util_Report::$templatePath . 'yui_item.js');
     } else {
         $template = new PHPCoverage_Util_Template(PHPCoverage_Util_Report::$templatePath . 'file_no_yui.html');
     }
     $i = 1;
     $lines = '';
     $ignore = FALSE;
     foreach ($this->codeLines as $line) {
         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 = '';
                     $testCSS = '';
                     /*
                      * foreach ($this->executedLines[$i] as $test) { if
                      * (!isset($test->__liHtml)) { $test->__liHtml = ''; if
                      * ($test instanceof
                      * PHPCoverage_Framework_SelfDescribing) { $testName =
                      * $test->toString(); if ($test instanceof
                      * PHPCoverage_Framework_TestCase) { switch
                      * ($test->getStatus()) { case
                      * PHPCoverage_Runner_BaseTestRunner::STATUS_PASSED: {
                      * $testCSS = ' class=\"testPassed\"'; } break; case
                      * PHPCoverage_Runner_BaseTestRunner::STATUS_FAILURE: {
                      * $testCSS = ' class=\"testFailure\"'; } break; case
                      * PHPCoverage_Runner_BaseTestRunner::STATUS_ERROR: {
                      * $testCSS = ' class=\"testError\"'; } break; case
                      * PHPCoverage_Runner_BaseTestRunner::STATUS_INCOMPLETE:
                      * case
                      * PHPCoverage_Runner_BaseTestRunner::STATUS_SKIPPED: {
                      * $testCSS = ' class=\"testIncomplete\"'; } break;
                      * default: { $testCSS = ''; } } } } $test->__liHtml .=
                      * sprintf( '<li%s>%s</li>', $testCSS,
                      * addslashes(htmlspecialchars($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 );
             $css = sprintf('<span class="%s">  ##BRANCH_FLAG##  %s : ', $color, $count);
             $branch_flag = $this->formatBranchFlag($i);
             $css = str_replace("##BRANCH_FLAG##", $branch_flag, $css);
         }
         $fillup = array_shift($this->codeLinesFillup);
         if ($fillup > 0) {
             $line .= str_repeat(' ', $fillup);
         }
         /* original
            $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>' : '' 
            );
            */
         // add for branch
         if ($this->useBranchSplit && in_array($i, array_keys($this->branchInformation)) && count($this->branchInformation[$i]) > 1) {
             $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->getBranchFlagMax() . '           : ', !$this->highlight ? htmlspecialchars($line) : $line, !empty($css) ? '</span>' : '');
             $branch_lines_num = count($this->branchInformation[$i]);
             $next_branch_line = $line;
             for ($current_branch = $branch_lines_num; $current_branch > 0; $current_branch--) {
                 if ($current_branch > 1) {
                     $branch_position = PHPCoverage_Util_File::getFirstLogicPos($next_branch_line);
                     if ($branch_position == -1) {
                         break;
                     }
                     $branch_line = substr($next_branch_line, 0, $branch_position) . PHPCoverage_Util_File::getBlankSpace(strlen($line) - $branch_position);
                     $next_branch_line = PHPCoverage_Util_File::getBlankSpace($branch_position) . substr($next_branch_line, $branch_position);
                 } else {
                     $branch_line = $next_branch_line;
                 }
                 $branch_flag = $this->formatBranchFlag($i, count($this->branchInformation[$i]) - $current_branch);
                 $branchColor = $this->formatBranchColor($i, count($this->branchInformation[$i]) - $current_branch);
                 $branch_css = sprintf('<span class="%s">  ##BRANCH_FLAG##        : ', $branchColor);
                 $branch_css = str_replace("##BRANCH_FLAG##", $branch_flag, $branch_css);
                 $lines .= sprintf('<span class="lineNum" id="container%d"><a name="%d"></a><a href="#%d" id="line%d">        </a> </span>%s%s%s' . "\n", $i, $i, $i, $i, !empty($branch_css) ? $branch_css : '  ' . $this->getBranchFlagMax() . '           : ', !$this->highlight ? htmlspecialchars($branch_line) : $branch_line, !empty($branch_css) ? '</span>' : '');
             }
         } else {
             $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->getBranchFlagMax() . '           : ', !$this->highlight ? htmlspecialchars($line) : $line, !empty($css) ? '</span>' : '');
         }
         $i++;
     }
     $items = '';
     foreach ($this->classes as $className => $classData) {
         // f ($classData['executedLines'] == $classData['executableLines'])
         // {
         if ($classData['executedLines'] > 0) {
             $numTestedClasses = 1;
             $testedClassesPercent = 100;
         } else {
             $numTestedClasses = 0;
             $testedClassesPercent = 0;
         }
         $numTestedMethods = 0;
         $numMethods = count($classData['methods']);
         foreach ($classData['methods'] as $method) {
             // f ($method['executedLines'] == $method['executableLines']) {
             if ($method['executedLines'] > 0) {
                 $numTestedMethods++;
             }
         }
         $items .= $this->doRenderItem(array('name' => sprintf('<b><a href="#%d">%s</a></b>', $classData['startLine'], $className), 'numClasses' => 1, 'numTestedClasses' => $numTestedClasses, 'testedClassesPercent' => sprintf('%01.2f', $testedClassesPercent), 'numMethods' => $numMethods, 'numTestedMethods' => $numTestedMethods, 'testedMethodsPercent' => $this->calculatePercent($numTestedMethods, $numMethods), 'numExecutableLines' => $classData['executableLines'], 'numExecutedLines' => $classData['executedLines'], 'executedLinesPercent' => $this->calculatePercent($classData['executedLines'], $classData['executableLines'])), $lowUpperBound, $highLowerBound);
         foreach ($classData['methods'] as $methodName => $methodData) {
             // f ($methodData['executedLines'] ==
             // $methodData['executableLines']) {
             if ($methodData['executedLines'] > 0) {
                 $numTestedMethods = 1;
                 $testedMethodsPercent = 100;
             } else {
                 $numTestedMethods = 0;
                 $testedMethodsPercent = 0;
             }
             $items .= $this->doRenderItem(array('name' => sprintf('&nbsp;<a href="#%d">%s</a>', $methodData['startLine'], htmlspecialchars($methodData['signature'])), 'numClasses' => '', 'numTestedClasses' => '', 'testedClassesPercent' => '', 'numMethods' => 1, 'numTestedMethods' => $numTestedMethods, 'testedMethodsPercent' => sprintf('%01.2f', $testedMethodsPercent), '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 = PHPCoverage_Util_Filesystem::getSafeFilename($this->getId());
     $template->renderTo($target . $cleanId . '.html');
     $this->yuiPanelJS = '';
     $this->executedLines = array();
 }
Пример #3
0
 /**
  *
  * @param $template PHPCoverage_Util_Template       	
  * @param $title string       	
  * @param $charset string       	
  */
 protected function setTemplateVars(PHPCoverage_Util_Template $template, $title, $charset)
 {
     $template->setVar(array('title' => $title, 'charset' => $charset, 'link' => $this->getLink(TRUE), 'num_executable_lines' => $this->getNumExecutableLines(), 'num_executed_lines' => $this->getNumExecutedLines(), 'lines_executed_percent' => $this->getLineExecutedPercent(), 'date' => $template->getDate(), 'PHPCoverage_version' => '1.0', 'xdebug_version' => phpversion('xdebug'), 'php_version' => PHP_VERSION));
 }