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.
This commit is contained in:
mark_story 2010-10-04 00:23:54 -04:00
parent b6602f1d0d
commit a55098b00b
2 changed files with 13 additions and 14 deletions

View file

@ -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;

View file

@ -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.');