function it_is_not_allowing_to_remove_not_managed_task(Task $task) { $task->isNotManaged()->willReturn(true); $task->getName()->willReturn("Some Name"); $this->getNotManagedTasks()->shouldHaveCount(0); $this->addTask($task); $this->getNotManagedTasks()->shouldHaveCount(1); $this->shouldThrow(new NotManagedException("This task is not managed by this application so you cannot remove it!"))->duringRemoveTask($task); }
/** * @param Task $task * * @return $this * @throws NotManagedException */ public function removeTask(Task $task) { if ($task->isNotManaged()) { throw new NotManagedException('This task is not managed by this application so you cannot remove it!'); } foreach ($this->managedTasks as $key => $taskIteration) { if ($taskIteration->getName() === $task->getName()) { unset($this->managedTasks[$key]); } } return $this; }
/** * @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, " ")); }