run() публичный Метод

public run ( GrumPHP\Task\Context\ContextInterface $context ) : GrumPHP\Runner\TaskResultInterface
$context GrumPHP\Task\Context\ContextInterface
Результат GrumPHP\Runner\TaskResultInterface
Пример #1
0
 function it_triggers_events_during_error_flow(EventDispatcherInterface $eventDispatcher, TaskInterface $task1, TaskInterface $task2, ContextInterface $context)
 {
     $task1->run($context)->willThrow('GrumPHP\\Exception\\RuntimeException');
     $task2->run($context)->willThrow('GrumPHP\\Exception\\RuntimeException');
     $eventDispatcher->dispatch(RunnerEvents::RUNNER_RUN, Argument::type('GrumPHP\\Event\\RunnerEvent'))->shouldBeCalled();
     $eventDispatcher->dispatch(TaskEvents::TASK_RUN, Argument::type('GrumPHP\\Event\\TaskEvent'))->shouldBeCalled();
     $eventDispatcher->dispatch(TaskEvents::TASK_FAILED, Argument::type('GrumPHP\\Event\\TaskFailedEvent'))->shouldBeCalled();
     $eventDispatcher->dispatch(RunnerEvents::RUNNER_FAILED, Argument::type('GrumPHP\\Event\\RunnerFailedEvent'))->shouldBeCalled();
     $this->shouldThrow('GrumPHP\\Exception\\FailureException')->duringRun($context);
 }
Пример #2
0
 function it_runs_subsequent_tasks_if_one_fails(TaskInterface $task1, TaskInterface $task2, ContextInterface $context)
 {
     $task1->run($context)->willThrow('GrumPHP\\Exception\\RuntimeException');
     $task2->run($context)->shouldBeCalled();
     $this->shouldThrow('GrumPHP\\Exception\\FailureException')->duringRun($context);
 }
Пример #3
0
 function it_triggers_events_during_error_flow(EventDispatcherInterface $eventDispatcher, TaskInterface $task1, TaskInterface $task2, ContextInterface $context)
 {
     $task1->run($context)->willReturn(TaskResult::createFailed($task1->getWrappedObject(), $context->getWrappedObject(), ''));
     $task2->run($context)->willReturn(TaskResult::createFailed($task1->getWrappedObject(), $context->getWrappedObject(), ''));
     $eventDispatcher->dispatch(RunnerEvents::RUNNER_RUN, Argument::type('GrumPHP\\Event\\RunnerEvent'))->shouldBeCalled();
     $eventDispatcher->dispatch(TaskEvents::TASK_RUN, Argument::type('GrumPHP\\Event\\TaskEvent'))->shouldBeCalled();
     $eventDispatcher->dispatch(TaskEvents::TASK_FAILED, Argument::type('GrumPHP\\Event\\TaskFailedEvent'))->shouldBeCalled();
     $eventDispatcher->dispatch(RunnerEvents::RUNNER_FAILED, Argument::type('GrumPHP\\Event\\RunnerFailedEvent'))->shouldBeCalled();
     $this->run($context);
 }
Пример #4
0
 /**
  * @param TaskInterface    $task
  * @param ContextInterface $context
  *
  * @return TaskResultInterface
  * @throws RuntimeException
  */
 private function runTask(TaskInterface $task, ContextInterface $context)
 {
     try {
         $this->eventDispatcher->dispatch(TaskEvents::TASK_RUN, new TaskEvent($task, $context));
         $result = $task->run($context);
     } catch (RuntimeException $e) {
         $result = TaskResult::createFailed($task, $context, $e->getMessage());
     }
     if (!$result instanceof TaskResultInterface) {
         throw RuntimeException::invalidTaskReturnType($task);
     }
     if (!$result->isPassed() && !$this->grumPHP->isBlockingTask($task->getName())) {
         $result = TaskResult::createNonBlockingFailed($result->getTask(), $result->getContext(), $result->getMessage());
     }
     if (!$result->isPassed()) {
         $e = new RuntimeException($result->getMessage());
         $this->eventDispatcher->dispatch(TaskEvents::TASK_FAILED, new TaskFailedEvent($task, $context, $e));
         return $result;
     }
     $this->eventDispatcher->dispatch(TaskEvents::TASK_COMPLETE, new TaskEvent($task, $context));
     return $result;
 }