ConfigTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Test\Unit\Model;
  7. use Magento\Analytics\Model\Config;
  8. use Magento\Framework\Config\DataInterface;
  9. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  10. /**
  11. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  12. */
  13. class ConfigTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var DataInterface|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. private $dataInterfaceMock;
  19. /**
  20. * @var ObjectManagerHelper
  21. */
  22. private $objectManagerHelper;
  23. /**
  24. * @var Config
  25. */
  26. private $config;
  27. /**
  28. * @return void
  29. */
  30. protected function setUp()
  31. {
  32. $this->dataInterfaceMock = $this->getMockBuilder(DataInterface::class)
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35. $this->objectManagerHelper = new ObjectManagerHelper($this);
  36. $this->config = $this->objectManagerHelper->getObject(
  37. Config::class,
  38. [
  39. 'data' => $this->dataInterfaceMock,
  40. ]
  41. );
  42. }
  43. /**
  44. * @return void
  45. */
  46. public function testGet()
  47. {
  48. $key = 'configKey';
  49. $defaultValue = 'mock';
  50. $configValue = 'emptyString';
  51. $this->dataInterfaceMock
  52. ->expects($this->once())
  53. ->method('get')
  54. ->with($key, $defaultValue)
  55. ->willReturn($configValue);
  56. $this->assertSame($configValue, $this->config->get($key, $defaultValue));
  57. }
  58. }