web/lib/Zend/Tool/Project/Provider/Action.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
--- a/web/lib/Zend/Tool/Project/Provider/Action.php	Thu Mar 21 17:31:31 2013 +0100
+++ b/web/lib/Zend/Tool/Project/Provider/Action.php	Thu Mar 21 19:50:53 2013 +0100
@@ -15,9 +15,9 @@
  * @category   Zend
  * @package    Zend_Tool
  * @subpackage Framework
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @version    $Id: Action.php 20851 2010-02-02 21:45:51Z ralph $
+ * @version    $Id: Action.php 24593 2012-01-05 20:35:02Z matthew $
  */
 
 /**
@@ -33,7 +33,7 @@
 /**
  * @category   Zend
  * @package    Zend_Tool
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
 class Zend_Tool_Project_Provider_Action
@@ -92,7 +92,7 @@
         if ($controllerFile == null) {
             throw new Zend_Tool_Project_Provider_Exception('Controller ' . $controllerName . ' was not found.');
         }
-       
+
         return (($controllerFile->search(array('actionMethod' => array('actionName' => $actionName)))) instanceof Zend_Tool_Project_Profile_Resource);
     }
 
@@ -131,33 +131,50 @@
 
         $this->_loadProfile();
 
+        // get request/response object
+        $request = $this->_registry->getRequest();
+        $response = $this->_registry->getResponse();
+
+        // determine if testing is enabled in the project
+        require_once 'Zend/Tool/Project/Provider/Test.php';
+        $testingEnabled = Zend_Tool_Project_Provider_Test::isTestingEnabled($this->_loadedProfile);
+
+        if ($testingEnabled && !Zend_Tool_Project_Provider_Test::isPHPUnitAvailable()) {
+            $testingEnabled = false;
+            $response->appendContent(
+                'Note: PHPUnit is required in order to generate controller test stubs.',
+                array('color' => array('yellow'))
+                );
+        }
+
         // Check that there is not a dash or underscore, return if doesnt match regex
         if (preg_match('#[_-]#', $name)) {
             throw new Zend_Tool_Project_Provider_Exception('Action names should be camel cased.');
         }
-        
+
         $originalName = $name;
         $originalControllerName = $controllerName;
-        
+
         // ensure it is camelCase (lower first letter)
         $name = strtolower(substr($name, 0, 1)) . substr($name, 1);
-        
+
         // ensure controller is MixedCase
         $controllerName = ucfirst($controllerName);
-        
+
         if (self::hasResource($this->_loadedProfile, $name, $controllerName, $module)) {
             throw new Zend_Tool_Project_Provider_Exception('This controller (' . $controllerName . ') already has an action named (' . $name . ')');
         }
-        
-        $actionMethod = self::createResource($this->_loadedProfile, $name, $controllerName, $module);
+
+        $actionMethodResource = self::createResource($this->_loadedProfile, $name, $controllerName, $module);
 
-        // get request/response object
-        $request = $this->_registry->getRequest();
-        $response = $this->_registry->getResponse();
-        
+        $testActionMethodResource = null;
+        if ($testingEnabled) {
+            $testActionMethodResource = Zend_Tool_Project_Provider_Test::createApplicationResource($this->_loadedProfile, $controllerName, $name, $module);
+        }
+
         // alert the user about inline converted names
         $tense = (($request->isPretend()) ? 'would be' : 'is');
-        
+
         if ($name !== $originalName) {
             $response->appendContent(
                 'Note: The canonical action name that ' . $tense
@@ -166,7 +183,7 @@
                 array('color' => array('yellow'))
                 );
         }
-        
+
         if ($controllerName !== $originalControllerName) {
             $response->appendContent(
                 'Note: The canonical controller name that ' . $tense
@@ -175,20 +192,31 @@
                 array('color' => array('yellow'))
                 );
         }
-        
+
         unset($tense);
-        
+
         if ($request->isPretend()) {
             $response->appendContent(
                 'Would create an action named ' . $name .
-                ' inside controller at ' . $actionMethod->getParentResource()->getContext()->getPath()
+                ' inside controller at ' . $actionMethodResource->getParentResource()->getContext()->getPath()
                 );
+
+            if ($testActionMethodResource) {
+                $response->appendContent('Would create an action test in ' . $testActionMethodResource->getParentResource()->getContext()->getPath());
+            }
+
         } else {
             $response->appendContent(
                 'Creating an action named ' . $name .
-                ' inside controller at ' . $actionMethod->getParentResource()->getContext()->getPath()
+                ' inside controller at ' . $actionMethodResource->getParentResource()->getContext()->getPath()
                 );
-            $actionMethod->create();
+            $actionMethodResource->create();
+
+            if ($testActionMethodResource) {
+                $response->appendContent('Creating an action test in ' . $testActionMethodResource->getParentResource()->getContext()->getPath());
+                $testActionMethodResource->create();
+            }
+
             $this->_storeProfile();
         }