Skip to content
Permalink
Browse files

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.
  • Loading branch information...
markstory committed Oct 4, 2010
1 parent b6602f1 commit a55098b00b7e0f48b1367ed97e7c6e436999d739
Showing with 13 additions and 14 deletions.
  1. +6 −6 cake/console/libs/task_collection.php
  2. +7 −8 cake/tests/cases/console/libs/task_collection.test.php
@@ -20,20 +20,20 @@
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
*
* @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 @@ public function load($task, $settings = array(), $enable = true) {
}
}
$this->_loaded[$name] = new $taskClass($this->_Dispatch);
$this->_loaded[$name] = new $taskClass($this->_Shell);
if ($enable === true) {
$this->_enabled[] = $name;
}
@@ -75,7 +75,7 @@ public function load($task, $settings = array(), $enable = true) {
* @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;
@@ -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 @@ function testLoadMissingTaskFile() {
* @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.');

0 comments on commit a55098b

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