/** * @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_command_dispatch_when_command_is_a_workflow_message() { $message = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', NodeName::defaultName()); $commandDispatch = new CommandDispatch(); $commandDispatch->setCommand($message); $router = new SingleTargetMessageRouter($this->getTestWorkflowProcessor()); $router->onRouteCommand($commandDispatch); $this->assertSame($this->getTestWorkflowProcessor(), $commandDispatch->getCommandHandler()); }
/** * @test */ public function it_handles_a_collect_data_message() { $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 2); $wfMessage = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', NodeName::defaultName()); $wfMessage->connectToProcessTask($taskListPosition); $this->workflowMessageHandler->handleWorkflowMessage($wfMessage); $this->assertSame($wfMessage, $this->workflowMessageHandler->lastCollectDataMessage()); $this->assertInstanceOf('Prooph\\Processing\\Message\\LogMessage', $this->lastProcessingMessage); }
/** * @test */ public function it_invokes_processing_command_on_workflow_message_handler() { $wfCommand = WorkflowMessage::collectDataOf(UserDictionary::prototype(), 'test-case', NodeName::defaultName()); $commandBus = new CommandBus(); $commandRouter = new CommandRouter(); $commandRouter->route($wfCommand->messageName())->to($this->workflowMessageHandler); $commandBus->utilize($commandRouter); $commandBus->utilize(new HandleWorkflowMessageInvokeStrategy()); $commandBus->dispatch($wfCommand); $this->assertSame($wfCommand, $this->workflowMessageHandler->lastWorkflowMessage()); }
/** * @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); }
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); }
/** * @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()); }
/** * @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()); }
/** * @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]); }
/** * @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()); }