DeviceDataBuilderTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\Request\PayPal;
  7. use Magento\Braintree\Gateway\SubjectReader;
  8. use Magento\Braintree\Gateway\Request\PayPal\DeviceDataBuilder;
  9. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  10. use Magento\Payment\Model\InfoInterface;
  11. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  12. /**
  13. * Tests \Magento\Braintree\Gateway\Request\PayPal\DeviceDataBuilder.
  14. */
  15. class DeviceDataBuilderTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var SubjectReader|MockObject
  19. */
  20. private $subjectReaderMock;
  21. /**
  22. * @var PaymentDataObjectInterface|MockObject
  23. */
  24. private $paymentDataObjectMock;
  25. /**
  26. * @var InfoInterface|MockObject
  27. */
  28. private $paymentInfoMock;
  29. /**
  30. * @var DeviceDataBuilder
  31. */
  32. private $builder;
  33. protected function setUp()
  34. {
  35. $this->subjectReaderMock = $this->getMockBuilder(SubjectReader::class)
  36. ->disableOriginalConstructor()
  37. ->setMethods(['readPayment'])
  38. ->getMock();
  39. $this->paymentDataObjectMock = $this->createMock(PaymentDataObjectInterface::class);
  40. $this->paymentInfoMock = $this->createMock(InfoInterface::class);
  41. $this->builder = new DeviceDataBuilder($this->subjectReaderMock);
  42. }
  43. /**
  44. * @covers \Magento\Braintree\Gateway\Request\PayPal\DeviceDataBuilder::build
  45. * @param array $paymentData
  46. * @param array $expected
  47. * @dataProvider buildDataProvider
  48. */
  49. public function testBuild(array $paymentData, array $expected)
  50. {
  51. $subject = [
  52. 'payment' => $this->paymentDataObjectMock,
  53. ];
  54. $this->subjectReaderMock->expects(static::once())
  55. ->method('readPayment')
  56. ->with($subject)
  57. ->willReturn($this->paymentDataObjectMock);
  58. $this->paymentDataObjectMock->expects(static::once())
  59. ->method('getPayment')
  60. ->willReturn($this->paymentInfoMock);
  61. $this->paymentInfoMock->expects(static::once())
  62. ->method('getAdditionalInformation')
  63. ->willReturn($paymentData);
  64. $actual = $this->builder->build($subject);
  65. static::assertEquals($expected, $actual);
  66. }
  67. /**
  68. * Get variations for build method testing
  69. * @return array
  70. */
  71. public function buildDataProvider()
  72. {
  73. return [
  74. [
  75. 'paymentData' => [
  76. 'device_data' => '{correlation_id: 12s3jf9as}'
  77. ],
  78. 'expected' => [
  79. 'deviceData' => '{correlation_id: 12s3jf9as}'
  80. ]
  81. ],
  82. [
  83. 'paymentData' => [
  84. 'device_data' => null,
  85. ],
  86. 'expected' => []
  87. ],
  88. [
  89. 'paymentData' => [
  90. 'deviceData' => '{correlation_id: 12s3jf9as}',
  91. ],
  92. 'expected' => []
  93. ],
  94. [
  95. 'paymentData' => [],
  96. 'expected' => []
  97. ]
  98. ];
  99. }
  100. }