Esempio n. 1
0
        private function enrichByFile(fDOMDocument $dom) {
            $fileNode = $dom->queryOne('//phpdox:file');
            if (!$fileNode) {
                return;
            }

            $fileInfo = new FileInfo($fileNode->getAttribute('path'));
            $srcDir = $this->config->getSourceDirectory();
            $paths = explode('/', (string)$fileInfo->getRelative($srcDir));
            $file = $fileNode->getAttribute('file');
            $paths = array_slice($paths, 1);

            $query = sprintf('//pu:project/pu:directory[@name = "%s"]', $srcDir->getRealPath());
            foreach($paths as $path) {
                $query .= sprintf('/pu:directory[@name = "%s"]', $path);
            }
            $query .= sprintf('/pu:file[@name = "%s"]', $file);

            $phpunitFileNode = $this->index->queryOne($query);
            if (!$phpunitFileNode) {
                return;
            }

            $refDom = $this->loadXML($phpunitFileNode->getAttribute('href'));
            $this->processUnit($dom, $refDom);
        }
Esempio n. 2
0
        public function export() {
            if (count($this->collection) == 0) {
                return $this->workDom;
            }

            $root = $this->workDom->documentElement;
            while($root->hasChildNodes()) {
                $root->nodeValue = null;
            }

            foreach ($this->collection as $path => $file) {
                $pathInfo = new FileInfo($path);
                $dirs = explode('/', dirname($pathInfo->getRelative($this->srcDir)));
                $dirs[0] = $this->srcDir->getRealPath();
                $ctx = $root;
                foreach ($dirs as $dir) {
                    $node = $ctx->queryOne('phpdox:dir[@name="' . $dir . '"]');
                    if (!$node) {
                        $node = $ctx->appendElementNS('http://xml.phpdox.net/src#', 'dir');
                        $node->setAttribute('name', $dir);
                    }
                    $ctx = $node;
                }
                $ctx->appendChild($this->workDom->importNode($file, TRUE));
            }

            $this->collection = array();
            return $this->workDom;
        }
Esempio n. 3
0
 /**
  * @param fDOMDocument $dom
  *
  * @return fDOMDocument
  *
  * @throws EnricherException
  * @throws PHPUnitEnricherException
  */
 private function loadCoverageInformation(fDOMDocument $dom)
 {
     $fileNode = $dom->queryOne('//phpdox:file');
     if (!$fileNode) {
         throw new PHPUnitEnricherException('No file header in event dom');
     }
     $fileInfo = new FileInfo($fileNode->getAttribute('path'));
     $srcDir = $this->getSourceDirectory();
     $paths = explode('/', (string) $fileInfo->getRelative($srcDir));
     $file = $fileNode->getAttribute('file');
     $paths = array_slice($paths, 1);
     $query = sprintf('//pu:project/pu:directory[@name = "%s"]', $srcDir->getRealPath());
     foreach ($paths as $path) {
         $query .= sprintf('/pu:directory[@name = "%s"]', $path);
     }
     $query .= sprintf('/pu:file[@name = "%s"]', $file);
     $phpunitFileNode = $this->index->queryOne($query);
     if (!$phpunitFileNode) {
         throw new PHPUnitEnricherException('No coverage information for file');
     }
     $refDom = $this->loadXML($phpunitFileNode->getAttribute('href'));
     return $refDom;
 }
Esempio n. 4
0
 public function removeFile(FileInfo $file)
 {
     $relPath = (string) $file->getRelative($this->srcDir);
     unset($this->collection[$relPath]);
 }
Esempio n. 5
0
 public function getRelativeName(FileInfo $path)
 {
     $file = new FileInfo($this->asDom()->getElementsByTagNameNS(SourceFile::XMLNS, 'file')->item(0)->getAttribute('realpath'));
     return $file->getRelative($path, FALSE);
 }
Esempio n. 6
0
 /**
  * @param $path
  * @return \DOMNodeList
  */
 public function findUnitNodesBySrcFile($path) {
     $search = new FileInfo($path);
     return $this->getRootElement()->query(sprintf('//*[@src="%s"]', $search->getRelative($this->srcDir)));
 }