CloseParentTransactionHandlerTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\CloseParentTransactionHandler;
  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 CloseParentTransactionHandlerTest extends TestCase
  16. {
  17. /**
  18. * @var CloseParentTransactionHandler
  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 CloseParentTransactionHandler(new SubjectReader());
  36. }
  37. public function testHandleClosesTransactionByDefault()
  38. {
  39. $subject = [
  40. 'payment' => $this->paymentDOMock
  41. ];
  42. $response = [
  43. 'transactionResponse' => []
  44. ];
  45. // Assert the parent transaction i closed
  46. $this->paymentMock->expects($this->once())
  47. ->method('setShouldCloseParentTransaction')
  48. ->with(true);
  49. $this->handler->handle($subject, $response);
  50. // Assertions are via mock expects above
  51. }
  52. }