/** * @test */ public function it_can_be_converted_to_array_and_back() { $task = CollectData::from('online-shop', UserDictionary::prototype(), ['metadata' => true]); $arrayCopy = $task->getArrayCopy(); $task2 = CollectData::reconstituteFromArray($arrayCopy); $this->assertNotSame($task, $task2); $this->assertTrue($task->equals($task2)); }
/** * @test */ public function it_performs_next_task_after_receiving_answer_for_previous_task() { $task1 = CollectData::from('test-case', UserDictionary::prototype()); $task2 = ProcessData::address('test-target', ['Prooph\\ProcessingTest\\Mock\\UserDictionary']); $process = LinearProcess::setUp(NodeName::defaultName(), [$task1, $task2]); $wfm = WorkflowMessage::collectDataOf(UserDictionary::prototype(), NodeName::defaultName(), 'test-case'); $answer1 = $wfm->answerWith(UserDictionary::fromNativeValue(['id' => 1, 'name' => 'John Doe', 'address' => ['street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City']])); $this->workflowMessageHandler->setNextAnswer($answer1); $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 2); //Fake follow up task execution $processDataMessage = $answer1->prepareDataProcessing($taskListPosition, 'test-handler'); //Remove TaskListPosition again $ref = new \ReflectionClass($processDataMessage); $taskListPositionProp = $ref->getProperty('processTaskListPosition'); $taskListPositionProp->setAccessible(true); $taskListPositionProp->setValue($processDataMessage, null); $this->commandRouter->route($processDataMessage->messageName())->to($this->workflowMessageHandler); $answer2 = $processDataMessage->answerWithDataProcessingCompleted(); $eventBus = new EventBus(); $eventRouter = new EventRouter([$answer1->messageName() => [function (WorkflowMessage $answer) use($process, $answer2) { $this->workflowMessageHandler->setNextAnswer($answer2); $process->receiveMessage($answer, $this->workflowEngine); }], $answer2->messageName() => [function (WorkflowMessage $answer) use($process) { $process->receiveMessage($answer, $this->workflowEngine); }]]); $eventBus->utilize($eventRouter)->utilize(new CallbackStrategy()); $workflowEngine = new RegistryWorkflowEngine(); $workflowEngine->registerEventBus($eventBus, [NodeName::defaultName()->toString()]); $this->workflowMessageHandler->useWorkflowEngine($workflowEngine); $process->perform($this->workflowEngine); $this->assertTrue($process->isFinished()); $this->assertTrue($process->isSuccessfulDone()); }
/** * @param CollectData $collectData * @param TaskListPosition $taskListPosition * @param WorkflowEngine $workflowEngine * @param WorkflowMessage $previousMessage */ protected function performCollectData(CollectData $collectData, TaskListPosition $taskListPosition, WorkflowEngine $workflowEngine, WorkflowMessage $previousMessage = null) { $metadata = $collectData->metadata(); if (!is_null($previousMessage)) { $metadata = ArrayUtils::merge($previousMessage->metadata(), $collectData->metadata()); } $workflowMessage = WorkflowMessage::collectDataOf($collectData->prototype(), $this->taskList->taskListId()->nodeName(), $collectData->source(), $metadata); $workflowMessage->connectToProcessTask($taskListPosition); 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); } }
protected function getTestTaskListEntry() { $processId = ProcessId::generate(); $taskListId = TaskListId::linkWith(NodeName::defaultName(), $processId); $taskListPosition = TaskListPosition::at($taskListId, 1); $task = CollectData::from('test-crm', UserDictionary::prototype()); return TaskListEntry::newEntryAt($taskListPosition, $task); }
/** * @test */ public function it_logs_wrong_message_received_for_task_as_error() { $wfMessage = $this->getTestWorkflowMessage(); $task = CollectData::from('crm', UserDictionary::prototype()); $logMessage = LogMessage::logWrongMessageReceivedFor($task, $wfMessage->processTaskListPosition(), $wfMessage); $this->assertTrue($logMessage->isError()); $this->assertEquals(415, $logMessage->msgCode()); $this->assertEquals($wfMessage->processTaskListPosition()->taskListId()->nodeName()->toString(), $logMessage->origin()); $this->assertTrue($wfMessage->processTaskListPosition()->equals($logMessage->processTaskListPosition())); $this->assertTrue(isset($logMessage->msgParams()['task_class'])); $this->assertTrue(isset($logMessage->msgParams()['task_as_json'])); $this->assertTrue(isset($logMessage->msgParams()['task_list_position'])); $this->assertTrue(isset($logMessage->msgParams()['process_id'])); $this->assertTrue(isset($logMessage->msgParams()['message_name'])); $this->assertEquals(NodeName::defaultName()->toString(), $logMessage->target()); $this->assertEquals($wfMessage->processTaskListPosition()->taskListId()->processId()->toString(), $logMessage->msgParams()['process_id']); $this->assertEquals($wfMessage->processTaskListPosition()->position(), $logMessage->msgParams()['task_list_position']); $this->assertEquals(get_class($task), $logMessage->msgParams()['task_class']); $this->assertEquals(json_encode($task->getArrayCopy()), $logMessage->msgParams()['task_as_json']); $this->assertEquals($wfMessage->messageName(), $logMessage->msgParams()['message_name']); }
/** * @param array $taskDefinition * @return CollectData */ private function createCollectDataTaskFromDefinition(array $taskDefinition) { Assertion::keyExists($taskDefinition, "source"); Assertion::notEmpty($taskDefinition["source"]); Assertion::string($taskDefinition["source"]); Assertion::keyExists($taskDefinition, "processing_type"); Assertion::implementsInterface($taskDefinition["processing_type"], 'Prooph\\Processing\\Type\\Type'); $processingType = $taskDefinition["processing_type"]; $prototype = $processingType::prototype(); $metadata = isset($taskDefinition['metadata']) ? $taskDefinition['metadata'] : array(); return CollectData::from($taskDefinition["source"], $prototype, $metadata); }
/** * @return TaskList */ protected function getTestTaskList() { $task1 = CollectData::from('crm', UserDictionary::prototype()); $task2 = CollectData::from('online-shop', UserDictionary::prototype()); $task3 = CollectData::from('address-book', UserDictionary::prototype()); $processId = ProcessId::generate(); $taskListId = TaskListId::linkWith(NodeName::defaultName(), $processId); return TaskList::scheduleTasks($taskListId, [$task1, $task2, $task3]); }