Skip to content

Commit

Permalink
Fix bake & other shells exiting incorrectly.
Browse files Browse the repository at this point in the history
If a shell command method returns `null`, we should treat the command as
successful. Only when a shell returns `false` should we exit non-zero.

Refs #5063
  • Loading branch information
markstory committed Nov 4, 2014
1 parent 91d0de0 commit 0495731
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
16 changes: 5 additions & 11 deletions src/Console/ShellDispatcher.php
Expand Up @@ -157,7 +157,11 @@ protected function _bootstrap() {
* @return int The cli command exit code. 0 is success.
*/
public function dispatch() {
return $this->_dispatch() === true ? 0 : 1;
$r = $this->_dispatch();
if ($r === null || $r === true) {
return 0;
}
return 1;
}

/**
Expand Down Expand Up @@ -322,14 +326,4 @@ public function help() {
$this->dispatch();
}

/**
* Stop execution of the current script
*
* @param int|string $status see http://php.net/exit for values
* @return void
*/
protected function _stop($status = 0) {
exit($status);
}

}
1 change: 1 addition & 0 deletions src/Shell/BakeShell.php
Expand Up @@ -85,6 +85,7 @@ public function main() {
}
$this->out('');
$this->out('By using <info>`cake bake [name]`</info> you can invoke a specific bake task.');
return false;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions tests/TestCase/Console/ShellDispatcherTest.php
Expand Up @@ -129,9 +129,10 @@ public function testDispatchShellWithMain() {
$Shell = $this->getMock('Cake\Console\Shell');

$Shell->expects($this->once())->method('initialize');
$Shell->expects($this->once())->method('runCommand')
->with([])
$Shell->expects($this->at(0))->method('runCommand')
->will($this->returnValue(true));
$Shell->expects($this->at(1))->method('runCommand')
->will($this->returnValue(null));

$dispatcher->expects($this->any())
->method('findShell')
Expand All @@ -140,7 +141,12 @@ public function testDispatchShellWithMain() {

$dispatcher->args = array('mock_with_main');
$result = $dispatcher->dispatch();
$this->assertEquals(0, $result);
$this->assertSame(0, $result);
$this->assertEquals(array(), $dispatcher->args);

$dispatcher->args = array('mock_with_main');
$result = $dispatcher->dispatch();
$this->assertSame(0, $result);
$this->assertEquals(array(), $dispatcher->args);
}

Expand Down

0 comments on commit 0495731

Please sign in to comment.