diff --git a/tests/Test.php b/tests/Test.php index a6e2fa055..ec39803b0 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -3,6 +3,13 @@ class GroupTest { protected $_testCases = array(); + public function __construct() + { + if (extension_loaded('xdebug')) { + //xdebug_start_code_coverage(XDEBUG_CC_DEAD_CODE | XDEBUG_CC_UNUSED); + } + } + public function addTestCase(UnitTestCase $testCase) { $this->_testCases[] = $testCase; diff --git a/tests/UnitTestCase.php b/tests/UnitTestCase.php index 2b698d3d4..8b6b36cfc 100644 --- a/tests/UnitTestCase.php +++ b/tests/UnitTestCase.php @@ -100,6 +100,8 @@ class Doctrine_UnitTestCase extends UnitTestCase $this->driverName = 'Sqlite'; break; } + + $module = $e[1]; if(count($e) > 3) { $driver = $e[2]; @@ -148,12 +150,23 @@ class Doctrine_UnitTestCase extends UnitTestCase $this->manager->setAttribute(Doctrine::ATTR_LISTENER, $this->listener); } if ($this->driverName !== 'main') { - $this->export = $this->connection->export; - $this->transaction = $this->connection->transaction; - $this->dataDict = $this->connection->dataDict; - $this->expr = $this->connection->expression; - $this->sequence = $this->connection->sequence; - $this->import = $this->connection->import; + + if (isset($module)) { + switch($module) { + case 'Export': + case 'Import': + case 'Transaction': + case 'Sequence': + case 'Expression': + $lower = strtolower($module); + + $this->$lower = $this->connection->$lower; + break; + case 'DataDict': + $this->dataDict = $this->connection->dataDict; + break; + } + } } $this->unitOfWork = $this->connection->unitOfWork; $this->connection->setListener(new Doctrine_EventListener()); diff --git a/tests/run.php b/tests/run.php index 3eeebc60e..94b6c5894 100644 --- a/tests/run.php +++ b/tests/run.php @@ -3,8 +3,9 @@ ini_set('max_execution_time', 900); function autoload($class) { - if(strpos($class, 'TestCase') === false) + if(strpos($class, 'TestCase') === false) { return false; + } $e = explode('_', $class); $count = count($e); @@ -63,7 +64,6 @@ $test = new GroupTest('Doctrine Framework Unit Tests'); // DATABASE ABSTRACTION tests -/** */ // Temp tests /** @@ -323,7 +323,7 @@ $test->addTestCase(new Doctrine_Record_SaveBlankRecord_TestCase()); $test->addTestCase(new Doctrine_Template_TestCase()); - /** */ + //$test->addTestCase(new Doctrine_IntegrityAction_TestCase()); //$test->addTestCase(new Doctrine_AuditLog_TestCase()); @@ -375,7 +375,53 @@ class MyReporter extends HtmlReporter { run(new MyReporter()); +$path = Doctrine::getPath() . DIRECTORY_SEPARATOR; + ?> + + + class + coverage + + +$coverage = xdebug_get_code_coverage(); +ksort($coverage); +foreach ($coverage as $file => $lines) { + + $pos = strpos($file, $path); + + $values = array_values($lines); + $i = count($values); + $covered = 0; + while ($i--) { + if ($values[$i] > 0) { + $covered++; + } + } + + if ($pos !== false) { + $class = str_replace(DIRECTORY_SEPARATOR, '_', substr($file, strlen($path), -4)); + + if (strpos($class, '_Interface')) { + continue; + } + + $refl = new ReflectionClass($class); + $total = 0; + foreach ($refl->getMethods() as $method) { + $total += ($method->getEndLine() - $method->getStartLine()); + } + if ($total === 0) { + $total = 1; + } + print "" . $class . "" . round(($covered / $total) * 100, 2) . " % "; + } +} +*/ +?> +