public function testDeviceDetector()
 {
     $testUA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.4.10 Version/8.0.4 Safari/600.4.10';
     $detector = DeviceDetectorFactory::getInstance($testUA);
     $this->assertEquals('Safari', $detector->getClient()['name']);
     $this->assertSame($detector, DeviceDetectorFactory::getInstance($testUA));
     DeviceDetectorFactory::clearInstances();
     $this->assertNotSame($detector, DeviceDetectorFactory::getInstance($testUA));
 }
 /**
  * Identify previous visits
  *
  * @param array $entities
  */
 protected function updateVisits($entities)
 {
     /** @var TrackingVisit $visit */
     foreach ($entities as $visit) {
         $this->logger->info(sprintf('Process visit id: %s, visitorUid: %s', $visit->getId(), $visit->getVisitorUid()));
         $identifier = $visit->getIdentifierTarget();
         if ($identifier) {
             // update tracking event identifiers
             $associationName = ExtendHelper::buildAssociationName(ClassUtils::getClass($identifier), VisitEventAssociationExtension::ASSOCIATION_KIND);
             $qb = $this->getEntityManager()->createQueryBuilder();
             $subSelect = $qb->select('entity.id')->from(self::TRACKING_VISIT_ENTITY, 'entity')->where('entity.visitorUid = :visitorUid')->andWhere('entity.firstActionTime < :maxDate')->andWhere('entity.identifierDetected = false')->andWhere('entity.parsedUID = 0')->andWhere('entity.trackingWebsite  = :website')->setParameter('visitorUid', $visit->getVisitorUid())->setParameter('maxDate', $visit->getFirstActionTime())->setParameter('website', $visit->getTrackingWebsite())->getQuery()->getArrayResult();
             if (!empty($subSelect)) {
                 array_walk($subSelect, function (&$value) {
                     $value = $value['id'];
                 });
                 $this->getEntityManager()->createQueryBuilder()->update(self::TRACKING_VISIT_EVENT_ENTITY, 'event')->set('event.' . $associationName, ':identifier')->where('event.visit in(' . implode(',', $subSelect) . ')')->setParameter('identifier', $identifier)->getQuery()->execute();
             }
             $associationName = ExtendHelper::buildAssociationName(ClassUtils::getClass($identifier), IdentifierEventExtension::ASSOCIATION_KIND);
             $this->getEntityManager()->createQueryBuilder()->update(self::TRACKING_VISIT_ENTITY, 'entity')->set('entity.' . $associationName, ':identifier')->set('entity.identifierDetected', ':detected')->where('entity.visitorUid = :visitorUid')->andWhere('entity.firstActionTime < :maxDate')->andWhere('entity.identifierDetected = false')->andWhere('entity.parsedUID = 0')->andWhere('entity.trackingWebsite  = :website')->setParameter('visitorUid', $visit->getVisitorUid())->setParameter('maxDate', $visit->getFirstActionTime())->setParameter('website', $visit->getTrackingWebsite())->setParameter('identifier', $identifier)->setParameter('detected', true)->getQuery()->execute();
         }
     }
     $this->deviceDetector->clearInstances();
 }