/Zend/Tool/Project/Context/Zf/TestApplicationControllerFile.php

https://github.com/MontmereLimited/ZendFramework-v1 · PHP · 131 lines · 56 code · 16 blank · 59 comment · 3 complexity · c4d1fbbba3ce714fbdb2783d73723e5c MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Tool
  17. * @subpackage Framework
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: TestApplicationControllerFile.php 24161 2011-06-28 16:41:59Z adamlundrigan $
  21. */
  22. /**
  23. * @see Zend_Tool_Project_Context_Filesystem_File
  24. */
  25. // // // // // // // // require_once 'Zend/Tool/Project/Context/Filesystem/File.php';
  26. /**
  27. * This class is the front most class for utilizing Zend_Tool_Project
  28. *
  29. * A profile is a hierarchical set of resources that keep track of
  30. * items within a specific project.
  31. *
  32. * @category Zend
  33. * @package Zend_Tool
  34. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Tool_Project_Context_Zf_TestApplicationControllerFile extends Zend_Tool_Project_Context_Filesystem_File
  38. {
  39. /**
  40. * @var string
  41. */
  42. protected $_forControllerName = '';
  43. /**
  44. * getName()
  45. *
  46. * @return string
  47. */
  48. public function getName()
  49. {
  50. return 'TestApplicationControllerFile';
  51. }
  52. /**
  53. * init()
  54. *
  55. * @return Zend_Tool_Project_Context_Zf_TestApplicationControllerFile
  56. */
  57. public function init()
  58. {
  59. $this->_forControllerName = $this->_resource->getAttribute('forControllerName');
  60. $this->_filesystemName = ucfirst($this->_forControllerName) . 'ControllerTest.php';
  61. parent::init();
  62. return $this;
  63. }
  64. /**
  65. * getPersistentAttributes()
  66. *
  67. * @return unknown
  68. */
  69. public function getPersistentAttributes()
  70. {
  71. $attributes = array();
  72. if ($this->_forControllerName) {
  73. $attributes['forControllerName'] = $this->getForControllerName();
  74. }
  75. return $attributes;
  76. }
  77. public function getForControllerName()
  78. {
  79. return $this->_forControllerName;
  80. }
  81. /**
  82. * getContents()
  83. *
  84. * @return string
  85. */
  86. public function getContents()
  87. {
  88. $filter = new Zend_Filter_Word_DashToCamelCase();
  89. $className = $filter->filter($this->_forControllerName) . 'ControllerTest';
  90. /* @var $controllerDirectoryResource Zend_Tool_Project_Profile_Resource */
  91. $controllerDirectoryResource = $this->_resource->getParentResource();
  92. if ($controllerDirectoryResource->getParentResource()->getName() == 'TestApplicationModuleDirectory') {
  93. $className = $filter->filter(ucfirst($controllerDirectoryResource->getParentResource()->getForModuleName()))
  94. . '_' . $className;
  95. }
  96. $codeGenFile = new Zend_CodeGenerator_Php_File(array(
  97. 'classes' => array(
  98. new Zend_CodeGenerator_Php_Class(array(
  99. 'name' => $className,
  100. 'extendedClass' => 'Zend_Test_PHPUnit_ControllerTestCase',
  101. 'methods' => array(
  102. new Zend_CodeGenerator_Php_Method(array(
  103. 'name' => 'setUp',
  104. 'body' => <<<EOS
  105. \$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
  106. parent::setUp();
  107. EOS
  108. ))
  109. )
  110. ))
  111. )
  112. ));
  113. return $codeGenFile->generate();
  114. }
  115. }