Esempio n. 1
0
 /**
  * @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_injects_target_handler_to_event_dispatch_when_event_is_a_workflow_message()
 {
     $message = WorkflowMessage::newDataCollected(UserDictionary::fromNativeValue(['id' => 1, 'name' => 'John Doe', 'address' => ['street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City']]), 'test-case', NodeName::defaultName());
     $eventDispatch = new EventDispatch();
     $eventDispatch->setEvent($message);
     $router = new SingleTargetMessageRouter($this->getTestWorkflowProcessor());
     $router->onRouteEvent($eventDispatch);
     $this->assertSame($this->getTestWorkflowProcessor(), $eventDispatch->getEventListeners()[0]);
 }
 /**
  * @test
  */
 public function it_handles_a_process_data_message()
 {
     $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 2);
     $wfMessage = WorkflowMessage::newDataCollected(UserDictionary::fromNativeValue(['id' => 1, 'name' => 'John Doe', 'address' => ['street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City']]), 'test-case', NodeName::defaultName());
     $wfMessage->connectToProcessTask($taskListPosition);
     $wfMessage = $wfMessage->prepareDataProcessing($taskListPosition, 'message-handler');
     $this->workflowMessageHandler->handleWorkflowMessage($wfMessage);
     $this->assertSame($wfMessage, $this->workflowMessageHandler->lastProcessDataMessage());
     $this->assertInstanceOf('Prooph\\Processing\\Message\\LogMessage', $this->lastProcessingMessage);
 }
Esempio n. 4
0
 /**
  * @test
  */
 public function it_returns_start_sub_process_command_including_previous_message()
 {
     $subProcessDefinition = ["process_type" => Definition::PROCESS_LINEAR_MESSAGING, "tasks" => [["task_type" => Definition::TASK_COLLECT_DATA, "source" => 'test-case', "processing_type" => 'Prooph\\ProcessingTest\\Mock\\UserDictionary']]];
     $task = RunSubProcess::setUp(NodeName::defaultName(), $subProcessDefinition);
     $parentTaskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $previousMessage = WorkflowMessage::newDataCollected(UserDictionary::fromNativeValue(['id' => 1, 'name' => 'John Doe', 'address' => ['street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City']]), 'test-case', NodeName::defaultName());
     $startSubProcess = $task->generateStartCommandForSubProcess($parentTaskListPosition, $previousMessage);
     $this->assertTrue($parentTaskListPosition->equals($startSubProcess->parentTaskListPosition()));
     $this->assertEquals($subProcessDefinition, $startSubProcess->subProcessDefinition());
     $this->assertEquals($previousMessage->messageName(), $startSubProcess->previousWorkflowMessage()->messageName());
 }
Esempio n. 5
0
 /**
  * @test
  */
 public function it_collects_information_for_the_sub_process()
 {
     $subProcessDefinition = ["process_type" => Definition::PROCESS_LINEAR_MESSAGING, "tasks" => [["task_type" => Definition::TASK_COLLECT_DATA, "source" => 'test-case', "processing_type" => 'Prooph\\ProcessingTest\\Mock\\UserDictionary']]];
     $previousMessage = WorkflowMessage::newDataCollected(UserDictionary::fromNativeValue(['id' => 1, 'name' => 'John Doe', 'address' => ['street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City']]), 'test-case', 'processor');
     $parentTaskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $command = StartSubProcess::at($parentTaskListPosition, $subProcessDefinition, true, 'sub-processor', $previousMessage);
     $this->assertTrue($parentTaskListPosition->equals($command->parentTaskListPosition()));
     $this->assertTrue($command->syncLogMessages());
     $this->assertEquals($subProcessDefinition, $command->subProcessDefinition());
     $this->assertEquals($previousMessage->messageName(), $command->previousWorkflowMessage()->messageName());
     $this->assertEquals(NodeName::defaultName()->toString(), $command->origin());
     $this->assertEquals('sub-processor', $command->target());
 }
 /**
  * @test
  */
 public function it_invokes_processing_event_on_workflow_message_handler()
 {
     $userData = array('id' => 1, 'name' => 'Alex', 'address' => array('street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City'));
     $user = UserDictionary::fromNativeValue($userData);
     $wfEvent = WorkflowMessage::newDataCollected($user, 'test-case', NodeName::defaultName());
     $eventBus = new EventBus();
     $eventRouter = new EventRouter();
     $eventRouter->route($wfEvent->messageName())->to($this->workflowMessageHandler);
     $eventBus->utilize($eventRouter);
     $eventBus->utilize(new HandleWorkflowMessageInvokeStrategy());
     $eventBus->dispatch($wfEvent);
     $this->assertSame($wfEvent, $this->workflowMessageHandler->lastWorkflowMessage());
 }
