Skip to content
This repository
Browse code

Assert own tasks are loaded before trying to access taskNames.

  • Loading branch information...
commit c23531e806b932181cf8fbaa737ecd1ae4ec14c8 1 parent ad1b806
Mark authored
1  lib/Cake/Console/Shell.php
@@ -201,6 +201,7 @@ public function __construct($stdout = null, $stderr = null, $stdin = null) {
201 201
  */
202 202
 	public function initialize() {
203 203
 		$this->_loadModels();
  204
+		$this->loadTasks();
204 205
 	}
205 206
 
206 207
 /**
1  lib/Cake/Console/ShellDispatcher.php
@@ -206,7 +206,6 @@ public function dispatch() {
206 206
 
207 207
 		if ($Shell instanceof Shell) {
208 208
 			$Shell->initialize();
209  
-			$Shell->loadTasks();
210 209
 			return $Shell->runCommand($command, $this->args);
211 210
 		}
212 211
 		$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));
4  lib/Cake/Test/Case/Console/ShellDispatcherTest.php
@@ -441,7 +441,6 @@ public function testDispatchShellWithMain() {
441 441
 		$Mock = $this->getMock('Shell', array(), array(), 'MockWithMainShell');
442 442
 
443 443
 		$Mock->expects($this->once())->method('initialize');
444  
-		$Mock->expects($this->once())->method('loadTasks');
445 444
 		$Mock->expects($this->once())->method('runCommand')
446 445
 			->with(null, array())
447 446
 			->will($this->returnValue(true));
@@ -467,7 +466,6 @@ public function testDispatchShellWithoutMain() {
467 466
 		$this->mockObjects[] = $Shell;
468 467
 
469 468
 		$Shell->expects($this->once())->method('initialize');
470  
-		$Shell->expects($this->once())->method('loadTasks');
471 469
 		$Shell->expects($this->once())->method('runCommand')
472 470
 			->with('initdb', array('initdb'))
473 471
 			->will($this->returnValue(true));
@@ -491,7 +489,6 @@ public function testDispatchNotAShellWithMain() {
491 489
 		$Shell = $this->getMock('Object', $methods, array(), 'MockWithMainNotAShell');
492 490
 
493 491
 		$Shell->expects($this->never())->method('initialize');
494  
-		$Shell->expects($this->never())->method('loadTasks');
495 492
 		$Shell->expects($this->once())->method('startup');
496 493
 		$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
497 494
 		$Dispatcher->TestShell = $Shell;
@@ -524,7 +521,6 @@ public function testDispatchNotAShellWithoutMain() {
524 521
 		$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell');
525 522
 
526 523
 		$Shell->expects($this->never())->method('initialize');
527  
-		$Shell->expects($this->never())->method('loadTasks');
528 524
 		$Shell->expects($this->once())->method('startup');
529 525
 		$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
530 526
 		$Dispatcher->TestShell = $Shell;
2  lib/Cake/Test/Case/Console/ShellTest.php
@@ -195,6 +195,7 @@ public function testInitialize() {
195 195
 		), App::RESET);
196 196
 
197 197
 		CakePlugin::load('TestPlugin');
  198
+		$this->Shell->tasks = array('DbConfig' => array('one', 'two'));
198 199
 		$this->Shell->uses = array('TestPlugin.TestPluginPost');
199 200
 		$this->Shell->initialize();
200 201
 
@@ -208,6 +209,7 @@ public function testInitialize() {
208 209
 		$this->assertTrue(isset($this->Shell->Comment));
209 210
 		$this->assertInstanceOf('Comment', $this->Shell->Comment);
210 211
 		$this->assertEquals('Comment', $this->Shell->modelClass);
  212
+		$this->assertInstanceOf('DbConfigTask', $this->Shell->DbConfig);
211 213
 
212 214
 		App::build();
213 215
 	}

1 note on commit c23531e

Mischa ter Smitten

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.