Beispiel #1
0
 public function testSave()
 {
     $inputData = file_get_contents(dirname(__DIR__) . '/Data/crontabRead.txt');
     $outputData = file_get_contents(dirname(__DIR__) . '/Data/crontabWrite.txt');
     $crontab = $this->getCrontabWithMockedProcesses($this->getMockedProcessRead($inputData), $this->getMockedProcessWrite($outputData));
     $jobs = $crontab->getJobs();
     $jobs[0]->setCommand('changed command');
     $newJob = new Job();
     $newJob->setCommand('new command');
     $newJob->setHour('5');
     $newJob->setMinute('4');
     $newJob->setDayOfMonth('3');
     $newJob->setDayOfWeek('2');
     $newJob->setMonth('1');
     $crontab->addJob($newJob);
     $crontab->save();
 }
Beispiel #2
0
 /**
  * @param string $line
  * @return Job|null
  */
 private function parseLine($line)
 {
     if (strlen($line) === 0) {
         return null;
     }
     if ($line[0] === '#') {
         // It's a comment
         return null;
     }
     $elements = explode(' ', $line, 6);
     if (count($elements) < 6) {
         throw ParserException::insufficientArgumentsForJob($line);
     }
     $job = new Job();
     $job->setMinute($elements[0]);
     $job->setHour($elements[1]);
     $job->setDayOfMonth($elements[2]);
     $job->setMonth($elements[3]);
     $job->setDayOfWeek($elements[4]);
     $job->setCommand($elements[5]);
     return $job;
 }