Permalink
Browse files

- Prevent duplicate entries in blacklist and whitelist.

- Optionally add uncovered files from the whitelist to coverage data.
  • Loading branch information...
1 parent df991d9 commit c84376873f9abffa3f7ec0e2e7f24abad9ce4d08 @sebastianbergmann committed Jun 20, 2007
Showing with 42 additions and 4 deletions.
  1. +42 −4 PHPUnit/Util/Filter.php
View
@@ -119,7 +119,11 @@ class PHPUnit_Util_Filter
*/
public static function addFileToFilter($filename, $group = 'DEFAULT')
{
- self::$blacklistedFiles[$group][] = self::getCanonicalFilename($filename);
+ $filename = self::getCanonicalFilename($filename);
+
+ if (!in_array($filename, self::$blacklistedFiles[$group])) {
+ self::$blacklistedFiles[$group][] = $filename;
+ }
}
/**
@@ -157,7 +161,11 @@ public static function removeFileFromFilter($filename, $group = 'DEFAULT')
*/
public static function addFileToWhitelist($filename)
{
- self::$whitelistedFiles[] = self::getCanonicalFilename($filename);
+ $filename = self::getCanonicalFilename($filename);
+
+ if (!in_array($filename, self::$whitelistedFiles)) {
+ self::$whitelistedFiles[] = $filename;
+ }
}
/**
@@ -185,19 +193,49 @@ public static function removeFileFromWhitelist($filename)
* @param array $codeCoverageInformation
* @param boolean $filterTests
* @param boolean $filterPHPUnit
+ * @param boolean $addUncoveredFilesFromWhitelist
* @return array
* @access public
* @static
*/
- public static function getFilteredCodeCoverage(array $codeCoverageInformation, $filterTests = TRUE, $filterPHPUnit = TRUE)
+ public static function getFilteredCodeCoverage(array $codeCoverageInformation, $filterTests = TRUE, $filterPHPUnit = TRUE, $addUncoveredFilesFromWhitelist = TRUE)
{
if (self::$filter) {
- $max = count($codeCoverageInformation);
+ $coveredFiles = array();
+ $max = count($codeCoverageInformation);
for ($i = 0; $i < $max; $i++) {
foreach (array_keys($codeCoverageInformation[$i]['files']) as $file) {
if (self::isFiltered($file, $filterTests, $filterPHPUnit)) {
unset($codeCoverageInformation[$i]['files'][$file]);
+ } else {
+ $coveredFiles[] = $file;
+ }
+ }
+ }
+
+ if ($addUncoveredFilesFromWhitelist) {
+ $coveredFiles = array_unique($coveredFiles);
+
+ foreach (self::$whitelistedFiles as $whitelistedFile) {
+ if (!in_array($whitelistedFile, $coveredFiles)) {
+ 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();
+
+ if (isset($coverage[$whitelistedFile])) {
+ $codeCoverageInformation[] = array(
+ 'test' => NULL,
+ 'files' => array(
+ $whitelistedFile => $coverage[$whitelistedFile]
+ )
+ );
+
+ $coveredFiles[] = $whitelistedFile;
+ }
+ }
}
}
}

0 comments on commit c843768

Please sign in to comment.