PayflowproTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model;
  7. class PayflowproTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\ObjectManagerInterface
  11. */
  12. protected $_objectManager;
  13. /**
  14. * @var \Magento\Paypal\Model\Payflowpro
  15. */
  16. protected $_model;
  17. /**
  18. * @var \Magento\Framework\HTTP\ZendClient
  19. */
  20. protected $_httpClientMock;
  21. /**
  22. * @var \Magento\Paypal\Model\Payflow\Service\Gateway
  23. */
  24. protected $gatewayMock;
  25. public function setUp()
  26. {
  27. $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  28. $httpClientFactoryMock = $this->getMockBuilder(\Magento\Framework\HTTP\ZendClientFactory::class)
  29. ->setMethods(['create'])
  30. ->disableOriginalConstructor()
  31. ->getMock();
  32. $this->_httpClientMock = $this->getMockBuilder(\Magento\Framework\HTTP\ZendClient::class)->setMethods([])
  33. ->disableOriginalConstructor()->getMock();
  34. $this->_httpClientMock->expects($this->any())->method('setUri')->will($this->returnSelf());
  35. $this->_httpClientMock->expects($this->any())->method('setConfig')->will($this->returnSelf());
  36. $this->_httpClientMock->expects($this->any())->method('setMethod')->will($this->returnSelf());
  37. $this->_httpClientMock->expects($this->any())->method('setParameterPost')->will($this->returnSelf());
  38. $this->_httpClientMock->expects($this->any())->method('setHeaders')->will($this->returnSelf());
  39. $this->_httpClientMock->expects($this->any())->method('setUrlEncodeBody')->will($this->returnSelf());
  40. $httpClientFactoryMock->expects($this->any())->method('create')
  41. ->will($this->returnValue($this->_httpClientMock));
  42. $mathRandomMock = $this->createMock(\Magento\Framework\Math\Random::class);
  43. $loggerMock = $this->createMock(\Magento\Payment\Model\Method\Logger::class);
  44. $this->gatewayMock =$this->_objectManager->create(
  45. \Magento\Paypal\Model\Payflow\Service\Gateway::class,
  46. [
  47. 'httpClientFactory' => $httpClientFactoryMock,
  48. 'mathRandom' => $mathRandomMock,
  49. 'logger' => $loggerMock,
  50. ]
  51. );
  52. $this->_model = $this->_objectManager->create(
  53. \Magento\Paypal\Model\Payflowpro::class,
  54. ['gateway' => $this->gatewayMock]
  55. );
  56. }
  57. /**
  58. * @magentoDataFixture Magento/Sales/_files/order_paid_with_payflowpro.php
  59. */
  60. public function testReviewPaymentNullResponce()
  61. {
  62. /** @var \Magento\Sales\Model\Order $order */
  63. $order = $this->_objectManager->create(\Magento\Sales\Model\Order::class);
  64. $order->loadByIncrementId('100000001');
  65. $this->_httpClientMock->expects($this->any())->method('request')
  66. ->will($this->returnValue(new \Magento\Framework\DataObject(['body' => 'RESULTval=12&val2=34'])));
  67. $expectedResult = ['resultval' => '12', 'val2' => '34', 'result_code' => null];
  68. $this->assertEquals($expectedResult, $this->_model->acceptPayment($order->getPayment()));
  69. }
  70. }