Пример #1
0
 function let(Crontab $crontab, Task $nmTask1, Task $nmTask2, Task $task1, Task $task2, Variables $variables1)
 {
     $this->prepareTask($task1, $variables1);
     $this->prepareTask($task2, $variables1);
     $this->prepareTask($nmTask1, $variables1, true);
     $this->prepareTask($nmTask2, $variables1, true);
     $crontab->getName()->willReturn("TestAopTest");
     $crontab->getManagedTasks()->willReturn(array($task1, $task2));
     $crontab->getNotManagedTasks()->willReturn(array($nmTask1, $nmTask2));
 }
Пример #2
0
    function it_works_with_crons_without_comments(Task $taskWC, Variables $variablesWC, Crontab $crontabWC)
    {
        $this->prepareTask($taskWC, $variablesWC, true, false);
        $variablesWC->current()->willReturn('value');
        $variablesWC->key()->willReturn('key');
        $variablesWC->rewind()->shouldBeCalled();
        $variablesWC->valid()->willReturn(true, false);
        $variablesWC->next()->shouldBeCalled();
        $crontabWC->getName()->willReturn("TestAopTest");
        $crontabWC->getManagedTasks()->willReturn(array($taskWC));
        $crontabWC->getNotManagedTasks()->willReturn(array());
        //        echo($this->getContent($crontabWC)->getWrappedObject());
        //        die();
        $this->getContent($crontabWC)->shouldReturn(<<<CONTENT
#WARNING!!!
#This crontab file it at least partially managed by Crontab by Hexmedia, please check all restrictions that comes with that library at: https://github.com/Hexmedia/Crontab/blob/master/README.md
#EOT



# ------------ CURRENTLY MANAGED by TestAopTest --------------

key=value
*/10 * * * *       test > some_log_file.log

CONTENT
);
    }
Пример #3
0
 /**
  * @param Task $task
  *
  * @return string
  */
 private function prepareTask(Task $task, Crontab $crontab)
 {
     $log = $task->getLogFile() ? '> ' . $task->getLogFile() : '';
     if ($task->isNotManaged()) {
         $comment = $task->getBeforeComment();
     } else {
         $comment = $this->prepareTaskNameLine($task, $crontab->getName()) . $task->getBeforeComment();
     }
     $comment = $this->prepareComment($comment);
     $variables = '';
     if ($task->getVariables() instanceof \Iterator) {
         foreach ($task->getVariables() as $name => $value) {
             $variables .= sprintf("%s=%s\n", $name, $value);
         }
     }
     return trim(sprintf('%s%s%s %s %s %s %s       %s %s', $comment, $variables, $task->getMinute(), $task->getHour(), $task->getDayOfMonth(), $task->getMonth(), $task->getDayOfWeek(), $task->getCommand(), $log, " "));
 }