Esempio n. 1
0
 /**
  * @covers \TheSeer\fDOM\fDOMDocument::__clone
  */
 public function testCloningTriggersCreationOfNewDOMXPathInstance()
 {
     $this->dom->loadXML('<?xml version="1.0" ?><test />');
     $xp1 = $this->dom->getDOMXPath();
     $clone = clone $this->dom;
     $xp2 = $clone->getDOMXPath();
     $this->assertNotSame($xp2, $xp1);
 }
Esempio n. 2
0
 private function processUnit(fDOMDocument $unit, fDOMDocument $coverage)
 {
     $enrichment = $this->getEnrichtmentContainer($unit->documentElement, 'phpunit');
     $className = $unit->documentElement->getAttribute('name');
     $classNamespace = $unit->documentElement->getAttribute('namespace');
     $classNode = $coverage->queryOne(sprintf('//pu:class[@name = "%s" and pu:namespace[@name = "%s"]]', $className, $classNamespace));
     if (!$classNode) {
         // This class seems to be newer than the last phpunit run
         return;
     }
     $coverageTarget = $enrichment->appendElementNS(self::XMLNS, 'coverage');
     foreach (array('executable', 'executed', 'crap') as $attr) {
         $coverageTarget->appendChild($coverageTarget->ownerDocument->importNode($classNode->getAttributeNode($attr)));
     }
     $result = array('PASSED' => 0, 'SKIPPED' => 0, 'INCOMPLETE' => 0, 'FAILURE' => 0, 'ERROR' => 0, 'RISKY' => 0);
     $methods = $unit->query('/phpdox:*/phpdox:constructor|/phpdox:*/phpdox:destructor|/phpdox:*/phpdox:method');
     $xp = $this->index->getDOMXPath();
     foreach ($methods as $method) {
         $start = $method->getAttribute('start');
         $end = $method->getAttribute('end');
         $enrichment = $this->getEnrichtmentContainer($method, 'phpunit');
         $coverageTarget = $enrichment->appendElementNS(self::XMLNS, 'coverage');
         /** @var fDOMElement $coverageMethod */
         $coverageMethod = $coverage->queryOne(sprintf('//pu:method[@start = "%d" and @end = "%d"]', $start, $end));
         if ($coverageMethod != NULL) {
             foreach (array('executable', 'executed', 'coverage', 'crap') as $attr) {
                 $coverageTarget->appendChild($coverageTarget->ownerDocument->importNode($coverageMethod->getAttributeNode($attr)));
             }
         }
         $coveredNodes = $coverage->query(sprintf('//pu:coverage/pu:line[@nr >= "%d" and @nr <= "%d"]/pu:covered', $start, $end));
         $seen = array();
         foreach ($coveredNodes as $coveredNode) {
             $by = $coveredNode->getAttribute('by');
             if (isset($seen[$by])) {
                 continue;
             }
             $seen[$by] = true;
             $name = $xp->prepare(':name', array('name' => $by));
             $test = $coverageTarget->appendChild($unit->importNode($this->index->queryOne(sprintf('//pu:tests/pu:test[@name = %s]', $name))));
             $result[$test->getAttribute('status')]++;
         }
     }
     if (!isset($this->results[$classNamespace])) {
         $this->results[$classNamespace] = array();
         $this->coverage[$classNamespace] = array();
     }
     $this->results[$classNamespace][$className] = $result;
     $this->coverage[$classNamespace][$className] = $coverageTarget->cloneNode(false);
 }
 /**
  * @param  string $xpath
  * @return array
  */
 public function parse($xpath = '')
 {
     $result = array('items' => array(), 'excludes' => array(), 'names' => array());
     foreach ($this->xml->getDOMXPath()->query($xpath . 'include/directory') as $item) {
         $result['items'][] = $this->toAbsolutePath($item->nodeValue);
     }
     foreach ($this->xml->getDOMXPath()->query($xpath . 'include/file') as $item) {
         $result['items'][] = $this->toAbsolutePath($item->nodeValue);
     }
     foreach ($this->xml->getDOMXPath()->query($xpath . 'exclude') as $exclude) {
         $result['excludes'][] = $exclude->nodeValue;
     }
     foreach ($this->xml->getDOMXPath()->query($xpath . 'name') as $name) {
         $result['names'][] = $name->nodeValue;
     }
     return $result;
 }
Esempio n. 4
0
 public function setUp()
 {
     $this->dom = new fDOMDocument();
     $this->dom->loadXML('<?xml version="1.0" ?><root><node attr="foo" /></root>');
     $this->xp = $this->dom->getDOMXPath();
 }