Test.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Tool_Project_Provider_Abstract
  24. */
  25. require_once 'Zend/Tool/Project/Provider/Abstract.php';
  26. /**
  27. * @see Zend_Tool_Project_Provider_Exception
  28. */
  29. require_once 'Zend/Tool/Project/Provider/Exception.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Tool
  33. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Tool_Project_Provider_Test extends Zend_Tool_Project_Provider_Abstract
  37. {
  38. protected $_specialties = array('Application', 'Library');
  39. /**
  40. * isTestingEnabled()
  41. *
  42. * @param Zend_Tool_Project_Profile $profile
  43. * @return bool
  44. */
  45. public static function isTestingEnabled(Zend_Tool_Project_Profile $profile)
  46. {
  47. $profileSearchParams = array('testsDirectory');
  48. $testsDirectory = $profile->search($profileSearchParams);
  49. return $testsDirectory->isEnabled();
  50. }
  51. /**
  52. * createApplicationResource()
  53. *
  54. * @param Zend_Tool_Project_Profile $profile
  55. * @param string $controllerName
  56. * @param string $actionName
  57. * @param string $moduleName
  58. * @return Zend_Tool_Project_Profile_Resource
  59. */
  60. public static function createApplicationResource(Zend_Tool_Project_Profile $profile, $controllerName, $actionName, $moduleName = null)
  61. {
  62. if (!is_string($controllerName)) {
  63. throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createApplicationResource() expects \"controllerName\" is the name of a controller resource to create.');
  64. }
  65. if (!is_string($actionName)) {
  66. throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createApplicationResource() expects \"actionName\" is the name of a controller resource to create.');
  67. }
  68. $testsDirectoryResource = $profile->search('testsDirectory');
  69. if (($testAppDirectoryResource = $testsDirectoryResource->search('testApplicationDirectory')) === false) {
  70. $testAppDirectoryResource = $testsDirectoryResource->createResource('testApplicationDirectory');
  71. }
  72. if ($moduleName) {
  73. //@todo $moduleName
  74. $moduleName = '';
  75. }
  76. if (($testAppControllerDirectoryResource = $testAppDirectoryResource->search('testApplicationControllerDirectory')) === false) {
  77. $testAppControllerDirectoryResource = $testAppDirectoryResource->createResource('testApplicationControllerDirectory');
  78. }
  79. $testAppControllerFileResource = $testAppControllerDirectoryResource->createResource('testApplicationControllerFile', array('forControllerName' => $controllerName));
  80. return $testAppControllerFileResource;
  81. }
  82. /**
  83. * createLibraryResource()
  84. *
  85. * @param Zend_Tool_Project_Profile $profile
  86. * @param string $libraryClassName
  87. * @return Zend_Tool_Project_Profile_Resource
  88. */
  89. public static function createLibraryResource(Zend_Tool_Project_Profile $profile, $libraryClassName)
  90. {
  91. $testLibraryDirectoryResource = $profile->search(array('TestsDirectory', 'TestLibraryDirectory'));
  92. $fsParts = explode('_', $libraryClassName);
  93. $currentDirectoryResource = $testLibraryDirectoryResource;
  94. while ($nameOrNamespacePart = array_shift($fsParts)) {
  95. if (count($fsParts) > 0) {
  96. if (($libraryDirectoryResource = $currentDirectoryResource->search(array('TestLibraryNamespaceDirectory' => array('namespaceName' => $nameOrNamespacePart)))) === false) {
  97. $currentDirectoryResource = $currentDirectoryResource->createResource('TestLibraryNamespaceDirectory', array('namespaceName' => $nameOrNamespacePart));
  98. } else {
  99. $currentDirectoryResource = $libraryDirectoryResource;
  100. }
  101. } else {
  102. if (($libraryFileResource = $currentDirectoryResource->search(array('TestLibraryFile' => array('forClassName' => $libraryClassName)))) === false) {
  103. $libraryFileResource = $currentDirectoryResource->createResource('TestLibraryFile', array('forClassName' => $libraryClassName));
  104. }
  105. }
  106. }
  107. return $libraryFileResource;
  108. }
  109. public function enable()
  110. {
  111. }
  112. public function disable()
  113. {
  114. }
  115. /**
  116. * create()
  117. *
  118. * @param unknown_type $libraryClassName
  119. */
  120. public function create($libraryClassName)
  121. {
  122. $profile = $this->_loadProfile();
  123. if (!self::isTestingEnabled($profile)) {
  124. $this->_registry->getResponse()->appendContent('Testing is not enabled for this project.');
  125. }
  126. $testLibraryResource = self::createLibraryResource($profile, $libraryClassName);
  127. $response = $this->_registry->getResponse();
  128. if ($this->_registry->getRequest()->isPretend()) {
  129. $response->appendContent('Would create a library stub in location ' . $testLibraryResource->getContext()->getPath());
  130. } else {
  131. $response->appendContent('Creating a library stub in location ' . $testLibraryResource->getContext()->getPath());
  132. $testLibraryResource->create();
  133. $this->_storeProfile();
  134. }
  135. }
  136. }