FetchTransactionInfoCommandTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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\Command;
  8. use Magento\AuthorizenetAcceptjs\Gateway\Command\FetchTransactionInfoCommand;
  9. use Magento\AuthorizenetAcceptjs\Gateway\Config;
  10. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  11. use Magento\Payment\Gateway\Command\CommandPoolInterface;
  12. use Magento\Payment\Gateway\Command\ResultInterface;
  13. use Magento\Payment\Gateway\CommandInterface;
  14. use Magento\Payment\Gateway\Data\PaymentDataObject;
  15. use Magento\Payment\Gateway\Response\HandlerInterface;
  16. use Magento\Sales\Model\Order;
  17. use Magento\Sales\Model\Order\Payment;
  18. use PHPUnit\Framework\MockObject\MockObject;
  19. use PHPUnit\Framework\TestCase;
  20. class FetchTransactionInfoCommandTest extends TestCase
  21. {
  22. /**
  23. * @var CommandInterface|MockObject
  24. */
  25. private $transactionDetailsCommandMock;
  26. /**
  27. * @var CommandPoolInterface|MockObject
  28. */
  29. private $commandPoolMock;
  30. /**
  31. * @var FetchTransactionInfoCommand
  32. */
  33. private $command;
  34. /**
  35. * @var ResultInterface|MockObject
  36. */
  37. private $transactionResultMock;
  38. /**
  39. * @var PaymentDataObject|MockObject
  40. */
  41. private $paymentDOMock;
  42. /**
  43. * @var Payment|MockObject
  44. */
  45. private $paymentMock;
  46. /**
  47. * @var Config
  48. */
  49. private $configMock;
  50. /**
  51. * @var HandlerInterface
  52. */
  53. private $handlerMock;
  54. protected function setUp()
  55. {
  56. $this->paymentDOMock = $this->createMock(PaymentDataObject::class);
  57. $this->paymentMock = $this->createMock(Payment::class);
  58. $this->paymentDOMock->method('getPayment')
  59. ->willReturn($this->paymentMock);
  60. $this->configMock = $this->createMock(Config::class);
  61. $this->configMock->method('getTransactionInfoSyncKeys')
  62. ->willReturn(['foo', 'bar']);
  63. $orderMock = $this->createMock(Order::class);
  64. $this->paymentDOMock->method('getOrder')
  65. ->willReturn($orderMock);
  66. $this->transactionDetailsCommandMock = $this->createMock(CommandInterface::class);
  67. $this->transactionResultMock = $this->createMock(ResultInterface::class);
  68. $this->commandPoolMock = $this->createMock(CommandPoolInterface::class);
  69. $this->handlerMock = $this->createMock(HandlerInterface::class);
  70. $this->command = new FetchTransactionInfoCommand(
  71. $this->commandPoolMock,
  72. new SubjectReader(),
  73. $this->configMock,
  74. $this->handlerMock
  75. );
  76. }
  77. public function testCommandWillMarkTransactionAsApprovedWhenNotVoid()
  78. {
  79. $response = [
  80. 'transaction' => [
  81. 'transactionStatus' => 'authorizedPendingCapture',
  82. 'foo' => 'abc',
  83. 'bar' => 'cba',
  84. 'dontreturnme' => 'justdont'
  85. ]
  86. ];
  87. $this->commandPoolMock->method('get')
  88. ->willReturnMap([
  89. ['get_transaction_details', $this->transactionDetailsCommandMock],
  90. ]);
  91. $this->transactionResultMock->method('get')
  92. ->willReturn($response);
  93. $buildSubject = [
  94. 'payment' => $this->paymentDOMock
  95. ];
  96. $this->transactionDetailsCommandMock->expects($this->once())
  97. ->method('execute')
  98. ->with($buildSubject)
  99. ->willReturn($this->transactionResultMock);
  100. $this->handlerMock->expects($this->once())
  101. ->method('handle')
  102. ->with($buildSubject, $response)
  103. ->willReturn($this->transactionResultMock);
  104. $result = $this->command->execute($buildSubject);
  105. $expected = [
  106. 'foo' => 'abc',
  107. 'bar' => 'cba'
  108. ];
  109. $this->assertSame($expected, $result);
  110. }
  111. }