Ejemplo n.º 1
0
 /**
  * Returns an array of PHPUnit2_Framework_TestCase classes that are declared
  * by the files included by the filesets
  *
  * @return array an array of PHPUnit2_Framework_TestCase classes.
  */
 function elements()
 {
     $filenames = $this->getFilenames();
     $declaredClasses = array();
     foreach ($filenames as $filename) {
         $definedClasses = PHPUnit2Util::getDefinedClasses($filename, $this->classpath);
         $declaredClasses = array_merge($declaredClasses, $definedClasses);
     }
     $elements = array_filter($declaredClasses, array($this, "filterTests"));
     return $elements;
 }
 protected function transformCoverageInformation($filename, $coverageInformation)
 {
     // Strip last line of coverage information
     end($coverageInformation);
     unset($coverageInformation[key($coverageInformation)]);
     $classes = PHPUnit2Util::getDefinedClasses($filename, $this->classpath);
     if (is_array($classes)) {
         foreach ($classes as $classname) {
             $reflection = new ReflectionClass($classname);
             $methods = $reflection->getMethods();
             $classElement = $this->doc->createElement('class');
             $classElement->setAttribute('name', $reflection->getName());
             $this->addClassToPackage($reflection->getName(), $classElement);
             $classStartLine = $reflection->getStartLine();
             $methodscovered = 0;
             $methodcount = 0;
             // Strange PHP5 reflection bug, classes without parent class or implemented interfaces seem to start one line off
             if ($reflection->getParentClass() == NULL && count($reflection->getInterfaces()) == 0) {
                 unset($coverageInformation[$classStartLine + 1]);
             } else {
                 unset($coverageInformation[$classStartLine]);
             }
             reset($coverageInformation);
             foreach ($methods as $method) {
                 // PHP5 reflection considers methods of a parent class to be part of a subclass, we don't
                 if ($method->getDeclaringClass()->getName() != $reflection->getName()) {
                     continue;
                 }
                 // small fix for XDEBUG_CC_UNUSED
                 if (isset($coverageInformation[$method->getStartLine()])) {
                     unset($coverageInformation[$method->getStartLine()]);
                 }
                 if (isset($coverageInformation[$method->getEndLine()])) {
                     unset($coverageInformation[$method->getEndLine()]);
                 }
                 if ($method->isAbstract()) {
                     continue;
                 }
                 $linenr = key($coverageInformation);
                 while ($linenr !== null && $linenr < $method->getStartLine()) {
                     next($coverageInformation);
                     $linenr = key($coverageInformation);
                 }
                 if (current($coverageInformation) > 0 && $method->getStartLine() <= $linenr && $linenr <= $method->getEndLine()) {
                     $methodscovered++;
                 }
                 $methodcount++;
             }
             $statementcount = count($coverageInformation);
             $statementscovered = count(array_filter($coverageInformation, array($this, 'filterCovered')));
             $classElement->appendChild($this->transformSourceFile($filename, $coverageInformation, $classStartLine));
             $classElement->setAttribute('methodcount', $methodcount);
             $classElement->setAttribute('methodscovered', $methodscovered);
             $classElement->setAttribute('statementcount', $statementcount);
             $classElement->setAttribute('statementscovered', $statementscovered);
             $classElement->setAttribute('totalcount', $methodcount + $statementcount);
             $classElement->setAttribute('totalcovered', $methodscovered + $statementscovered);
         }
     }
 }