Example #1
0
 /**
  * {@inheritdoc}
  */
 public function notify(NotificationInterface $notification)
 {
     $failedSms = [];
     $tos = $notification->getTo();
     if (empty($tos)) {
         throw new NotificationFailedException('No recipients specified');
     }
     foreach ($tos as $to) {
         $skebbySms = SkebbySms::create()->addRecipient($to)->setText($notification->getContent());
         $result = new Result('skebby', $this->name, Result::OK);
         try {
             $response = $this->skebby->send($skebbySms)[0];
             $result->setResponse($response);
             if (!$response->isSuccessful()) {
                 $result->setResult(Result::FAIL);
                 $failedSms[] = ['to' => $to, 'error_message' => $response->getErrorMessage()];
             }
         } catch (\Exception $e) {
             $result->setResult(Result::FAIL)->setResponse($e);
             $failedSms[] = ['to' => $to, 'error_message' => $e->getMessage()];
         }
         $notification->addResult($result);
     }
     if (count($tos) === count($failedSms)) {
         throw new NotificationFailedException('All the sms failed to be send', ['failed_sms' => $failedSms]);
     }
 }
Example #2
0
 /**
  * @dataProvider right
  *
  * @expectedException \Fazland\Notifire\Exception\NotificationFailedException
  *
  * @param Sms $sms
  */
 public function testNotifyShouldCallSkebbySendReceiveFailingResponseAndThrowNotificationFailedException(Sms $sms)
 {
     $skebbySms = SkebbySms::create()->setRecipients($sms->getTo())->setText($sms->getContent());
     $response = new Response(self::RESPONSE_FAIL);
     $this->skebby->send($skebbySms)->shouldBeCalled();
     $this->skebby->send($skebbySms)->willReturn([$response]);
     $this->handler->notify($sms);
     /** @var Result $result */
     foreach ($sms->getResultSet()->all() as $result) {
         $this->assertTrue(Result::FAIL === $result->getResult());
     }
 }