public function testAddTask() { $task = $this->prophesize(TaskInterface::class); $task->getInterval()->willReturn(null); $task->getFirstExecution()->willReturn(new \DateTime()); $execution = $this->prophesize(TaskExecutionInterface::class); $this->eventDispatcher->dispatch(Events::TASK_CREATE, Argument::that(function (TaskEvent $event) use($task) { return $event->getTask() === $task->reveal(); }))->shouldBeCalled(); $this->eventDispatcher->dispatch(Events::TASK_EXECUTION_CREATE, Argument::that(function (TaskExecutionEvent $event) use($task, $execution) { return $event->getTask() === $task->reveal() && $event->getTaskExecution() === $execution->reveal(); }))->shouldBeCalled(); $this->taskRepository->save($task->reveal())->shouldBeCalled(); $this->taskExecutionRepository->findByTask($task)->willReturn([]); $this->taskExecutionRepository->findPending($task)->willReturn(null); $this->taskExecutionRepository->create($task, Argument::type(\DateTime::class))->willReturn($execution); $this->taskExecutionRepository->save($execution->reveal())->shouldBeCalledTimes(1); $this->taskScheduler->addTask($task->reveal()); }
/** * {@inheritdoc} */ public function schedule() { $this->taskScheduler->addTask($this->task); return $this->task; }