public function testPickFromListWorksWithAbort() { $command = Mockery::mock('Illuminate\\Console\\Command'); $command->shouldReceive('info')->once(); $command->shouldReceive('line')->times(3); $command->shouldReceive('ask')->once()->andReturn(2); $choice = pick_from_list($command, 'title', array('option'), 0, "Abort"); $this->assertEquals(-1, $choice); }
/** * Get the task # of a list, either from the argument or prompt the user. * Keep in mind the # present to the user always begins with 1, but the * number we return is always one less (starting with 0) * * @param ListInterface $list The Todo List * @param bool $showNext Show next actions in prompt list * @param bool $showNormal Show normal tasks in prompt list * @param bool $showComplete Show completed tasks in prompt list * @return mixed NULL if user aborts, otherwise integer of task number */ protected function getTaskNo(\GSD\Entities\ListInterface $list, $showNext, $showNormal, $showComplete) { // Return the # if provided on command line $taskNo = $this->argument('task-number'); if (!is_null($taskNo)) { return (int) $taskNo - 1; } // Build list of tasks $tasks = array(); foreach ($list->tasks() as $task) { if ($task->isComplete()) { if ($showComplete) { $tasks[] = (string) $task; } } elseif ($task->isNextAction()) { if ($showNext) { $tasks[] = (string) $task; } } elseif ($showNormal) { $tasks[] = (string) $task; } } // Let user pick from list, return result $selectTitle = rtrim($this->taskNoDescription, '.') . ':'; $result = pick_from_list($this, $selectTitle, $tasks, 0, "Cancel"); if ($result == -1) { return null; } return $result - 1; }