svn: /pear2/Pyrus_Developer/trunk/src/Pyrus/Developer/CoverageAnalyzer/ Sqlite.php

[email protected] (Brett Bieber)
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
saltybeagle                              Wed, 26 May 2010 16:48:53 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=299802

Log:
Improve old test deletion. Minor readability improvements. Patch from Helgi.

Changed paths:
    U   pear2/Pyrus_Developer/trunk/src/Pyrus/Developer/CoverageAnalyzer/Sqlite.php

Modified: pear2/Pyrus_Developer/trunk/src/Pyrus/Developer/CoverageAnalyzer/Sqlite.php
===================================================================
--- pear2/Pyrus_Developer/trunk/src/Pyrus/Developer/CoverageAnalyzer/Sqlite.php	2010-05-26 16:47:44 UTC (rev 299801)
+++ pear2/Pyrus_Developer/trunk/src/Pyrus/Developer/CoverageAnalyzer/Sqlite.php	2010-05-26 16:48:53 UTC (rev 299802)
@@ -15,6 +15,7 @@
     private $statement;
     private $lines = array();
     private $files = array();
+    private $deleted = array();

     const COVERAGE_COVERED      = 1;
     const COVERAGE_NOT_EXECUTED = 0;
@@ -430,16 +431,31 @@
             $id = $this->getTestId($testpath);
         }

-        echo "deleting old test ", $testpath,'.';
+        // gather information
+        $sql = 'SELECT DISTINCT files_id FROM coverage
+                WHERE
+                    tests_id = ' . $id ;
+        if (!empty($this->deleted)) {
+            $sql .= '
+                AND
+                    files_id NOT IN (' . implode(', ', $this->deleted) . ')';
+        }
+
+        $result = $this->db->query($sql);
+        while ($res = $result->fetchArray(SQLITE3_ASSOC)) {
+            $this->deleted[] = $res['files_id'];
+        }
+
+        echo "\ndeleting old test ", $testpath," .";
         $this->db->exec('DELETE FROM tests WHERE id = ' . $id);
         echo '.';
         $this->db->exec('DELETE FROM coverage WHERE tests_id = ' . $id);
         echo '.';
         $this->db->exec('DELETE FROM coverage_nonsource WHERE tests_id = ' . $id);
         echo '.';
-        $this->db->exec('DELETE FROM xdebugs WHERE path = "' .
-                        $this->db->escapeString(str_replace('.phpt', '.xdebug', $testpath)) . '"');
-        echo "done\n";
+        $p = $this->db->escapeString(str_replace('.phpt', '.xdebug', $testpath));
+        $this->db->exec('DELETE FROM xdebugs WHERE path = "' . $p . '"');
+        echo " done\n";
     }

     function addTest($testpath, $id = null)
@@ -605,7 +621,13 @@
                     // Only allow lines that are in the new rollout.
                     isset($this->lines[$id][$line]) ||
                     // Line already marked as covered.
-                    (isset($this->lines[$id][$line]) && $this->lines[$id][$line] !== 1 && $state > $this->lines[$id][$line])
+                    (
+                        isset($this->lines[$id][$line]) &&
+                        (
+                         $this->lines[$id][$line] !== Sqlite::COVERAGE_COVERED ||
+                         $state > $this->lines[$id][$line]
+                        )
+                    )
                 ) {
                     $this->lines[$id][$line] = $state;
                 }
@@ -764,7 +786,7 @@
                     if (
                         !isset($this->lines[$id][$line]) ||
                         // Line already marked as covered.
-                        $this->lines[$id][$line] !== 1 ||
+                        $this->lines[$id][$line] !== Sqlite::COVERAGE_COVERED ||
                         $state > $this->lines[$id][$line]
                     ) {
                         $this->lines[$id][$line] = $state;
@@ -811,10 +833,11 @@
         // first scan for new .phpt files
         $tests = array();
         foreach (new \RegexIterator(
-                                    new \RecursiveIteratorIterator(
-                                        new \RecursiveDirectoryIterator($this->testpath,
-                                                                        0|\RecursiveDirectoryIterator::SKIP_DOTS)),
-                                    '/\.phpt$/') as $file) {
+                    new \RecursiveIteratorIterator(
+                        new \RecursiveDirectoryIterator($this->testpath,
+                                                        0|\RecursiveDirectoryIterator::SKIP_DOTS)
+                    ), '/\.phpt$/') as $file
+        ) {
             if (strpos((string) $file, '.svn')) {
                 continue;
             }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.