From a55098b00b7e0f48b1367ed97e7c6e436999d739 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 4 Oct 2010 00:23:54 -0400 Subject: [PATCH] Making TaskCollection require a Shell instead of a ShellDispatcher. This will help reduce the coupling between ShellDispatcher and other objects. Since ShellDispatcher never directly uses or interacts with TaskCollection, it doesn't make much sense for it to have one. Instead shells will either get their own, or be passed one in. --- cake/console/libs/task_collection.php | 12 ++++++------ .../cases/console/libs/task_collection.test.php | 15 +++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cake/console/libs/task_collection.php b/cake/console/libs/task_collection.php index d1ec21733..b0fc6aea1 100644 --- a/cake/console/libs/task_collection.php +++ b/cake/console/libs/task_collection.php @@ -20,11 +20,11 @@ App::import('Core', 'ObjectCollection'); class TaskCollection extends ObjectCollection { /** - * Shell Dispatcher to give to tasks. and use to find tasks. + * Shell to give to tasks. and use to find tasks. * * @var array */ - protected $_Dispatch; + protected $_Shell; /** * Constructor @@ -32,8 +32,8 @@ class TaskCollection extends ObjectCollection { * @param array $paths Array of paths to search for tasks on . * @return void */ - public function __construct(ShellDispatcher $Dispatcher) { - $this->_Dispatch = $Dispatcher; + public function __construct(Shell $Shell) { + $this->_Shell = $Shell; } /** * Loads/constructs a task. Will return the instance in the registry if it already exists. @@ -60,7 +60,7 @@ class TaskCollection extends ObjectCollection { } } - $this->_loaded[$name] = new $taskClass($this->_Dispatch); + $this->_loaded[$name] = new $taskClass($this->_Shell); if ($enable === true) { $this->_enabled[] = $name; } @@ -75,7 +75,7 @@ class TaskCollection extends ObjectCollection { * @throws MissingTaskFileException */ protected function _getPath($file) { - foreach ($this->_Dispatch->shellPaths as $path) { + foreach ($this->_Shell->shellPaths as $path) { $taskPath = $path . 'tasks' . DS . $file . '.php'; if (file_exists($taskPath)) { return $taskPath; diff --git a/cake/tests/cases/console/libs/task_collection.test.php b/cake/tests/cases/console/libs/task_collection.test.php index bbbbf7314..94935106b 100644 --- a/cake/tests/cases/console/libs/task_collection.test.php +++ b/cake/tests/cases/console/libs/task_collection.test.php @@ -17,7 +17,6 @@ * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -require_once CAKE . 'console' . DS . 'shell_dispatcher.php'; App::import('Shell', 'TaskCollection', false); App::import('Shell', 'Shell', false); @@ -29,9 +28,9 @@ class TaskCollectionTest extends CakeTestCase { * @return void */ function setup() { - $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false); - $dispatcher->shellPaths = App::path('shells'); - $this->Tasks = new TaskCollection($dispatcher); + $shell = $this->getMock('Shell', array(), array(), '', false); + $shell->shellPaths = App::path('shells'); + $this->Tasks = new TaskCollection($shell); } /** @@ -87,10 +86,10 @@ class TaskCollectionTest extends CakeTestCase { * @return void */ function testLoadPluginTask() { - $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false); - $dispatcher->shellPaths = App::path('shells'); - $dispatcher->shellPaths[] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'vendors' . DS . 'shells' . DS; - $this->Tasks = new TaskCollection($dispatcher); + $shell = $this->getMock('Shell', array(), array(), '', false); + $shell->shellPaths = App::path('shells'); + $shell->shellPaths[] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'vendors' . DS . 'shells' . DS; + $this->Tasks = new TaskCollection($shell); $result = $this->Tasks->load('TestPlugin.OtherTask'); $this->assertType('OtherTaskTask', $result, 'Task class is wrong.');