Skip to content

Commit 70809f9

Browse files
fix integration test
1 parent a6049d5 commit 70809f9

File tree

1 file changed

+62
-16
lines changed

1 file changed

+62
-16
lines changed

dev/tests/integration/testsuite/Magento/Config/Console/Command/ConfigShowCommandTest.php

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66

77
namespace Magento\Config\Console\Command;
88

9+
use Magento\Config\Model\Config\Structure;
910
use Magento\Framework\App\DeploymentConfig\FileReader;
1011
use Magento\Framework\App\DeploymentConfig\Writer;
1112
use Magento\Framework\App\Filesystem\DirectoryList;
1213
use Magento\Framework\Config\File\ConfigFilePool;
1314
use Magento\Framework\Console\Cli;
1415
use Magento\Framework\Filesystem;
15-
use Magento\Framework\ObjectManagerInterface;
1616
use Magento\Store\Model\ScopeInterface;
1717
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
1819
use Symfony\Component\Console\Tester\CommandTester;
1920

20-
class ConfigShowCommandTest extends \PHPUnit\Framework\TestCase
21+
/**
22+
* Test for \Magento\Config\Console\Command\ConfigShowCommand.
23+
*/
24+
class ConfigShowCommandTest extends TestCase
2125
{
22-
/**
23-
* @var ObjectManagerInterface
24-
*/
25-
private $objectManager;
26-
2726
/**
2827
* @var CommandTester
2928
*/
@@ -64,16 +63,22 @@ class ConfigShowCommandTest extends \PHPUnit\Framework\TestCase
6463
*/
6564
private $envConfig;
6665

66+
/**
67+
* @var Structure
68+
*/
69+
private $structure;
70+
6771
/**
6872
* @inheritdoc
6973
*/
7074
protected function setUp(): void
7175
{
72-
$this->objectManager = Bootstrap::getObjectManager();
73-
$this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
74-
$this->filesystem = $this->objectManager->get(Filesystem::class);
75-
$this->reader = $this->objectManager->get(FileReader::class);
76-
$this->writer = $this->objectManager->get(Writer::class);
76+
$objectManager = Bootstrap::getObjectManager();
77+
$this->configFilePool = $objectManager->get(ConfigFilePool::class);
78+
$this->filesystem = $objectManager->get(Filesystem::class);
79+
$this->reader = $objectManager->get(FileReader::class);
80+
$this->writer = $objectManager->get(Writer::class);
81+
$this->structure = $objectManager->get(Structure::class);
7782

7883
$this->config = $this->loadConfig();
7984
$this->envConfig = $this->loadEnvConfig();
@@ -89,21 +94,27 @@ protected function setUp(): void
8994
$_ENV['CONFIG__WEBSITES__BASE__WEB__TEST2__TEST_VALUE_4'] = 'value4.env.website_base.test';
9095
$_ENV['CONFIG__STORES__DEFAULT__WEB__TEST2__TEST_VALUE_4'] = 'value4.env.store_default.test';
9196

92-
$command = $this->objectManager->create(ConfigShowCommand::class);
97+
$command = $objectManager->create(ConfigShowCommand::class);
9398
$this->commandTester = new CommandTester($command);
9499
}
95100

96101
/**
102+
* Test execute config show command
103+
*
97104
* @param string $scope
98105
* @param string $scopeCode
99106
* @param int $resultCode
100107
* @param array $configs
108+
* @return void
109+
*
101110
* @magentoDbIsolation enabled
102111
* @magentoDataFixture Magento/Config/_files/config_data.php
103112
* @dataProvider executeDataProvider
104113
*/
105-
public function testExecute($scope, $scopeCode, $resultCode, array $configs)
114+
public function testExecute($scope, $scopeCode, $resultCode, array $configs): void
106115
{
116+
$this->setConfigPaths();
117+
107118
foreach ($configs as $inputPath => $configValue) {
108119
$arguments = [
109120
ConfigShowCommand::INPUT_ARGUMENT_PATH => $inputPath
@@ -130,6 +141,41 @@ public function testExecute($scope, $scopeCode, $resultCode, array $configs)
130141
}
131142
}
132143

144+
/**
145+
* Set config paths to structure
146+
*
147+
* @return void
148+
*/
149+
private function setConfigPaths(): void
150+
{
151+
$reflection = new \ReflectionClass(Structure::class);
152+
$mappedPaths = $reflection->getProperty('mappedPaths');
153+
$mappedPaths->setAccessible(true);
154+
$mappedPaths->setValue($this->structure, $this->getConfigPaths());
155+
}
156+
157+
/**
158+
* Returns config paths
159+
*
160+
* @return array
161+
*/
162+
private function getConfigPaths(): array
163+
{
164+
$configs = [
165+
'web/test/test_value_1',
166+
'web/test/test_value_2',
167+
'web/test2/test_value_3',
168+
'web/test2/test_value_4',
169+
'carriers/fedex/account',
170+
'paypal/fetch_reports/ftp_password',
171+
'web/test',
172+
'web/test2',
173+
'web',
174+
];
175+
176+
return array_flip($configs);
177+
}
178+
133179
/**
134180
* @return array
135181
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -240,7 +286,7 @@ public function executeDataProvider()
240286
Cli::RETURN_FAILURE,
241287
[
242288
'web/test/test_wrong_value' => [
243-
'Configuration for path: "web/test/test_wrong_value" doesn\'t exist'
289+
'The "web/test/test_wrong_value" path doesn\'t exist. Verify and try again.'
244290
],
245291
]
246292
],
@@ -250,7 +296,7 @@ public function executeDataProvider()
250296
Cli::RETURN_FAILURE,
251297
[
252298
'web/test/test_wrong_value' => [
253-
'Configuration for path: "web/test/test_wrong_value" doesn\'t exist'
299+
'The "web/test/test_wrong_value" path doesn\'t exist. Verify and try again.'
254300
],
255301
]
256302
],

0 commit comments

Comments
 (0)