TransactionIdHandlerTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\TransactionIdHandler;
  9. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  10. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  11. use Magento\Sales\Model\Order\Payment;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use PHPUnit\Framework\TestCase;
  14. class TransactionIdHandlerTest extends TestCase
  15. {
  16. /**
  17. * @var TransactionIdHandler
  18. */
  19. private $builder;
  20. /**
  21. * @var Payment|MockObject
  22. */
  23. private $paymentMock;
  24. /**
  25. * @var Payment|MockObject
  26. */
  27. private $paymentDOMock;
  28. protected function setUp()
  29. {
  30. $this->paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
  31. $this->paymentMock = $this->createMock(Payment::class);
  32. $this->paymentDOMock->method('getPayment')
  33. ->willReturn($this->paymentMock);
  34. $this->builder = new TransactionIdHandler(new SubjectReader());
  35. }
  36. public function testHandleDefaultResponse()
  37. {
  38. $this->paymentMock->method('getParentTransactionId')
  39. ->willReturn(null);
  40. // Assert the id is set
  41. $this->paymentMock->expects($this->once())
  42. ->method('setTransactionId')
  43. ->with('thetransid');
  44. // Assert the id is set in the additional info for later
  45. $this->paymentMock->expects($this->once())
  46. ->method('setTransactionAdditionalInfo')
  47. ->with('real_transaction_id', 'thetransid');
  48. $response = [
  49. 'transactionResponse' => [
  50. 'transId' => 'thetransid',
  51. ]
  52. ];
  53. $subject = [
  54. 'payment' => $this->paymentDOMock
  55. ];
  56. $this->builder->handle($subject, $response);
  57. // Assertions are part of mocking above
  58. }
  59. public function testHandleDifferenceInTransactionId()
  60. {
  61. $this->paymentMock->method('getParentTransactionId')
  62. ->willReturn('somethingElse');
  63. // Assert the id is set
  64. $this->paymentMock->expects($this->once())
  65. ->method('setTransactionId')
  66. ->with('thetransid');
  67. $response = [
  68. 'transactionResponse' => [
  69. 'transId' => 'thetransid',
  70. ]
  71. ];
  72. $subject = [
  73. 'payment' => $this->paymentDOMock
  74. ];
  75. $this->builder->handle($subject, $response);
  76. // Assertions are part of mocking above
  77. }
  78. }