/**
  * Register EmailAddress object
  *
  * @param EmailAddress $obj
  * @throws \LogicException
  */
 public function addAddress(EmailAddress $obj)
 {
     $key = strtolower($obj->getEmail());
     if (isset($this->addresses[$key])) {
         throw new \LogicException(sprintf('The email address "%s" already exists in the batch.', $obj->getEmail()));
     }
     $this->addresses[$key] = $obj;
 }
 /**
  * @param object $getOwnerResult
  * @param object $getUserResult
  * @param int    $getToCalls
  *
  * @dataProvider createReplyEmailModelProvider
  */
 public function testCreateReplyAllEmailModel($getOwnerResult, $getUserResult, $getToCalls)
 {
     $this->fromEmailAddress = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailAddress');
     $this->fromCcEmailAddress = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailAddress');
     $this->fromEmailAddress->expects($this->once())->method('getOwner')->willReturn($getOwnerResult);
     $this->helper->expects($this->any())->method('getUser')->willReturn($getUserResult);
     $getUserResult->expects($this->any())->method('getEmails')->willReturn([]);
     $this->email->expects($this->once())->method('getFromEmailAddress')->willReturn($this->fromEmailAddress);
     $this->email->expects($this->any())->method('getId');
     $emailAddress = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailAddress');
     $emailAddress->expects($this->exactly($getToCalls))->method('getEmail')->willReturn(null);
     $emailRecipient = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailRecipient');
     $emailRecipient->expects($this->exactly($getToCalls))->method('getEmailAddress')->willReturn($emailAddress);
     $to = new ArrayCollection();
     $to->add($emailRecipient);
     $this->email->expects($this->exactly($getToCalls))->method('getTo')->willReturn($to);
     $emailCcRecipient = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailRecipient');
     $emailCcRecipient->expects($this->once())->method('getEmailAddress')->willReturn($this->fromCcEmailAddress);
     $cc = new ArrayCollection();
     $cc->add($emailCcRecipient);
     $this->email->expects($this->exactly($getToCalls))->method('getCc')->willReturn($cc);
     $this->helper->expects($this->once())->method('prependWith');
     $this->helper->expects($this->once())->method('getEmailBody');
     $this->activityListProvider->expects($this->once())->method('getTargetEntities')->willReturn([]);
     $result = $this->emailModelBuilder->createReplyAllEmailModel($this->email);
     $this->assertInstanceOf('Oro\\Bundle\\EmailBundle\\Form\\Model\\Email', $result);
 }
 /**
  * Determines whether two email addresses are the same
  *
  * @param EmailAddress|null $address1
  * @param EmailAddress|null $address2
  *
  *@return bool
  */
 protected function areAddressesEqual($address1, $address2)
 {
     if ($address1 === $address2) {
         return true;
     }
     if (null === $address1 || null === $address2) {
         return false;
     }
     return strtolower($address1->getEmail()) === strtolower($address2->getEmail());
 }