Exemplo n.º 1
0
 /**
  * Calculates the Code Coverage for the class.
  *
  * @param $codeCoverage array       	
  */
 protected function calculateCodeCoverage(&$codeCoverage)
 {
     $statistics = PHPCoverage_Util_CodeCoverage::getStatistics($codeCoverage, $this->class->getFileName(), $this->class->getStartLine(), $this->class->getEndLine());
     $this->coverage = $statistics['coverage'];
     $this->loc = $statistics['loc'];
     $this->locExecutable = $statistics['locExecutable'];
     $this->locExecuted = $statistics['locExecuted'];
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param $name string       	
  * @param $parent PHPCoverage_Util_Report_Node       	
  * @param $executedLines array       	
  * @param $yui boolean       	
  * @param $highlight boolean       	
  * @throws RuntimeException
  */
 public function __construct($name, PHPCoverage_Util_Report_Node $parent = NULL, array $executedLines, $yui = TRUE, $highlight = FALSE)
 {
     parent::__construct($name, $parent);
     $path = $this->getPath();
     if (!file_exists($path)) {
         throw new Exception(sprintf('Path "%s" does not exist.', $path));
     }
     $this->executedLines = $executedLines;
     $this->highlight = $highlight;
     $this->yui = $yui;
     $this->codeLines = $this->loadFile($path);
     $this->branchInformation = PHPCoverage_Util_CodeCoverage::getBranchInformation($path);
     $this->calculateStatistics();
 }
Exemplo n.º 3
0
 /**
  *
  * @param $codeCoverageInformation array       	
  * @param $filterTests boolean       	
  * @return array
  */
 public static function getFilteredCodeCoverage(array $codeCoverageLineInformation, $filterTests = TRUE)
 {
     if (self::$filter) {
         list($isFilteredCache, $missedFiles) = self::getFileCodeCoverageDisposition($codeCoverageLineInformation, $filterTests);
         foreach ($codeCoverageLineInformation as $k => $test) {
             foreach (array_keys($test['files']) as $file) {
                 if (isset($isFilteredCache[$file]) && $isFilteredCache[$file]) {
                     unset($codeCoverageLineInformation[$k]['files'][$file]);
                 }
             }
             foreach (array_keys($test['dead']) as $file) {
                 if (isset($isFilteredCache[$file]) && $isFilteredCache[$file]) {
                     unset(${$codeCoverageLineInformation}[$k]['dead'][$file]);
                 }
             }
             foreach (array_keys($test['executable']) as $file) {
                 if (isset($isFilteredCache[$file]) && $isFilteredCache[$file]) {
                     unset($codeCoverageLineInformation[$k]['executable'][$file]);
                 }
             }
         }
         $codeCoverageBranchInformation = array();
         if (self::$addUncoveredFilesFromWhitelist) {
             foreach (self::$whitelistedFiles as $whitelistedFile) {
                 if (!isset(self::$coveredFiles[$whitelistedFile]) && !self::isFiltered($whitelistedFile, $filterTests, TRUE)) {
                     if (file_exists($whitelistedFile)) {
                         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
                         include_once $whitelistedFile;
                         $coverage = xdebug_get_code_coverage();
                         xdebug_stop_code_coverage();
                         foreach ($coverage as $file => $fileCoverage) {
                             if (!in_array($file, self::$whitelistedFiles) || isset(self::$coveredFiles[$file])) {
                                 unset($coverage[$file]);
                                 continue;
                             }
                             self::addCoveredFile($file);
                             foreach ($fileCoverage as $line => $flags) {
                                 if (is_array($flags)) {
                                     foreach (array_keys($flags) as $flag) {
                                         $coverage[$file][$line][$flag] = 0;
                                     }
                                 } else {
                                     $coverage[$file][$line] = -1;
                                 }
                             }
                         }
                         $coverage = PHPCoverage_Util_CodeCoverage::formatCodeCoverage($coverage);
                         $coverage_line = $coverage['codeCoverage_line'];
                         $coverage_branch = $coverage['codeCoverage_branch'];
                         unset($coverage);
                         foreach ($coverage_line as $file => $fileCoverage) {
                             $codeCoverageLineInformation[] = array('test' => NULL, 'files' => array($file => $fileCoverage));
                             if (in_array($file, array_keys($coverage_branch))) {
                                 /*
                                                                     $codeCoverageBranchInformation[] = array(
                                    $file => $coverage_branch[$file],
                                                                     );
                                 */
                                 $codeCoverageBranchInformation[$file] = $coverage_branch[$file];
                             }
                         }
                     }
                 }
             }
         }
     }
     $retArray = array('codeCoverage_line' => $codeCoverageLineInformation, 'codeCoverage_branch' => $codeCoverageBranchInformation);
     self::$filtedCoverageInformation = $retArray;
     unset($retArray);
     return self::$filtedCoverageInformation;
 }
Exemplo n.º 4
0
 /**
  * Renders the report.
  *
  * @param $codeCoverageLineInformation      code coverage (line)	
  * @param $codeCoverageBranchInformation    code coverage (branch)	
  * @param $title string       	
  * @param $target string       	
  * @param $charset string       	
  * @param $yui boolean       	
  * @param $highlight boolean       	
  * @param $lowUpperBound integer       	
  * @param $highLowerBound integer       	
  */
 public static function render($codeCoverageLineInformation, $codeCoverageBranchInformation = array(), $target = 'CoverageReport', $title = 'PHP Coverage Report', $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
 {
     ini_set('memory_limit', '2048M');
     $target = PHPCoverage_Util_Filesystem::getDirectory($target);
     self::$templatePath = sprintf('%s%sReport%sTemplate%s', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
     $files = self::formatCoverageData($codeCoverageLineInformation);
     PHPCoverage_Util_CodeCoverage::setBranchInformation($codeCoverageBranchInformation);
     $commonPath = PHPCoverage_Util_Filesystem::reducePaths($files);
     $items = self::buildDirectoryStructure($files);
     unset($codeCoverageLineInformation);
     $root = new PHPCoverage_Util_Report_Node_Directory($commonPath, NULL);
     unset($commonPath);
     self::addItems($root, $items, $files, $yui, $highlight);
     self::copyFiles($target);
     PHPCoverage_Util_CodeCoverage::clearSummary();
     $root->render($target, $title, $charset, $lowUpperBound, $highLowerBound);
 }
 public function generateReport()
 {
     $this->_coverageData = array();
     $this->getRecord();
     echo "INFO____: Generating report, this may take a few minutes, please wait patiently...\n";
     //echo "INFO____: Memory used: " . (int)(xdebug_memory_usage()/(1024*1024)) . "M.\n";
     if (!empty($this->_backupLog)) {
         $this->backupRecord();
     }
     $data = PHPCoverage_Util_CodeCoverage::formatCodeCoverage($this->_coverageData);
     $codeCoverageLineInformation = $data['codeCoverage_line'];
     $codeCoverageBranchInformation = $data['codeCoverage_branch'];
     unset($data);
     PHPCoverage_Util_Report::render($codeCoverageLineInformation, $codeCoverageBranchInformation, $this->_coverageReportDirectory, $this->_coverageReportTitle);
 }
Exemplo n.º 6
0
 public static function setBranchInformation($data)
 {
     if (is_array($data)) {
         self::$totalBranchInformation = $data;
     }
 }
Exemplo n.º 7
0
 /**
  * Calculates the Code Coverage for the class.
  *
  * @param $codeCoverage array       	
  */
 protected function calculateCodeCoverage(&$codeCoverage)
 {
     $statistics = PHPCoverage_Util_CodeCoverage::getStatistics($codeCoverage, $this->filename, 1, $this->loc);
     $this->coverage = $statistics['coverage'];
     $this->loc = $statistics['loc'];
     $this->locExecutable = $statistics['locExecutable'];
     $this->locExecuted = $statistics['locExecuted'];
 }