ConfigTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Test\Unit;
  7. use Magento\Framework\App\Config;
  8. use Magento\Framework\App\Config\ConfigTypeInterface;
  9. use Magento\Framework\App\Config\ScopeCodeResolver;
  10. use Magento\Framework\App\ScopeInterface;
  11. class ConfigTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var ScopeCodeResolver|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. private $scopeCodeResolver;
  17. /**
  18. * @var ConfigTypeInterface|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $configType;
  21. /**
  22. * @var ScopeInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $scope;
  25. /**
  26. * @var Config
  27. */
  28. private $appConfig;
  29. public function setUp()
  30. {
  31. $this->scopeCodeResolver = $this->getMockBuilder(ScopeCodeResolver::class)
  32. ->disableOriginalConstructor()
  33. ->getMock();
  34. $this->configType = $this->getMockBuilder(ConfigTypeInterface::class)
  35. ->getMockForAbstractClass();
  36. $this->scope = $this->getMockBuilder(ScopeInterface::class)
  37. ->getMockForAbstractClass();
  38. $this->appConfig = new Config($this->scopeCodeResolver, ['system' => $this->configType]);
  39. }
  40. /**
  41. * @param string $scope
  42. * @param string|null $scopeCode
  43. *
  44. * @dataProvider getValueDataProvider
  45. * @return void
  46. */
  47. public function testGetValue($scope, $scopeCode = null)
  48. {
  49. $path = 'path';
  50. if (!is_string($scope)) {
  51. $this->scopeCodeResolver->expects($this->once())
  52. ->method('resolve')
  53. ->with('stores', $scopeCode)
  54. ->willReturn('myStore');
  55. } elseif (!$scopeCode) {
  56. $this->scope->expects($this->once())
  57. ->method('getCode')
  58. ->willReturn('myWebsite');
  59. }
  60. $this->configType->expects($this->once())
  61. ->method('get')
  62. ->with($scope =='store' ? 'stores/path' : 'websites/myWebsite/path')
  63. ->willReturn(true);
  64. $this->assertTrue($this->appConfig->getValue($path, $scope, $scopeCode ?: $this->scope));
  65. }
  66. /**
  67. * @return array
  68. */
  69. public function getValueDataProvider()
  70. {
  71. return [
  72. ['store', 1],
  73. ['website'],
  74. ];
  75. }
  76. }