Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Assert own tasks are loaded before trying to access taskNames.

  • Loading branch information...
commit c23531e806b932181cf8fbaa737ecd1ae4ec14c8 1 parent ad1b806
@dereuromark dereuromark authored
View
1  lib/Cake/Console/Shell.php
@@ -201,6 +201,7 @@ public function __construct($stdout = null, $stderr = null, $stdin = null) {
*/
public function initialize() {
$this->_loadModels();
+ $this->loadTasks();
}
/**
View
1  lib/Cake/Console/ShellDispatcher.php
@@ -206,7 +206,6 @@ public function dispatch() {
if ($Shell instanceof Shell) {
$Shell->initialize();
- $Shell->loadTasks();
return $Shell->runCommand($command, $this->args);
}
$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));
View
4 lib/Cake/Test/Case/Console/ShellDispatcherTest.php
@@ -441,7 +441,6 @@ public function testDispatchShellWithMain() {
$Mock = $this->getMock('Shell', array(), array(), 'MockWithMainShell');
$Mock->expects($this->once())->method('initialize');
- $Mock->expects($this->once())->method('loadTasks');
$Mock->expects($this->once())->method('runCommand')
->with(null, array())
->will($this->returnValue(true));
@@ -467,7 +466,6 @@ public function testDispatchShellWithoutMain() {
$this->mockObjects[] = $Shell;
$Shell->expects($this->once())->method('initialize');
- $Shell->expects($this->once())->method('loadTasks');
$Shell->expects($this->once())->method('runCommand')
->with('initdb', array('initdb'))
->will($this->returnValue(true));
@@ -491,7 +489,6 @@ public function testDispatchNotAShellWithMain() {
$Shell = $this->getMock('Object', $methods, array(), 'MockWithMainNotAShell');
$Shell->expects($this->never())->method('initialize');
- $Shell->expects($this->never())->method('loadTasks');
$Shell->expects($this->once())->method('startup');
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Dispatcher->TestShell = $Shell;
@@ -524,7 +521,6 @@ public function testDispatchNotAShellWithoutMain() {
$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell');
$Shell->expects($this->never())->method('initialize');
- $Shell->expects($this->never())->method('loadTasks');
$Shell->expects($this->once())->method('startup');
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Dispatcher->TestShell = $Shell;
View
2  lib/Cake/Test/Case/Console/ShellTest.php
@@ -195,6 +195,7 @@ public function testInitialize() {
), App::RESET);
CakePlugin::load('TestPlugin');
+ $this->Shell->tasks = array('DbConfig' => array('one', 'two'));
$this->Shell->uses = array('TestPlugin.TestPluginPost');
$this->Shell->initialize();
@@ -208,6 +209,7 @@ public function testInitialize() {
$this->assertTrue(isset($this->Shell->Comment));
$this->assertInstanceOf('Comment', $this->Shell->Comment);
$this->assertEquals('Comment', $this->Shell->modelClass);
+ $this->assertInstanceOf('DbConfigTask', $this->Shell->DbConfig);
App::build();
}

1 comment on commit c23531e

@tersmitten

This patch causes problems when loading tasks like this:

$taskName = substr($task, 0, -4);
$this->Tasks->load($plugin . $taskName);
$this->tasks[] = $taskName;

Changing it to:

$taskName = substr($task, 0, -4);
$this->{$plugin . $taskName} = $this->Tasks->load($plugin . $taskName); 
$this->tasks[] = $taskName;

resolved the problem.

Please sign in to comment.
Something went wrong with that request. Please try again.