/** * @param array $iterable * * @dataProvider sendDataProvider */ public function testSendError($iterable, $to) { $segment = new Segment(); $marketingList = new MarketingList(); $marketingList->setSegment($segment); $campaign = new EmailCampaign(); $campaign->setMarketingList($marketingList)->setSenderEmail(reset($to)); $itCount = count($iterable); $this->marketingListProvider->expects($this->once())->method('getMarketingListEntitiesIterator')->will($this->returnValue($iterable)); $manager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($manager)); $manager->expects($this->once())->method('persist')->with($campaign); $manager->expects($this->atLeastOnce())->method('flush'); $manager->expects($this->exactly($itCount))->method('beginTransaction'); $manager->expects($this->exactly($itCount))->method('rollback'); if ($itCount) { $this->contactInformationFieldsProvider->expects($this->exactly($itCount))->method('getQueryContactInformationFields')->with($this->equalTo($segment), $this->isType('object'), $this->equalTo(ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL))->will($this->returnValue($to)); $this->marketingListConnector->expects($this->exactly($itCount))->method('contact')->with($this->equalTo($marketingList), $this->equalTo(self::ENTITY_ID))->will($this->returnCallback(function () { throw new \Exception('Error'); })); $this->logger->expects($this->exactly($itCount))->method('error'); } $this->transport->expects($this->exactly($itCount))->method('send'); $this->transportProvider->expects($this->once())->method('getTransportByName')->will($this->returnValue($this->transport)); $this->sender->setEmailCampaign($campaign); $this->sender->send($campaign); }
/** * @param array $iterable * @param array $to * @param object $type * @dataProvider sendDataProvider */ public function testSendError($iterable, $to, $type) { $segment = new Segment(); $entity = '\\stdClass'; $marketingList = new MarketingList(); $marketingList->setSegment($segment); $marketingList->setType($type); $marketingList->setEntity($entity); $campaign = new EmailCampaign(); $campaign->setMarketingList($marketingList)->setSenderEmail(reset($to)); $itCount = count($iterable); $this->marketingListProvider->expects($this->once())->method('getMarketingListEntitiesIterator')->will($this->returnValue($iterable)); $manager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($manager)); $manager->expects($this->once())->method('persist')->with($campaign); $manager->expects($this->atLeastOnce())->method('flush'); $manager->expects($this->exactly($itCount))->method('beginTransaction'); $manager->expects($this->exactly($itCount))->method('rollback'); $fields = ['email']; $this->assertFieldsCall($fields, $marketingList); if ($itCount) { $this->contactInformationFieldsProvider->expects($this->exactly($itCount))->method('getTypedFieldsValues')->with($this->equalTo($fields), $this->isType('object'))->will($this->returnValue($to)); $this->statisticsConnector->expects($this->exactly($itCount))->method('getStatisticsRecord')->with($this->equalTo($campaign), $this->isInstanceOf('stdClass'))->willThrowException(new \Exception('Error')); $this->logger->expects($this->exactly($itCount))->method('error'); } $this->transport->expects($this->exactly($itCount))->method('send'); $this->transportProvider->expects($this->once())->method('getTransportByName')->will($this->returnValue($this->transport)); $this->sender->setEmailCampaign($campaign); $this->sender->send($campaign); }
/** * @param EmailCampaign $emailCampaign * @return EmailCampaignSender */ public function getSender(EmailCampaign $emailCampaign) { $this->campaignSender->setEmailCampaign($emailCampaign); return $this->campaignSender; }