Crontab\CrontabFileHandler::writeToFile PHP Method

writeToFile() public method

Write the current crons to a file.
public writeToFile ( Crontab $crontab, string $filename ) : CrontabFileHandler
$crontab Crontab
$filename string
return CrontabFileHandler
    public function writeToFile(Crontab $crontab, $filename)
    {
        if (!is_writable($filename)) {
            throw new \InvalidArgumentException('File ' . $filename . ' is not writable.');
        }
        file_put_contents($filename, $crontab->render() . PHP_EOL);
        return $this;
    }

Usage Example

 /**
  * @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.
 }
All Usage Examples Of Crontab\CrontabFileHandler::writeToFile