/**
  * @param array|TrackingEvent[] $entities
  */
 protected function processTrackingVisits($entities)
 {
     $em = $this->getEntityManager();
     /** @var  TrackingEvent $event */
     foreach ($entities as $event) {
         $this->logger->info('Processing event - ' . $event->getId());
         $trackingVisitEvent = new TrackingVisitEvent();
         $trackingVisitEvent->setParsingCount(0);
         $trackingVisitEvent->setEvent($this->getEventType($event));
         $eventData = $event->getEventData();
         $decodedData = json_decode($eventData->getData(), true);
         $trackingVisit = $this->getTrackingVisit($event, $decodedData);
         $trackingVisitEvent->setVisit($trackingVisit);
         $trackingVisitEvent->setWebEvent($event);
         $trackingVisitEvent->setWebsite($event->getWebsite());
         $targets = $this->trackingIdentification->processEvent($trackingVisitEvent);
         if (!empty($targets)) {
             foreach ($targets as $target) {
                 $trackingVisitEvent->addAssociationTarget($target);
             }
         }
         $event->setParsed(true);
         $em->persist($event);
         $em->persist($trackingVisitEvent);
         $em->persist($trackingVisit);
     }
     $em->flush();
     $this->updateVisits($this->collectedVisits);
     $this->collectedVisits = [];
     $this->eventDictionary = [];
     $em->clear();
     $this->logger->info(sprintf('<comment>Memory usage (currently) %dMB/ (max) %dMB</comment>', round(memory_get_usage(true) / 1024 / 1024), memory_get_peak_usage(true) / 1024 / 1024));
 }
 /**
  * @dataProvider processEventProvider
  *
  * @param $eventType
  * @param $eventValue
  * @param $repoClass
  * @param $parameters
  * @param $channel
  */
 public function testProcessEvent($eventType, $eventValue, $repoClass, $parameters, $channel)
 {
     $trackingEvent = new TrackingVisitEvent();
     $visit = new TrackingVisit();
     $channel->setChannelType(ChannelType::TYPE);
     $website = new TestTrackingWebsite();
     $website->setChannel($channel);
     $visit->setTrackingWebsite($website);
     $trackingDict = new TrackingEventDictionary();
     $trackingDict->setName($eventType);
     $trackingEvent->setEvent($trackingDict);
     $trackingEvent->setWebsite($website);
     $trackingEvent->setVisit($visit);
     $webEvent = new TrackingEvent();
     $webEvent->setValue($eventValue);
     $trackingEvent->setWebEvent($webEvent);
     $repo = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->once())->method('getRepository')->with($repoClass)->willReturn($repo);
     $repo->expects($this->once())->method('findOneBy')->with($parameters)->willReturn(new \stdClass());
     $this->provider->processEvent($trackingEvent);
 }