Skip to content
This repository
Browse code

Adding test case for api console.

Fixing issue where methods with no parameters were omitted from api method lists.
Fixes #6474

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8203 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 285fdc22c6f1dc25a91e21ebd2e4d6dae41fbaa0 1 parent fd818bc
Mark Story authored June 25, 2009
30  cake/console/libs/api.php
@@ -151,17 +151,17 @@ function help() {
151 151
 
152 152
 		$commands = array(
153 153
 			'path' => "\t<type>\n" .
154  
-						"\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
155  
-						"\t\tAvailable values:\n\n".
156  
-						"\t\tbehavior\tLook for class in CakePHP behavior path\n".
157  
-						"\t\tcache\tLook for class in CakePHP cache path\n".
158  
-						"\t\tcontroller\tLook for class in CakePHP controller path\n".
159  
-						"\t\tcomponent\tLook for class in CakePHP component path\n".
160  
-						"\t\thelper\tLook for class in CakePHP helper path\n".
161  
-						"\t\tmodel\tLook for class in CakePHP model path\n".
162  
-						"\t\tview\tLook for class in CakePHP view path\n",
  154
+				"\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
  155
+				"\t\tAvailable values:\n\n".
  156
+				"\t\tbehavior\tLook for class in CakePHP behavior path\n".
  157
+				"\t\tcache\tLook for class in CakePHP cache path\n".
  158
+				"\t\tcontroller\tLook for class in CakePHP controller path\n".
  159
+				"\t\tcomponent\tLook for class in CakePHP component path\n".
  160
+				"\t\thelper\tLook for class in CakePHP helper path\n".
  161
+				"\t\tmodel\tLook for class in CakePHP model path\n".
  162
+				"\t\tview\tLook for class in CakePHP view path\n",
163 163
 			'className' => "\t<className>\n" .
164  
-						"\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
  164
+				"\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
165 165
 		);
166 166
 
167 167
 		$this->out($head);
@@ -196,16 +196,16 @@ function __parseClass($path) {
196 196
 
197 197
 		$contents = $File->read();
198 198
 
199  
-		if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.+\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
  199
+		if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.*\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
200 200
 			foreach ($result[2] as $key => $method) {
201 201
 				$method = str_replace('function ', '', trim($method));
202 202
 
203 203
 				if (strpos($method, '__') === false && $method[0] != '_') {
204 204
 					$parsed[$method] = array(
205  
-											'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
206  
-											'method' => $method,
207  
-											'parameters' => trim($result[3][$key]),
208  
-											);
  205
+						'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
  206
+						'method' => $method,
  207
+						'parameters' => trim($result[3][$key])
  208
+					);
209 209
 				}
210 210
 			}
211 211
 		}
118  cake/tests/cases/console/libs/api.test.php
... ...
@@ -0,0 +1,118 @@
  1
+<?php
  2
+/* SVN FILE: $Id$ */
  3
+/**
  4
+ * TestTaskTest file
  5
+ *
  6
+ * Test Case for test generation shell task
  7
+ *
  8
+ * PHP versions 4 and 5
  9
+ *
  10
+ * CakePHP :  Rapid Development Framework (http://www.cakephp.org)
  11
+ * Copyright 2006-2008, Cake Software Foundation, Inc.
  12
+ *
  13
+ * Licensed under The MIT License
  14
+ * Redistributions of files must retain the above copyright notice.
  15
+ *
  16
+ * @filesource
  17
+ * @copyright     Copyright 2006-2008, Cake Software Foundation, Inc.
  18
+ * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
  19
+ * @package       cake
  20
+ * @subpackage    cake.tests.cases.console.libs.tasks
  21
+ * @since         CakePHP v 1.2.0.7726
  22
+ * @version       $Revision$
  23
+ * @modifiedby    $LastChangedBy$
  24
+ * @lastmodified  $Date$
  25
+ * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
  26
+ */
  27
+App::import('Core', 'Shell');
  28
+
  29
+if (!defined('DISABLE_AUTO_DISPATCH')) {
  30
+	define('DISABLE_AUTO_DISPATCH', true);
  31
+}
  32
+
  33
+if (!class_exists('ShellDispatcher')) {
  34
+	ob_start();
  35
+	$argv = false;
  36
+	require CAKE . 'console' .  DS . 'cake.php';
  37
+	ob_end_clean();
  38
+}
  39
+
  40
+if (!class_exists('ApiShell')) {
  41
+	require CAKE . 'console' .  DS . 'libs' . DS . 'api.php';
  42
+}
  43
+
  44
+Mock::generatePartial(
  45
+	'ShellDispatcher', 'ApiShellMockShellDispatcher',
  46
+	array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  47
+);
  48
+Mock::generatePartial(
  49
+	'ApiShell', 'MockApiShell',
  50
+	array('in', 'out', 'createFile', 'hr', '_stop')
  51
+);
  52
+
  53
+/**
  54
+ * TestTaskTest class
  55
+ *
  56
+ * @package       cake
  57
+ * @subpackage    cake.tests.cases.console.libs.tasks
  58
+ */
  59
+class TestTaskTest extends CakeTestCase {
  60
+/**
  61
+ * setUp method
  62
+ *
  63
+ * @return void
  64
+ * @access public
  65
+ */
  66
+	function startTest() {
  67
+		$this->Dispatcher =& new ApiShellMockShellDispatcher();
  68
+		$this->Shell =& new MockApiShell($this->Dispatcher);
  69
+		$this->Shell->Dispatch = new $this->Dispatcher;
  70
+	}
  71
+/**
  72
+ * tearDown method
  73
+ *
  74
+ * @return void
  75
+ * @access public
  76
+ */
  77
+	function endTest() {
  78
+		ClassRegistry::flush();
  79
+	}
  80
+/**
  81
+ * Test that method names are detected properly including those with no arguments.
  82
+ *
  83
+ * @access public
  84
+ * @return void
  85
+ */
  86
+	function testMethodNameDetection () {
  87
+		$this->Shell->setReturnValueAt(0, 'in', 'q');
  88
+		$this->Shell->expectAt(0, 'out', array('Controller'));
  89
+		$expected = array(
  90
+			array(
  91
+				'1. afterFilter()',
  92
+				'2. beforeFilter()',
  93
+				'3. beforeRender()',
  94
+				'4. constructClasses()',
  95
+				'5. disableCache()',
  96
+				'6. flash($message, $url, $pause = 1)',
  97
+				'7. header($status)',
  98
+				'8. isAuthorized()',
  99
+				'9. loadModel($modelClass = null, $id = null)',
  100
+				'10. paginate($object = null, $scope = array(), $whitelist = array())',
  101
+				'11. postConditions($data = array(), $op = null, $bool = \'AND\', $exclusive = false)',
  102
+				'12. redirect($url, $status = null, $exit = true)',
  103
+				'13. referer($default = null, $local = false)',
  104
+				'14. render($action = null, $layout = null, $file = null)',
  105
+				'15. set($one, $two = null)',
  106
+				'16. setAction($action)',
  107
+				'17. validate()',
  108
+				'18. validateErrors()'
  109
+			)A
  110
+		);
  111
+		$this->Shell->expectAt(1, 'out', $expected);
  112
+	
  113
+		$this->Shell->args = array('controller');
  114
+		$this->Shell->paths['controller'] = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'controller' . DS;
  115
+		$this->Shell->main();
  116
+	}
  117
+}
  118
+?>

0 notes on commit 285fdc2

Please sign in to comment.
Something went wrong with that request. Please try again.