/** * @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'); }
/** * @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'); }