diff -r e62d28bce2a7 code_coverage.admin.inc
--- a/code_coverage.admin.inc	Thu Sep 17 16:22:10 2009 +0200
+++ b/code_coverage.admin.inc	Thu Sep 17 16:38:24 2009 +0200
@@ -28,8 +28,8 @@
   // Generate a list of all files we /could/ generate reports for.
   $result = db_query('SELECT DISTINCT(filename) FROM {code_coverage}');
   $files = array();
-  while ($filename = db_fetch_array($result)) {
-    $files[$filename['filename']] = str_replace('\\', '/', substr(str_replace(getcwd() , '', $filename['filename']), 1));
+  foreach($result as $filename) {
+    $files[$filename->filename] = str_replace('\\', '/', substr(str_replace(getcwd() , '', $filename->filename), 1));
   }
 
   $form['code_coverage_all'] = array(
@@ -124,8 +124,8 @@
   if (is_null($cid)) {
     $result = db_query('SELECT DISTINCT(cid) FROM {code_coverage}');
     $items = array();
-    while ($cid = db_fetch_array($result)) {
-      $items[] = l(t('Code coverage report #@num', array('@num' => $cid['cid'])), 'coverage/'. $reporter . '/' . $cid['cid']);
+    foreach ($result as $cid) {
+      $items[] = l(t('Code coverage report #@num', array('@num' => $cid->cid)), 'coverage/'. $reporter . '/' . $cid->cid);
     }
     return theme('item_list', $items, t('Choose from any of the following reports.'), 'ol');
   }
@@ -171,8 +171,8 @@
     $result = db_query('SELECT * FROM {code_coverage} WHERE cid = %d', $cid);
   }
   $lines = array();
-  while ($line = db_fetch_array($result)) {
-    $lines[$line['filename']][$line['line']] = $line['times'];
+  foreach ($result as $line) {
+    $lines[$line->filename][$line->line] = $line->times;
   }
   ksort($lines);
   return $lines;
@@ -237,7 +237,12 @@
       $row[] = $covered_lines[$file];
       $row[] = $uncovered_lines[$file];
       $row[] = sprintf('%04.2f%%', ($covered_lines[$file] * 100) / ($covered_lines[$file] + $uncovered_lines[$file]));
-      $rows[] = array('data' => $row, 'class' => ((substr(end($row), 0, -1) >= $good) ? 'code-coverage-covered' : ((substr(end($row), 0, -1) >= $ok) ? 'code-coverage-moderate' : 'code-coverage-uncovered')));
+      $rows[] = array(
+        'data' => $row,
+        'class' => array(
+          ((substr(end($row), 0, -1) >= $good) ? 'code-coverage-covered' : ((substr(end($row), 0, -1) >= $ok) ? 'code-coverage-moderate' : 'code-coverage-uncovered'))
+        )
+      );
     }
     $total_covered = array_sum($covered_lines);
     $total_uncovered = array_sum($uncovered_lines);
@@ -246,9 +251,24 @@
     $row[] = $total_covered;
     $row[] = $total_uncovered;
     $row[] = sprintf('%04.2f%%', ($total_covered * 100) / ($total_covered + $total_uncovered));
-    $row = array('data' => $row, 'class' => 'code-coverage-overview ' . ((substr(end($row), 0, -1) > $good) ? 'code-coverage-covered' : ((substr(end($row), 0, -1) > $ok) ? 'code-coverage-moderate' : 'code-coverage-uncovered')));
+    $row = array(
+      'data' => $row,
+      'class' => array(
+        'code-coverage-overview',
+        ((substr(end($row), 0, -1) > $good) ? 'code-coverage-covered' : ((substr(end($row), 0, -1) > $ok) ? 'code-coverage-moderate' : 'code-coverage-uncovered'))
+      )
+    );
     array_unshift($rows, $row);
-    return theme('table', array(t('File !arrow', array('!arrow' => theme('image', 'misc/arrow-asc.png'))), t('Covered lines'), t('Uncovered lines'), t('Code coverage %')), $rows, array('class' => 'code-coverage-overview-report'));
+
+    $header = array(
+      t('File !arrow',
+      array('!arrow' => theme('image', 'misc/arrow-asc.png'))),
+      t('Covered lines'),
+      t('Uncovered lines'),
+      t('Code coverage %')
+    );
+
+    return theme('table', $header, $rows, array('class' => array('code-coverage-overview-report')));
   }
   else {
     drupal_set_title(t('Code coverage for @file', array('@file' => str_replace('\\', '/', substr(str_replace(getcwd() , '', $file), 1)))));
@@ -261,9 +281,15 @@
       $row[] = $key + 1;
       $row[] = isset($lines[$key + 1]) ? $lines[$key + 1] : '';
       $row[] = '<pre>' . check_plain(wordwrap($line)) . '</pre>';
-      $rows[] = array('data' => $row, 'id' => 'code-coverage-' . ($key + 1), 'class' => (isset($lines[$key + 1]) ? ($lines[$key + 1] >= $covered ? 'code-coverage-covered' : 'code-coverage-uncovered') : 'code-coverage-none'));
+      $rows[] = array(
+        'data' => $row,
+        'id' => 'code-coverage-' . ($key + 1),
+        'class' => array(
+          (isset($lines[$key + 1]) ? ($lines[$key + 1] >= $covered ? 'code-coverage-covered' : 'code-coverage-uncovered') : 'code-coverage-none')
+        )
+      );
     }
-    return theme('table', array(t('Line #'), t('Times called'), t('Code')), $rows, array('class' => 'code-coverage-file-report'));
+    return theme('table', array(t('Line #'), t('Times called'), t('Code')), $rows, array('class' => array('code-coverage-file-report')));
   }
 }
 
