Skip to content

Commit

Permalink
Fixing Shell tests to use ConsoleInput.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 14, 2010
1 parent e816a49 commit 7921ef1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
7 changes: 7 additions & 0 deletions cake/console/libs/shell.php
Expand Up @@ -155,6 +155,13 @@ class Shell extends Object {
*/
public $stderr;

/**
* stdin object
*
* @var ConsoleInput
*/
public $stdin;

/**
* Constructs this Shell instance.
*
Expand Down
38 changes: 16 additions & 22 deletions cake/tests/cases/console/libs/shell.test.php
Expand Up @@ -110,7 +110,8 @@ public function setUp() {
);
$output = $this->getMock('ConsoleOutput');
$error = $this->getMock('ConsoleOutput');
$this->Shell =& new TestShell($this->Dispatcher, $output, $error);
$in = $this->getMock('ConsoleInput');
$this->Shell =& new TestShell($this->Dispatcher, $output, $error, $in);
}

/**
Expand Down Expand Up @@ -174,29 +175,24 @@ public function testInitialize() {
* @return void
*/
public function testIn() {
$this->Dispatcher->expects($this->at(0))
->method('getInput')
->with('Just a test?', array('y', 'n'), 'n')
$this->Shell->stdin->expects($this->at(0))
->method('read')
->will($this->returnValue('n'));

$this->Dispatcher->expects($this->at(1))
->method('getInput')
->with('Just a test?', array('y', 'n'), 'n')
$this->Shell->stdin->expects($this->at(1))
->method('read')
->will($this->returnValue('Y'));

$this->Dispatcher->expects($this->at(2))
->method('getInput')
->with('Just a test?', 'y,n', 'n')
$this->Shell->stdin->expects($this->at(2))
->method('read')
->will($this->returnValue('y'));

$this->Dispatcher->expects($this->at(3))
->method('getInput')
->with('Just a test?', 'y/n', 'n')
$this->Shell->stdin->expects($this->at(3))
->method('read')
->will($this->returnValue('y'));

$this->Dispatcher->expects($this->at(4))
->method('getInput')
->with('Just a test?', 'y', 'y')
$this->Shell->stdin->expects($this->at(4))
->method('read')
->will($this->returnValue('y'));

$result = $this->Shell->in('Just a test?', array('y', 'n'), 'n');
Expand Down Expand Up @@ -471,14 +467,12 @@ function testCreateFileInteractive() {

$this->Shell->interactive = true;

$this->Shell->Dispatch->expects($this->at(5))
->method('getInput')
->withAnyParameters()
$this->Shell->stdin->expects($this->at(0))
->method('read')
->will($this->returnValue('n'));

$this->Shell->Dispatch->expects($this->at(9))
->method('getInput')
->withAnyParameters()
$this->Shell->stdin->expects($this->at(1))
->method('read')
->will($this->returnValue('y'));


Expand Down

0 comments on commit 7921ef1

Please sign in to comment.