Skip to content

Commit

Permalink
Making TaskCollection require a Shell instead of a ShellDispatcher.
Browse files Browse the repository at this point in the history
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 14, 2010
1 parent b6602f1 commit a55098b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
12 changes: 6 additions & 6 deletions cake/console/libs/task_collection.php
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
15 changes: 7 additions & 8 deletions cake/tests/cases/console/libs/task_collection.test.php
Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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.');
Expand Down

0 comments on commit a55098b

Please sign in to comment.