TransactionIdHandlerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Test\Unit\Gateway\Response;
  7. use Magento\Braintree\Gateway\SubjectReader;
  8. use Magento\Braintree\Gateway\Response\TransactionIdHandler;
  9. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  10. use Magento\Sales\Model\Order\Payment;
  11. class TransactionIdHandlerTest extends \PHPUnit\Framework\TestCase
  12. {
  13. public function testHandle()
  14. {
  15. $paymentDO = $this->createMock(PaymentDataObjectInterface::class);
  16. $paymentInfo = $this->getMockBuilder(Payment::class)
  17. ->disableOriginalConstructor()
  18. ->getMock();
  19. $handlingSubject = [
  20. 'payment' => $paymentDO
  21. ];
  22. $transaction = \Braintree\Transaction::factory(['id' => 1]);
  23. $response = [
  24. 'object' => new \Braintree\Result\Successful($transaction, 'transaction')
  25. ];
  26. $subjectReader = $this->getMockBuilder(SubjectReader::class)
  27. ->disableOriginalConstructor()
  28. ->getMock();
  29. $subjectReader->expects(static::once())
  30. ->method('readPayment')
  31. ->with($handlingSubject)
  32. ->willReturn($paymentDO);
  33. $paymentDO->expects(static::atLeastOnce())
  34. ->method('getPayment')
  35. ->willReturn($paymentInfo);
  36. $subjectReader->expects(static::once())
  37. ->method('readTransaction')
  38. ->with($response)
  39. ->willReturn($transaction);
  40. $paymentInfo->expects(static::once())
  41. ->method('setTransactionId')
  42. ->with(1);
  43. $paymentInfo->expects(static::once())
  44. ->method('setIsTransactionClosed')
  45. ->with(false);
  46. $paymentInfo->expects(static::once())
  47. ->method('setShouldCloseParentTransaction')
  48. ->with(false);
  49. $handler = new TransactionIdHandler($subjectReader);
  50. $handler->handle($handlingSubject, $response);
  51. }
  52. }