File indexing completed on 2025-01-19 05:21:36
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Tool 0017 * @subpackage Framework 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Tool_Project_Context_Filesystem_File 0025 */ 0026 // require_once 'Zend/Tool/Project/Context/Filesystem/File.php'; 0027 0028 /** 0029 * This class is the front most class for utilizing Zend_Tool_Project 0030 * 0031 * A profile is a hierarchical set of resources that keep track of 0032 * items within a specific project. 0033 * 0034 * @category Zend 0035 * @package Zend_Tool 0036 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0037 * @license http://framework.zend.com/license/new-bsd New BSD License 0038 */ 0039 class Zend_Tool_Project_Context_Zf_TestApplicationControllerFile extends Zend_Tool_Project_Context_Filesystem_File 0040 { 0041 0042 /** 0043 * @var string 0044 */ 0045 protected $_forControllerName = ''; 0046 0047 /** 0048 * getName() 0049 * 0050 * @return string 0051 */ 0052 public function getName() 0053 { 0054 return 'TestApplicationControllerFile'; 0055 } 0056 0057 /** 0058 * init() 0059 * 0060 * @return Zend_Tool_Project_Context_Zf_TestApplicationControllerFile 0061 */ 0062 public function init() 0063 { 0064 $this->_forControllerName = $this->_resource->getAttribute('forControllerName'); 0065 $this->_filesystemName = ucfirst($this->_forControllerName) . 'ControllerTest.php'; 0066 parent::init(); 0067 return $this; 0068 } 0069 0070 /** 0071 * getPersistentAttributes() 0072 * 0073 * @return unknown 0074 */ 0075 public function getPersistentAttributes() 0076 { 0077 $attributes = array(); 0078 0079 if ($this->_forControllerName) { 0080 $attributes['forControllerName'] = $this->getForControllerName(); 0081 } 0082 0083 return $attributes; 0084 } 0085 0086 public function getForControllerName() 0087 { 0088 return $this->_forControllerName; 0089 } 0090 0091 /** 0092 * getContents() 0093 * 0094 * @return string 0095 */ 0096 public function getContents() 0097 { 0098 0099 $filter = new Zend_Filter_Word_DashToCamelCase(); 0100 0101 $className = $filter->filter($this->_forControllerName) . 'ControllerTest'; 0102 0103 /* @var $controllerDirectoryResource Zend_Tool_Project_Profile_Resource */ 0104 $controllerDirectoryResource = $this->_resource->getParentResource(); 0105 if ($controllerDirectoryResource->getParentResource()->getName() == 'TestApplicationModuleDirectory') { 0106 $className = $filter->filter(ucfirst($controllerDirectoryResource->getParentResource()->getForModuleName())) 0107 . '_' . $className; 0108 } 0109 0110 $codeGenFile = new Zend_CodeGenerator_Php_File(array( 0111 'classes' => array( 0112 new Zend_CodeGenerator_Php_Class(array( 0113 'name' => $className, 0114 'extendedClass' => 'Zend_Test_PHPUnit_ControllerTestCase', 0115 'methods' => array( 0116 new Zend_CodeGenerator_Php_Method(array( 0117 'name' => 'setUp', 0118 'body' => <<<EOS 0119 \$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); 0120 parent::setUp(); 0121 EOS 0122 )) 0123 ) 0124 )) 0125 ) 0126 )); 0127 0128 return $codeGenFile->generate(); 0129 } 0130 0131 }