SubjectReaderTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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;
  8. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  9. use Magento\Payment\Gateway\Data\OrderAdapterInterface;
  10. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  11. use PHPUnit\Framework\TestCase;
  12. class SubjectReaderTest extends TestCase
  13. {
  14. /**
  15. * @var SubjectReader
  16. */
  17. private $subjectReader;
  18. /**
  19. * @inheritdoc
  20. */
  21. protected function setUp()
  22. {
  23. $this->subjectReader = new SubjectReader();
  24. }
  25. public function testReadPayment(): void
  26. {
  27. $paymentDO = $this->createMock(PaymentDataObjectInterface::class);
  28. $this->assertSame($paymentDO, $this->subjectReader->readPayment(['payment' => $paymentDO]));
  29. }
  30. /**
  31. * @expectedException \InvalidArgumentException
  32. * @expectedExceptionMessage Payment data object should be provided
  33. */
  34. public function testReadPaymentThrowsExceptionWhenNotAPaymentObject(): void
  35. {
  36. $this->subjectReader->readPayment(['payment' => 'nope']);
  37. }
  38. /**
  39. * @expectedException \InvalidArgumentException
  40. * @expectedExceptionMessage Payment data object should be provided
  41. */
  42. public function testReadPaymentThrowsExceptionWhenNotSet(): void
  43. {
  44. $this->subjectReader->readPayment([]);
  45. }
  46. public function testReadResponse(): void
  47. {
  48. $expected = ['foo' => 'bar'];
  49. $this->assertSame($expected, $this->subjectReader->readResponse(['response' => $expected]));
  50. }
  51. /**
  52. * @expectedException \InvalidArgumentException
  53. * @expectedExceptionMessage Response does not exist
  54. */
  55. public function testReadResponseThrowsExceptionWhenNotAvailable(): void
  56. {
  57. $this->subjectReader->readResponse([]);
  58. }
  59. public function testReadStoreId(): void
  60. {
  61. $this->assertEquals(123, $this->subjectReader->readStoreId(['store_id' => '123']));
  62. }
  63. public function testReadStoreIdFromOrder(): void
  64. {
  65. $paymentDOMock = $this->createMock(PaymentDataObjectInterface::class);
  66. $orderMock = $this->createMock(OrderAdapterInterface::class);
  67. $paymentDOMock->method('getOrder')
  68. ->willReturn($orderMock);
  69. $orderMock->method('getStoreID')
  70. ->willReturn('123');
  71. $result = $this->subjectReader->readStoreId([
  72. 'payment' => $paymentDOMock
  73. ]);
  74. $this->assertEquals(123, $result);
  75. }
  76. public function testReadLoginId(): void
  77. {
  78. $this->assertEquals('abc', $this->subjectReader->readLoginId([
  79. 'merchantAuthentication' => ['name' => 'abc']
  80. ]));
  81. }
  82. public function testReadTransactionKey(): void
  83. {
  84. $this->assertEquals('abc', $this->subjectReader->readTransactionKey([
  85. 'merchantAuthentication' => ['transactionKey' => 'abc']
  86. ]));
  87. }
  88. public function testReadAmount(): void
  89. {
  90. $this->assertSame('123.12', $this->subjectReader->readAmount(['amount' => 123.12]));
  91. }
  92. /**
  93. * @expectedException \InvalidArgumentException
  94. * @expectedExceptionMessage Amount should be provided
  95. */
  96. public function testReadAmountThrowsExceptionWhenNotAvailable(): void
  97. {
  98. $this->subjectReader->readAmount([]);
  99. }
  100. }