示例#1
0
文件: Sms.php 项目: LitGroup/sms.php
 /**
  * @inheritDoc
  */
 public function sendMessage(Message $message)
 {
     try {
         $this->gateway->sendMessage($message);
     } catch (GatewayException $e) {
         $this->logGatewayException($e);
         throw new SmsException('Gateway problem has occurred.', $e);
     }
 }
示例#2
0
 /**
  * @test
  */
 public function shouldThrowSmsExceptionIfGatewayProblemOccurred()
 {
     $gatewayException = $this->getMockForGatewayException();
     $this->gateway->expects($this->once())->method('sendMessage')->willThrowException($gatewayException);
     try {
         $this->messageService->sendMessage($this->getMockForMessage());
     } catch (SmsException $e) {
         $this->assertSame($gatewayException, $e->getPrevious(), 'GatewayException must be attached');
         // Check log:
         $logEntry = $this->logger->getAlerts()[0];
         $this->assertSame('Problem with SMS Gateway has occurred.', $logEntry['message']);
         $this->assertSame($gatewayException, $logEntry['context']['exception']);
         return;
     }
     $this->fail('SmsException should be thrown');
 }
示例#3
0
 /**
  * @test
  */
 public function shouldThrowCascadeGatewayExceptionIfAllGatewaysAreInoperable()
 {
     $message = $this->getMockForMessage();
     $exceptionA = $this->getGatewayException();
     $exceptionB = $this->getGatewayException();
     $this->gatewayA->expects($this->once())->method('sendMessage')->with($this->identicalTo($message))->willThrowException($exceptionA);
     $this->gatewayB->expects($this->once())->method('sendMessage')->with($this->identicalTo($message))->willThrowException($exceptionB);
     try {
         $this->cascadeGateway->sendMessage($message);
     } catch (CascadeGatewayException $e) {
         $this->assertCount(2, $this->logger->getWarnings());
         $this->assertCount(2, $e->getCascadeExceptions());
         $this->assertSame([self::GATEWAY_A => $exceptionA, self::GATEWAY_B => $exceptionB], $e->getCascadeExceptions());
         return;
     }
     $this->fail('CascadeGatewayException was not thrown');
 }