public function testFromReflectionFile() { //$this->markTestSkipped('Must support namespaces'); $file = __DIR__ . '/TestAsset/TestSampleSingleClass.php'; require_once $file; $codeGenFileFromDisk = PHP\PHPFile::fromReflection(new Reflection\ReflectionFile($file)); $codeGenFileFromDisk->getClass()->setMethod(array('name' => 'foobar')); $expectedOutput = <<<EOS <?php /** * File header here * * @author Ralph Schindler <*****@*****.**> * */ /** * @namespace */ namespace ZendTest\\CodeGenerator\\PHP\\TestAsset; /** * class docblock * * @package Zend_Reflection_TestSampleSingleClass * */ class TestSampleSingleClass { /** * Enter description here... * * @return bool * */ public function someMethod() { /* test test */ } public function foobar() { } } EOS; $this->assertEquals($expectedOutput, $codeGenFileFromDisk->generate()); }
/** * registerFileCodeGnereator() * * A file code generator registry * * @param PHPFile $fileCodeGenerator * @param string $fileName */ public static function registerFileCodeGenerator(PHPFile $fileCodeGenerator, $fileName = null) { if ($fileName == null) { $fileName = $fileCodeGenerator->getFilename(); } if ($fileName == '') { throw new Exception('FileName does not exist.'); } // cannot use realpath since the file might not exist, but we do need to have the index // in the same DIRECTORY_SEPARATOR that realpath would use: $fileName = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $fileName); self::$_fileCodeGenerators[$fileName] = $fileCodeGenerator; }