19 use Symfony\Component\Console\Helper\QuestionHelper;
20 use Symfony\Component\Console\Input\InputInterface;
21 use Symfony\Component\Console\Output\OutputInterface;
26 class SensitiveConfigSetCommandTest
extends \PHPUnit\Framework\TestCase
46 private $configFilePool;
66 public function setUp()
69 $this->reader = $this->objectManager->get(FileReader::class);
70 $this->writer = $this->objectManager->get(Writer::class);
71 $this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
72 $this->filesystem = $this->objectManager->get(Filesystem::class);
74 $this->envConfig = $this->loadEnvConfig();
75 $this->config = $this->loadConfig();
92 public function testExecute($scope, $scopeCode, callable $assertCallback)
94 $outputMock = $this->createMock(OutputInterface::class);
95 $outputMock->expects($this->at(0))
97 ->with(
'<info>Configuration value saved in app/etc/env.php</info>');
101 $inputMocks[] = $this->createInputMock(
102 'some/config/path_two',
108 $inputMocks[] = $this->createInputMock(
109 'some/config/path_three',
116 $inputMocks[] = $this->createInputMock(
117 'some/config/path_three',
123 foreach ($inputMocks as $inputMock) {
125 $command = $this->objectManager->create(SensitiveConfigSetCommand::class);
126 $command->run($inputMock, $outputMock);
129 $config = $this->loadEnvConfig();
134 public function executeDataProvider()
141 $this->assertTrue(isset(
$config[
'system'][
'default'][
'some'][
'config'][
'path_two']));
142 $this->assertTrue(isset(
$config[
'system'][
'default'][
'some'][
'config'][
'path_three']));
145 $config[
'system'][
'default'][
'some'][
'config'][
'path_two']
149 $config[
'system'][
'default'][
'some'][
'config'][
'path_three']
157 $this->assertTrue(isset(
$config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_two']));
160 $config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_two']
164 $config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_three']
180 public function testExecuteInteractive($scope, $scopeCode, callable $assertCallback)
182 $inputMock = $this->createInputMock(
null,
null, $scope, $scopeCode);
184 $outputMock = $this->createMock(OutputInterface::class);
185 $outputMock->expects($this->at(0))
187 ->with(
'<info>Please set configuration values or skip them by pressing [Enter]:</info>');
188 $outputMock->expects($this->at(1))
190 ->with(
'<info>Configuration values saved in app/etc/env.php</info>');
192 $command = $this->createInteractiveCommand(
'sensitiveValue');
193 $command->run($inputMock, $outputMock);
196 $inputMock = $this->createInputMock(
null,
null, $scope, $scopeCode);
197 $command = $this->createInteractiveCommand(
null);
198 $command->run($inputMock, $outputMock);
200 $config = $this->loadEnvConfig();
205 public function executeInteractiveDataProvider()
212 $this->assertTrue(isset(
$config[
'system'][
'default'][
'some'][
'config'][
'path_one']));
213 $this->assertTrue(isset(
$config[
'system'][
'default'][
'some'][
'config'][
'path_two']));
214 $this->assertTrue(isset(
$config[
'system'][
'default'][
'some'][
'config'][
'path_three']));
217 $config[
'system'][
'default'][
'some'][
'config'][
'path_one']
221 $config[
'system'][
'default'][
'some'][
'config'][
'path_two']
225 $config[
'system'][
'default'][
'some'][
'config'][
'path_three']
233 $this->assertTrue(isset(
$config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_one']));
234 $this->assertTrue(isset(
$config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_two']));
235 $this->assertTrue(isset(
$config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_three']));
238 $config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_one']
242 $config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_two']
246 $config[
'system'][
'website'][
'test'][
'some'][
'config'][
'path_three']
256 public function tearDown()
260 "<?php\n return array();\n" 264 "<?php\n return array();\n" 268 $writer = $this->objectManager->get(Writer::class);
272 $writer = $this->objectManager->get(Writer::class);
279 private function loadEnvConfig()
287 private function loadConfig()
299 private function createInputMock($key, $val, $scope, $scopeCode)
301 $inputMock = $this->createMock(InputInterface::class);
302 $isInteractive = $key ===
null;
304 if (!$isInteractive) {
305 $inputMock->expects($this->exactly(2))
306 ->method(
'getArgument')
311 ->willReturnOnConsecutiveCalls(
317 $inputMock->expects($this->exactly(3))
318 ->method(
'getOption')
324 ->willReturnOnConsecutiveCalls(
337 private function createInteractiveCommand($inputValue)
339 $questionHelperMock = $this->createMock(QuestionHelper::class);
340 $questionHelperMock->expects($this->exactly(3))
342 ->willReturn($inputValue);
344 $interactiveCollectorMock = $this->objectManager->create(
345 InteractiveCollector::class,
347 'questionHelper' => $questionHelperMock
350 $collectorFactoryMock = $this->getMockBuilder(CollectorFactory::class)
351 ->disableOriginalConstructor()
354 $collectorFactoryMock->expects($this->once())
357 ->willReturn($interactiveCollectorMock);
360 $command = $this->objectManager->create(
361 SensitiveConfigSetCommand::class,
363 'facade' => $this->objectManager->create(
364 SensitiveConfigSetFacade::class,
366 'collectorFactory' => $collectorFactoryMock
defined('TESTS_BP')||define('TESTS_BP' __DIR__
const INPUT_OPTION_INTERACTIVE
const INPUT_OPTION_SCOPE_CODE
const INPUT_ARGUMENT_PATH
const INPUT_ARGUMENT_VALUE
static getObjectManager()