Esempio n. 1
0
 protected function printCoverageCounts($numberOfCoveredElements, $totalNumberOfElements, $presicion)
 {
     $format = '%' . $presicion . 's';
     return PHP_CodeCoverage_Util::percent($numberOfCoveredElements, $totalNumberOfElements, true, true) . ' (' . sprintf($format, $numberOfCoveredElements) . '/' . sprintf($format, $totalNumberOfElements) . ')';
 }
Esempio n. 2
0
 /**
  * @param  PHP_CodeCoverage $coverage
  * @param  string           $target
  * @param  string           $name
  * @return string
  */
 public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL)
 {
     $document = new DOMDocument('1.0', 'UTF-8');
     $document->formatOutput = TRUE;
     $root = $document->createElement('coverage');
     $root->setAttribute('generated', (int) $_SERVER['REQUEST_TIME']);
     $document->appendChild($root);
     $project = $document->createElement('project');
     $project->setAttribute('timestamp', (int) $_SERVER['REQUEST_TIME']);
     if (is_string($name)) {
         $project->setAttribute('name', $name);
     }
     $root->appendChild($project);
     $files = $coverage->getSummary();
     $packages = array();
     $projectStatistics = array('files' => 0, 'loc' => 0, 'ncloc' => 0, 'classes' => 0, 'methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
     foreach ($files as $filename => $data) {
         $namespace = 'global';
         if (file_exists($filename)) {
             $fileStatistics = array('classes' => 0, 'methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
             $file = $document->createElement('file');
             $file->setAttribute('name', $filename);
             $tokens = PHP_Token_Stream_CachingFactory::get($filename);
             $classesInFile = $tokens->getClasses();
             $linesOfCode = $tokens->getLinesOfCode();
             unset($tokens);
             $ignoredLines = PHP_CodeCoverage_Util::getLinesToBeIgnored($filename);
             $lines = array();
             foreach ($classesInFile as $className => $_class) {
                 $classStatistics = array('methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
                 foreach ($_class['methods'] as $methodName => $method) {
                     $classStatistics['methods']++;
                     $methodCount = 0;
                     $methodLines = 0;
                     $methodLinesCovered = 0;
                     for ($i = $method['startLine']; $i <= $method['endLine']; $i++) {
                         if (isset($ignoredLines[$i])) {
                             continue;
                         }
                         $add = TRUE;
                         $count = 0;
                         if (isset($files[$filename][$i])) {
                             if ($files[$filename][$i] != -2) {
                                 $classStatistics['statements']++;
                                 $methodLines++;
                             }
                             if (is_array($files[$filename][$i])) {
                                 $classStatistics['coveredStatements']++;
                                 $methodLinesCovered++;
                                 $count = count($files[$filename][$i]);
                             } else {
                                 if ($files[$filename][$i] == -2) {
                                     $add = FALSE;
                                 }
                             }
                         } else {
                             $add = FALSE;
                         }
                         $methodCount = max($methodCount, $count);
                         if ($add) {
                             $lines[$i] = array('count' => $count, 'type' => 'stmt');
                         }
                     }
                     if ($methodCount > 0) {
                         $classStatistics['coveredMethods']++;
                     }
                     $lines[$method['startLine']] = array('count' => $methodCount, 'crap' => PHP_CodeCoverage_Util::crap($method['ccn'], PHP_CodeCoverage_Util::percent($methodLinesCovered, $methodLines)), 'type' => 'method', 'name' => $methodName);
                 }
                 $package = PHP_CodeCoverage_Util::getPackageInformation($className, $_class['docblock']);
                 if (!empty($package['namespace'])) {
                     $namespace = $package['namespace'];
                 }
                 $class = $document->createElement('class');
                 $class->setAttribute('name', $className);
                 $class->setAttribute('namespace', $namespace);
                 if (!empty($package['fullPackage'])) {
                     $class->setAttribute('fullPackage', $package['fullPackage']);
                 }
                 if (!empty($package['category'])) {
                     $class->setAttribute('category', $package['category']);
                 }
                 if (!empty($package['package'])) {
                     $class->setAttribute('package', $package['package']);
                 }
                 if (!empty($package['subpackage'])) {
                     $class->setAttribute('subpackage', $package['subpackage']);
                 }
                 $file->appendChild($class);
                 $metrics = $document->createElement('metrics');
                 $metrics->setAttribute('methods', $classStatistics['methods']);
                 $metrics->setAttribute('coveredmethods', $classStatistics['coveredMethods']);
                 $metrics->setAttribute('conditionals', $classStatistics['conditionals']);
                 $metrics->setAttribute('coveredconditionals', $classStatistics['coveredConditionals']);
                 $metrics->setAttribute('statements', $classStatistics['statements']);
                 $metrics->setAttribute('coveredstatements', $classStatistics['coveredStatements']);
                 $metrics->setAttribute('elements', $classStatistics['conditionals'] + $classStatistics['statements'] + $classStatistics['methods']);
                 $metrics->setAttribute('coveredelements', $classStatistics['coveredConditionals'] + $classStatistics['coveredStatements'] + $classStatistics['coveredMethods']);
                 $class->appendChild($metrics);
                 $fileStatistics['methods'] += $classStatistics['methods'];
                 $fileStatistics['coveredMethods'] += $classStatistics['coveredMethods'];
                 $fileStatistics['conditionals'] += $classStatistics['conditionals'];
                 $fileStatistics['coveredConditionals'] += $classStatistics['coveredConditionals'];
                 $fileStatistics['statements'] += $classStatistics['statements'];
                 $fileStatistics['coveredStatements'] += $classStatistics['coveredStatements'];
                 $fileStatistics['classes']++;
             }
             foreach ($data as $_line => $_data) {
                 if (isset($lines[$_line]) || isset($ignoredLines[$_line])) {
                     continue;
                 }
                 if ($_data != -2) {
                     $fileStatistics['statements']++;
                     if (is_array($_data)) {
                         $count = count($_data);
                         $fileStatistics['coveredStatements']++;
                     } else {
                         $count = 0;
                     }
                     $lines[$_line] = array('count' => $count, 'type' => 'stmt');
                 }
             }
             ksort($lines);
             foreach ($lines as $_line => $_data) {
                 if (isset($ignoredLines[$_line])) {
                     continue;
                 }
                 $line = $document->createElement('line');
                 $line->setAttribute('num', $_line);
                 $line->setAttribute('type', $_data['type']);
                 if (isset($_data['name'])) {
                     $line->setAttribute('name', $_data['name']);
                 }
                 if (isset($_data['crap'])) {
                     $line->setAttribute('crap', $_data['crap']);
                 }
                 $line->setAttribute('count', $_data['count']);
                 $file->appendChild($line);
             }
             $metrics = $document->createElement('metrics');
             $metrics->setAttribute('loc', $linesOfCode['loc']);
             $metrics->setAttribute('ncloc', $linesOfCode['ncloc']);
             $metrics->setAttribute('classes', $fileStatistics['classes']);
             $metrics->setAttribute('methods', $fileStatistics['methods']);
             $metrics->setAttribute('coveredmethods', $fileStatistics['coveredMethods']);
             $metrics->setAttribute('conditionals', $fileStatistics['conditionals']);
             $metrics->setAttribute('coveredconditionals', $fileStatistics['coveredConditionals']);
             $metrics->setAttribute('statements', $fileStatistics['statements']);
             $metrics->setAttribute('coveredstatements', $fileStatistics['coveredStatements']);
             $metrics->setAttribute('elements', $fileStatistics['conditionals'] + $fileStatistics['statements'] + $fileStatistics['methods']);
             $metrics->setAttribute('coveredelements', $fileStatistics['coveredConditionals'] + $fileStatistics['coveredStatements'] + $fileStatistics['coveredMethods']);
             $file->appendChild($metrics);
             if ($namespace == 'global') {
                 $project->appendChild($file);
             } else {
                 if (!isset($packages[$namespace])) {
                     $packages[$namespace] = $document->createElement('package');
                     $packages[$namespace]->setAttribute('name', $namespace);
                     $project->appendChild($packages[$namespace]);
                 }
                 $packages[$namespace]->appendChild($file);
             }
             $projectStatistics['loc'] += $linesOfCode['loc'];
             $projectStatistics['ncloc'] += $linesOfCode['ncloc'];
             $projectStatistics['classes'] += $fileStatistics['classes'];
             $projectStatistics['methods'] += $fileStatistics['methods'];
             $projectStatistics['coveredMethods'] += $fileStatistics['coveredMethods'];
             $projectStatistics['conditionals'] += $fileStatistics['conditionals'];
             $projectStatistics['coveredConditionals'] += $fileStatistics['coveredConditionals'];
             $projectStatistics['statements'] += $fileStatistics['statements'];
             $projectStatistics['coveredStatements'] += $fileStatistics['coveredStatements'];
             $projectStatistics['files']++;
         }
     }
     $metrics = $document->createElement('metrics');
     $metrics->setAttribute('files', $projectStatistics['files']);
     $metrics->setAttribute('loc', $projectStatistics['loc']);
     $metrics->setAttribute('ncloc', $projectStatistics['ncloc']);
     $metrics->setAttribute('classes', $projectStatistics['classes']);
     $metrics->setAttribute('methods', $projectStatistics['methods']);
     $metrics->setAttribute('coveredmethods', $projectStatistics['coveredMethods']);
     $metrics->setAttribute('conditionals', $projectStatistics['conditionals']);
     $metrics->setAttribute('coveredconditionals', $projectStatistics['coveredConditionals']);
     $metrics->setAttribute('statements', $projectStatistics['statements']);
     $metrics->setAttribute('coveredstatements', $projectStatistics['coveredStatements']);
     $metrics->setAttribute('elements', $projectStatistics['conditionals'] + $projectStatistics['statements'] + $projectStatistics['methods']);
     $metrics->setAttribute('coveredelements', $projectStatistics['coveredConditionals'] + $projectStatistics['coveredStatements'] + $projectStatistics['coveredMethods']);
     $project->appendChild($metrics);
     if ($target !== NULL) {
         return $document->save($target);
     } else {
         return $document->saveXML();
     }
 }
Esempio n. 3
0
 /**
  * Renders this node.
  *
  * @param string  $target
  * @param string  $title
  * @param string  $charset
  * @param integer $lowUpperBound
  * @param integer $highLowerBound
  * @param string  $generator
  */
 public function render($target, $title, $charset = 'UTF-8', $lowUpperBound = 35, $highLowerBound = 70, $generator = '')
 {
     if ($this->yui) {
         $template = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'file.html');
         $yuiTemplate = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'yui_item.js');
     } else {
         $template = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'file_no_yui.html');
     }
     $i = 1;
     $lines = '';
     foreach ($this->codeLines as $line) {
         $css = '';
         if (!isset($this->ignoredLines[$i]) && 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) {
                         switch ($test['status']) {
                             case 0:
                                 $testCSS = ' class=\\"testPassed\\"';
                                 break;
                             case 1:
                             case 2:
                                 $testCSS = ' class=\\"testIncomplete\\"';
                                 break;
                             case 3:
                                 $testCSS = ' class=\\"testFailure\\"';
                                 break;
                             case 4:
                                 $testCSS = ' class=\\"testError\\"';
                                 break;
                             default:
                                 $testCSS = '';
                         }
                         $buffer .= sprintf('<li%s>%s</li>', $testCSS, addslashes(htmlspecialchars($test['id'])));
                     }
                     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) {
         if ($classData['executedLines'] == $classData['executableLines']) {
             $numTestedClasses = 1;
             $testedClassesPercent = 100;
         } else {
             $numTestedClasses = 0;
             $testedClassesPercent = 0;
         }
         $numMethods = 0;
         $numTestedMethods = 0;
         foreach ($classData['methods'] as $method) {
             if ($method['executableLines'] > 0) {
                 $numMethods++;
                 if ($method['executedLines'] == $method['executableLines']) {
                     $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' => PHP_CodeCoverage_Util::percent($numTestedMethods, $numMethods, TRUE), 'numExecutableLines' => $classData['executableLines'], 'numExecutedLines' => $classData['executedLines'], 'executedLinesPercent' => PHP_CodeCoverage_Util::percent($classData['executedLines'], $classData['executableLines'], TRUE)), $lowUpperBound, $highLowerBound);
         foreach ($classData['methods'] as $methodData) {
             if ($methodData['executableLines'] > 0) {
                 if ($methodData['executedLines'] == $methodData['executableLines']) {
                     $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' => PHP_CodeCoverage_Util::percent($methodData['executedLines'], $methodData['executableLines'], TRUE), 'crap' => PHP_CodeCoverage_Util::crap($methodData['ccn'], PHP_CodeCoverage_Util::percent($methodData['executedLines'], $methodData['executableLines']))), $lowUpperBound, $highLowerBound, 'method_item.html');
             }
         }
     }
     $this->setTemplateVars($template, $title, $charset, $generator);
     $template->setVar(array('lines' => $lines, 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound, FALSE), 'items' => $items, 'yuiPanelJS' => $this->yuiPanelJS));
     $cleanId = PHP_CodeCoverage_Util::getSafeFilename($this->getId());
     $template->renderTo($target . $cleanId . '.html');
     $this->yuiPanelJS = '';
     $this->executedLines = array();
 }
Esempio n. 4
0
 public function setNumFunctions($count, $tested)
 {
     $this->functionsNode->setAttribute('count', $count);
     $this->functionsNode->setAttribute('tested', $tested);
     $this->functionsNode->setAttribute('percent', PHP_CodeCoverage_Util::percent($tested, $count, true));
 }
Esempio n. 5
0
 /**
  * @param  PHP_CodeCoverage $coverage
  * @param  string           $target
  * @param  string           $name
  * @return string
  */
 public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL)
 {
     $xmlDocument = new DOMDocument('1.0', 'UTF-8');
     $xmlDocument->formatOutput = TRUE;
     $xmlCoverage = $xmlDocument->createElement('coverage');
     $xmlCoverage->setAttribute('generated', (int) $_SERVER['REQUEST_TIME']);
     $xmlDocument->appendChild($xmlCoverage);
     $xmlProject = $xmlDocument->createElement('project');
     $xmlProject->setAttribute('timestamp', (int) $_SERVER['REQUEST_TIME']);
     if (is_string($name)) {
         $xmlProject->setAttribute('name', $name);
     }
     $xmlCoverage->appendChild($xmlProject);
     $packages = array();
     $report = $coverage->getReport();
     unset($coverage);
     foreach ($report as $item) {
         $namespace = 'global';
         if (!$item instanceof PHP_CodeCoverage_Report_Node_File) {
             continue;
         }
         $xmlFile = $xmlDocument->createElement('file');
         $xmlFile->setAttribute('name', $item->getPath());
         $classes = array_merge($item->getClasses(), $item->getTraits());
         $coverage = $item->getCoverageData();
         $lines = array();
         $ignoredLines = $item->getIgnoredLines();
         foreach ($classes as $className => $class) {
             $classStatements = 0;
             $coveredClassStatements = 0;
             $coveredMethods = 0;
             foreach ($class['methods'] as $methodName => $method) {
                 $methodCount = 0;
                 $methodLines = 0;
                 $methodLinesCovered = 0;
                 for ($i = $method['startLine']; $i <= $method['endLine']; $i++) {
                     if (isset($ignoredLines[$i])) {
                         continue;
                     }
                     $add = TRUE;
                     $count = 0;
                     if (isset($coverage[$i])) {
                         if ($coverage[$i] !== NULL) {
                             $classStatements++;
                             $methodLines++;
                         } else {
                             $add = FALSE;
                         }
                         $count = count($coverage[$i]);
                         if ($count > 0) {
                             $coveredClassStatements++;
                             $methodLinesCovered++;
                         }
                     } else {
                         $add = FALSE;
                     }
                     $methodCount = max($methodCount, $count);
                     if ($add) {
                         $lines[$i] = array('count' => $count, 'type' => 'stmt');
                     }
                 }
                 if ($methodCount > 0) {
                     $coveredMethods++;
                 }
                 $lines[$method['startLine']] = array('count' => $methodCount, 'crap' => PHP_CodeCoverage_Util::crap($method['ccn'], PHP_CodeCoverage_Util::percent($methodLinesCovered, $methodLines)), 'type' => 'method', 'name' => $methodName);
             }
             if (!empty($class['package']['namespace'])) {
                 $namespace = $class['package']['namespace'];
             }
             $xmlClass = $xmlDocument->createElement('class');
             $xmlClass->setAttribute('name', $className);
             $xmlClass->setAttribute('namespace', $namespace);
             if (!empty($class['package']['fullPackage'])) {
                 $xmlClass->setAttribute('fullPackage', $class['package']['fullPackage']);
             }
             if (!empty($class['package']['category'])) {
                 $xmlClass->setAttribute('category', $class['package']['category']);
             }
             if (!empty($class['package']['package'])) {
                 $xmlClass->setAttribute('package', $class['package']['package']);
             }
             if (!empty($class['package']['subpackage'])) {
                 $xmlClass->setAttribute('subpackage', $class['package']['subpackage']);
             }
             $xmlFile->appendChild($xmlClass);
             $xmlMetrics = $xmlDocument->createElement('metrics');
             $xmlMetrics->setAttribute('methods', count($class['methods']));
             $xmlMetrics->setAttribute('coveredmethods', $coveredMethods);
             $xmlMetrics->setAttribute('conditionals', 0);
             $xmlMetrics->setAttribute('coveredconditionals', 0);
             $xmlMetrics->setAttribute('statements', $classStatements);
             $xmlMetrics->setAttribute('coveredstatements', $coveredClassStatements);
             $xmlMetrics->setAttribute('elements', count($class['methods']) + $classStatements);
             $xmlMetrics->setAttribute('coveredelements', $coveredMethods + $coveredClassStatements);
             $xmlClass->appendChild($xmlMetrics);
         }
         foreach ($coverage as $line => $data) {
             if ($data === NULL || isset($lines[$line]) || isset($ignoredLines[$line])) {
                 continue;
             }
             $lines[$line] = array('count' => count($data), 'type' => 'stmt');
         }
         ksort($lines);
         foreach ($lines as $line => $data) {
             if (isset($ignoredLines[$line])) {
                 continue;
             }
             $xmlLine = $xmlDocument->createElement('line');
             $xmlLine->setAttribute('num', $line);
             $xmlLine->setAttribute('type', $data['type']);
             if (isset($data['name'])) {
                 $xmlLine->setAttribute('name', $data['name']);
             }
             if (isset($data['crap'])) {
                 $xmlLine->setAttribute('crap', $data['crap']);
             }
             $xmlLine->setAttribute('count', $data['count']);
             $xmlFile->appendChild($xmlLine);
         }
         $linesOfCode = $item->getLinesOfCode();
         $xmlMetrics = $xmlDocument->createElement('metrics');
         $xmlMetrics->setAttribute('loc', $linesOfCode['loc']);
         $xmlMetrics->setAttribute('ncloc', $linesOfCode['ncloc']);
         $xmlMetrics->setAttribute('classes', $item->getNumClasses());
         $xmlMetrics->setAttribute('methods', $item->getNumMethods());
         $xmlMetrics->setAttribute('coveredmethods', $item->getNumTestedMethods());
         $xmlMetrics->setAttribute('conditionals', 0);
         $xmlMetrics->setAttribute('coveredconditionals', 0);
         $xmlMetrics->setAttribute('statements', $item->getNumExecutableLines());
         $xmlMetrics->setAttribute('coveredstatements', $item->getNumExecutedLines());
         $xmlMetrics->setAttribute('elements', $item->getNumMethods() + $item->getNumExecutableLines());
         $xmlMetrics->setAttribute('coveredelements', $item->getNumTestedMethods() + $item->getNumExecutedLines());
         $xmlFile->appendChild($xmlMetrics);
         if ($namespace == 'global') {
             $xmlProject->appendChild($xmlFile);
         } else {
             if (!isset($packages[$namespace])) {
                 $packages[$namespace] = $xmlDocument->createElement('package');
                 $packages[$namespace]->setAttribute('name', $namespace);
                 $xmlProject->appendChild($packages[$namespace]);
             }
             $packages[$namespace]->appendChild($xmlFile);
         }
     }
     $linesOfCode = $report->getLinesOfCode();
     $xmlMetrics = $xmlDocument->createElement('metrics');
     $xmlMetrics->setAttribute('files', count($report));
     $xmlMetrics->setAttribute('loc', $linesOfCode['loc']);
     $xmlMetrics->setAttribute('ncloc', $linesOfCode['ncloc']);
     $xmlMetrics->setAttribute('classes', $report->getNumClasses());
     $xmlMetrics->setAttribute('methods', $report->getNumMethods());
     $xmlMetrics->setAttribute('coveredmethods', $report->getNumTestedMethods());
     $xmlMetrics->setAttribute('conditionals', 0);
     $xmlMetrics->setAttribute('coveredconditionals', 0);
     $xmlMetrics->setAttribute('statements', $report->getNumExecutableLines());
     $xmlMetrics->setAttribute('coveredstatements', $report->getNumExecutedLines());
     $xmlMetrics->setAttribute('elements', $report->getNumMethods() + $report->getNumExecutableLines());
     $xmlMetrics->setAttribute('coveredelements', $report->getNumTestedMethods() + $report->getNumExecutedLines());
     $xmlProject->appendChild($xmlMetrics);
     if ($target !== NULL) {
         if (!is_dir(dirname($target))) {
             mkdir(dirname($target), 0777, TRUE);
         }
         return $xmlDocument->save($target);
     } else {
         return $xmlDocument->saveXML();
     }
 }
Esempio n. 6
0
 /**
  * Returns the percentage of executed lines.
  *
  * @param  boolean $asString
  * @return integer
  */
 public function getLineExecutedPercent($asString = TRUE)
 {
     return PHP_CodeCoverage_Util::percent($this->getNumExecutedLines(), $this->getNumExecutableLines(), $asString);
 }
Esempio n. 7
0
 /**
  * @covers PHP_CodeCoverage_Util::percent
  */
 public function testPercent()
 {
     $this->assertEquals(100, PHP_CodeCoverage_Util::percent(100, 0));
     $this->assertEquals(100, PHP_CodeCoverage_Util::percent(100, 100));
     $this->assertEquals('100.00%', PHP_CodeCoverage_Util::percent(100, 100, TRUE));
 }
Esempio n. 8
0
 /**
  * @param  array         $items
  * @param  Text_Template $template
  *
  * @return string
  */
 protected function renderTraitOrClassItems(array $items, Text_Template $template, Text_Template $methodItemTemplate)
 {
     if (empty($items)) {
         return '';
     }
     $buffer = '';
     foreach ($items as $name => $item) {
         $numMethods = count($item['methods']);
         $numTestedMethods = 0;
         foreach ($item['methods'] as $method) {
             if ($method['executedLines'] == $method['executableLines']) {
                 $numTestedMethods++;
             }
         }
         $buffer .= $this->renderItemTemplate($template, array('name' => $name, 'numClasses' => 1, 'numTestedClasses' => $numTestedMethods == $numMethods ? 1 : 0, 'numMethods' => $numMethods, 'numTestedMethods' => $numTestedMethods, 'linesExecutedPercent' => PHP_CodeCoverage_Util::percent($item['executedLines'], $item['executableLines'], false), 'linesExecutedPercentAsString' => PHP_CodeCoverage_Util::percent($item['executedLines'], $item['executableLines'], true), 'numExecutedLines' => $item['executedLines'], 'numExecutableLines' => $item['executableLines'], 'testedMethodsPercent' => PHP_CodeCoverage_Util::percent($numTestedMethods, $numMethods, false), 'testedMethodsPercentAsString' => PHP_CodeCoverage_Util::percent($numTestedMethods, $numMethods, true), 'testedClassesPercent' => PHP_CodeCoverage_Util::percent($numTestedMethods == $numMethods ? 1 : 0, 1, false), 'testedClassesPercentAsString' => PHP_CodeCoverage_Util::percent($numTestedMethods == $numMethods ? 1 : 0, 1, true), 'crap' => $item['crap']));
         foreach ($item['methods'] as $method) {
             $buffer .= $this->renderFunctionOrMethodItem($methodItemTemplate, $method, '&nbsp;');
         }
     }
     return $buffer;
 }
Esempio n. 9
0
 /**
  * @param  Text_Template $template
  * @return string
  */
 protected function renderFunctionOrMethodItem(Text_Template $template, array $item, $indent = '')
 {
     $numTestedItems = $item['executedLines'] == $item['executableLines'] ? 1 : 0;
     return $this->renderItemTemplate($template, array('name' => sprintf('%s<a href="#%d"><abbr title="%s">%s</abbr></a>', $indent, $item['startLine'], htmlspecialchars($item['signature']), isset($item['functionName']) ? $item['functionName'] : $item['methodName']), 'numMethods' => 1, 'numTestedMethods' => $numTestedItems, 'linesExecutedPercent' => PHP_CodeCoverage_Util::percent($item['executedLines'], $item['executableLines'], false), 'linesExecutedPercentAsString' => PHP_CodeCoverage_Util::percent($item['executedLines'], $item['executableLines'], true), 'numExecutedLines' => $item['executedLines'], 'numExecutableLines' => $item['executableLines'], 'testedMethodsPercent' => PHP_CodeCoverage_Util::percent($numTestedItems, 1, false), 'testedMethodsPercentAsString' => PHP_CodeCoverage_Util::percent($numTestedItems, 1, true), 'crap' => $item['crap']));
 }