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 * @param string $crontabName * * @return string */ private function prepareTaskNameLine(Task $task, $crontabName) { return sprintf("DO NOT MODIFY! This task is managed by Crontab library by Hexmedia %s\n", $this->prepareTaskHash($task->getName(), $crontabName)); }