mirror of
https://github.com/vrana/adminer.git
synced 2025-08-26 07:44:37 +02:00
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:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user