]> git.joonet.de Git - adminer.git/commitdiff
Code coverage
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Thu, 2 Oct 2008 16:42:55 +0000 (16:42 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Thu, 2 Oct 2008 16:42:55 +0000 (16:42 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@514 7c3ca157-0c34-0410-bff1-cbf682f78f5c

_compile.php
_coverage.php [new file with mode: 0644]
design.inc.php
index.php
tests/0-login.html
tests/coverage.html [new file with mode: 0644]

index b2872bcf8797926259446876285c62a852ef7806..28f13555a0d22085aa816c768f251efe78756411 100644 (file)
@@ -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("<?php switch_lang(); ?>\n", "", $file);
diff --git a/_coverage.php b/_coverage.php
new file mode 100644 (file)
index 0000000..3c0dd65
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+error_reporting(E_ALL & ~E_NOTICE);
+if (!ini_get("session.auto_start")) {
+       session_name("phpMinAdmin_SID");
+       session_set_cookie_params(ini_get("session.cookie_lifetime"), preg_replace('~_coverage\\.php(\\?.*)?$~', '', $_SERVER["REQUEST_URI"]));
+       session_start();
+}
+
+function xhtml_open_tags($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 ($_GET["start"]) {
+       $_SESSION["coverage"] = array();
+       header("Location: .");
+       exit;
+} elseif ($_GET["filename"]) {
+       $filename = basename($_GET["filename"]);
+       $coverage = $_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 ($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 "<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";
+       }
+} elseif (isset($_SESSION["coverage"])) {
+       echo "<ul>\n";
+       foreach (glob("*.php") as $filename) {
+               if ($filename{0} != "_") {
+                       $coverage = $_SESSION["coverage"][realpath($filename)];
+                       echo "<li><a href='_coverage.php?filename=$filename'>$filename</a> (" . (isset($coverage) ? "tested" : "untested") . ")</li>\n";
+               }
+       }
+       echo "</ul>\n";
+}
+?>
+<p><a href="_coverage.php?start=1">Start new coverage</a> (requires <a href="http://www.xdebug.org">Xdebug</a>)</p>
index 12f3ba4b9e1bcb7ff7e38e971276d4471cde4f3f..577cefa3bd657f10ddd9f1d0ce3eec9e4e118a2f 100644 (file)
@@ -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) {
index 1a7e94ba5a65210c985ebcd16172e930378a7811..c8f530858bc446b47f52921173ab35387e24ccc5 100644 (file)
--- 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)) {
index 4cdf71720265b297b41442698d969178e9d34bfa..5354cdcbf233ea6c0cdeac3fbc2e56acdcf9ce5f 100644 (file)
 <thead>
 <tr><td rowspan="1" colspan="3">Create database</td></tr>
 </thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/phpMinAdmin/_coverage.php?start=1</td>
+       <td></td>
+</tr>
 <tr>
        <td>open</td>
        <td>/phpMinAdmin/?lang=en&amp;username=</td>
diff --git a/tests/coverage.html b/tests/coverage.html
new file mode 100644 (file)
index 0000000..512dd02
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!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" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>Coverage</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">Coverage</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/phpMinAdmin/_coverage.php</td>
+       <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>