@@ -291,4 +317,4 @@
   print $xml;
   drupal_page_footer();
   exit;
-}
\ No newline at end of file
+}
diff -r e62d28bce2a7 code_coverage.module
--- a/code_coverage.module	Thu Sep 17 16:22:10 2009 +0200
+++ b/code_coverage.module	Thu Sep 17 16:38:24 2009 +0200
@@ -1,9 +1,21 @@
 <?php
 // $Id: code_coverage.module,v 1.4 2008/06/29 00:43:48 cwgordon7 Exp $
 
+define('CODE_COVERAGE_PHASE_START', 0);
+define('CODE_COVERAGE_PHASE_LOADED', 1);
+
+set_time_limit(600);
 if (preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT']) && function_exists('xdebug_start_code_coverage')) {
-  xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
-  register_shutdown_function('code_coverage_log');
+  code_coverage_start(CODE_COVERAGE_PHASE_START);
+}
+
+function code_coverage_start() {
+  static $started = FALSE;
+
+  if (!$started) {
+    xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
+    register_shutdown_function('code_coverage_log');
+  }
 }
 
 /**
@@ -16,7 +28,7 @@
     if (!variable_get('code_coverage_hacks', FALSE)) {
       $passes = TRUE;
       foreach (array('index.php', 'xmlrpc.php') as $file) {
-        $code = 'require_once \'./' . str_replace('\\', '/', substr(str_replace(getcwd(), '', __FILE__), 1)) . '\';' . "\n";
+        $code = 'require_once DRUPAL_ROOT . \'/' . str_replace('\\', '/', substr(str_replace(getcwd(), '', __FILE__), 1)) . '\';' . "\n";
         $contents = file_get_contents("./$file");
         if (strpos($contents, $code) === FALSE) {
           $passes = FALSE;
@@ -47,12 +59,13 @@
 function code_coverage_menu() {
   $items = array();
 
-  $items['admin/settings/coverage'] = array(
+  $items['admin/config/development/coverage'] = array(
     'title' => 'Code coverage',
     'description' => 'Configure the generation of Drupal\'s code coverage reports.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('code_coverage_settings_form'),
     'access arguments' => array('administer code coverage'),
+    'file' => 'code_coverage.admin.inc',
   );
 
   $items['coverage'] = array(
@@ -60,6 +73,7 @@
     'description' => 'Generate code coverage reports based on the collected coverage data.',
     'page callback' => 'code_coverage_generate_report',
     'access arguments' => array('view code coverage reports'),
+    'file' => 'code_coverage.admin.inc',
   );
 
   return $items;
@@ -91,7 +105,7 @@
   global $db_prefix, $db_prefix_original;
   $preserved_prefix = $db_prefix;
   $db_prefix = $db_prefix_original;
-  $GLOBALS['conf'] = variable_init();
+  $GLOBALS['conf'] = variable_initialize();
   $info = xdebug_get_code_coverage();
   $text = '';
   foreach ($info as $file => $lines) {
@@ -111,17 +125,18 @@
   }
   file_put_contents(variable_get('code_coverage_tmp_storage', '/tmp/') . variable_get('code_coverage_id', 1) . '.txt', $text, FILE_APPEND);
   $db_prefix = $preserved_prefix;
-  $GLOBALS['conf'] = variable_init();
+  $GLOBALS['conf'] = variable_initialize();
 }
 
 /**
  * Fetch all the code coverage data from a file and store it to the database.
  */
 function code_coverage_fetch_data() {
-  $file = variable_get('code_coverage_tmp_storage', '/tmp/') . variable_get('code_coverage_id', 1) . '.txt';
-  if (file_exists($file) && is_file($file) && $_GET['q'] == 'admin/build/testing' && user_access('administer code coverage')) {
+  $cid = variable_get('code_coverage_id', 1);
+  $file = variable_get('code_coverage_tmp_storage', '/tmp/') . $cid . '.txt';
+
+  if (file_exists($file) && is_file($file) && $_GET['q'] == 'admin/config/development/testing' && user_access('administer code coverage')) {
     $contents = file_get_contents($file);
-    file_delete($file);
     $entries = explode("\n", $contents);
     $data = array();
     foreach ($entries as $entry) {
@@ -134,11 +149,29 @@
         }
       }
     }
+
+    $query = db_insert('code_coverage')->fields(
+      array(
+        'cid',
+        'filename',
+        'line',
+        'times'
+      )
+    );
+
     foreach ($data as $filename => $info) {
       foreach ($info as $line => $times) {
-        db_query("INSERT INTO {code_coverage} VALUES (%d, '%s', %d, %d)", variable_get('code_coverage_id', 1), $filename, $line, $times);
+        $query->values(
+          array(
+            'cid' => $cid,
+            'filename' => $filename,
+            'line' => $line,
+            'times' => (int)$times
+          )
+        )->execute();
       }
     }
-    variable_set('code_coverage_id', variable_get('code_coverage_id', 1) + 1);
+    variable_set('code_coverage_id', $cid + 1);
+    unlink($file);
   }
