Created
November 8, 2012 14:44
-
-
Save chrisns/4039188 to your computer and use it in GitHub Desktop.
drupal 7 codecoverage patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git includes/bootstrap.inc includes/bootstrap.inc | |
index 74853b2..282a232 100644 | |
--- includes/bootstrap.inc | |
+++ includes/bootstrap.inc | |
@@ -3383,3 +3383,52 @@ function _drupal_shutdown_function() { | |
} | |
} | |
} | |
+ | |
+ | |
+if (file_exists("coverageon")) { | |
+ require 'PHP/CodeCoverage/Autoload.php'; | |
+ global $coverage; | |
+ $coverage = new PHP_CodeCoverage; | |
+ $coverage->start("drupal"); | |
+ drupal_register_shutdown_function("simpletest_xdebug_code_coverage_addon_shutdown"); | |
+} | |
+/** | |
+ * php shutdown callback | |
+ * @global type $coverage | |
+ */ | |
+function simpletest_xdebug_code_coverage_addon_shutdown() { | |
+ global $coverage; | |
+ $filter = $coverage->filter(); | |
+ if (!function_exists("cache_get")) return; | |
+ $lists = cache_get("coverage_lists")->data; | |
+ if($lists) { | |
+ $filter->addFilesToBlacklist($lists['black']); | |
+ $filter->addFilesToWhitelist($lists['white']); | |
+ } | |
+ else { | |
+ $filter->addDirectoryToBlacklist('/usr/share/pear'); | |
+ $filter->addDirectoryToBlacklist('/var/www/html'); | |
+ $filter->addDirectoryToWhitelist('/vagrant/drupal_code/', '.php'); | |
+ $filter->addDirectoryToWhitelist('/vagrant/drupal_code/', '.module'); | |
+ $filter->addDirectoryToWhitelist('/vagrant/drupal_code/', '.install'); | |
+ $filter->addDirectoryToWhitelist('/vagrant/drupal_code/', '.inc'); | |
+ cache_set("coverage_lists", array("white" => $filter->getWhitelist(), "black" => $filter->getBlacklist())); | |
+ } | |
+ $prevdata = (array)cache_get("simpletest_xdebug_code_coverage")->data; | |
+ if (!empty($prevdata)) { | |
+ $coverage->append($prevdata, "drupal", TRUE); | |
+ } | |
+ $coverage->stop(); | |
+ $data = $coverage->getData(); | |
+ foreach ($data as $files => &$lines) { | |
+ foreach ($lines as $no => &$line) { | |
+ if ($line) { | |
+ $line = 1; | |
+ } | |
+ else { | |
+ unset($lines[$no]); | |
+ } | |
+ } | |
+ } | |
+ cache_set("simpletest_xdebug_code_coverage", $data); | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment