diff --git a/app/code/Magento/Config/Console/Command/ConfigShowCommand.php b/app/code/Magento/Config/Console/Command/ConfigShowCommand.php index 445fd8e67937e..0c6b65fb444a0 100644 --- a/app/code/Magento/Config/Console/Command/ConfigShowCommand.php +++ b/app/code/Magento/Config/Console/Command/ConfigShowCommand.php @@ -172,13 +172,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $configValue = $this->emulatedAreaProcessor->process(function () { $this->scopeValidator->isValid($this->scope, $this->scopeCode); + $configPath = $this->pathResolver->resolve($this->inputPath, $this->scope, $this->scopeCode); if ($this->inputPath) { $pathValidator = $this->pathValidatorFactory->create(); - $pathValidator->validate($this->inputPath); + $pathValidator->validate($configPath); } - - $configPath = $this->pathResolver->resolve($this->inputPath, $this->scope, $this->scopeCode); - return $this->configSource->get($configPath); }); diff --git a/app/code/Magento/Config/Model/Config/PathValidator.php b/app/code/Magento/Config/Model/Config/PathValidator.php index d0d1d46303b8e..61a4bf6551fcb 100644 --- a/app/code/Magento/Config/Model/Config/PathValidator.php +++ b/app/code/Magento/Config/Model/Config/PathValidator.php @@ -6,7 +6,7 @@ namespace Magento\Config\Model\Config; -use Magento\Config\Model\Config\Structure\Element\Field; +use Magento\Config\App\Config\Source\RuntimeConfigSource; use Magento\Framework\Exception\ValidatorException; /** @@ -17,22 +17,23 @@ class PathValidator { /** - * The config structure. + * Source of configurations. * - * @var Structure + * @var RuntimeConfigSource */ - private $structure; + private $configSource; /** - * @param Structure $structure The config structure + * @param RuntimeConfigSource $configSource Source of configurations */ - public function __construct(Structure $structure) - { - $this->structure = $structure; + public function __construct( + RuntimeConfigSource $configSource + ) { + $this->configSource = $configSource; } /** - * Checks whether the config path present in configuration structure. + * Checks whether the config path present in configuration. * * @param string $path The config path * @return true The result of validation @@ -41,14 +42,7 @@ public function __construct(Structure $structure) */ public function validate($path) { - $element = $this->structure->getElementByConfigPath($path); - if ($element instanceof Field && $element->getConfigPath()) { - $path = $element->getConfigPath(); - } - - $allPaths = $this->structure->getFieldPaths(); - - if (!array_key_exists($path, $allPaths)) { + if (is_null($this->configSource->get($path))) { throw new ValidatorException(__('The "%1" path doesn\'t exist. Verify and try again.', $path)); } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/PathValidatorTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/PathValidatorTest.php index d7152f47f296c..88d29f2c9a098 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/PathValidatorTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/PathValidatorTest.php @@ -8,7 +8,7 @@ namespace Magento\Config\Test\Unit\Model\Config; use Magento\Config\Model\Config\PathValidator; -use Magento\Config\Model\Config\Structure; +use Magento\Config\App\Config\Source\RuntimeConfigSource; use PHPUnit\Framework\MockObject\MockObject as Mock; use PHPUnit\Framework\TestCase; @@ -25,33 +25,29 @@ class PathValidatorTest extends TestCase private $model; /** - * @var Structure|Mock + * @var RuntimeConfigSource|Mock */ - private $structureMock; + private $configMock; /** * @inheritdoc */ protected function setUp(): void { - $this->structureMock = $this->getMockBuilder(Structure::class) + $this->configMock = $this->getMockBuilder(RuntimeConfigSource::class) ->disableOriginalConstructor() ->getMock(); $this->model = new PathValidator( - $this->structureMock + $this->configMock ); } public function testValidate() { - $this->structureMock->expects($this->once()) - ->method('getFieldPaths') - ->willReturn([ - 'test/test/test' => [ - 'test/test/test' - ] - ]); + $this->configMock->expects($this->once()) + ->method('get') + ->willReturn('test'); $this->assertTrue($this->model->validate('test/test/test')); } @@ -60,9 +56,9 @@ public function testValidateWithException() { $this->expectException('Magento\Framework\Exception\ValidatorException'); $this->expectExceptionMessage('The "test/test/test" path doesn\'t exist. Verify and try again.'); - $this->structureMock->expects($this->once()) - ->method('getFieldPaths') - ->willReturn([]); + $this->configMock->expects($this->once()) + ->method('get') + ->willReturn(null); $this->assertTrue($this->model->validate('test/test/test')); }