function it_has_failed_if_it_contains_failed_task_result(TaskInterface $task, ContextInterface $context)
 {
     $aTask = $task->getWrappedObject();
     $aContext = $context->getWrappedObject();
     $this->add(TaskResult::createPassed($aTask, $aContext));
     $this->add(TaskResult::createNonBlockingFailed($aTask, $aContext, 'non blocking'));
     $this->isFailed()->shouldReturn(false);
     $this->add(TaskResult::createFailed($aTask, $aContext, 'failed message'));
     $this->isFailed()->shouldReturn(true);
 }
Beispiel #2
0
 function it_should_filter_by_context(TaskInterface $task1, TaskInterface $task2, ContextInterface $context)
 {
     $task1->canRunInContext($context)->willReturn(true);
     $task2->canRunInContext($context)->willReturn(false);
     $result = $this->filterByContext($context);
     $result->shouldBeAnInstanceOf('GrumPHP\\Collection\\TasksCollection');
     $result->count()->shouldBe(1);
     $tasks = $result->toArray();
     $tasks[0]->shouldBe($task1);
 }
 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);
 }
Beispiel #4
0
 function it_should_display_warning_of_non_blocking_failed_tasks(OutputInterface $output, TaskRunner $taskRunner, TaskInterface $task, ContextInterface $context)
 {
     $aTask = $task->getWrappedObject();
     $aContext = $context->getWrappedObject();
     $nonBlockingFailedTaskResult = TaskResult::createNonBlockingFailed($aTask, $aContext, 'non blocking task message');
     $taskResults = new TaskResultCollection();
     $taskResults->add($nonBlockingFailedTaskResult);
     $taskRunner->run($context)->willReturn($taskResults);
     $output->isDecorated()->willReturn(false);
     $output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_NORMAL);
     $output->writeln(Argument::containingString('non blocking task message'))->shouldBeCalled();
     $output->writeln(Argument::any())->shouldBeCalled();
     $this->run($output, $context);
 }
 function it_should_sort_on_priority(TaskInterface $task1, TaskInterface $task2, TaskInterface $task3, GrumPHP $grumPHP)
 {
     $this->beConstructedWith(array($task1, $task2, $task3));
     $task1->getName()->willReturn('task1');
     $task2->getName()->willReturn('task2');
     $task3->getName()->willReturn('task3');
     $grumPHP->getTaskMetadata('task1')->willReturn(array('priority' => 100));
     $grumPHP->getTaskMetadata('task2')->willReturn(array('priority' => 200));
     $grumPHP->getTaskMetadata('task3')->willReturn(array('priority' => 100));
     $result = $this->sortByPriority($grumPHP);
     $result->shouldBeAnInstanceOf('GrumPHP\\Collection\\TasksCollection');
     $result->count()->shouldBe(3);
     $tasks = $result->toArray();
     $tasks[0]->shouldBe($task2);
     $tasks[1]->shouldBe($task1);
     $tasks[2]->shouldBe($task3);
 }
Beispiel #6
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);
 }
Beispiel #7
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);
 }
Beispiel #8
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;
 }
Beispiel #9
0
 /**
  * @param TaskInterface $task
  *
  * @return RuntimeException
  */
 public static function invalidTaskReturnType(TaskInterface $task)
 {
     return new self(sprintf('The %s task did not return a TaskResult.', $task->getName()));
 }