Skip to content
Browse files

Code coverage

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@514 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent c49331e commit bb1ae0ba5405f4cffcf0ca59af8ab284c9542fe2 jakubvrana committed Oct 2, 2008
Showing with 108 additions and 1 deletion.
  1. +1 −0 _compile.php
  2. +66 −0 _coverage.php
  3. +1 −1 design.inc.php
  4. +13 −0 index.php
  5. +5 −0 tests/0-login.html
  6. +22 −0 tests/coverage.html
View
1 _compile.php
@@ -101,6 +101,7 @@ function php_shrink($input) {
$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);
View
66 _coverage.php
@@ -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>
View
2 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) {
View
13 index.php
@@ -12,6 +12,19 @@
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)) {
View
5 tests/0-login.html
@@ -13,6 +13,11 @@
</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>
<td></td>
</tr>
View
22 tests/coverage.html
@@ -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>

0 comments on commit bb1ae0b

Please sign in to comment.
Something went wrong with that request. Please try again.