PaymentDataBuilderTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\Request;
  8. use Magento\AuthorizenetAcceptjs\Gateway\Request\PaymentDataBuilder;
  9. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  10. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  11. use Magento\Sales\Model\Order;
  12. use Magento\Sales\Model\Order\Payment;
  13. use PHPUnit\Framework\MockObject\MockObject;
  14. use PHPUnit\Framework\TestCase;
  15. class PaymentDataBuilderTest extends TestCase
  16. {
  17. /**
  18. * @var PaymentDataBuilder
  19. */
  20. private $builder;
  21. /**
  22. * @var Payment|MockObject
  23. */
  24. private $paymentMock;
  25. /**
  26. * @var Payment|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->orderMock = $this->createMock(Order::class);
  34. $this->paymentDOMock->method('getPayment')
  35. ->willReturn($this->paymentMock);
  36. $this->builder = new PaymentDataBuilder(new SubjectReader());
  37. }
  38. public function testBuild()
  39. {
  40. $this->paymentMock->method('getAdditionalInformation')
  41. ->willReturnMap([
  42. ['opaqueDataDescriptor', 'foo'],
  43. ['opaqueDataValue', 'bar']
  44. ]);
  45. $expected = [
  46. 'transactionRequest' => [
  47. 'payment' => [
  48. 'opaqueData' => [
  49. 'dataDescriptor' => 'foo',
  50. 'dataValue' => 'bar'
  51. ]
  52. ]
  53. ]
  54. ];
  55. $buildSubject = [
  56. 'payment' => $this->paymentDOMock,
  57. 'amount' => 123.45
  58. ];
  59. $this->assertEquals($expected, $this->builder->build($buildSubject));
  60. }
  61. }