public function testParse() { // ARRANGE // ACT $cron = Cron::parse('1 2 3 4 5 ls > output.log 2> error.log #comment'); // ASSERT $this->assertSame('ls', $cron->getCommand()); $this->assertSame('comment', $cron->getComment()); $this->assertSame('error.log', $cron->getErrorFile()); $this->assertSame('output.log', $cron->getLogFile()); $this->assertEquals(1, $cron->getMinute()); $this->assertEquals(2, $cron->getHour()); $this->assertEquals(3, $cron->getDayOfMonth()); $this->assertEquals(4, $cron->getMonth()); $this->assertEquals(5, $cron->getDayOfWeek()); }
function __construct() { // parsing cron file $process = new Process('crontab -l'); $process->run(); $lines = \array_filter(\explode(PHP_EOL, $process->getOutput()), function ($line) { return '' != \trim($line); }); foreach ($lines as $lineNumber => $line) { // if line is nt a comment, convert it to a cron if (0 !== \strpos($line, '#', 0)) { $line = Cron::parse($line); } $this->lines['l' . $lineNumber] = $line; } $this->error = $process->getErrorOutput(); }
function __construct() { // parsing cron file $process = new Process('crontab -l'); $process->run(); $lines = \array_filter(\explode(PHP_EOL, $process->getOutput()), function ($line) { return '' != \trim($line); }); foreach ($lines as $lineNumber => $line) { // if line is nt a comment, convert it to a cron if (\strpos($line, '#suspended: ', 0) === 0 || 0 !== \strpos($line, '#', 0)) { try { $line = Cron::parse($line); } catch (\Exception $e) { $process->addErrorOutput('CronManager was unable to parse crontab at line ' . $lineNumber); } } $this->lines['l' . $lineNumber] = $line; } $this->error = $process->getErrorOutput(); }
public function testParseSuspended() { // ARRANGE $cron = Cron::parse('#suspended: 1 2 3 4 5 ls > output.log 2> error.log #comment'); $this->assertEquals(true, $cron->isSuspended()); }