Skip to content

Issue #35751 bin/magento config:show fails #35815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/code/Magento/Config/Console/Command/ConfigShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This IF is not longer needed

$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);
});

Expand Down
28 changes: 11 additions & 17 deletions app/code/Magento/Config/Model/Config/PathValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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'));
}
Expand All @@ -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'));
}
Expand Down