Save coverage to database
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@906 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
b2107e8985
commit
70c8343ffd
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
//! measure Editor
|
||||
|
||||
function xhtml_open_tags($s) {
|
||||
// returns array of opened tags in $s
|
||||
$return = array();
|
||||
preg_match_all('~<([^>]+)~', $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 "<p class='message'>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("<br />", 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 "<div" . ($prev_color ? " style='background-color: $prev_color;'" : "") . ">" . $s;
|
||||
$open_tags = xhtml_open_tags($s);
|
||||
foreach (array_reverse($open_tags) as $tag) {
|
||||
echo "</" . preg_replace('~ .*~', '', $tag) . ">";
|
||||
}
|
||||
echo "</div>\n";
|
||||
$s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : "");
|
||||
$prev_color = $color;
|
||||
}
|
||||
$s .= "$line<br>\n";
|
||||
}
|
||||
} else {
|
||||
// display list of files
|
||||
echo "<table cellspacing='0'>\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 "<tr><td align='right' style='background-color: " . ($ratio < 50 ? "Red" : ($ratio < 75 ? "#FFEA20" : "#A7FC9D")) . ";'>$ratio%<th><a href=\"" . htmlspecialchars($SELF) . "coverage=$filename\">$filename</a>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'coverage=0">Start new coverage</a>' . "\n";
|
||||
}
|
||||
page_footer("auth");
|
||||
exit;
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
error_reporting(4343); // errors and warnings
|
||||
|
||||
include "../adminer/include/coverage.inc.php";
|
||||
|
||||
// disable filter.default
|
||||
$filter = (!ereg('^(unsafe_raw)?$', ini_get("filter.default")) || ini_get("filter.default_flags"));
|
||||
if ($filter) {
|
||||
|
@ -44,21 +46,6 @@ if (!ini_get("session.auto_start")) {
|
|||
session_start();
|
||||
}
|
||||
|
||||
if (isset($_SESSION["coverage"])) {
|
||||
// coverage is used in tests and removed in compilation
|
||||
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');
|
||||
}
|
||||
|
||||
// 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";
|
||||
|
|
25
adminer/include/coverage.inc.php
Normal file
25
adminer/include/coverage.inc.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
// coverage is used in tests and removed in compilation
|
||||
if (extension_loaded("xdebug") && function_exists('mysql_query') && mysql_query('SELECT 1 FROM adminer_test.coverage LIMIT 0')) {
|
||||
function save_coverage() {
|
||||
$coverage = array();
|
||||
$result = mysql_query("SELECT filename, coverage_serialize FROM adminer_test.coverage");
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$coverage[$row["filename"]] = unserialize($row["coverage_serialize"]);
|
||||
}
|
||||
mysql_free_result($result);
|
||||
foreach (xdebug_get_code_coverage() as $filename => $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');
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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"]) {
|
||||
|
|
92
coverage.php
Normal file
92
coverage.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="cs">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Coverage</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
function xhtml_open_tags($s) {
|
||||
// returns array of opened tags in $s
|
||||
$return = array();
|
||||
preg_match_all('~<([^>]+)~', $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 "<p class='error'>Xdebug has to be enabled.</p>\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 "<p class='message'>Coverage started.</p>\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("<br />", 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 "<div" . ($prev_color ? " style='background-color: $prev_color;'" : "") . ">" . $s;
|
||||
$open_tags = xhtml_open_tags($s);
|
||||
foreach (array_reverse($open_tags) as $tag) {
|
||||
echo "</" . preg_replace('~ .*~', '', $tag) . ">";
|
||||
}
|
||||
echo "</div>\n";
|
||||
$s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : "");
|
||||
$prev_color = $color;
|
||||
}
|
||||
$s .= "$line<br />\n";
|
||||
}
|
||||
} else {
|
||||
// display list of files
|
||||
$result = mysql_query("SELECT filename, coverage_serialize FROM adminer_test.coverage");
|
||||
if ($result) {
|
||||
echo "<table border='1' cellspacing='0'>\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 "<tr><td align='right' style='background-color: " . ($ratio < 50 ? "Red" : ($ratio < 75 ? "#FFEA20" : "#A7FC9D")) . ";'>$ratio%</td><td><a href='coverage.php?coverage=$filename'>$filename</a></td></tr>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
echo "<p><a href='coverage.php?coverage=0'>Start new coverage</a></p>\n";
|
||||
}
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -11,11 +11,6 @@
|
|||
<thead>
|
||||
<tr><td rowspan="1" colspan="3">Create database</td></tr>
|
||||
</thead><tbody>
|
||||
<tr>
|
||||
<td>open</td>
|
||||
<td>/adminer/adminer/?coverage=0</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>open</td>
|
||||
<td>/adminer/adminer/?lang=en&username=</td>
|
||||
|
|
|
@ -41,6 +41,11 @@
|
|||
<td>Database has been created.</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>open</td>
|
||||
<td>/adminer/coverage.php?coverage=0</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
</tbody></table>
|
||||
</body>
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>open</td>
|
||||
<td>/adminer/adminer/?coverage=</td>
|
||||
<td>/adminer/coverage.php</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
<tr><td><a href="19-procedures.html">Procedures</a></td></tr>
|
||||
<tr><td><a href="21-variables.html">Variables</a></td></tr>
|
||||
<tr><td><a href="22-history.html">History</a></td></tr>
|
||||
<tr><td><a href="logout.html">Logout</a></td></tr>
|
||||
<tr><td><a href="23-editor.html">Editor</a></td></tr>
|
||||
<tr><td><a href="logout.html">Logout</a></td></tr>
|
||||
</tbody></table>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue