/** * getContents() * * @return string */ public function getContents() { $filter = new \Zend\Filter\Word\DashToCamelCase(); $className = $filter->filter($this->_forControllerName) . 'ControllerTest'; $codeGenFile = new Php\PhpFile(array('requiredFiles' => array('PHPUnit/Framework/TestCase.php'), 'classes' => array(new Php\PhpClass(array('name' => $className, 'extendedClass' => 'PHPUnit_Framework_TestCase', 'methods' => array(new Php\PhpMethod(array('name' => 'setUp', 'body' => ' /* Setup Routine */')), new Php\PhpMethod(array('name' => 'tearDown', 'body' => ' /* Tear Down Routine */')))))))); return $codeGenFile->generate(); }
/** * getContents() * * @return string */ public function getContents() { $codeGenerator = new PhpFile(array('body' => <<<EOS // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); require_once 'Zend/Loader/StandardAutoloader.php'; \$loader = new Zend\\Loader\\StandardAutoloader(array( 'fallback_autoloader' => true, )) \$loader->register(); EOS )); return $codeGenerator->generate(); }
public function testFromReflection() { $tempFile = tempnam(sys_get_temp_dir(), 'UnitFile'); $codeGenFile = new Php\PhpFile(array('class' => array('name' => 'SampleClass'))); file_put_contents($tempFile, $codeGenFile->generate()); require_once $tempFile; $codeGenFileFromDisk = Php\PhpFile::fromReflection(new Reflection\ReflectionFile($tempFile)); unlink($tempFile); $this->assertEquals(get_class($codeGenFileFromDisk), 'Zend\\CodeGenerator\\Php\\PhpFile'); $this->assertEquals(count($codeGenFileFromDisk->getClasses()), 1); }
public function getContents() { $className = $this->getFullClassName($this->_dbTableName, 'Model\\DbTable'); $codeGenFile = new Php\PhpFile(array('fileName' => $this->getPath(), 'classes' => array(new Php\PhpClass(array('name' => $className, 'extendedClass' => '\\Zend\\Db\\Table\\AbstractTable', 'properties' => array(new Php\PhpProperty(array('name' => '_name', 'visibility' => Php\PhpProperty::VISIBILITY_PROTECTED, 'defaultValue' => $this->_actualTableName)))))))); return $codeGenFile->generate(); }
public function testGeneratesNamespaceStatements() { $file = new Php\PhpFile(); $file->setNamespace('Foo\Bar'); $generated = $file->generate(); $this->assertContains('namespace Foo\\Bar', $generated, $generated); }