TransactionDetailsResponseHandlerTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\Config;
  9. use Magento\AuthorizenetAcceptjs\Gateway\Response\TransactionDetailsResponseHandler;
  10. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  11. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  12. use Magento\Payment\Model\InfoInterface;
  13. use Magento\Sales\Model\Order\Payment;
  14. use PHPUnit\Framework\MockObject\MockObject;
  15. use PHPUnit\Framework\TestCase;
  16. class TransactionDetailsResponseHandlerTest extends TestCase
  17. {
  18. /**
  19. * @var TransactionDetailsResponseHandler
  20. */
  21. private $handler;
  22. /**
  23. * @var InfoInterface|MockObject
  24. */
  25. private $paymentMock;
  26. /**
  27. * @var PaymentDataObjectInterface|MockObject
  28. */
  29. private $paymentDOMock;
  30. /**
  31. * @var Config|MockObject
  32. */
  33. private $configMock;
  34. protected function setUp()
  35. {
  36. $this->paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
  37. $this->paymentMock = $this->createMock(Payment::class);
  38. $this->configMock = $this->createMock(Config::class);
  39. $this->paymentDOMock->method('getPayment')
  40. ->willReturn($this->paymentMock);
  41. $this->handler = new TransactionDetailsResponseHandler(new SubjectReader(), $this->configMock);
  42. }
  43. public function testHandle()
  44. {
  45. $subject = [
  46. 'payment' => $this->paymentDOMock,
  47. 'store_id' => 123,
  48. ];
  49. $response = [
  50. 'transactionResponse' => [
  51. 'dontsaveme' => 'dontdoti',
  52. 'abc' => 'foobar',
  53. ]
  54. ];
  55. // Assert the information comes from the right store config
  56. $this->configMock->method('getAdditionalInfoKeys')
  57. ->with(123)
  58. ->willReturn(['abc']);
  59. // Assert the payment has the most recent information always set on it
  60. $this->paymentMock->expects($this->once())
  61. ->method('setAdditionalInformation')
  62. ->with('abc', 'foobar');
  63. // Assert the transaction has the raw details from the transaction
  64. $this->paymentMock->expects($this->once())
  65. ->method('setTransactionAdditionalInfo')
  66. ->with('raw_details_info', ['abc' => 'foobar']);
  67. $this->handler->handle($subject, $response);
  68. // Assertions are via mock expects above
  69. }
  70. }