/** * Get all commands that are due to be run * * @param Debugger $debugger * * @throws \InvalidArgumentException * @return \Indatus\Dispatcher\Queue */ public function getQueue(Debugger $debugger) { /** @var \Indatus\Dispatcher\Queue $queue */ $queue = App::make('Indatus\\Dispatcher\\Queue'); /** @var \Indatus\Dispatcher\Scheduling\ScheduledCommandInterface $command */ foreach ($this->getScheduledCommands() as $command) { /** @var \Indatus\Dispatcher\Scheduling\Schedulable $scheduler */ $scheduler = App::make('Indatus\\Dispatcher\\Scheduling\\Schedulable'); //could be multiple schedules based on arguments $schedules = $command->schedule($scheduler); if (!is_array($schedules)) { $schedules = array($schedules); } $willBeRun = false; foreach ($schedules as $schedule) { if ($schedule instanceof Schedulable === false) { throw new \InvalidArgumentException('Schedule for "' . $command->getName() . '" is not an instance of Schedulable'); } if ($this->isDue($schedule)) { /** @var \Indatus\Dispatcher\QueueItem $queueItem */ $queueItem = App::make('Indatus\\Dispatcher\\QueueItem'); $queueItem->setCommand($command); $queueItem->setScheduler($schedule); if ($queue->add($queueItem)) { $willBeRun = true; } } } //it didn't run, so record that it didn't run if ($willBeRun === false) { $debugger->commandNotRun($command, 'No schedules were due'); } } return $queue; }
public function testCommandNotRun() { $reason = 'Because I said so'; $this->output->shouldReceive('writeln')->once()->with(' <comment>' . $this->commandName . '</comment>: ' . $reason); $debugger = new Debugger($this->optionReader, $this->output); $debugger->commandNotRun($this->scheduledCommand, $reason); }