Esempio n. 1
0
    public function testGeneratesEntriesForEachPublicMethod()
    {
        $docBook = $this->generator->generate();
        $dom     = new DOMDocument();
        $dom->loadXML($docBook);
        $xpath = new DOMXPath($dom);
        $xpath->registerNamespace('docbook', 'http://docbook.org/ns/docbook');

        $baseId  = 'zend-test.doc-book.test-asset.parsed-class.methods';
        $methods = $this->parser->getMethods();

        // Get list of varlistentry items
        $nodes = $xpath->query(
            '//docbook:section[@xml:id="' . $baseId . '"]/docbook:variablelist/docbook:varlistentry');

        $this->assertEquals(count($methods), $nodes->length);

        // Get varlistentry IDs, methodnames, and funcparams
        for ($i = 0; $i < $nodes->length; $i++) {
            $xml    = $dom->saveXML($nodes->item($i));
            $method = $methods[$i];

            $this->assertContains($method->getId(), $xml);

            $prototype = $method->getPrototype();
            if (empty($prototype)) {
                $this->assertContains('<funcparams/>', $xml);
            } else {
                $this->assertContains('<funcparams>' . $prototype . '</funcparams>', $xml, $xml);
            }
            $this->assertContains($method->getReturnType(), $xml);

            $short = $method->getShortDescription();
            if (empty($short)) {
                $this->assertContains('<para/>', $xml);
            } else {
                $this->assertContains($short, $xml);
            }

            $long = $method->getLongDescription();
            if (!empty($long)) {
                $this->assertContains($long, $xml);
            }
        }
    }
Esempio n. 2
0
$class = $opts->c;
if (!class_exists($class) && !interface_exists($class)) {
    // Invalid class name == no execution
    printf("Invalid class '%s' provided' class not found\n\n", $class);
    echo $opts->getUsageMessage();
    exit(2);
}

// Was a specific filename provided for the generated output?
if (isset($opts->o)) {
    $docbookPath = dirname($opts->o);
    $docbookFile = basename($opts->o);
}

$parser    = new ClassParser(new ReflectionClass($class));
$generator = new SkeletonGenerator($parser);
$xml       = $generator->generate();

// Normalize per CS
$xml = strtr($xml, array(
    '  '              => '    ',              // 4 space tabs
    '</info>'         => "</info>\n",         // Extra newline between blocks
    '</section>'      => "</section>\n",
    '</term>'         => "</term>\n",
    '</varlistentry>' => "</varlistentry>\n",
));

// Strip extra whitespace at end of document
$xml = str_replace("</section>\n\n</section>\n", "</section>\n</section>", $xml);

// Write file