Updating tests for Shell so they pass with the changes in the Shell internals.

This commit is contained in:
mark_story 2010-10-04 22:37:20 -04:00
parent 131433739e
commit 76c6decb52

View file

@ -39,6 +39,7 @@ class TestShell extends Shell {
* @access public * @access public
*/ */
public $name = 'TestShell'; public $name = 'TestShell';
/** /**
* stopped property * stopped property
* *
@ -107,7 +108,9 @@ class ShellTest extends CakeTestCase {
'ShellDispatcher', 'ShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear') array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear')
); );
$this->Shell =& new TestShell($this->Dispatcher); $output = $this->getMock('ConsoleOutput');
$error = $this->getMock('ConsoleOutput');
$this->Shell =& new TestShell($this->Dispatcher, $output, $error);
} }
/** /**
@ -129,6 +132,8 @@ class ShellTest extends CakeTestCase {
$this->assertEquals($this->Dispatcher, $this->Shell->Dispatch); $this->assertEquals($this->Dispatcher, $this->Shell->Dispatch);
$this->assertEqual($this->Shell->name, 'TestShell'); $this->assertEqual($this->Shell->name, 'TestShell');
$this->assertEqual($this->Shell->alias, 'TestShell'); $this->assertEqual($this->Shell->alias, 'TestShell');
$this->assertType('ConsoleOutput', $this->Shell->stdout);
$this->assertType('ConsoleOutput', $this->Shell->stderr);
} }
/** /**
@ -221,21 +226,21 @@ class ShellTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOut() { public function testOut() {
$this->Shell->Dispatch->expects($this->at(0)) $this->Shell->stdout->expects($this->at(0))
->method('stdout') ->method('write')
->with("Just a test\n", false); ->with("Just a test", 1);
$this->Shell->Dispatch->expects($this->at(1)) $this->Shell->stdout->expects($this->at(1))
->method('stdout') ->method('write')
->with("Just\na\ntest\n", false); ->with(array('Just', 'a', 'test'), 1);
$this->Shell->Dispatch->expects($this->at(2)) $this->Shell->stdout->expects($this->at(2))
->method('stdout') ->method('write')
->with("Just\na\ntest\n\n", false); ->with(array('Just', 'a', 'test'), 2);
$this->Shell->Dispatch->expects($this->at(3)) $this->Shell->stdout->expects($this->at(3))
->method('stdout') ->method('write')
->with("\n", false); ->with('', 1);
$this->Shell->out('Just a test'); $this->Shell->out('Just a test');
@ -252,21 +257,21 @@ class ShellTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testErr() { public function testErr() {
$this->Shell->Dispatch->expects($this->at(0)) $this->Shell->stderr->expects($this->at(0))
->method('stderr') ->method('write')
->with("Just a test\n"); ->with("Just a test", 1);
$this->Shell->Dispatch->expects($this->at(1)) $this->Shell->stderr->expects($this->at(1))
->method('stderr') ->method('write')
->with("Just\na\ntest\n"); ->with(array('Just', 'a', 'test'), 1);
$this->Shell->Dispatch->expects($this->at(2)) $this->Shell->stderr->expects($this->at(2))
->method('stderr') ->method('write')
->with("Just\na\ntest\n\n"); ->with(array('Just', 'a', 'test'), 2);
$this->Shell->Dispatch->expects($this->at(3)) $this->Shell->stderr->expects($this->at(3))
->method('stderr') ->method('write')
->with("\n"); ->with('', 1);
$this->Shell->err('Just a test'); $this->Shell->err('Just a test');
@ -298,17 +303,17 @@ class ShellTest extends CakeTestCase {
public function testHr() { public function testHr() {
$bar = '---------------------------------------------------------------'; $bar = '---------------------------------------------------------------';
$this->Shell->Dispatch->expects($this->at(0))->method('stdout')->with('', false); $this->Shell->stdout->expects($this->at(0))->method('write')->with('', 0);
$this->Shell->Dispatch->expects($this->at(1))->method('stdout')->with($bar . "\n", false); $this->Shell->stdout->expects($this->at(1))->method('write')->with($bar, 1);
$this->Shell->Dispatch->expects($this->at(2))->method('stdout')->with('', false); $this->Shell->stdout->expects($this->at(2))->method('write')->with('', 0);
$this->Shell->Dispatch->expects($this->at(3))->method('stdout')->with("\n", false); $this->Shell->stdout->expects($this->at(3))->method('write')->with("", true);
$this->Shell->Dispatch->expects($this->at(4))->method('stdout')->with($bar . "\n", false); $this->Shell->stdout->expects($this->at(4))->method('write')->with($bar, 1);
$this->Shell->Dispatch->expects($this->at(5))->method('stdout')->with("\n", false); $this->Shell->stdout->expects($this->at(5))->method('write')->with("", true);
$this->Shell->Dispatch->expects($this->at(6))->method('stdout')->with("\n\n", false); $this->Shell->stdout->expects($this->at(6))->method('write')->with("", 2);
$this->Shell->Dispatch->expects($this->at(7))->method('stdout')->with($bar . "\n", false); $this->Shell->stdout->expects($this->at(7))->method('write')->with($bar, 1);
$this->Shell->Dispatch->expects($this->at(8))->method('stdout')->with("\n\n", false); $this->Shell->stdout->expects($this->at(8))->method('write')->with("", 2);
$this->Shell->hr(); $this->Shell->hr();
@ -323,17 +328,17 @@ class ShellTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testError() { public function testError() {
$this->Shell->Dispatch->expects($this->at(0)) $this->Shell->stderr->expects($this->at(0))
->method('stderr') ->method('write')
->with("<error>Error:</error> Foo Not Found\n"); ->with("<error>Error:</error> Foo Not Found", 1);
$this->Shell->Dispatch->expects($this->at(1)) $this->Shell->stderr->expects($this->at(1))
->method('stderr') ->method('write')
->with("<error>Error:</error> Foo Not Found\n"); ->with("<error>Error:</error> Foo Not Found", 1);
$this->Shell->Dispatch->expects($this->at(2)) $this->Shell->stderr->expects($this->at(2))
->method('stderr') ->method('write')
->with("Searched all...\n"); ->with("Searched all...", 1);
$this->Shell->error('Foo Not Found'); $this->Shell->error('Foo Not Found');
$this->assertIdentical($this->Shell->stopped, 1); $this->assertIdentical($this->Shell->stopped, 1);