/**
  * @param StaticSegment $staticSegment
  *
  * {@inheritdoc}
  */
 protected function createSubordinateIterator($staticSegment)
 {
     $this->assertRequiredDependencies();
     if (!$staticSegment->getExtendedMergeVars()) {
         return new \EmptyIterator();
     }
     $qb = $this->getIteratorQueryBuilder($staticSegment);
     $marketingList = $staticSegment->getMarketingList();
     $memberIdentifier = MarketingListQueryBuilderAdapter::MEMBER_ALIAS . '.id';
     $fieldExpr = $this->fieldHelper->getFieldExpr($marketingList->getEntity(), $qb, $this->doctrineHelper->getSingleEntityIdentifierFieldName($marketingList->getEntity()));
     $qb->addSelect($fieldExpr . ' AS entity_id');
     $qb->addSelect($memberIdentifier . ' AS member_id');
     $qb->andWhere($qb->expr()->andX($qb->expr()->isNotNull($memberIdentifier)));
     $bufferedIterator = new BufferedQueryResultIterator($qb);
     $bufferedIterator->setHydrationMode(AbstractQuery::HYDRATE_ARRAY)->setReverse(true);
     $uniqueMembers =& $this->uniqueMembers;
     return new \CallbackFilterIterator($bufferedIterator, function (&$current) use($staticSegment, &$uniqueMembers) {
         if (is_array($current)) {
             if (!empty($current['member_id']) && in_array($current['member_id'], $uniqueMembers, true)) {
                 return false;
             }
             $current['subscribersList_id'] = $staticSegment->getSubscribersList()->getId();
             $current['static_segment_id'] = $staticSegment->getId();
             $uniqueMembers[] = $current['member_id'];
             unset($current['id']);
         }
         return true;
     });
 }
 public function testGetSyncedExtendedMergeVars()
 {
     $this->assertEmpty($this->entity->getExtendedMergeVars());
     $var1 = new ExtendedMergeVar();
     $var2 = new ExtendedMergeVar();
     $var1->markSynced();
     $var2->markDropped();
     $this->entity->addExtendedMergeVar($var1);
     $this->entity->addExtendedMergeVar($var2);
     $extendedMergeVars = $this->entity->getSyncedExtendedMergeVars();
     $this->assertCount(1, $extendedMergeVars);
     $this->assertContainsOnly($var1, $extendedMergeVars);
 }