AcceptPaymentStrategyCommandTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\AcceptPaymentStrategyCommand;
  9. use Magento\AuthorizenetAcceptjs\Gateway\Command\RefundTransactionStrategyCommand;
  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 PHPUnit\Framework\MockObject\MockObject;
  15. use PHPUnit\Framework\TestCase;
  16. class AcceptPaymentStrategyCommandTest extends TestCase
  17. {
  18. /**
  19. * @var CommandInterface|MockObject
  20. */
  21. private $commandMock;
  22. /**
  23. * @var CommandInterface|MockObject
  24. */
  25. private $transactionDetailsCommandMock;
  26. /**
  27. * @var CommandPoolInterface|MockObject
  28. */
  29. private $commandPoolMock;
  30. /**
  31. * @var RefundTransactionStrategyCommand
  32. */
  33. private $command;
  34. /**
  35. * @var ResultInterface|MockObject
  36. */
  37. private $transactionResultMock;
  38. protected function setUp()
  39. {
  40. $this->transactionDetailsCommandMock = $this->createMock(CommandInterface::class);
  41. $this->commandMock = $this->createMock(CommandInterface::class);
  42. $this->transactionResultMock = $this->createMock(ResultInterface::class);
  43. $this->commandPoolMock = $this->createMock(CommandPoolInterface::class);
  44. $this->command = new AcceptPaymentStrategyCommand(
  45. $this->commandPoolMock,
  46. new SubjectReader()
  47. );
  48. }
  49. /**
  50. * @param string $status
  51. * @dataProvider inReviewStatusesProvider
  52. */
  53. public function testCommandWillAcceptInTheGatewayWhenInFDSReview(string $status)
  54. {
  55. // Assert command is executed
  56. $this->commandMock->expects($this->once())
  57. ->method('execute');
  58. $this->commandPoolMock->method('get')
  59. ->willReturnMap([
  60. ['get_transaction_details', $this->transactionDetailsCommandMock],
  61. ['accept_fds', $this->commandMock]
  62. ]);
  63. $this->transactionResultMock->method('get')
  64. ->willReturn([
  65. 'transaction' => [
  66. 'transactionStatus' => $status
  67. ]
  68. ]);
  69. $buildSubject = [
  70. 'foo' => '123'
  71. ];
  72. $this->transactionDetailsCommandMock->expects($this->once())
  73. ->method('execute')
  74. ->with($buildSubject)
  75. ->willReturn($this->transactionResultMock);
  76. $this->command->execute($buildSubject);
  77. }
  78. public function testCommandWillDoNothingWhenTransactionHasAlreadyBeenAuthorized()
  79. {
  80. // Assert command is never executed
  81. $this->commandMock->expects($this->never())
  82. ->method('execute');
  83. $this->commandPoolMock->method('get')
  84. ->willReturnMap([
  85. ['get_transaction_details', $this->transactionDetailsCommandMock],
  86. ]);
  87. $this->transactionResultMock->method('get')
  88. ->willReturn([
  89. 'transaction' => [
  90. 'transactionStatus' => 'anythingelseisfine'
  91. ]
  92. ]);
  93. $buildSubject = [
  94. 'foo' => '123'
  95. ];
  96. $this->transactionDetailsCommandMock->expects($this->once())
  97. ->method('execute')
  98. ->with($buildSubject)
  99. ->willReturn($this->transactionResultMock);
  100. $this->command->execute($buildSubject);
  101. }
  102. public function inReviewStatusesProvider()
  103. {
  104. return [
  105. ['FDSPendingReview'],
  106. ['FDSAuthorizedPendingReview']
  107. ];
  108. }
  109. }