/**
  * Tests if scheduled in the past gives an exception.
  **/
 public function testSchedulingCommandInThePast()
 {
     $this->setExpectedException('ConnectHolland\\Tactician\\SchedulerPlugin\\Exception\\ScheduledInThePastException');
     $command = new ScheduledCommand();
     $command->setTimestamp(time() - 1);
     $this->commandBus->handle($command);
 }
 /**
  * testMissingScheduledCommandThrowsException.
  */
 public function testMissingScheduledCommandThrowsException()
 {
     $scheduler = new FileBasedScheduler($this->path);
     $command = new ScheduledCommand();
     $command->setTimestamp(time() + 1);
     $id = $scheduler->schedule($command);
     $this->assertFileExists($this->path . $id);
     unlink($this->path . $id);
     sleep(1);
     $this->setExpectedException(ScheduledCommandNotFoundException::class);
     $scheduler->getCommands();
 }
 /**
  * testExecuteScheduledCommand.
  */
 public function testExecuteScheduledCommand()
 {
     // schedule a command
     $command = new ScheduledCommand();
     $command->setTimestamp(time() + 2);
     $id = $this->commandBus->handle($command);
     $this->assertFileExists($this->path . $id);
     // does nothing yet
     $application = new Application();
     $application->add(new DaemonCommand());
     $consoleCommand = $application->find('scheduler:daemon');
     $commandTester = new CommandTester($consoleCommand);
     $commandTester->execute(array('command' => $consoleCommand->getName(), 'bootstrap' => 'tests/Fixtures/bootstrap.php', 'interval' => 1, 'count' => 3));
     $this->assertFileNotExists($this->path . $id);
 }
 /**
  * testGetCommands
  */
 public function testGetCommands()
 {
     $con = new MongoClient('mongodb://localhost');
     $db = $con->selectDB('ConnectHollandTacticianSchedulerTest');
     $collection = $db->selectCollection('MongoScheduler');
     $scheduler = new MongoScheduler($collection);
     $command = new ScheduledCommand();
     $command->setTimestamp(time() + 1);
     $identifier = $scheduler->schedule($command);
     $nothing = $scheduler->getCommands();
     $this->assertEquals(0, count($nothing));
     sleep(1);
     $todo = $scheduler->getCommands();
     $this->assertEquals(1, count($todo));
     $this->assertEquals($command, $todo[0]);
     $stored = $collection->findOne(['_id' => new MongoId($identifier)]);
     $this->assertEmpty($stored);
 }