diff --git a/adminer/coverage.inc.php b/adminer/coverage.inc.php deleted file mode 100644 index 47f5cf1d..00000000 --- a/adminer/coverage.inc.php +++ /dev/null @@ -1,72 +0,0 @@ -]+)~', $s, $matches); - foreach ($matches[1] as $val) { - if ($val{0} == "/") { - array_pop($return); - } elseif (substr($val, -1) != "/") { - $return[] = $val; - } - } - return $return; -} - -page_header("Coverage", (extension_loaded("xdebug") ? "" : "Xdebug has to be enabled.")); - -if ($_GET["coverage"] === "0") { - unset($_SESSION["coverage"]); // disable coverage if it is not available - if (extension_loaded("xdebug")) { - $_SESSION["coverage"] = array(); - echo "

Coverage started.\n"; - } -} elseif (preg_match('~^(include/)?[-_.a-z0-9]+$~i', $_GET["coverage"])) { - // highlight single file - $filename = $_GET["coverage"]; - $cov = $_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 ($cov[$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 "" . $s; - $open_tags = xhtml_open_tags($s); - foreach (array_reverse($open_tags) as $tag) { - echo ""; - } - echo "\n"; - $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : ""); - $prev_color = $color; - } - $s .= "$line
\n"; - } -} else { - // display list of files - echo "\n"; - foreach (array_merge(glob("*.php"), glob("include/*.php")) as $filename) { - $cov = $_SESSION["coverage"][realpath($filename)]; - $ratio = 0; - if (isset($cov)) { - $values = array_count_values($cov); - $ratio = round(100 - 100 * $values[-1] / count($cov)); - } - echo "
$ratio%$filename\n"; - } - echo "
\n"; - echo '

Start new coverage' . "\n"; -} -page_footer("auth"); -exit; diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index 5d07e803..d042fe5a 100644 --- a/adminer/include/bootstrap.inc.php +++ b/adminer/include/bootstrap.inc.php @@ -1,6 +1,8 @@ $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'); -} - // disable magic quotes to be able to use database escaping function if (get_magic_quotes_gpc()) { $process = array(&$_GET, &$_POST, &$_COOKIE); @@ -86,9 +73,6 @@ include "../adminer/include/lang.inc.php"; include "../adminer/lang/$LANG.inc.php"; include "./include/adminer.inc.php"; include "../adminer/include/design.inc.php"; -if (isset($_GET["coverage"])) { - include "../adminer/coverage.inc.php"; -} include "../adminer/include/pdo.inc.php"; include "../adminer/include/mysql.inc.php"; include "../adminer/include/auth.inc.php"; diff --git a/adminer/include/coverage.inc.php b/adminer/include/coverage.inc.php new file mode 100644 index 00000000..1883c66a --- /dev/null +++ b/adminer/include/coverage.inc.php @@ -0,0 +1,25 @@ + $lines) { + foreach ($lines as $l => $val) { + if (!$coverage[$filename][$l] || $val > 0) { + $coverage[$filename][$l] = $val; + } + } + mysql_query(" + REPLACE adminer_test.coverage (filename, coverage_serialize) + VALUES ('" . mysql_real_escape_string($filename) . "', '" . mysql_real_escape_string(serialize($coverage[$filename])) . "') + "); + } + } + xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); + register_shutdown_function('save_coverage'); +} diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index c627b110..0174d1b7 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -46,7 +46,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") { if (strlen($_GET["db"]) && $databases && !in_array($_GET["db"], $databases, true)) { $databases = null; } - if (isset($databases) && !isset($_GET["sql"]) && !isset($_SESSION["coverage"])) { + if (isset($databases) && !isset($_GET["sql"])) { // improves concurrency if a user opens several pages at once session_write_close(); } diff --git a/compile.php b/compile.php index 2515dfee..a2a670f8 100644 --- a/compile.php +++ b/compile.php @@ -192,9 +192,8 @@ if (isset($_SERVER["argv"][1])) { $file = file_get_contents(dirname(__FILE__) . "/$project/index.php"); $file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file); -$file = preg_replace('(' . str_replace(' ', '\\s*', preg_quote(' if (isset($_GET["coverage"])) { include "../adminer/coverage.inc.php"; }')) . ')', '', $file); +$file = str_replace('include "../adminer/include/coverage.inc.php";', '', $file); $file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file); // bootstrap.inc.php -$file = preg_replace("~if \\(isset\\(\\\$_SESSION\\[\"coverage.*\n}\n| && !isset\\(\\\$_SESSION\\[\"coverage\"\\]\\)~sU", '', $file); $file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file); $file = preg_replace_callback('~\\b(include|require) "([^"]*\\$LANG.inc.php)";~', 'put_file_lang', $file); if ($_COOKIE["adminer_lang"]) { diff --git a/coverage.php b/coverage.php new file mode 100644 index 00000000..794946df --- /dev/null +++ b/coverage.php @@ -0,0 +1,92 @@ + + + + +Coverage + + + + +]+)~', $s, $matches); + foreach ($matches[1] as $val) { + if ($val{0} == "/") { + array_pop($return); + } elseif (substr($val, -1) != "/") { + $return[] = $val; + } + } + return $return; +} + +if (!extension_loaded("xdebug")) { + echo "

Xdebug has to be enabled.

\n"; +} elseif ($_GET["coverage"] === "0") { + mysql_query("DROP TABLE IF EXISTS adminer_test.coverage"); + mysql_query("CREATE TABLE adminer_test.coverage ( + filename varchar(100) NOT NULL, + coverage_serialize mediumtext NOT NULL, + PRIMARY KEY (filename) + )"); + echo "

Coverage started.

\n"; +} elseif (preg_match('~^(adminer|editor)/(include/)?[-_.a-z0-9]+$~i', $_GET["coverage"])) { + // highlight single file + $filename = $_GET["coverage"]; + $row = mysql_fetch_row(mysql_query("SELECT coverage_serialize FROM adminer_test.coverage WHERE filename = '" . mysql_real_escape_string(realpath($filename)) . "'")); + $cov = ($row ? unserialize($row[0]) : array()); + $file = explode("
", highlight_file($filename, true)); + unset($prev_color); + $s = ""; + for ($l=0; $l <= count($file); $l++) { + $line = $file[$l]; + $color = "#C0FFC0"; // tested + switch ($cov[$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 "" . $s; + $open_tags = xhtml_open_tags($s); + foreach (array_reverse($open_tags) as $tag) { + echo ""; + } + echo "\n"; + $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : ""); + $prev_color = $color; + } + $s .= "$line
\n"; + } +} else { + // display list of files + $result = mysql_query("SELECT filename, coverage_serialize FROM adminer_test.coverage"); + if ($result) { + echo "\n"; + $coverage = array(); + while ($row = mysql_fetch_assoc($result)) { + $coverage[$row["filename"]] = unserialize($row["coverage_serialize"]); + } + mysql_free_result($result); + foreach (array_merge(glob("adminer/*.php"), glob("adminer/include/*.php"), glob("editor/*.php"), glob("editor/include/*.php")) as $filename) { + $cov = $coverage[realpath($filename)]; + $ratio = 0; + if (is_array($cov)) { + $values = array_count_values($cov); + $ratio = round(100 - 100 * $values[-1] / count($cov)); + } + echo "\n"; + } + echo "
$ratio%$filename
\n"; + } + echo "

Start new coverage

\n"; +} +?> + + + diff --git a/tests/0-login.html b/tests/0-login.html index 6263e746..8e741f73 100644 --- a/tests/0-login.html +++ b/tests/0-login.html @@ -11,11 +11,6 @@ Create database - - open - /adminer/adminer/?coverage=0 - - open /adminer/adminer/?lang=en&username= diff --git a/tests/1-create-database.html b/tests/1-create-database.html index 5ff2dc98..f44f7851 100644 --- a/tests/1-create-database.html +++ b/tests/1-create-database.html @@ -41,6 +41,11 @@ Database has been created. + + open + /adminer/coverage.php?coverage=0 + + diff --git a/tests/logout.html b/tests/logout.html index d3358b14..1e1480cd 100644 --- a/tests/logout.html +++ b/tests/logout.html @@ -38,7 +38,7 @@ open - /adminer/adminer/?coverage= + /adminer/coverage.php diff --git a/tests/selenium.html b/tests/selenium.html index 42d3517f..dc9639a2 100644 --- a/tests/selenium.html +++ b/tests/selenium.html @@ -31,8 +31,8 @@ Procedures Variables History -Logout Editor +Logout