/** * create() * * @return Zend_Tool_Project_Context_Zf_ActionMethod */ public function create() { $file = $this->_testApplicationControllerPath; if (!file_exists($file)) { // require_once 'Zend/Tool/Project/Context/Exception.php'; throw new Zend_Tool_Project_Context_Exception('Could not create action within test controller ' . $file . ' with action name ' . $this->_forActionName); } $actionParam = $this->getForActionName(); $controllerParam = $this->_resource->getParentResource()->getForControllerName(); //$moduleParam = null;// /* @var $controllerDirectoryResource Zend_Tool_Project_Profile_Resource */ $controllerDirectoryResource = $this->_resource->getParentResource()->getParentResource(); if ($controllerDirectoryResource->getParentResource()->getName() == 'TestApplicationModuleDirectory') { $moduleParam = $controllerDirectoryResource->getParentResource()->getForModuleName(); } else { $moduleParam = 'default'; } if ($actionParam == 'index' && $controllerParam == 'Index' && $moduleParam == 'default') { $assert = '$this->assertQueryContentContains("div#welcome h3", "This is your project\'s main page");'; } else { $assert = <<<EOS \$this->assertQueryContentContains( 'div#view-content p', 'View script for controller <b>' . \$params['controller'] . '</b> and script/action name <b>' . \$params['action'] . '</b>' ); EOS; } $codeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName($file, true, true); $codeGenFile->getClass()->setMethod(array('name' => 'test' . ucfirst($actionParam) . 'Action', 'body' => <<<EOS \$params = array('action' => '{$actionParam}', 'controller' => '{$controllerParam}', 'module' => '{$moduleParam}'); \$urlParams = \$this->urlizeOptions(\$params); \$url = \$this->url(\$urlParams); \$this->dispatch(\$url); // assertions \$this->assertModule(\$urlParams['module']); \$this->assertController(\$urlParams['controller']); \$this->assertAction(\$urlParams['action']); {$assert} EOS )); file_put_contents($file, $codeGenFile->generate()); return $this; }
/** * @group ZF-11703 */ public function testNewMethodKeepTwoDocBlock() { $codeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName(dirname(__FILE__) . '/_files/zf-11703_1.php', true, true); $target = <<<EOS <?php /** * For manipulating files. */ /** * Class Foo1 */ class Foo1 { public function bar() { // action body } public function bar2() { // action body } } EOS; $codeGenFile->getClass()->setMethod(array('name' => 'bar2', 'body' => '// action body')); $this->assertEquals($target, $codeGenFile->generate()); }
/** * getCodeGenerator() * * @return Zend_CodeGenerator_Php_Class */ public function getCodeGenerator() { $codeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName($this->getPath()); $codeGenFileClasses = $codeGenFile->getClasses(); $class = array_shift($codeGenFileClasses); return $class; }
/** * hasActionMethod() * * @param string $controllerPath * @param string $actionName * @return bool */ public static function hasActionMethod($controllerPath, $actionName) { if (!file_exists($controllerPath)) { return false; } $controllerCodeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName($controllerPath, true, true); return $controllerCodeGenFile->getClass()->hasMethod($actionName . 'Action'); }
/** * addAction() * * @param string $actionName */ public function addAction($actionName) { //require_once $this->getPath(); //$codeGenFile = Zend_CodeGenerator_Php_File::fromReflection(new Zend_Reflection_File($this->getPath())); $codeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName($this->getPath()); $codeGenFileClasses = $codeGenFile->getClasses(); $class = array_shift($codeGenFileClasses); $class->setMethod(array('name' => $actionName . 'Action', 'body' => ' // action body here')); file_put_contents($this->getPath(), $codeGenFile->generate()); }