Skip to content

Commit

Permalink
Fix failing tests on ApiShell
Browse files Browse the repository at this point in the history
ApiShell should probably be re-written or removed as its not overly
useful as it stands.
  • Loading branch information
markstory committed Oct 7, 2012
1 parent eca1e0c commit b825a52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 69 deletions.
35 changes: 10 additions & 25 deletions lib/Cake/Console/Command/ApiShell.php
@@ -1,11 +1,5 @@
<?php <?php
/** /**
* API shell to get CakePHP core method signatures.
*
* Implementation of a Cake Shell to show CakePHP core method signatures.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* *
Expand All @@ -18,6 +12,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
namespace Cake\Console\Command; namespace Cake\Console\Command;

use Cake\Console\Shell; use Cake\Console\Shell;
use Cake\Core\App; use Cake\Core\App;
use Cake\Utility\Inflector; use Cake\Utility\Inflector;
Expand Down Expand Up @@ -81,19 +76,16 @@ public function main() {
$file = Inflector::underscore($this->args[1]); $file = Inflector::underscore($this->args[1]);
$class = Inflector::camelize($this->args[1]); $class = Inflector::camelize($this->args[1]);
} }
$objects = App::objects('class', $path); $path = $path . Inflector::camelize($type);
if (in_array($class, $objects)) { $file = $path . '.php';
if (in_array($type, array('behavior', 'component', 'helper')) && $type !== $file) { $classPath = str_replace(CORE_PATH, '', $path);
if (!preg_match('/' . Inflector::camelize($type) . '$/', $class)) { $className = str_replace(DS, '\\', $classPath);
$class .= Inflector::camelize($type);
}
}


} else { if (!class_exists($className)) {
$this->error(__d('cake_console', '%s not found', $class)); return $this->error(__d('cake_console', '%s not found', $class));
} }


$parsed = $this->_parseClass($path . $class . '.php', $class); $parsed = $this->_parseClass($className);


if (!empty($parsed)) { if (!empty($parsed)) {
if (isset($this->params['method'])) { if (isset($this->params['method'])) {
Expand Down Expand Up @@ -196,23 +188,16 @@ public function help() {
* Parse a given class (located on given file) and get public methods and their * Parse a given class (located on given file) and get public methods and their
* signatures. * signatures.
* *
* @param string $path File path
* @param string $class Class name * @param string $class Class name
* @return array Methods and signatures indexed by method name * @return array Methods and signatures indexed by method name
*/ */
protected function _parseClass($path, $class) { protected function _parseClass($class) {
$parsed = array(); $parsed = array();


if (!class_exists($class)) {
if (!include_once $path) {
$this->err(__d('cake_console', '%s could not be found', $path));
}
}

$reflection = new \ReflectionClass($class); $reflection = new \ReflectionClass($class);


foreach ($reflection->getMethods() as $method) { foreach ($reflection->getMethods() as $method) {
if (!$method->isPublic() || strpos($method->getName(), '_') === 0) { if (!$method->isPublic()) {
continue; continue;
} }
if ($method->getDeclaringClass()->getName() != $class) { if ($method->getDeclaringClass()->getName() != $class) {
Expand Down
60 changes: 16 additions & 44 deletions lib/Cake/Test/TestCase/Console/Command/ApiShellTest.php
@@ -1,9 +1,5 @@
<?php <?php
/** /**
* ApiShellTest file
*
* PHP 5
*
* CakePHP : Rapid Development Framework (http://cakephp.org) * CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. * Copyright 2005-2012, Cake Software Foundation, Inc.
* *
Expand All @@ -16,8 +12,8 @@
* @since CakePHP v 1.2.0.7726 * @since CakePHP v 1.2.0.7726
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */

namespace Cake\Test\TestCase\Console\Command; namespace Cake\Test\TestCase\Console\Command;

use Cake\Console\Command\ApiShellShell; use Cake\Console\Command\ApiShellShell;
use Cake\TestSuite\TestCase; use Cake\TestSuite\TestCase;


Expand All @@ -35,13 +31,13 @@ class ApiShellTest extends TestCase {
*/ */
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false); $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
$in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false); $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);


$this->Shell = $this->getMock( $this->Shell = $this->getMock(
'Cake\Console\Command\ApiShell', 'Cake\Console\Command\ApiShell',
array('in', 'out', 'createFile', 'hr', '_stop'), ['in', 'out', 'createFile', 'hr', '_stop'],
array( $out, $out, $in) [$out, $out, $in]
); );
} }


Expand All @@ -51,43 +47,19 @@ public function setUp() {
* @return void * @return void
*/ */
public function testMethodNameDetection() { public function testMethodNameDetection() {
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('q')); $this->Shell->expects($this->any())
$this->Shell->expects($this->at(0))->method('out')->with('Controller'); ->method('in')->will($this->returnValue('q'));
$this->Shell->expects($this->at(0))
->method('out')->with('Controller');


$expected = array( $this->Shell->expects($this->at(2))
'1. afterFilter()', ->method('out')
'2. afterScaffoldSave($method)', ->with($this->logicalAnd(
'3. afterScaffoldSaveError($method)', $this->contains('8. beforeFilter()'),
'4. beforeFilter()', $this->contains('24. render($view = NULL, $layout = NULL)')
'5. beforeRedirect($url, $status = NULL, $exit = true)', ));
'6. beforeRender()',
'7. beforeScaffold($method)',
'8. constructClasses()',
'9. disableCache()',
'10. flash($message, $url, $pause = 1, $layout = \'flash\')',
'11. getEventManager()',
'12. header($status)',
'13. httpCodes($code = NULL)',
'14. implementedEvents()',
'15. invokeAction($request)',
'16. loadModel($modelClass = NULL, $id = NULL)',
'17. paginate($object = NULL, $scope = array (), $whitelist = array ())',
'18. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)',
'19. redirect($url, $status = NULL, $exit = true)',
'20. referer($default = NULL, $local = false)',
'21. render($view = NULL, $layout = NULL)',
'22. scaffoldError($method)',
'23. set($one, $two = NULL)',
'24. setAction($action)',
'25. setRequest($request)',
'26. shutdownProcess()',
'27. startupProcess()',
'28. validate()',
'29. validateErrors()'
);
$this->Shell->expects($this->at(2))->method('out')->with($expected);


$this->Shell->args = array('controller'); $this->Shell->args = ['controller'];
$this->Shell->paths['controller'] = CAKE . 'Controller/'; $this->Shell->paths['controller'] = CAKE . 'Controller/';
$this->Shell->main(); $this->Shell->main();
} }
Expand Down

0 comments on commit b825a52

Please sign in to comment.