Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@markstory markstory authored
Showing with 133 additions and 15 deletions.
  1. +15 −15 cake/console/libs/api.php
  2. +118 −0 cake/tests/cases/console/libs/api.test.php
View
30 cake/console/libs/api.php
@@ -151,17 +151,17 @@ function help() {
$commands = array(
'path' => "\t<type>\n" .
- "\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
- "\t\tAvailable values:\n\n".
- "\t\tbehavior\tLook for class in CakePHP behavior path\n".
- "\t\tcache\tLook for class in CakePHP cache path\n".
- "\t\tcontroller\tLook for class in CakePHP controller path\n".
- "\t\tcomponent\tLook for class in CakePHP component path\n".
- "\t\thelper\tLook for class in CakePHP helper path\n".
- "\t\tmodel\tLook for class in CakePHP model path\n".
- "\t\tview\tLook for class in CakePHP view path\n",
+ "\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
+ "\t\tAvailable values:\n\n".
+ "\t\tbehavior\tLook for class in CakePHP behavior path\n".
+ "\t\tcache\tLook for class in CakePHP cache path\n".
+ "\t\tcontroller\tLook for class in CakePHP controller path\n".
+ "\t\tcomponent\tLook for class in CakePHP component path\n".
+ "\t\thelper\tLook for class in CakePHP helper path\n".
+ "\t\tmodel\tLook for class in CakePHP model path\n".
+ "\t\tview\tLook for class in CakePHP view path\n",
'className' => "\t<className>\n" .
- "\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
+ "\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
);
$this->out($head);
@@ -196,16 +196,16 @@ function __parseClass($path) {
$contents = $File->read();
- if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.+\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
+ if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.*\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
foreach ($result[2] as $key => $method) {
$method = str_replace('function ', '', trim($method));
if (strpos($method, '__') === false && $method[0] != '_') {
$parsed[$method] = array(
- 'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
- 'method' => $method,
- 'parameters' => trim($result[3][$key]),
- );
+ 'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])),
+ 'method' => $method,
+ 'parameters' => trim($result[3][$key])
+ );
}
}
}
View
118 cake/tests/cases/console/libs/api.test.php
@@ -0,0 +1,118 @@
+<?php
+/* SVN FILE: $Id$ */
+/**
+ * TestTaskTest file
+ *
+ * Test Case for test generation shell task
+ *
+ * PHP versions 4 and 5
+ *
+ * CakePHP : Rapid Development Framework (http://www.cakephp.org)
+ * Copyright 2006-2008, Cake Software Foundation, Inc.
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @filesource
+ * @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
+ * @package cake
+ * @subpackage cake.tests.cases.console.libs.tasks
+ * @since CakePHP v 1.2.0.7726
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+App::import('Core', 'Shell');
+
+if (!defined('DISABLE_AUTO_DISPATCH')) {
+ define('DISABLE_AUTO_DISPATCH', true);
+}
+
+if (!class_exists('ShellDispatcher')) {
+ ob_start();
+ $argv = false;
+ require CAKE . 'console' . DS . 'cake.php';
+ ob_end_clean();
+}
+
+if (!class_exists('ApiShell')) {
+ require CAKE . 'console' . DS . 'libs' . DS . 'api.php';
+}
+
+Mock::generatePartial(
+ 'ShellDispatcher', 'ApiShellMockShellDispatcher',
+ array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
+);
+Mock::generatePartial(
+ 'ApiShell', 'MockApiShell',
+ array('in', 'out', 'createFile', 'hr', '_stop')
+);
+
+/**
+ * TestTaskTest class
+ *
+ * @package cake
+ * @subpackage cake.tests.cases.console.libs.tasks
+ */
+class TestTaskTest extends CakeTestCase {
+/**
+ * setUp method
+ *
+ * @return void
+ * @access public
+ */
+ function startTest() {
+ $this->Dispatcher =& new ApiShellMockShellDispatcher();
+ $this->Shell =& new MockApiShell($this->Dispatcher);
+ $this->Shell->Dispatch = new $this->Dispatcher;
+ }
+/**
+ * tearDown method
+ *
+ * @return void
+ * @access public
+ */
+ function endTest() {
+ ClassRegistry::flush();
+ }
+/**
+ * Test that method names are detected properly including those with no arguments.
+ *
+ * @access public
+ * @return void
+ */
+ function testMethodNameDetection () {
+ $this->Shell->setReturnValueAt(0, 'in', 'q');
+ $this->Shell->expectAt(0, 'out', array('Controller'));
+ $expected = array(
+ array(
+ '1. afterFilter()',
+ '2. beforeFilter()',
+ '3. beforeRender()',
+ '4. constructClasses()',
+ '5. disableCache()',
+ '6. flash($message, $url, $pause = 1)',
+ '7. header($status)',
+ '8. isAuthorized()',
+ '9. loadModel($modelClass = null, $id = null)',
+ '10. paginate($object = null, $scope = array(), $whitelist = array())',
+ '11. postConditions($data = array(), $op = null, $bool = \'AND\', $exclusive = false)',
+ '12. redirect($url, $status = null, $exit = true)',
+ '13. referer($default = null, $local = false)',
+ '14. render($action = null, $layout = null, $file = null)',
+ '15. set($one, $two = null)',
+ '16. setAction($action)',
+ '17. validate()',
+ '18. validateErrors()'
+ )A
+ );
+ $this->Shell->expectAt(1, 'out', $expected);
+
+ $this->Shell->args = array('controller');
+ $this->Shell->paths['controller'] = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'controller' . DS;
+ $this->Shell->main();
+ }
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.