diff --git a/lib/Cake/Console/Command/ApiShell.php b/lib/Cake/Console/Command/ApiShell.php index 40d03bcb7a4..60af122d959 100644 --- a/lib/Cake/Console/Command/ApiShell.php +++ b/lib/Cake/Console/Command/ApiShell.php @@ -1,11 +1,5 @@ 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) { diff --git a/lib/Cake/Test/TestCase/Console/Command/ApiShellTest.php b/lib/Cake/Test/TestCase/Console/Command/ApiShellTest.php index ede1f9b1a67..9e6daa6cdbd 100644 --- a/lib/Cake/Test/TestCase/Console/Command/ApiShellTest.php +++ b/lib/Cake/Test/TestCase/Console/Command/ApiShellTest.php @@ -1,9 +1,5 @@ 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(); }