writeToFile() public method

Write the current crons to a file.
public writeToFile ( Crontab $crontab, string $filename ) : CrontabFileHandler
$crontab Crontab
$filename string
return CrontabFileHandler
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testWriteToFileThrowsExceptionWhenFileIsNotWritable()
 {
     $this->crontabFileHandler->parseFromFile($this->crontab, $this->fixtureFile);
     touch($this->tempFile);
     chmod($this->tempFile, 0400);
     $this->crontabFileHandler->writeToFile($this->crontab, $this->tempFile);
     // Expected an InvalidArgumentException because the file is not writable.
 }
Esempio n. 2
0
 /**
  * Save crons to file
  * 
  * @param string $file /path/to/file/
  */
 public function save()
 {
     $crontabFile = $this->getCrontabFile();
     if (!is_null($crontabFile)) {
         $this->crontabFileHandler->writeToFile($this->crontab, $crontabFile);
     } else {
         $this->crontabFileHandler->write($this->crontab);
     }
     return $this;
 }
 public function testWriteToFileThrowsExceptionWhenFileIsNotWritable()
 {
     $fail = true;
     $this->crontabFileHandler->parseFromFile($this->crontab, $this->fixturesDir . '/crontab');
     $file = tempnam(sys_get_temp_dir(), 'cron');
     touch($file);
     chmod($file, 0400);
     try {
         // We cannot use @expectedException annotation,
         // because we have to remove the temp file afterwards.
         $this->crontabFileHandler->writeToFile($this->crontab, $file);
     } catch (\InvalidArgumentException $e) {
         $fail = false;
     }
     chmod($file, 0600);
     unlink($file);
     if ($fail) {
         $this->fail('Expected an InvalidArgumentException because the file is not writable.');
     }
 }