Skip to content
Permalink
Browse files

Fix failing tests on ApiShell

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 b825a52459e59b384c62b44e1c0f7f694554c699
Showing with 26 additions and 69 deletions.
  1. +10 −25 lib/Cake/Console/Command/ApiShell.php
  2. +16 −44 lib/Cake/Test/TestCase/Console/Command/ApiShellTest.php
@@ -1,11 +1,5 @@
<?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)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -18,6 +12,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Console\Command;
use Cake\Console\Shell;
use Cake\Core\App;
use Cake\Utility\Inflector;
@@ -81,19 +76,16 @@ public function main() {
$file = Inflector::underscore($this->args[1]);
$class = Inflector::camelize($this->args[1]);
}
$objects = App::objects('class', $path);
if (in_array($class, $objects)) {
if (in_array($type, array('behavior', 'component', 'helper')) && $type !== $file) {
if (!preg_match('/' . Inflector::camelize($type) . '$/', $class)) {
$class .= Inflector::camelize($type);
}
}
$path = $path . Inflector::camelize($type);
$file = $path . '.php';
$classPath = str_replace(CORE_PATH, '', $path);
$className = str_replace(DS, '\\', $classPath);
} else {
$this->error(__d('cake_console', '%s not found', $class));
if (!class_exists($className)) {
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 (isset($this->params['method'])) {
@@ -196,23 +188,16 @@ public function help() {
* Parse a given class (located on given file) and get public methods and their
* signatures.
*
* @param string $path File path
* @param string $class Class name
* @return array Methods and signatures indexed by method name
*/
protected function _parseClass($path, $class) {
protected function _parseClass($class) {
$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);
foreach ($reflection->getMethods() as $method) {
if (!$method->isPublic() || strpos($method->getName(), '_') === 0) {
if (!$method->isPublic()) {
continue;
}
if ($method->getDeclaringClass()->getName() != $class) {
@@ -1,9 +1,5 @@
<?php
/**
* ApiShellTest file
*
* PHP 5
*
* CakePHP : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc.
*
@@ -16,8 +12,8 @@
* @since CakePHP v 1.2.0.7726
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Console\Command;
use Cake\Console\Command\ApiShellShell;
use Cake\TestSuite\TestCase;
@@ -35,13 +31,13 @@ class ApiShellTest extends TestCase {
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
$out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
$in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
$this->Shell = $this->getMock(
'Cake\Console\Command\ApiShell',
array('in', 'out', 'createFile', 'hr', '_stop'),
array( $out, $out, $in)
['in', 'out', 'createFile', 'hr', '_stop'],
[$out, $out, $in]
);
}
@@ -51,43 +47,19 @@ public function setUp() {
* @return void
*/
public function testMethodNameDetection() {
$this->Shell->expects($this->any())->method('in')->will($this->returnValue('q'));
$this->Shell->expects($this->at(0))->method('out')->with('Controller');
$this->Shell->expects($this->any())
->method('in')->will($this->returnValue('q'));
$this->Shell->expects($this->at(0))
->method('out')->with('Controller');
$expected = array(
'1. afterFilter()',
'2. afterScaffoldSave($method)',
'3. afterScaffoldSaveError($method)',
'4. beforeFilter()',
'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->expects($this->at(2))
->method('out')
->with($this->logicalAnd(
$this->contains('8. beforeFilter()'),
$this->contains('24. render($view = NULL, $layout = NULL)')
));
$this->Shell->args = array('controller');
$this->Shell->args = ['controller'];
$this->Shell->paths['controller'] = CAKE . 'Controller/';
$this->Shell->main();
}

0 comments on commit b825a52

Please sign in to comment.
You can’t perform that action at this time.