Ejemplo n.º 1
0
 /**
  * @test
  */
 public function it_can_be_converted_to_array_and_back()
 {
     $task = ProcessData::address('online-shop', ['Prooph\\ProcessingTest\\Mock\\UserDictionary', 'Prooph\\ProcessingTest\\Mock\\AddressDictionary'], 'Prooph\\ProcessingTest\\Mock\\AddressDictionary', ['metadata' => true]);
     $taskData = $task->getArrayCopy();
     $this->assertTrue(is_array($taskData));
     $copiedTask = ProcessData::reconstituteFromArray($taskData);
     $this->assertEquals('online-shop', $copiedTask->target());
     $this->assertEquals(['Prooph\\ProcessingTest\\Mock\\UserDictionary', 'Prooph\\ProcessingTest\\Mock\\AddressDictionary'], $copiedTask->allowedTypes());
     $this->assertEquals('Prooph\\ProcessingTest\\Mock\\AddressDictionary', $copiedTask->preferredType());
     $this->assertEquals(['metadata' => true], $copiedTask->metadata());
 }
Ejemplo n.º 2
0
 /**
  * @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());
 }
Ejemplo n.º 3
0
 /**
  * @param ProcessData $processData
  * @param TaskListPosition $taskListPosition
  * @param WorkflowMessage $previousMessage
  * @param WorkflowEngine $workflowEngine
  */
 protected function performProcessData(ProcessData $processData, TaskListPosition $taskListPosition, WorkflowMessage $previousMessage, WorkflowEngine $workflowEngine)
 {
     $workflowMessage = $previousMessage->prepareDataProcessing($taskListPosition, $processData->target(), $processData->metadata());
     if (!in_array($workflowMessage->payload()->getTypeClass(), $processData->allowedTypes())) {
         $workflowMessage->changeProcessingType($processData->preferredType());
     }
     try {
         $workflowEngine->dispatch($workflowMessage);
     } catch (CommandDispatchException $ex) {
         $this->receiveMessage(LogMessage::logException($ex->getPrevious(), $workflowMessage), $workflowEngine);
     } catch (\Exception $ex) {
         $this->receiveMessage(LogMessage::logException($ex, $workflowMessage), $workflowEngine);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param array $taskDefinition
  * @return ProcessData
  */
 private function createProcessDataTaskFromDefinition(array $taskDefinition)
 {
     Assertion::keyExists($taskDefinition, "target");
     Assertion::notEmpty($taskDefinition["target"]);
     Assertion::string($taskDefinition["target"]);
     Assertion::keyExists($taskDefinition, "allowed_types");
     Assertion::isArray($taskDefinition["allowed_types"]);
     Assertion::allString($taskDefinition["allowed_types"]);
     $preferredType = isset($taskDefinition["preferred_type"]) ? $taskDefinition["preferred_type"] : null;
     $metadata = isset($taskDefinition['metadata']) ? $taskDefinition['metadata'] : array();
     return ProcessData::address($taskDefinition["target"], $taskDefinition["allowed_types"], $preferredType, $metadata);
 }