Example #1
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;
 }
 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);
 }