protected function setUp() { parent::setUp(); $this->eventDispatcher = new EventDispatcher(); $this->conn = static::createConnection('bpm_', $this->eventDispatcher); static::migrateDirectoryUp($this->conn, __DIR__ . '/../../migration'); $logger = NULL; if (NULL !== ($logLevel = $this->getLogLevel())) { $stderr = fopen('php://stderr', 'wb'); $levels = array_change_key_case(Logger::getLevels(), CASE_UPPER); $logger = new Logger('BPMN'); $logger->pushHandler(new StreamHandler($stderr, $levels[strtoupper($logLevel)])); $logger->pushProcessor(new PsrLogMessageProcessor()); fwrite($stderr, "\n"); fwrite($stderr, sprintf("TEST CASE: %s\n", $this->getName())); // $this->conn$conn->setDebug(true); // $this->conn->setLogger($logger); } $this->messageHandlers = []; $this->serviceTaskHandlers = []; // Provide message handler subscriptions. $this->eventDispatcher->connect(function (MessageThrownEvent $event) { $def = $this->repositoryService->createProcessDefinitionQuery()->processDefinitionId($event->execution->getProcessDefinitionId())->findOne(); $key = $def->getKey(); $id = $event->execution->getActivityId(); if (isset($this->messageHandlers[$key][$id])) { return $this->messageHandlers[$key][$id]($event); } }); $this->eventDispatcher->connect(function (TaskExecutedEvent $event) { $execution = $this->runtimeService->createExecutionQuery()->executionId($event->execution->getExecutionId())->findOne(); $key = $execution->getProcessDefinition()->getKey(); $id = $event->execution->getActivityId(); if (isset($this->serviceTaskHandlers[$key][$id])) { $this->serviceTaskHandlers[$key][$id]($event->execution); } }); // Allow for assertions in expressions, e.g. #{ @test.assertEquals(2, processVariable) } $this->eventDispatcher->connect(function (CreateExpressionContextEvent $event) { $event->access->setVariable('@test', $this); }); $this->delegateTasks = new DelegateTaskRegistry(); $this->processEngine = new ProcessEngine($this->conn, $this->eventDispatcher, new ExpressionContextFactory()); $this->processEngine->setDelegateTaskFactory($this->delegateTasks); $this->processEngine->setLogger($logger); $scheduler = new TestJobScheduler($this->processEngine); $this->jobExecutor = new JobExecutor($this->processEngine, $scheduler); $this->processEngine->setJobExecutor($this->jobExecutor); $this->repositoryService = $this->processEngine->getRepositoryService(); $this->runtimeService = $this->processEngine->getRuntimeService(); $this->taskService = $this->processEngine->getTaskService(); $this->historyService = $this->processEngine->getHistoryService(); $this->managementService = $this->processEngine->getManagementService(); if ($this->typeInfo === NULL) { $this->typeInfo = new ReflectionTypeInfo(new \ReflectionClass(get_class($this))); } foreach ($this->typeInfo->getMethods() as $method) { if (!$method->isPublic() || $method->isStatic()) { continue; } foreach ($method->getAnnotations() as $anno) { if ($anno instanceof MessageHandler) { $this->messageHandlers[$anno->processKey][$anno->value] = [$this, $method->getName()]; } if ($anno instanceof ServiceTaskHandler) { $this->serviceTaskHandlers[$anno->processKey][$anno->value] = [$this, $method->getName()]; } } } }