/** * Run test placeRequest method * * @return void */ public function testPlaceRequestSuccess() { $response = $this->getResponseObject(); $this->adapter->expects($this->once())->method('sale')->with($this->getTransferData())->willReturn($response); $this->loggerMock->expects($this->once())->method('debug')->with(['request' => $this->getTransferData(), 'client' => TransactionSale::class, 'response' => ['success' => 1]]); $actualResult = $this->model->placeRequest($this->getTransferObjectMock()); $this->assertTrue(is_object($actualResult['object'])); $this->assertEquals(['object' => $response], $actualResult); }
/** * @param array $expectedRequest * @param array $expectedResponse * @param array $expectedHeaders * * @dataProvider placeRequestDataProvider */ public function testPlaceRequest(array $expectedRequest, array $expectedResponse, array $expectedHeaders) { /** @var TransferInterface|\PHPUnit_Framework_MockObject_MockObject $transferObject */ $transferObject = $this->getMock(TransferInterface::class); $transferObject->expects(static::once())->method('getBody')->willReturn($expectedRequest); $transferObject->expects(static::once())->method('getHeaders')->willReturn($expectedHeaders); $this->clientMock->expects(static::once())->method('generateTxnId')->willReturn(self::TXN_ID); $this->logger->expects(static::once())->method('debug')->with(['request' => $expectedRequest, 'response' => $expectedResponse]); static::assertEquals($expectedResponse, $this->clientMock->placeRequest($transferObject)); }
public function testPostRequestOk() { $configInterfaceMock = $this->getMockBuilder('\\Magento\\Payment\\Model\\Method\\ConfigInterface')->getMockForAbstractClass(); $zendResponseMock = $this->getMockBuilder('\\Zend_Http_Response')->setMethods(['getBody'])->disableOriginalConstructor()->getMock(); $zendResponseMock->expects($this->once())->method('getBody')->willReturn('RESULT=0&RESPMSG=Approved&SECURETOKEN=8ZIaw2&SECURETOKENID=2481d53'); $this->zendClientMock->expects($this->once())->method('request')->willReturn($zendResponseMock); $configMap = [['getDebugReplacePrivateDataKeys', null, ['masked']], ['debug', null, true]]; $configInterfaceMock->expects($this->any())->method('getValue')->will($this->returnValueMap($configMap)); $this->loggerMock->expects($this->once())->method('debug'); $object = new \Magento\Framework\DataObject(); $result = $this->object->postRequest($object, $configInterfaceMock); $this->assertInstanceOf('Magento\\Framework\\DataObject', $result); $this->assertArrayHasKey('result_code', $result->getData()); }
public function testPostRequestOk() { $configMap = [['getDebugReplacePrivateDataKeys', null, ['masked']], ['debug', null, true]]; $expectedResponse = 'RESULT=0&RESPMSG=Approved&SECURETOKEN=8ZIaw2&SECURETOKENID=2481d53'; /** @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::once())->method('getBody')->willReturn($expectedResponse); $this->zendClientMock->expects(static::once())->method('request')->willReturn($zendResponseMock); $configInterfaceMock->expects(static::any())->method('getValue')->willReturnMap($configMap); $this->loggerMock->expects(static::once())->method('debug'); $object = new DataObject(); $result = $this->object->postRequest($object, $configInterfaceMock); static::assertInstanceOf(DataObject::class, $result); static::assertArrayHasKey('result_code', $result->getData()); }
public function testDeleteException() { $exception = new \Braintree_Exception(); $cardToken = 1; $this->braintreeCreditCardMock->expects($this->once())->method('delete')->with($cardToken)->willThrowException($exception); $this->loggerMock->expects($this->once())->method('critical')->with($exception); $return = $this->model->deleteCard($cardToken); $this->assertEquals(false, $return); }
/** * @param string $response * @param array $processableErrors * @param null|string $exception * @param string $exceptionMessage * @param null|int $exceptionCode * @dataProvider callDataProvider */ public function testCall($response, $processableErrors, $exception, $exceptionMessage = '', $exceptionCode = null) { if (isset($exception)) { $this->setExpectedException($exception, $exceptionMessage, $exceptionCode); } $this->curl->expects($this->once())->method('read')->will($this->returnValue($response)); $this->model->setProcessableErrors($processableErrors); $this->customLoggerMock->expects($this->once())->method('debug'); $this->model->call('some method', ['data' => 'some data']); }