浏览代码

Merge pull request #5072 from cakephp/issue-5063

Fix bake & other shells exiting incorrectly.
José Lorenzo Rodríguez 11 年之前
父节点
当前提交
493767ea41
共有 3 个文件被更改,包括 22 次插入18 次删除
  1. 8 11
      src/Console/ShellDispatcher.php
  2. 1 0
      src/Shell/BakeShell.php
  3. 13 7
      tests/TestCase/Console/ShellDispatcherTest.php

+ 8 - 11
src/Console/ShellDispatcher.php

@@ -154,10 +154,17 @@ class ShellDispatcher {
 /**
 /**
  * Dispatches a CLI request
  * Dispatches a CLI request
  *
  *
+ * Converts a shell command result into an exit code. Null/True
+ * are treated as success. All other return values are an error.
+ *
  * @return int The cli command exit code. 0 is success.
  * @return int The cli command exit code. 0 is success.
  */
  */
 	public function dispatch() {
 	public function dispatch() {
-		return $this->_dispatch() === true ? 0 : 1;
+		$result = $this->_dispatch();
+		if ($result === null || $result === true) {
+			return 0;
+		}
+		return 1;
 	}
 	}
 
 
 /**
 /**
@@ -328,14 +335,4 @@ class ShellDispatcher {
 		$this->dispatch();
 		$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 - 0
src/Shell/BakeShell.php

@@ -85,6 +85,7 @@ class BakeShell extends Shell {
 		}
 		}
 		$this->out('');
 		$this->out('');
 		$this->out('By using <info>`cake bake [name]`</info> you can invoke a specific bake task.');
 		$this->out('By using <info>`cake bake [name]`</info> you can invoke a specific bake task.');
+		return false;
 	}
 	}
 
 
 /**
 /**

+ 13 - 7
tests/TestCase/Console/ShellDispatcherTest.php

@@ -148,10 +148,11 @@ class ShellDispatcherTest extends TestCase {
 		$dispatcher = $this->getMock('Cake\Console\ShellDispatcher', ['findShell']);
 		$dispatcher = $this->getMock('Cake\Console\ShellDispatcher', ['findShell']);
 		$Shell = $this->getMock('Cake\Console\Shell');
 		$Shell = $this->getMock('Cake\Console\Shell');
 
 
-		$Shell->expects($this->once())->method('initialize');
-		$Shell->expects($this->once())->method('runCommand')
-			->with([])
+		$Shell->expects($this->exactly(2))->method('initialize');
+		$Shell->expects($this->at(0))->method('runCommand')
 			->will($this->returnValue(true));
 			->will($this->returnValue(true));
+		$Shell->expects($this->at(1))->method('runCommand')
+			->will($this->returnValue(null));
 
 
 		$dispatcher->expects($this->any())
 		$dispatcher->expects($this->any())
 			->method('findShell')
 			->method('findShell')
@@ -160,7 +161,12 @@ class ShellDispatcherTest extends TestCase {
 
 
 		$dispatcher->args = array('mock_with_main');
 		$dispatcher->args = array('mock_with_main');
 		$result = $dispatcher->dispatch();
 		$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);
 		$this->assertEquals(array(), $dispatcher->args);
 	}
 	}
 
 
@@ -212,7 +218,7 @@ class ShellDispatcherTest extends TestCase {
 
 
 		$dispatcher->args = array('example');
 		$dispatcher->args = array('example');
 		$result = $dispatcher->dispatch();
 		$result = $dispatcher->dispatch();
-		$this->assertEquals(1, $result);
+		$this->assertEquals(0, $result);
 	}
 	}
 
 
 /**
 /**
@@ -239,7 +245,7 @@ class ShellDispatcherTest extends TestCase {
 
 
 		$dispatcher->args = ['Example'];
 		$dispatcher->args = ['Example'];
 		$result = $dispatcher->dispatch();
 		$result = $dispatcher->dispatch();
-		$this->assertEquals(1, $result);
+		$this->assertEquals(0, $result);
 	}
 	}
 
 
 /**
 /**
@@ -266,7 +272,7 @@ class ShellDispatcherTest extends TestCase {
 
 
 		$dispatcher->args = array('sample');
 		$dispatcher->args = array('sample');
 		$result = $dispatcher->dispatch();
 		$result = $dispatcher->dispatch();
-		$this->assertEquals(1, $result);
+		$this->assertEquals(0, $result);
 	}
 	}
 
 
 /**
 /**