Permalink
Browse files

Save coverage to temporary file

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@927 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 988a29f commit be9c98afc204e78ac0b78b1e1455df5a3efec6f5 jakubvrana committed Jul 28, 2009
Showing with 17 additions and 34 deletions.
  1. +4 −11 adminer/include/coverage.inc.php
  2. +8 −18 coverage.php
  3. +5 −0 tests/0-login.html
  4. +0 −5 tests/1-create-database.html
View
15 adminer/include/coverage.inc.php
@@ -1,23 +1,16 @@
<?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')) {
+if (extension_loaded("xdebug") && file_exists(sys_get_temp_dir() . "/adminer_coverage.ser")) {
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);
+ $coverage_filename = sys_get_temp_dir() . "/adminer_coverage.ser";
+ $coverage = unserialize(file_get_contents($coverage_filename));
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])) . "')
- ");
+ file_put_contents($coverage_filename, serialize($coverage));
}
}
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
View
26 coverage.php
@@ -22,28 +22,23 @@ function xhtml_open_tags($s) {
return $return;
}
+$coverage_filename = sys_get_temp_dir() . "/adminer_coverage.ser";
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)
- )");
+ file_put_contents($coverage_filename, serialize(array()));
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());
+ $coverage = (file_exists($coverage_filename) ? unserialize(file_get_contents($coverage_filename)) : 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]) {
+ switch ($coverage[realpath($filename)][$l+1]) {
case -1: $color = "#FFC0C0"; break; // untested
case -2: $color = "Silver"; break; // dead code
case null: $color = ""; break; // not executable
@@ -64,21 +59,16 @@ function xhtml_open_tags($s) {
$s .= "$line<br />\n";
}
} else {
- // display list of files
- $result = mysql_query("SELECT filename, coverage_serialize FROM adminer_test.coverage");
- if ($result) {
+ if (file_exists($coverage_filename)) {
+ // display list of files
+ $coverage = unserialize(file_get_contents($coverage_filename));
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));
+ $ratio = round(100 - 100 * $values[-1] / (count($cov) - $values[-2]));
}
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";
}
View
5 tests/0-login.html
@@ -13,6 +13,11 @@
</thead><tbody>
<tr>
<td>open</td>
+ <td>/adminer/coverage.php?coverage=0</td>
+ <td></td>
+</tr>
+<tr>
+ <td>open</td>
<td>/adminer/adminer/?lang=en&amp;username=</td>
<td></td>
</tr>
View
5 tests/1-create-database.html
@@ -41,11 +41,6 @@
<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>

0 comments on commit be9c98a

Please sign in to comment.