Exemple #1
0
 /**
  * @param array $processDefinition
  * @param NodeName $nodeName
  * @param TaskListPosition|null $parentTaskListPosition
  * @throws \InvalidArgumentException If process definition is incomplete or invalid
  * @return Process
  */
 public function createProcessFromDefinition(array $processDefinition, NodeName $nodeName, TaskListPosition $parentTaskListPosition = null)
 {
     Assertion::keyExists($processDefinition, "process_type");
     Assertion::keyExists($processDefinition, "tasks");
     Assertion::isArray($processDefinition["tasks"]);
     $tasks = [];
     foreach ($processDefinition["tasks"] as $task) {
         Assertion::isArray($task);
         $tasks[] = $this->createTaskFromDefinition($task);
     }
     $processConfig = isset($processDefinition['config']) && is_array($processDefinition['config']) ? $processDefinition['config'] : array();
     switch ($processDefinition["process_type"]) {
         case Definition::PROCESS_LINEAR_MESSAGING:
             return is_null($parentTaskListPosition) ? LinearProcess::setUp($nodeName, $tasks, $processConfig) : LinearProcess::setUpAsSubProcess($parentTaskListPosition, $nodeName, $tasks, $processConfig);
         case Definition::PROCESS_PARALLEL_FOR_EACH:
             return is_null($parentTaskListPosition) ? ForEachProcess::setUp($nodeName, $tasks, $processConfig) : ForEachProcess::setUpAsSubProcess($parentTaskListPosition, $nodeName, $tasks, $processConfig);
         case Definition::PROCESS_PARALLEL_CHUNK:
             return is_null($parentTaskListPosition) ? ChunkProcess::setUp($nodeName, $tasks, $processConfig) : ChunkProcess::setUpAsSubProcess($parentTaskListPosition, $nodeName, $tasks, $processConfig);
         default:
             throw new \InvalidArgumentException(sprintf("Unsupported process_type given: %s", $processDefinition["process_type"]));
     }
 }
 /**
  * @test
  */
 public function it_sets_wf_message_target_to_target_defined_in_the_process_task()
 {
     $task = ProcessData::address('test-target', ['Prooph\\ProcessingTest\\Mock\\TargetUserDictionary']);
     $process = LinearProcess::setUp(NodeName::defaultName(), [$task]);
     $wfm = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', NodeName::defaultName());
     $answer = $wfm->answerWith(UserDictionary::fromNativeValue(['id' => 1, 'name' => 'John Doe', 'address' => ['street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City']]));
     $this->commandRouter->route(MessageNameUtils::getProcessDataCommandName('Prooph\\ProcessingTest\\Mock\\TargetUserDictionary'))->to($this->workflowMessageHandler);
     $process->perform($this->workflowEngine, $answer);
     $receivedMessage = $this->workflowMessageHandler->lastWorkflowMessage();
     $this->assertEquals('test-target', $receivedMessage->target());
 }