当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeCoverage_Util::percent方法代码示例

本文整理汇总了PHP中PHP_CodeCoverage_Util::percent方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeCoverage_Util::percent方法的具体用法?PHP PHP_CodeCoverage_Util::percent怎么用?PHP PHP_CodeCoverage_Util::percent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeCoverage_Util的用法示例。


在下文中一共展示了PHP_CodeCoverage_Util::percent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: printCoverageCounts

 protected function printCoverageCounts($numberOfCoveredElements, $totalNumberOfElements, $presicion)
 {
     $format = '%' . $presicion . 's';
     return PHP_CodeCoverage_Util::percent($numberOfCoveredElements, $totalNumberOfElements, true, true) . ' (' . sprintf($format, $numberOfCoveredElements) . '/' . sprintf($format, $totalNumberOfElements) . ')';
 }
开发者ID:illuminate3,项目名称:PMPortal,代码行数:5,代码来源:Text.php

示例2: process

 /**
  * @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']);
//.........这里部分代码省略.........
开发者ID:redlion09,项目名称:pcppi,代码行数:101,代码来源:Clover.php

示例3: render

 /**
  * 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);
//.........这里部分代码省略.........
开发者ID:reflectivedevelopment,项目名称:jfh-lib,代码行数:101,代码来源:File.php

示例4: setNumFunctions

 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));
 }
开发者ID:Ingothq,项目名称:multiarmedbandit,代码行数:6,代码来源:Totals.php

示例5: process

 /**
  * @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);
//.........这里部分代码省略.........
开发者ID:nbalonso,项目名称:MunkiFace,代码行数:101,代码来源:Clover.php

示例6: getLineExecutedPercent

 /**
  * 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);
 }
开发者ID:habibmasuro,项目名称:Bitcoin-PHP-API,代码行数:10,代码来源:Node.php

示例7: testPercent

 /**
  * @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));
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:9,代码来源:UtilTest.php

示例8: renderTraitOrClassItems

 /**
  * @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;
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:27,代码来源:File.php

示例9: renderFunctionOrMethodItem

 /**
  * @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']));
 }
开发者ID:akarimgh,项目名称:matrix42-slim-api,代码行数:9,代码来源:File.php


注:本文中的PHP_CodeCoverage_Util::percent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。