Skip to content

Commit

Permalink
Adding return from _stop() to help testing.
Browse files Browse the repository at this point in the history
Updating tests for getName()
  • Loading branch information
markstory committed May 27, 2010
1 parent 9647e35 commit 8ac46c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
3 changes: 1 addition & 2 deletions cake/console/libs/tasks/controller.php
Expand Up @@ -409,10 +409,9 @@ public function getName($useDbConfig = null) {

while ($enteredController == '') {
$enteredController = $this->in(__("Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q');

if ($enteredController === 'q') {
$this->out(__('Exit'));
$this->_stop();
return $this->_stop();
}

if ($enteredController == '' || intval($enteredController) > count($controllers)) {
Expand Down
35 changes: 20 additions & 15 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -139,27 +139,32 @@ public function testListAll() {
*
* @return void
*/
public function xxtestGetName() {
public function testGetNameValidIndex() {
$this->Task->interactive = true;
$this->Task->expects($this->any())->method('in')->will($this->returnValue(1));

$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));
$this->Task->expectOnce('_stop');
$this->Task->getName('test_suite');

$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue(3));
$result = $this->Task->getName('test_suite');
$expected = 'Articles';
$expected = 'Comments';
$this->assertEqual($result, $expected);

$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(3));
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue(1));
$result = $this->Task->getName('test_suite');
$expected = 'Comments';
$expected = 'Articles';
$this->assertEqual($result, $expected);
}

$this->Task->expects($this->at(3))->method('in')->will($this->returnValue(10));
$result = $this->Task->getName('test_suite');
$this->Task->expectOnce('err');
/**
* test getting invalid indexes.
*
* @return void
*/
function testGetNameInvalidIndex() {
$this->Task->interactive = true;
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue(10));
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue('q'));
$this->Task->expects($this->once())->method('err');
$this->Task->expects($this->once())->method('_stop');

$this->Task->getName('test_suite');
}

/**
Expand Down

0 comments on commit 8ac46c3

Please sign in to comment.