/**
  * @test
  */
 public function it_sends_remove_file_command_to_file_remover_via_php_resque()
 {
     $this->assertTrue(file_exists($this->testFile));
     $commandBus = new CommandBus();
     $commandRouter = new CommandRouter();
     $messageDispatcher = new MessageDispatcher(['track_job_status' => true, 'queue' => 'php-resque-test-queue']);
     $commandRouter->route('Prooph\\ServiceBusTest\\Mock\\RemoveFileCommand')->to($messageDispatcher);
     $commandBus->utilize($commandRouter);
     $commandBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new ProophDomainMessageToRemoteMessageTranslator()));
     $jobId = null;
     $messageDispatcher->events()->attach('dispatch.post', function (EventInterface $e) use(&$jobId) {
         $jobId = $e->getParam('jobId');
     });
     $removeFile = RemoveFileCommand::fromPayload($this->testFile);
     $commandBus->dispatch($removeFile);
     $this->assertNotNull($jobId);
     $status = new \Resque_Job_Status($jobId);
     $this->assertEquals(\Resque_Job_Status::STATUS_WAITING, $status->get());
     $worker = new \Resque_Worker(array('php-resque-test-queue'));
     $worker->logLevel = 1;
     $worker->work(0);
     $worker->shutdown();
     $this->assertEquals(\Resque_Job_Status::STATUS_COMPLETE, $status->get());
     $this->assertFalse(file_exists($this->testFile));
 }
 protected function setUp()
 {
     parent::setUp();
     $eventBus = new EventBus();
     $commandBus = new CommandBus();
     $commandRouter = new CommandRouter();
     $commandRouter->route(StartSubProcess::MSG_NAME)->to(function (StartSubProcess $command) {
         $this->receivedMessage = $command;
     });
     $commandRouter->route('processing-message-proophprocessingtestmockuserdictionary-collect-data')->to(function (WorkflowMessage $message) {
         $this->receivedMessage = $message;
     });
     $commandBus->utilize($commandRouter);
     $commandBus->utilize(new ToProcessingMessageTranslator());
     $commandBus->utilize(new CallbackStrategy());
     $eventRouter = new EventRouter();
     $eventRouter->route('processing-message-proophprocessingtestmockuserdictionary-data-collected')->to(function (WorkflowMessage $workflowMessage) {
         $this->receivedMessage = $workflowMessage;
     });
     $eventRouter->route('processing-log-message')->to(function (LogMessage $logMessage) {
         $this->receivedMessage = $logMessage;
     });
     $eventRouter->route(SubProcessFinished::MSG_NAME)->to(function (SubProcessFinished $event) {
         $this->receivedMessage = $event;
     });
     $eventBus->utilize($eventRouter);
     $eventBus->utilize(new ToProcessingMessageTranslator());
     $eventBus->utilize(new CallbackStrategy());
     $this->workflowEngine = new RegistryWorkflowEngine();
     $this->workflowEngine->registerCommandBus($commandBus, [NodeName::defaultName()->toString(), 'test-target', 'sub-processor']);
     $this->workflowEngine->registerEventBus($eventBus, [NodeName::defaultName()->toString()]);
 }
 /**
  * @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());
 }
Пример #4
0
 protected function setUp()
 {
     $commandBus = new CommandBus();
     $commandRouter = new CommandRouter();
     $commandRouter->route(StartSubProcess::MSG_NAME)->to(function ($command) {
         $this->startSubProcessCommands[] = $command;
     });
     $commandBus->utilize($commandRouter);
     $commandBus->utilize(new CallbackStrategy());
     $this->workflowEngine = new RegistryWorkflowEngine();
     $this->workflowEngine->registerCommandBus($commandBus, [NodeName::defaultName()->toString()]);
 }
Пример #5
0
 /**
  * @return WorkflowProcessor
  */
 protected function getOtherMachineWorkflowProcessor()
 {
     if (is_null($this->otherMachineWorkflowProcessor)) {
         $this->otherMachineWorkflowProcessor = new WorkflowProcessor(NodeName::fromString('other_machine'), $this->getOtherMachineEventStore(), $this->getOtherMachineProcessRepository(), $this->otherMachineWorkflowEngine, $this->getTestProcessFactory());
         $this->otherMachineCommandRouter->route(StartSubProcess::MSG_NAME)->to($this->otherMachineWorkflowProcessor);
     }
     return $this->otherMachineWorkflowProcessor;
 }
Пример #6
0
 /**
  * @test
  */
 public function it_creates_process_with_run_sub_process_task_from_definition()
 {
     $subProcessDefinition = ["process_type" => Definition::PROCESS_LINEAR_MESSAGING, "tasks" => [["task_type" => Definition::TASK_COLLECT_DATA, "source" => 'test-case', "processing_type" => 'Prooph\\ProcessingTest\\Mock\\UserDictionary']]];
     $runSubProcessTaskDefinition = ["target_node_name" => 'other_machine', "task_type" => Definition::TASK_RUN_SUB_PROCESS, "process_definition" => $subProcessDefinition];
     $parentProcessDefinition = ["process_type" => Definition::PROCESS_LINEAR_MESSAGING, "tasks" => [$runSubProcessTaskDefinition]];
     $processFactory = new ProcessFactory();
     $parentProcess = $processFactory->createProcessFromDefinition($parentProcessDefinition, NodeName::defaultName());
     /** @var $startSubProcess StartSubProcess */
     $startSubProcess = null;
     $otherMachineCommandBus = new CommandBus();
     $otherMachineCommandRouter = new CommandRouter();
     $otherMachineCommandRouter->route(StartSubProcess::MSG_NAME)->to(function (StartSubProcess $command) use(&$startSubProcess) {
         $startSubProcess = $command;
     });
     $otherMachineCommandBus->utilize($otherMachineCommandRouter);
     $otherMachineCommandBus->utilize(new CallbackStrategy());
     $this->workflowEngine->registerCommandBus($otherMachineCommandBus, ['other_machine']);
     $parentProcess->perform($this->workflowEngine);
     $this->assertNotNull($startSubProcess);
     $this->assertEquals($subProcessDefinition, $startSubProcess->subProcessDefinition());
 }
 /**
  * @test
  */
 public function it_sends_a_start_sub_process_command_via_message_dispatcher_to_a_handler()
 {
     $taskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1);
     $startSupProcess = StartSubProcess::at($taskListPosition, ['process_type' => 'faked'], true, 'sub-processor');
     $commandBus = new CommandBus();
     $commandRouter = new CommandRouter();
     $commandRouter->route(StartSubProcess::MSG_NAME)->to($this->messageDispatcher);
     $commandBus->utilize($commandRouter);
     $commandBus->utilize(new ForwardToRemoteMessageDispatcherStrategy(new FromProcessingMessageTranslator()));
     $commandBus->dispatch($startSupProcess);
     /** @var $receivedMessage StartSubProcess */
     $receivedMessage = $this->receivedMessage;
     $this->assertInstanceOf(get_class($startSupProcess), $receivedMessage);
     $this->assertTrue($taskListPosition->equals($receivedMessage->parentTaskListPosition()));
     $this->assertTrue($startSupProcess->uuid()->equals($receivedMessage->uuid()));
     $this->assertEquals($startSupProcess->payload(), $receivedMessage->payload());
     $this->assertEquals($startSupProcess->createdAt()->format('Y-m-d H:i:s'), $receivedMessage->createdAt()->format('Y-m-d H:i:s'));
     $this->assertEquals($startSupProcess->target(), $receivedMessage->target());
 }