ChannelDataBuilderTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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;
  7. use Magento\Braintree\Gateway\Request\ChannelDataBuilder;
  8. use Magento\Framework\App\ProductMetadataInterface;
  9. use Magento\Payment\Gateway\Config\Config;
  10. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  11. /**
  12. * Class PaymentDataBuilderTest
  13. *
  14. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  15. */
  16. class ChannelDataBuilderTest extends \PHPUnit\Framework\TestCase
  17. {
  18. /**
  19. * @var ProductMetadataInterface|MockObject
  20. */
  21. private $productMetadata;
  22. /**
  23. * @var Config|MockObject
  24. */
  25. private $config;
  26. /**
  27. * @var ChannelDataBuilder
  28. */
  29. private $builder;
  30. /**
  31. * @inheritdoc
  32. */
  33. protected function setUp()
  34. {
  35. $this->productMetadata = $this->getMockBuilder(ProductMetadataInterface::class)
  36. ->disableOriginalConstructor()
  37. ->getMock();
  38. $this->config = $this->getMockBuilder(Config::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->builder = new ChannelDataBuilder($this->productMetadata, $this->config);
  42. }
  43. /**
  44. * @param string $edition
  45. * @param array $expected
  46. * @covers \Magento\Braintree\Gateway\Request\ChannelDataBuilder::build
  47. * @dataProvider buildDataProvider
  48. */
  49. public function testBuild($edition, array $expected)
  50. {
  51. $buildSubject = [];
  52. $this->config->method('getValue')
  53. ->with(self::equalTo('channel'))
  54. ->willReturn(null);
  55. $this->productMetadata->method('getEdition')
  56. ->willReturn($edition);
  57. self::assertEquals($expected, $this->builder->build($buildSubject));
  58. }
  59. /**
  60. * Checks a case when a channel provided via payment method configuration.
  61. */
  62. public function testBuildWithChannelFromConfig()
  63. {
  64. $channel = 'Magento2_Cart_ConfigEdition_BT';
  65. $this->config->method('getValue')
  66. ->with(self::equalTo('channel'))
  67. ->willReturn($channel);
  68. $this->productMetadata->expects(self::never())
  69. ->method('getEdition');
  70. self::assertEquals(
  71. [
  72. 'channel' => $channel
  73. ],
  74. $this->builder->build([])
  75. );
  76. }
  77. /**
  78. * Get list of variations for build test
  79. * @return array
  80. */
  81. public function buildDataProvider()
  82. {
  83. return [
  84. ['FirstEdition', ['channel' => 'Magento2_Cart_FirstEdition_BT']],
  85. ['SecondEdition', ['channel' => 'Magento2_Cart_SecondEdition_BT']],
  86. ];
  87. }
  88. }