/**
  * @param StaticSegment $value
  * @param UniqueStaticSegmentNameConstraint|Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     if ($value instanceof StaticSegment && !$value->getOriginId()) {
         $this->transport->init($value->getChannel()->getTransport());
         $segments = $this->transport->getListStaticSegments($value->getSubscribersList());
         foreach ($segments as $segment) {
             if ($segment['name'] == $value->getName()) {
                 $this->context->addViolationAt('name', $constraint->message);
                 break;
             }
         }
     }
 }
 public function testGetMembersToSync()
 {
     $subscribersListRepository = $this->getMockBuilder('OroCRM\\Bundle\\MailChimpBundle\\Entity\\Repository\\SubscribersListRepository')->disableOriginalConstructor()->getMock();
     $this->managerRegistry->expects($this->once())->method('getRepository')->will($this->returnValue($subscribersListRepository));
     $subscribersList = $this->getMock('OroCRM\\Bundle\\MailChimpBundle\\Entity\\SubscribersList');
     $subscribersLists = new \ArrayIterator([$subscribersList]);
     $subscribersListRepository->expects($this->once())->method('getUsedSubscribersListIterator')->will($this->returnValue($subscribersLists));
     $since = new \DateTime('2015-02-15 21:00:01', new \DateTimeZone('Europe/Kiev'));
     $channel = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel')->disableOriginalConstructor()->getMock();
     $client = $this->initTransport();
     $result = $this->transport->getMembersToSync($channel, $since);
     $this->assertInstanceOf('OroCRM\\Bundle\\MailChimpBundle\\Provider\\Transport\\Iterator\\MemberIterator', $result);
     $this->assertAttributeSame($client, 'client', $result);
     $this->assertAttributeSame($subscribersLists, 'mainIterator', $result);
     $this->assertAttributeEquals(['status' => [Member::STATUS_SUBSCRIBED, Member::STATUS_UNSUBSCRIBED, Member::STATUS_CLEANED], 'since' => '2015-02-15 19:00:00'], 'parameters', $result);
 }