Пример #1
0
 public function generate()
 {
     $document = new fDOMDocument();
     // summary
     $root = $document->createElement('phpact');
     $root->setAttribute('project', $this->summary->getProjectName());
     $root->setAttribute('base', $this->summary->getBaseVersion());
     $root->setAttribute('challenger', $this->summary->getChallengerVersion());
     $root->setAttribute('date', date('c', $this->summary->getTime()));
     $root->setAttribute('signature', strip_tags($this->summary->getSignature()));
     // difference list
     $grouped = $this->groupDifferences($this->differences, Difference::UNIT_NAME);
     foreach ($grouped as $unitName => $differences) {
         /* @var $differences \RenanBr\PhpAct\Difference\DifferenceCollection */
         $family = $differences->current()->getTag(Difference::UNIT_FAMILY);
         $unitElement = $root->createElement($family);
         $unitElement->setAttribute('name', $unitName);
         $this->append($unitElement, 'constant', $differences, Difference::CONSTANT_NAME);
         $this->append($unitElement, 'member', $differences, Difference::MEMBER_NAME);
         $this->append($unitElement, 'method', $differences, Difference::METHOD_NAME);
         $root->appendChild($unitElement);
     }
     $document->appendChild($root);
     $document->preserveWhiteSpace = false;
     $document->formatOutput = true;
     return $document->saveXML();
 }
Пример #2
0
 /**
  * @param string[] $units
  * @param string[] $visibilities
  * @return fDOMDocument
  */
 private function createPhpDoxConfig(array $units, array $visibilities)
 {
     $dom = new fDOMDocument();
     $dom->loadXML($this->factory->getConfigSkeleton()->renderStripped());
     $dom->registerNamespace('config', ConfigLoader::XMLNS);
     // set up silent
     $silent = $this->output->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL ? 'true' : 'false';
     $dom->queryOne('//config:phpdox')->setAttribute('silent', $silent);
     // set up directories
     $projectNode = $dom->queryOne('//config:project');
     $projectNode->setAttribute('source', $this->sourceDirectory);
     $projectNode->setAttribute('workdir', $this->buildDirectory);
     // inject flag to avoid unecessary processing according to the visibility filter
     if (1 === count($visibilities) && in_array('public', $visibilities)) {
         $collectorNode = $dom->queryOne('//config:collector');
         $projectNode->setAttribute('publiconly', 'true');
     }
     // remove current masks
     $query = "//config:collector/*[name()='include' or name()='exclude']";
     foreach ($dom->query($query) as $mask) {
         $mask->parentNode->removeChild($mask);
     }
     // append files to be parsed
     $collector = $dom->queryOne('//config:collector');
     foreach ($units as $unitFile) {
         $include = $dom->createElement('include');
         $include->setAttribute('mask', $unitFile);
         $collector->appendChild($include);
     }
     return $dom;
 }
Пример #3
0
 /**
  * @covers \TheSeer\fDOM\fDOMDocument::inSameDocument
  */
 public function testThatANodeFromADifferentDocumentIsNotConsideredAsInSameDocument()
 {
     $dom = new fDOMDocument();
     $node = $dom->createElement('foo');
     $this->dom->loadXML('<?xml version="1.0" ?><root />');
     $this->assertFalse($this->dom->documentElement->inSameDocument($node));
 }
Пример #4
0
 /**
  * Merge all files.
  *
  * @param string $directory
  * @param Finder $finder
  *
  * @return fDOMDocument
  */
 private function mergeFiles($directory, Finder $finder)
 {
     $outXml = new fDOMDocument();
     $outXml->formatOutput = true;
     $outTestSuites = $outXml->createElement('testsuites');
     $outXml->appendChild($outTestSuites);
     $outTestSuite = $outXml->createElement('testsuite');
     $outTestSuites->appendChild($outTestSuite);
     $tests = 0;
     $assertions = 0;
     $failures = 0;
     $errors = 0;
     $time = 0;
     /** @var SplFileInfo $file */
     foreach ($finder as $file) {
         if ($this->isFileEmpty($file)) {
             continue;
         }
         $inXml = $this->loadFile($file->getRealpath());
         foreach ($inXml->query('//testsuites/testsuite') as $inElement) {
             $inName = $inElement->getAttribute('name');
             $outName = $inName;
             $suffix = 2;
             while ($outTestSuite->query('//testsuite[@name="' . $outName . '"]')->length !== 0) {
                 $outName = $inName . '_' . $suffix;
                 $suffix++;
             }
             $outElement = $outXml->importNode($inElement, true);
             $outElement->setAttribute('name', $outName);
             $outTestSuite->appendChild($outElement);
             $tests += $inElement->getAttribute('tests');
             $assertions += $inElement->getAttribute('assertions');
             $failures += $inElement->getAttribute('failures');
             $errors += $inElement->getAttribute('errors');
             $time += $inElement->getAttribute('time');
         }
     }
     $outTestSuite->setAttribute('name', $directory);
     $outTestSuite->setAttribute('tests', $tests);
     $outTestSuite->setAttribute('assertions', $assertions);
     $outTestSuite->setAttribute('failures', $failures);
     $outTestSuite->setAttribute('errors', $errors);
     $outTestSuite->setAttribute('time', $time);
     return $outXml;
 }