Browse Source

Fixing the CommandList shell, renaming the TestSuiteShell to TestsuiteShell for BC

Jose Lorenzo Rodriguez 15 years ago
parent
commit
48b3593a25

+ 13 - 20
lib/Cake/Console/Command/CommandListShell.php

@@ -16,6 +16,8 @@
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
 
+App::uses('Inflector', 'Utility');
+
 /**
  * Shows a list of commands available from the console.
  *
@@ -79,17 +81,18 @@ class CommandListShell extends Shell {
 	protected function _getShellList() {
 		$shellList = array();
 
-		$corePaths = App::core('shells');
-		$shellList = $this->_appendShells('CORE', $corePaths, $shellList);
+		$shells = App::objects('file', App::core('Console/Command'));
+		$shellList = $this->_appendShells('CORE', $shells, $shellList);
 
-		$appPaths = array_diff(App::path('shells'), $corePaths);
-		$shellList = $this->_appendShells('app', $appPaths, $shellList);
+		$appShells = App::objects('Console/Command', null, false);
+		$shellList = $this->_appendShells('app', $appShells, $shellList);
 
 		$plugins = App::objects('plugin');
 		foreach ($plugins as $plugin) {
-			$pluginPath = App::pluginPath($plugin) . 'console' . DS . 'shells' . DS;
-			$shellList = $this->_appendShells($plugin, array($pluginPath), $shellList);
+			$pluginShells = App::objects($plugin . '.Console/Command');
+			$shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
 		}
+
 		return $shellList;
 	}
 
@@ -98,20 +101,10 @@ class CommandListShell extends Shell {
  *
  * @return array
  */
-	protected function _appendShells($type, $paths, $shellList) {
-		foreach ($paths as $path) {
-			if (!is_dir($path)) {
-				continue;
-			}
- 			$shells = App::objects('file', $path);
-
-			if (empty($shells)) {
-				continue;
-			}
-			foreach ($shells as $shell) {
-				$shell = str_replace('Shell.php', '', $shell);
-				$shellList[$shell][$type] = $type;
-			}
+	protected function _appendShells($type, $shells, $shellList) {
+		foreach ($shells as $shell) {
+			$shell = Inflector::underscore(str_replace('Shell', '', $shell));
+			$shellList[$shell][$type] = $type;
 		}
 		return $shellList;
 	}

lib/Cake/Console/Command/TestSuiteShell.php → lib/Cake/Console/Command/TestsuiteShell.php


+ 4 - 3
lib/Cake/Core/App.php

@@ -454,7 +454,7 @@ class App {
 		if ($type === 'file' && !$path) {
 			return false;
 		} elseif ($type === 'file') {
-			$extension = '/.*/';
+			$extension = '/\.php$/';
 			$name = $type . str_replace(DS, '', $path);
 		}
 
@@ -477,9 +477,10 @@ class App {
 					$files = new RegexIterator(new DirectoryIterator($dir), $extension);
 					foreach ($files as $file) {
 						if (!$file->isDot()) {
-							if ($file->isDir() && $includeDirectories) {
+							$isDir = $file->isDir() ;
+							if ($isDir && $includeDirectories) {
 								$objects[] = basename($file);
-							} elseif (!$includeDirectories) {
+							} elseif (!$includeDirectories && !$isDir) {
 								$objects[] = substr(basename($file), 0, -4);
 							}
 						}

+ 5 - 4
lib/Cake/tests/cases/console/shells/command_list.test.php

@@ -18,6 +18,9 @@
  */
 
 App::uses('CommandListShell', 'Console/Command');
+App::uses('ConsoleOutput', 'Console');
+App::uses('ConsoleInput', 'Console');
+App::uses('Shell', 'Console');
 
 
 class TestStringOutput extends ConsoleOutput {
@@ -40,10 +43,7 @@ class CommandListTest extends CakeTestCase {
 			'plugins' => array(
 				LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
 			),
-			'shells' => array(
-				CORE_PATH ? 
-					CORE_PATH . CAKE . 'console' . DS . 'shells' . DS : 
-					CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS . 'shells' .DS, 
+			'Console/Command' => array(
 				LIBS . 'tests' . DS . 'test_app' . DS . 'console' . DS . 'shells' . DS
 			)
 		), true);
@@ -84,6 +84,7 @@ class CommandListTest extends CakeTestCase {
 		$expected = "/welcome \[.*TestPluginTwo.*\]/";
 		$this->assertPattern($expected, $output);
 
+
 		$expected = "/acl \[.*CORE.*\]/";
 		$this->assertPattern($expected, $output);
 

lib/Cake/tests/test_app/console/shells/sample.php → lib/Cake/tests/test_app/console/shells/SampleShell.php