Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 93 lines (88 sloc) 3.248 kb
70c8343 Save coverage to database
jakubvrana authored
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" lang="cs">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>Coverage</title>
6 </head>
7
8 <body>
9
10 <?php
11 function xhtml_open_tags($s) {
12 // returns array of opened tags in $s
13 $return = array();
14 preg_match_all('~<([^>]+)~', $s, $matches);
15 foreach ($matches[1] as $val) {
16 if ($val{0} == "/") {
17 array_pop($return);
18 } elseif (substr($val, -1) != "/") {
19 $return[] = $val;
20 }
21 }
22 return $return;
23 }
24
25 if (!extension_loaded("xdebug")) {
26 echo "<p class='error'>Xdebug has to be enabled.</p>\n";
27 } elseif ($_GET["coverage"] === "0") {
28 mysql_query("DROP TABLE IF EXISTS adminer_test.coverage");
29 mysql_query("CREATE TABLE adminer_test.coverage (
30 filename varchar(100) NOT NULL,
31 coverage_serialize mediumtext NOT NULL,
32 PRIMARY KEY (filename)
33 )");
34 echo "<p class='message'>Coverage started.</p>\n";
35 } elseif (preg_match('~^(adminer|editor)/(include/)?[-_.a-z0-9]+$~i', $_GET["coverage"])) {
36 // highlight single file
37 $filename = $_GET["coverage"];
38 $row = mysql_fetch_row(mysql_query("SELECT coverage_serialize FROM adminer_test.coverage WHERE filename = '" . mysql_real_escape_string(realpath($filename)) . "'"));
39 $cov = ($row ? unserialize($row[0]) : array());
40 $file = explode("<br />", highlight_file($filename, true));
41 unset($prev_color);
42 $s = "";
43 for ($l=0; $l <= count($file); $l++) {
44 $line = $file[$l];
45 $color = "#C0FFC0"; // tested
46 switch ($cov[$l+1]) {
47 case -1: $color = "#FFC0C0"; break; // untested
48 case -2: $color = "Silver"; break; // dead code
49 case null: $color = ""; break; // not executable
50 }
51 if (!isset($prev_color)) {
52 $prev_color = $color;
53 }
54 if ($prev_color != $color || !isset($line)) {
55 echo "<div" . ($prev_color ? " style='background-color: $prev_color;'" : "") . ">" . $s;
56 $open_tags = xhtml_open_tags($s);
57 foreach (array_reverse($open_tags) as $tag) {
58 echo "</" . preg_replace('~ .*~', '', $tag) . ">";
59 }
60 echo "</div>\n";
61 $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : "");
62 $prev_color = $color;
63 }
64 $s .= "$line<br />\n";
65 }
66 } else {
67 // display list of files
68 $result = mysql_query("SELECT filename, coverage_serialize FROM adminer_test.coverage");
69 if ($result) {
70 echo "<table border='1' cellspacing='0'>\n";
71 $coverage = array();
72 while ($row = mysql_fetch_assoc($result)) {
73 $coverage[$row["filename"]] = unserialize($row["coverage_serialize"]);
74 }
75 mysql_free_result($result);
76 foreach (array_merge(glob("adminer/*.php"), glob("adminer/include/*.php"), glob("editor/*.php"), glob("editor/include/*.php")) as $filename) {
77 $cov = $coverage[realpath($filename)];
78 $ratio = 0;
79 if (is_array($cov)) {
80 $values = array_count_values($cov);
81 $ratio = round(100 - 100 * $values[-1] / count($cov));
82 }
83 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";
84 }
85 echo "</table>\n";
86 }
87 echo "<p><a href='coverage.php?coverage=0'>Start new coverage</a></p>\n";
88 }
89 ?>
90
91 </body>
92 </html>
Something went wrong with that request. Please try again.