PaymentReviewStatusHandlerTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\AuthorizenetAcceptjs\Test\Unit\Gateway\Response;
  8. use Magento\AuthorizenetAcceptjs\Gateway\Response\PaymentReviewStatusHandler;
  9. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  10. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  11. use Magento\Payment\Model\InfoInterface;
  12. use Magento\Sales\Model\Order\Payment;
  13. use PHPUnit\Framework\MockObject\MockObject;
  14. use PHPUnit\Framework\TestCase;
  15. class PaymentReviewStatusHandlerTest extends TestCase
  16. {
  17. /**
  18. * @var PaymentReviewStatusHandler
  19. */
  20. private $handler;
  21. /**
  22. * @var InfoInterface|MockObject
  23. */
  24. private $paymentMock;
  25. /**
  26. * @var PaymentDataObjectInterface|MockObject
  27. */
  28. private $paymentDOMock;
  29. protected function setUp()
  30. {
  31. $this->paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
  32. $this->paymentMock = $this->createMock(Payment::class);
  33. $this->paymentDOMock->method('getPayment')
  34. ->willReturn($this->paymentMock);
  35. $this->handler = new PaymentReviewStatusHandler(new SubjectReader());
  36. }
  37. public function testApprovesPayment()
  38. {
  39. $subject = [
  40. 'payment' => $this->paymentDOMock
  41. ];
  42. $response = [
  43. 'transaction' => [
  44. 'transactionStatus' => 'approvedOrSomething',
  45. ]
  46. ];
  47. // Assert payment is handled correctly
  48. $this->paymentMock->expects($this->exactly(2))
  49. ->method('setData')
  50. ->withConsecutive(
  51. ['is_transaction_denied', false],
  52. ['is_transaction_approved', true]
  53. );
  54. $this->handler->handle($subject, $response);
  55. // Assertions are via mock expects above
  56. }
  57. /**
  58. * @param string $status
  59. * @dataProvider declinedTransactionStatusesProvider
  60. */
  61. public function testDeniesPayment(string $status)
  62. {
  63. $subject = [
  64. 'payment' => $this->paymentDOMock
  65. ];
  66. $response = [
  67. 'transaction' => [
  68. 'transactionStatus' => $status,
  69. ]
  70. ];
  71. // Assert payment is handled correctly
  72. $this->paymentMock->expects($this->exactly(2))
  73. ->method('setData')
  74. ->withConsecutive(
  75. ['is_transaction_denied', true],
  76. ['is_transaction_approved', false]
  77. );
  78. $this->handler->handle($subject, $response);
  79. }
  80. /**
  81. * @param string $status
  82. * @dataProvider pendingTransactionStatusesProvider
  83. */
  84. public function testDoesNothingWhenPending(string $status)
  85. {
  86. $subject = [
  87. 'payment' => $this->paymentDOMock
  88. ];
  89. $response = [
  90. 'transaction' => [
  91. 'transactionStatus' => $status,
  92. ]
  93. ];
  94. // Assert payment is handled correctly
  95. $this->paymentMock->expects($this->never())
  96. ->method('setData');
  97. $this->handler->handle($subject, $response);
  98. }
  99. public function pendingTransactionStatusesProvider()
  100. {
  101. return [
  102. ['FDSPendingReview'],
  103. ['FDSAuthorizedPendingReview']
  104. ];
  105. }
  106. public function declinedTransactionStatusesProvider()
  107. {
  108. return [
  109. ['void'],
  110. ['declined']
  111. ];
  112. }
  113. }