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); }
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; }
/** * @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; }
public function removeFile(FileInfo $file) { $relPath = (string) $file->getRelative($this->srcDir); unset($this->collection[$relPath]); }
public function getRelativeName(FileInfo $path) { $file = new FileInfo($this->asDom()->getElementsByTagNameNS(SourceFile::XMLNS, 'file')->item(0)->getAttribute('realpath')); return $file->getRelative($path, FALSE); }
/** * @param $path * @return \DOMNodeList */ public function findUnitNodesBySrcFile($path) { $search = new FileInfo($path); return $this->getRootElement()->query(sprintf('//*[@src="%s"]', $search->getRelative($this->srcDir))); }