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 17:00:11 +0000

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

Log:
Improve coverage generation for files with no test coverage.
* Set up a simple autoloader for additional files from src directory so 'extends' and 'implements' don't cause fatal errors when determining non-covered lines.
* When the non-covered file is Foo/Bar.php check class_exists for Foo_Bar, Foo\Bar, then PEAR2\Foo\Bar before attempting to include.
* Add todo item about files already loaded that need coverage added.

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:48:53 UTC (rev 299802)
+++ pear2/Pyrus_Developer/trunk/src/Pyrus/Developer/CoverageAnalyzer/Sqlite.php	2010-05-26 17:00:11 UTC (rev 299803)
@@ -701,6 +701,20 @@
             }
         }

+        $codepath = $this->codepath;
+        spl_autoload_register(function($class) use ($codepath){
+            $file = str_replace(array('\\', '_'), DIRECTORY_SEPARATOR, $class);
+            if (file_exists($codepath . DIRECTORY_SEPARATOR . $file . '.php')) {
+                include $codepath . DIRECTORY_SEPARATOR . $file . '.php';
+                return true;
+            }
+            if ($file = stream_resolve_include_path($file . '.php')) {
+                include $file;
+                return true;
+            }
+            return false;
+        });
+
         foreach ($this->files as $file) {
             if (empty($file)) {
                 continue;
@@ -712,11 +726,19 @@
             // Figure out of the file has been already inclduded or not
             $included = false;

-            $class = str_replace(array($this->codepath, '.php'), '', $file);
-            $class = 'PEAR2' . str_replace('/', '\\', $class);
+            $relative_file = substr($file, strlen($this->codepath . DIRECTORY_SEPARATOR), -4);

+            // We need to try a few things here to actually find the correct class
+            // Foo/Bar.php may mean Foo_Bar Foo\Bar or PEAR2\Foo\Bar
+            $class       = str_replace('/', '_', $relative_file);
+            $ns_class    = str_replace('/', '\\', $relative_file);
+            $pear2_class = 'PEAR2\\' . $ns_class;
+
             $classes = array_merge(get_declared_classes(), get_declared_interfaces());
-            if (in_array($class, $classes)) {
+
+            if (in_array($class, $classes)
+                || in_array($ns_class, $classes)
+                || in_array($pear2_class, $classes)) {
                 $included = true;
             }

@@ -726,6 +748,11 @@
                 include $file;
                 $data = xdebug_get_code_coverage(true);
                 $this->lines[$id] = $data[$file];
+            } else {
+                /*
+                 * @TODO files that already have been loaded need to have
+                 * their missing coverage lines added too
+                 */
             }
         }
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.