public function testWriteToFileIsSuccessfulWhenFileIsWritable() { $this->crontabFileHandler->parseFromFile($this->crontab, $this->fixturesDir . '/crontab'); $file = tempnam(sys_get_temp_dir(), 'cron'); $this->crontabFileHandler->writeToFile($this->crontab, $file); $this->assertSame($this->crontab->render() . PHP_EOL, file_get_contents($file)); unlink($file); }
/** * Write the current crons to a file. * * @param Crontab $crontab * @param string $filename * * @return CrontabFileHandler * @throws \InvalidArgumentException */ 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; }
public function testWriteToFileIsSuccessfulWhenFileIsWritable() { $this->crontabFileHandler->parseFromFile($this->crontab, $this->fixtureFile); $this->crontabFileHandler->writeToFile($this->crontab, $this->tempFile); $this->assertSame($this->crontab->render() . PHP_EOL, file_get_contents($this->tempFile)); }
public function render() { $description = implode(PHP_EOL, array("# AUTO GENERATED BY CRONMONITOR", "# PLEASE DON'T EDIT ANYTHING")); $result = sprintf("%s%s%s", $description, PHP_EOL, parent::render()); return $result; }