コード例 #1
0
 public function testPostFlush()
 {
     $serializedData = 'serializedData';
     $processDefinition = new ProcessDefinition();
     $processDefinition->setRelatedEntity(self::TEST_CLASS);
     $processTrigger = new ProcessTrigger();
     $processTrigger->setDefinition($processDefinition);
     $processData = new ProcessData();
     $processData->set('test', 'value');
     $processJob = new ProcessJob();
     $processJob->setProcessTrigger($processTrigger)->setData($processData);
     $unitOfWork = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
     $unitOfWork->expects($this->at(0))->method('getScheduledEntityInsertions')->will($this->returnValue(array($processJob)));
     $unitOfWork->expects($this->at(1))->method('getScheduledEntityUpdates')->will($this->returnValue(array($processJob)));
     $entityId = 1;
     $entityHash = ProcessJob::generateEntityHash(self::TEST_CLASS, $entityId);
     $this->serializer->expects($this->exactly(2))->method('serialize')->with($processJob->getData(), 'json', array('processJob' => $processJob))->will($this->returnCallback(function () use($processJob, $entityId, $serializedData) {
         $processJob->setEntityId($entityId);
         return $serializedData;
     }));
     $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $entityManager->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($unitOfWork));
     $entityManager->expects($this->once())->method('flush');
     $this->listener->onFlush(new OnFlushEventArgs($entityManager));
     $this->listener->postFlush(new PostFlushEventArgs($entityManager));
     $this->assertEquals($serializedData, $processJob->getSerializedData());
     $this->assertEquals($entityId, $processJob->getEntityId());
     $this->assertEquals($entityHash, $processJob->getEntityHash());
     $this->assertFalse($processJob->getData()->isModified());
 }
コード例 #2
0
 /**
  * Schedules EmailBody for processing.
  *
  * @param EmailBody $emailBody
  */
 protected function scheduleProcess(EmailBody $emailBody)
 {
     /*
      * Retrieve all process definitions to trigger
      */
     $definitions = $this->processStorage->getService()->getProcessDefinitionNames();
     $definitions = $this->getDefinitionRepository()->findBy(['name' => $definitions]);
     /*
      * Trigger process definitions with provided data
      */
     foreach ($definitions as $definition) {
         $trigger = new ProcessTrigger();
         $trigger->setDefinition($definition);
         $data = new ProcessData();
         $data->set('data', $emailBody);
         $this->handler->handleTrigger($trigger, $data);
     }
 }
コード例 #3
0
 /**
  * Schedules EmailBody for processing.
  *
  * @param EmailBody $emailBody
  */
 protected function scheduleProcess(EmailBody $emailBody)
 {
     /*
      * Retrieve all process definitions to trigger
      */
     $definitions = $this->processStorage->getService()->getProcessDefinitionNames();
     $definitions = $this->getDefinitionRepository()->findBy(['name' => $definitions]);
     /*
      * Trigger process definitions with provided data
      */
     foreach ($definitions as $definition) {
         $trigger = new ProcessTrigger();
         //id must be unique otherwise in cache will be saved and runned first definition with id = null
         $trigger->setId($definition->getName());
         $trigger->setDefinition($definition);
         $data = new ProcessData();
         $data->set('data', $emailBody);
         $this->handler->handleTrigger($trigger, $data);
     }
 }
コード例 #4
0
 /**
  * @param ProcessData $object
  * @param array $context
  * @dataProvider normalizeDataProvider
  */
 public function testNormalize($object, array $context)
 {
     $entity = $object['data'];
     $entityId = 1;
     $format = 'json';
     /** @var ProcessJob $processJob */
     $processJob = $context['processJob'];
     $triggerEvent = $processJob->getProcessTrigger()->getEvent();
     $normalizedData = array('serialized', 'data');
     if ($triggerEvent == ProcessTrigger::EVENT_DELETE) {
         $this->doctrineHelper->expects($this->never())->method('getSingleEntityIdentifier');
     } else {
         $this->doctrineHelper->expects($this->once())->method('getSingleEntityIdentifier')->with($entity)->will($this->returnValue($entityId));
     }
     $this->serializer->expects($this->once())->method('normalize')->with($object->getValues(), $format, $context)->will($this->returnValue($normalizedData));
     $this->assertEquals($normalizedData, $this->normalizer->normalize($object, $format, $context));
     if ($triggerEvent == ProcessTrigger::EVENT_DELETE) {
         $this->assertNull($processJob->getEntityId());
     } else {
         $this->assertEquals($entityId, $processJob->getEntityId());
     }
 }
コード例 #5
0
 /**
  * @param ProcessTrigger $trigger
  * @param object $entity
  * @param mixed|null $old
  * @param mixed|null $new
  */
 protected function scheduleProcess(ProcessTrigger $trigger, $entity, $old = null, $new = null)
 {
     $entityClass = ClassUtils::getClass($entity);
     // important to set modified flag to true
     $data = new ProcessData();
     $data->set('data', $entity);
     if ($old || $new) {
         $data->set('old', $old)->set('new', $new);
     }
     if (!$this->schedulePolicy->isScheduleAllowed($trigger, $data)) {
         $this->logger->debug('Policy declined process scheduling', $trigger, $data);
         return;
     }
     $this->scheduledProcesses[$entityClass][] = array('trigger' => $trigger, 'data' => $data);
 }
コード例 #6
0
 /**
  * @param array $data
  * @param bool $modified
  * @return ProcessData
  */
 protected function createProcessData(array $data, $modified = true)
 {
     $processData = new ProcessData($data);
     $processData->setModified($modified);
     return $processData;
 }
コード例 #7
0
 /**
  * @param integer $count
  * @return array
  */
 protected function createProcessJobs($count)
 {
     $definition = $this->entityManager->find('OroWorkflowBundle:ProcessDefinition', LoadProcessEntities::FIRST_DEFINITION);
     $trigger = $this->entityManager->getRepository('OroWorkflowBundle:ProcessTrigger')->findOneBy(['definition' => $definition]);
     $entity = $this->getUser();
     $entityHashes = [];
     for ($i = 0; $i < $count; $i++) {
         $processData = new ProcessData();
         $processData->set('data', $entity);
         $job = new ProcessJob();
         $job->setProcessTrigger($trigger)->setEntityId($i)->setData($processData);
         $this->entityManager->persist($job);
         $entityHashes[] = $job->getEntityHash();
     }
     $this->entityManager->flush();
     return $entityHashes;
 }