/**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $archived = $this->option('archived');
     $tasks = $this->option('tasks');
     if (!is_null($tasks)) {
         $validTasks = array('all', 'next', 'normal', 'done');
         if (!in_array($tasks, $validTasks)) {
             $msg = sprintf("Invalid --tasks=%s. Must be one of '%s'.", $tasks, join("', '", $validTasks));
             $this->abort($msg);
         }
         if ($tasks == 'next') {
             $tasks = 'next action';
         }
         $completeFmt = Config::get('todo.dateCompleteFormat');
         $dueFmt = Config::get('todo.dateDueFormat');
     }
     // Get lists
     $lists = \Todo::allLists($archived);
     $lists = $this->sortListIds($lists);
     // Output title
     $listType = $archived ? 'archived lists' : 'lists';
     $listWhat = is_null($tasks) ? 'all' : "{$tasks} tasks in all";
     $this->info("Listing {$listWhat} {$listType}");
     // Different headers based on tasks usage
     if (is_null($tasks)) {
         $headers = array('list', 'next', 'todos', 'completed');
     } else {
         $headers = array('List', 'Next', 'Description', 'Extra');
     }
     $rows = array();
     foreach ($lists as $listId) {
         $list = \Todo::get($listId, $archived);
         // We're just outputing the lists
         if (is_null($tasks)) {
             $rows[] = array($listId, $list->taskCount('next'), $list->taskCount('todo'), $list->taskCount('done'));
         } else {
             // Loop through tasks to figure which to output
             foreach ($list->tasks() as $task) {
                 if ($task->isComplete()) {
                     if ($tasks == 'done' || $tasks == 'all') {
                         $done = $task->dateCompleted()->format($completeFmt);
                         $rows[] = array($listId, '', $task->description(), "Done {$done}");
                     }
                 } else {
                     $next = $task->isNextAction() ? 'YES' : '';
                     $due = $task->dateDue() ? 'Due ' . $task->dateDue()->format($dueFmt) : '';
                     if ($tasks == 'all' or $tasks == 'next action' && $next == 'YES' or $tasks == 'normal' && $next == '') {
                         $rows[] = array($listId, $next, $task->description(), $due);
                     }
                 }
             }
         }
     }
     // Output a pretty table
     $table = $this->getHelperSet()->get('table');
     $table->setHeaders($headers)->setRows($rows)->render($this->getOutput());
 }
 public function testGetListReturnsCorrectType()
 {
     // Mock the repository
     App::bind('GSD\\Repositories\\TodoRepositoryInterface', function () {
         $list = Mockery::mock('GSD\\Entities\\ListInterface');
         $mock = Mockery::mock('GSD\\Repositories\\TodoRepositoryInterface');
         $mock->shouldReceive('exists')->once()->andReturn(true);
         $mock->shouldReceive('load')->once()->andReturn($list);
         return $mock;
     });
     // Should throw an error
     $list = Todo::get('abc');
     $this->assertInstanceOf('GSD\\Entities\\ListInterface', $list);
 }