/** * @expectedException \Exception */ public function testPostRequestFail() { $configInterfaceMock = $this->getMockBuilder('\\Magento\\Payment\\Model\\Method\\ConfigInterface')->getMockForAbstractClass(); $zendResponseMock = $this->getMockBuilder('\\Zend_Http_Response')->setMethods(['getBody'])->disableOriginalConstructor()->getMock(); $zendResponseMock->expects($this->never())->method('getBody'); $this->zendClientMock->expects($this->once())->method('request')->willThrowException(new \Exception()); $object = new \Magento\Framework\DataObject(); $this->object->postRequest($object, $configInterfaceMock); }
/** * @expectedException \Zend_Http_Client_Exception */ public function testPostRequestFail() { /** @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject $configInterfaceMock */ $configInterfaceMock = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass(); $zendResponseMock = $this->getMockBuilder(\Zend_Http_Response::class)->setMethods(['getBody'])->disableOriginalConstructor()->getMock(); $zendResponseMock->expects(static::never())->method('getBody'); $this->zendClientMock->expects(static::once())->method('request')->willThrowException(new \Zend_Http_Client_Exception()); $object = new DataObject(); $this->object->postRequest($object, $configInterfaceMock); }
/** * {inheritdoc} */ public function postRequest(DataObject $request, ConfigInterface $config) { try { return $this->gateway->postRequest($request, $config); } catch (\Zend_Http_Client_Exception $e) { throw new LocalizedException(__('Payment Gateway is unreachable at the moment. Please use another payment option.'), $e); } }
/** * {inheritdoc} */ public function postRequest(DataObject $request, ConfigInterface $config) { return $this->gateway->postRequest($request, $config); }