-}
\ No newline at end of file
+}
diff -r e62d28bce2a7 coverage.patch
--- a/coverage.patch	Thu Sep 17 16:22:10 2009 +0200
+++ b/coverage.patch	Thu Sep 17 16:38:24 2009 +0200
@@ -1,55 +1,56 @@
 Index: index.php
 ===================================================================
 RCS file: /cvs/drupal/drupal/index.php,v
-retrieving revision 1.94
-diff -u -p -r1.94 index.php
---- index.php	26 Dec 2007 08:46:48 -0000	1.94
-+++ index.php	9 Aug 2008 20:13:10 -0000
-@@ -1,6 +1,6 @@
- <?php
- // $Id: coverage.patch,v 1.1 2008/11/01 22:29:48 cwgordon7 Exp $
--
-+require_once './sites/all/modules/code_coverage/code_coverage.module';
- /**
-  * @file
-  * The PHP page that serves all page requests on a Drupal installation.
+retrieving revision 1.98
+diff -u -p -r1.98 index.php
+--- index.php	8 Feb 2009 20:27:51 -0000	1.98
++++ index.php	17 Sep 2009 13:14:06 -0000
+@@ -17,6 +17,10 @@
+  */
+ define('DRUPAL_ROOT', getcwd());
+
++// Patched for code coverage.
++require_once DRUPAL_ROOT . '/sites/all/modules/code_coverage/code_coverage.module';
++// End patch.
++
+ require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+ $return = menu_execute_active_handler();
 Index: xmlrpc.php
 ===================================================================
 RCS file: /cvs/drupal/drupal/xmlrpc.php,v
-retrieving revision 1.15
-diff -u -p -r1.15 xmlrpc.php
---- xmlrpc.php	10 Dec 2005 19:26:47 -0000	1.15
-+++ xmlrpc.php	9 Aug 2008 20:13:10 -0000
-@@ -1,6 +1,6 @@
- <?php
- // $Id: coverage.patch,v 1.1 2008/11/01 22:29:48 cwgordon7 Exp $
--
-+require_once './sites/all/modules/code_coverage/code_coverage.module';
- /**
-  * @file
-  * PHP page for handling incoming XML-RPC requests from clients.
+retrieving revision 1.17
+diff -u -p -r1.17 xmlrpc.php
+--- xmlrpc.php	8 Feb 2009 20:27:51 -0000	1.17
++++ xmlrpc.php	17 Sep 2009 13:14:06 -0000
+@@ -11,6 +11,10 @@
+  */
+ define('DRUPAL_ROOT', getcwd());
+
++// Patched for code coverage.
++require_once DRUPAL_ROOT . '/sites/all/modules/code_coverage/code_coverage.module';
++// End patch.
++
+ include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+ include_once DRUPAL_ROOT . '/includes/xmlrpc.inc';
 Index: modules/simpletest/simpletest.module
 ===================================================================
 RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v
-retrieving revision 1.8
-diff -u -p -r1.8 simpletest.module
---- modules/simpletest/simpletest.module	9 Aug 2008 12:41:22 -0000	1.8
-+++ modules/simpletest/simpletest.module	9 Aug 2008 20:13:12 -0000
-@@ -324,7 +324,7 @@ function simpletest_run_tests($test_list
-     simpletest_get_all_tests();
-     foreach ($test_list as $test_class) {
-       $test = new $test_class($test_id);
--      $test->run();
-+      xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);$test->run();code_coverage_log();
-     }
-     $_SESSION['test_id'] = $test_id;
-   }
-@@ -354,7 +354,7 @@ function _simpletest_batch_operation($te
+retrieving revision 1.72
+diff -u -p -r1.72 simpletest.module
+--- modules/simpletest/simpletest.module	17 Sep 2009 03:47:23 -0000	1.72
++++ modules/simpletest/simpletest.module	17 Sep 2009 13:14:07 -0000
+@@ -191,7 +191,13 @@ function _simpletest_batch_operation($te
    // Perform the next test.
    $test_class = array_shift($test_list);
    $test = new $test_class($test_id);
--  $test->run();
-+  xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);$test->run();code_coverage_log();
++
++  // Patched for code coverage.
++  xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
+   $test->run();
++  code_coverage_log();
++  // End patch.
++
    $size = count($test_list);
    $info = $test->getInfo();
- 
