diff --git a/_compile.php b/_compile.php
index b2872bcf..28f13555 100644
--- a/_compile.php
+++ b/_compile.php
@@ -101,6 +101,7 @@ if ($_SERVER["argc"] > 1) {
$filename = "phpMinAdmin" . ($_COOKIE["lang"] ? "-$_COOKIE[lang]" : "") . ".php";
$file = file_get_contents("index.php");
$file = preg_replace_callback('~(<\\?php)?\\s*(include|require) "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
+$file = preg_replace("~if \\(isset\\(\\\$_SESSION\\[\"coverage.*\n}\n| && !isset\\(\\\$_SESSION\\[\"coverage\"\\]\\)~sU", '', $file);
if ($_COOKIE["lang"]) {
$file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
$file = str_replace("\n", "", $file);
diff --git a/_coverage.php b/_coverage.php
new file mode 100644
index 00000000..3c0dd65a
--- /dev/null
+++ b/_coverage.php
@@ -0,0 +1,66 @@
+]+)~', $s, $matches);
+ foreach ($matches[1] as $val) {
+ if ($val{0} == "/") {
+ array_pop($return);
+ } elseif (substr($val, -1) != "/") {
+ $return[] = $val;
+ }
+ }
+ return $return;
+}
+
+if ($_GET["start"]) {
+ $_SESSION["coverage"] = array();
+ header("Location: .");
+ exit;
+} elseif ($_GET["filename"]) {
+ $filename = basename($_GET["filename"]);
+ $coverage = $_SESSION["coverage"][realpath($filename)];
+ $file = explode("
", highlight_file($filename, true));
+ unset($prev_color);
+ $s = "";
+ for ($l=0; $l <= count($file); $l++) {
+ $line = $file[$l];
+ $color = "#C0FFC0"; // tested
+ switch ($coverage[$l+1]) {
+ case -1: $color = "#FFC0C0"; break; // untested
+ case -2: $color = "Silver"; break; // dead code
+ case null: $color = ""; break; // not executable
+ }
+ if (!isset($prev_color)) {
+ $prev_color = $color;
+ }
+ if ($prev_color != $color || !isset($line)) {
+ echo "
Start new coverage (requires Xdebug)
diff --git a/design.inc.php b/design.inc.php index 12f3ba4b..577cefa3 100644 --- a/design.inc.php +++ b/design.inc.php @@ -53,7 +53,7 @@ function toggle(id) { if (strlen($_GET["db"]) && $databases && !in_array($_GET["db"], $databases, true)) { $databases = null; } - if (isset($databases) && !isset($_GET["sql"])) { + if (isset($databases) && !isset($_GET["sql"]) && !isset($_SESSION["coverage"])) { session_write_close(); } if ($error) { diff --git a/index.php b/index.php index 1a7e94ba..c8f53085 100644 --- a/index.php +++ b/index.php @@ -12,6 +12,19 @@ if (!ini_get("session.auto_start")) { session_set_cookie_params(ini_get("session.cookie_lifetime"), preg_replace('~\\?.*~', '', $_SERVER["REQUEST_URI"])); session_start(); } +if (isset($_SESSION["coverage"])) { + function save_coverage() { + foreach (xdebug_get_code_coverage() as $filename => $lines) { + foreach ($lines as $l => $val) { + if (!$_SESSION["coverage"][$filename][$l] || $val > 0) { + $_SESSION["coverage"][$filename][$l] = $val; + } + } + } + } + xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); + register_shutdown_function('save_coverage'); +} if (get_magic_quotes_gpc()) { $process = array(&$_GET, &$_POST); while (list($key, $val) = each($process)) { diff --git a/tests/0-login.html b/tests/0-login.html index 4cdf7172..5354cdcb 100644 --- a/tests/0-login.html +++ b/tests/0-login.html @@ -11,6 +11,11 @@Coverage | ||
open | +/phpMinAdmin/_coverage.php | ++ |