/**
  * Tests whether the generateFilename method returns a file according to
  * the right format.
  *
  * @covers phpDocumentor\Transformer\Transformer::generateFilename
  *
  * @return void
  */
 public function testGenerateFilename()
 {
     // separate the directories with the DIRECTORY_SEPARATOR constant to
     // prevent failing tests on windows
     $filename = 'directory' . DIRECTORY_SEPARATOR . 'directory2' . DIRECTORY_SEPARATOR . 'file.php';
     $this->assertEquals('directory.directory2.file.html', $this->fixture->generateFilename($filename));
 }
Example #2
0
 protected function buildFile(\DOMElement $parent, FileDescriptor $file, Transformer $transformer)
 {
     $child = new \DOMElement('file');
     $parent->appendChild($child);
     $path = ltrim($file->getPath(), './');
     $child->setAttribute('path', $path);
     $child->setAttribute('generated-path', $transformer->generateFilename($path));
     $child->setAttribute('hash', $file->getHash());
     $this->buildDocBlock($child, $file);
     // add namespace aliases
     foreach ($file->getNamespaceAliases() as $alias => $namespace) {
         $alias_obj = new \DOMElement('namespace-alias', $namespace);
         $child->appendChild($alias_obj);
         $alias_obj->setAttribute('name', $alias);
     }
     /** @var ConstantDescriptor $constant */
     foreach ($file->getConstants() as $constant) {
         $this->buildConstant($child, $constant);
     }
     /** @var FunctionDescriptor $function */
     foreach ($file->getFunctions() as $function) {
         $this->buildFunction($child, $function);
     }
     /** @var InterfaceDescriptor $interface */
     foreach ($file->getInterfaces() as $interface) {
         $this->buildInterface($child, $interface);
     }
     /** @var ClassDescriptor $class */
     foreach ($file->getClasses() as $class) {
         $this->buildClass($child, $class);
     }
     // add markers
     if (count($file->getMarkers()) > 0) {
         $markers = new \DOMElement('markers');
         $child->appendChild($markers);
         foreach ($file->getMarkers() as $marker) {
             $marker_obj = new \DOMElement(strtolower($marker['type']));
             $markers->appendChild($marker_obj);
             $marker_obj->appendChild(new \DOMText(trim($marker['message'])));
             $marker_obj->setAttribute('line', $marker['line']);
         }
     }
     if (count($file->getErrors()) > 0) {
         $parse_errors = new \DOMElement('parse_markers');
         $child->appendChild($parse_errors);
         /** @var Error $error */
         foreach ($file->getAllErrors() as $error) {
             $this->createErrorEntry($error, $parse_errors);
         }
     }
     // if we want to include the source for each file; append a new
     // element 'source' which contains a compressed, encoded version
     // of the source
     if ($file->getSource()) {
         $child->appendChild(new \DOMElement('source', base64_encode(gzcompress($file->getSource()))));
     }
 }