Esempio n. 7
0
 /**
  * @return WorkflowMessage
  */
 protected function getUserDataCollectedTestMessage()
 {
     $userData = array('id' => 1, 'name' => 'Alex', 'address' => array('street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City'));
     $user = UserDictionary::fromNativeValue($userData);
     return WorkflowMessage::newDataCollected($user, 'test-case', NodeName::defaultName()->toString());
 }
Esempio n. 8
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());
 }
 /**
  * @test
  */
 public function it_dispatches_a_service_bus_message()
 {
     $wfMessage = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', 'test-target', []);
     $sbMessage = $wfMessage->toServiceBusMessage();
     $this->workflowEngine->dispatch($sbMessage);
     $this->assertInstanceOf(get_class($wfMessage), $this->receivedMessage);
 }
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 /**
  * @test
  */
 public function it_compares_dictionaries_with_identifier_by_identifier_value()
 {
     $user = UserDictionary::fromNativeValue(array('id' => 1, 'name' => 'Alex', 'address' => array('street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City')));
     $sameUserWithChangedName = UserDictionary::fromNativeValue(array('id' => 1, 'name' => 'Alexander', 'address' => array('street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City')));
     $otherUser = UserDictionary::fromNativeValue(array('id' => 2, 'name' => 'Alex', 'address' => array('street' => 'Main Street', 'streetNumber' => 10, 'zip' => '12345', 'city' => 'Test City')));
     $this->assertTrue($user->sameAs($sameUserWithChangedName));
     $this->assertFalse($user->sameAs($otherUser));
 }
Esempio n. 12
0
 /**
  * @return WorkflowMessage
  */
 private function getTestWorkflowMessage()
 {
     $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $wfMessage = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', 'message-handler');
     $wfMessage->connectToProcessTask($taskListPosition);
     return $wfMessage;
 }
 /**
  * @test
  */
 public function it_creates_a_command_bus_that_dispatches_a_message_to_a_workflow_message_handler()
 {
     $env = Environment::setUp(["processing" => ["channels" => ['message_handler_channel' => ['targets' => ["test_command_handler"]]]]]);
     $messageHandler = new TestWorkflowMessageHandler();
     $env->services()->set('test_command_handler', $messageHandler);
     $commandBus = $env->services()->get("processing.command_bus.test_command_handler");
     $message = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', NodeName::defaultName());
     $commandBus->dispatch($message);
     $this->assertSame($message, $messageHandler->lastWorkflowMessage());
 }
Esempio n. 14
0
 /**
  * @test
  */
 public function it_translates_itself_to_service_bus_message_and_back()
 {
     $wfMessage = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', NodeName::defaultName()->toString(), array('metadata' => true));
     $sbMessage = $wfMessage->toServiceBusMessage();
     $this->assertInstanceOf('Prooph\\Common\\Messaging\\RemoteMessage', $sbMessage);
     $copyOfWfMessage = WorkflowMessage::fromServiceBusMessage($sbMessage);
     $this->assertInstanceOf('Prooph\\Processing\\Message\\WorkflowMessage', $copyOfWfMessage);
     $this->assertEquals(MessageNameUtils::MESSAGE_NAME_PREFIX . 'proophprocessingtestmockuserdictionary-collect-data', $copyOfWfMessage->messageName());
     $this->assertNull($copyOfWfMessage->payload()->extractTypeData());
     $this->assertEquals(array('metadata' => true), $copyOfWfMessage->metadata());
     $this->assertEquals(MessageNameUtils::COLLECT_DATA, $copyOfWfMessage->messageType());
     $this->assertEquals('test-case', $copyOfWfMessage->origin());
     $this->assertEquals(NodeName::defaultName()->toString(), $copyOfWfMessage->target());
 }
Esempio n. 15
0
 /**
  * @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]);
 }
Esempio n. 16
0
 /**
  * @test
  */
 public function it_encodes_and_decodes_payload_with_prototype_to_and_from_json()
 {
     $payload = Payload::fromPrototype(UserDictionary::prototype());
     $jsonString = json_encode($payload);
     $jsonDecodedData = json_decode($jsonString, true);
     $decodedPayload = Payload::fromJsonDecodedData($jsonDecodedData);
     $this->assertEquals('Prooph\\ProcessingTest\\Mock\\UserDictionary', $decodedPayload->getTypeClass());
 }