public function testSendNotificationsAzineNotifierService_NoNotifications()
 {
     $failedAddresses = array();
     $recipientIds = array(11, 12, 13, 14);
     $mocks = $this->getMockSetup();
     $this->mockRecipients($mocks['recipientProvider'], $recipientIds);
     $mocks['mailer']->expects($this->never())->method("sendSingleEmail")->will($this->returnCallback(array($this, 'sendSingleEmailCallBack')));
     $notificationsQueryBuilderMock = $this->getMockBuilder("Doctrine\\ORM\\QueryBuilder")->disableOriginalConstructor()->getMock();
     $notificationsQueryBuilderMock->expects($this->exactly(4))->method("getQuery")->will($this->returnValue(new AzineQueryMock(array())));
     $notificationsQueryBuilderMock->expects($this->any())->method("from")->will($this->returnSelf());
     $notificationsQueryBuilderMock->expects($this->any())->method("andWhere")->will($this->returnSelf());
     $notificationsQueryBuilderMock->expects($this->any())->method("setParameter")->will($this->returnSelf());
     $notificationsQueryBuilderMock->expects($this->any())->method("orderBy")->will($this->returnSelf());
     $notificationsRecipientQueryBuilderMock = $this->getMockBuilder("Doctrine\\ORM\\QueryBuilder")->disableOriginalConstructor()->getMock();
     $recipientQueryResult = array(array('recipient_id' => 11), array('recipient_id' => 12), array('recipient_id' => 13), array('recipient_id' => 14));
     $notificationsRecipientQueryBuilderMock->expects($this->once())->method("getQuery")->will($this->returnValue(new AzineQueryMock($recipientQueryResult)));
     $notificationsRecipientQueryBuilderMock->expects($this->any())->method("from")->will($this->returnSelf());
     $notificationsRecipientQueryBuilderMock->expects($this->any())->method("andWhere")->will($this->returnSelf());
     $notificationsRecipientQueryBuilderMock->expects($this->any())->method("distinct")->will($this->returnSelf());
     $maxSentQueryBuilderMock = $this->getMockBuilder("Doctrine\\ORM\\QueryBuilder")->disableOriginalConstructor()->getMock();
     $maxSentQueryResult = array(array(1 => "@0"));
     $maxSentQueryBuilderMock->expects($this->exactly(4))->method("getQuery")->will($this->returnValue(new AzineQueryMock($maxSentQueryResult)));
     $maxSentQueryBuilderMock->expects($this->any())->method("from")->will($this->returnSelf());
     $maxSentQueryBuilderMock->expects($this->any())->method("andWhere")->will($this->returnSelf());
     $maxSentQueryBuilderMock->expects($this->any())->method("setParameter")->will($this->returnSelf());
     $queryBuilderMock = $this->getMockBuilder("Doctrine\\ORM\\QueryBuilder")->disableOriginalConstructor()->getMock();
     $queryBuilderMock->expects($this->any())->method("select")->will($this->returnValueMap(array(array("max(n.sent)", $maxSentQueryBuilderMock), array("n.recipient_id", $notificationsRecipientQueryBuilderMock), array("n", $notificationsQueryBuilderMock))));
     $mocks['entityManager']->expects($this->exactly(9))->method("createQueryBuilder")->will($this->returnValue($queryBuilderMock));
     $mocks['logger']->expects($this->never())->method("warning");
     $mocks['logger']->expects($this->never())->method("error");
     // see sendSingleEmailCallBack, one mail-address fails
     $notifier = new AzineNotifierService($mocks['mailer'], $mocks['twig'], $mocks['logger'], $mocks['router'], $mocks['entityManager'], $mocks['templateProvider'], $mocks['recipientProvider'], $mocks['translator'], $mocks['parameters']);
     $sentMails = $notifier->sendNotifications($failedAddresses);
     $this->assertEquals(0, sizeof($failedAddresses), "Email-addresses failed unexpectedly:" . print_r($failedAddresses, true));
     $this->assertEquals(4, $sentMails, "Not the expected number of sent emails.");
 }
 /**
  * (non-PHPdoc)
  * @see Azine\EmailBundle\Services.AzineNotifierService::getRecipientSpecificNewsletterSubject()
  */
 public function getRecipientSpecificNewsletterSubject(array $generalContentItems, array $recipientContentItems, array $params, RecipientInterface $recipient, $locale)
 {
     return parent::getRecipientSpecificNewsletterSubject($generalContentItems, $recipientContentItems, $params, $recipient, $locale);
 }
 public function testSendNotificationsAzineNotifierService_NoNotifications()
 {
     $failedAddresses = array();
     $recipientIds = array(11, 12, 13, 14);
     $mocks = $this->getMockSetup();
     $this->mockRecipients($mocks['recipientProvider'], $recipientIds);
     $mocks['mailer']->expects($this->never())->method("sendSingleEmail")->will($this->returnCallback(array($this, 'sendSingleEmailCallBack')));
     $mocks['notificationRepository']->expects($this->once())->method('getNotificationRecipientIds')->will($this->returnValue($recipientIds));
     $mocks['notificationRepository']->expects($this->exactly(4))->method('getNotificationsToSend')->will($this->returnValue(array()));
     $mocks['notificationRepository']->expects($this->never())->method('getNotificationsToSendImmediately');
     $mocks['notificationRepository']->expects($this->never())->method('markAllNotificationsAsSentFarInThePast');
     $mocks['notificationRepository']->expects($this->exactly(4))->method('getLastNotificationDate')->will($this->returnValue(new \DateTime("@0")));
     $notifier = new AzineNotifierService($mocks['mailer'], $mocks['twig'], $mocks['router'], $mocks['managerRegistry'], $mocks['templateProvider'], $mocks['recipientProvider'], $mocks['translator'], $mocks['parameters']);
     $sentMails = $notifier->sendNotifications($failedAddresses);
     $this->assertEquals(0, sizeof($failedAddresses), "Email-addresses failed unexpectedly:" . print_r($failedAddresses, true));
     $this->assertEquals(4, $sentMails, "Not the expected number of sent emails.");
 }