Skip to content

Commit aadeea4

Browse files
MAGETWO-65308: CLI command config:set fails on configurations which requires session
1 parent 596c74f commit aadeea4

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

app/code/Magento/Config/Console/Command/ConfigSet/ProcessorFacade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ public function __construct(
5454
}
5555

5656
/**
57+
* Processes config:set command.
58+
*
5759
* @param string $path The configuration path in format group/section/field_name
5860
* @param string $value The configuration value
5961
* @param string $scope The configuration scope (default, website, or store)
6062
* @param string $scopeCode The scope code
63+
* @param boolean $lock The lock flag
6164
* @return string Processor response message
6265
* @throws LocalizedException If validation or processor failed
6366
*/
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Console\Command\ConfigSet;
7+
8+
use Magento\Config\Console\Command\ConfigSet\ConfigSetProcessorFactory;
9+
use Magento\Config\Console\Command\ConfigSet\ConfigSetProcessorInterface;
10+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacade;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\Scope\ValidatorInterface;
13+
use Magento\Config\Model\Config\PathValidator;
14+
use PHPUnit_Framework_MockObject_MockObject as Mock;
15+
16+
/**
17+
* Test for ProcessorFacade.
18+
*
19+
* @see ProcessorFacade
20+
*/
21+
class ProcessorFacadeTest extends \PHPUnit_Framework_TestCase
22+
{
23+
/**
24+
* @var ProcessorFacade
25+
*/
26+
private $model;
27+
28+
/**
29+
* @var ValidatorInterface|Mock
30+
*/
31+
private $scopeValidatorMock;
32+
33+
/**
34+
* @var PathValidator|Mock
35+
*/
36+
private $pathValidatorMock;
37+
38+
/**
39+
* @var ConfigSetProcessorFactory|Mock
40+
*/
41+
private $configSetProcessorFactoryMock;
42+
43+
/**
44+
* @var ConfigSetProcessorInterface|Mock
45+
*/
46+
private $processorMock;
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
protected function setUp()
52+
{
53+
$this->scopeValidatorMock = $this->getMockBuilder(ValidatorInterface::class)
54+
->getMockForAbstractClass();
55+
$this->pathValidatorMock = $this->getMockBuilder(PathValidator::class)
56+
->disableOriginalConstructor()
57+
->getMock();
58+
$this->configSetProcessorFactoryMock = $this->getMockBuilder(ConfigSetProcessorFactory::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$this->processorMock = $this->getMockBuilder(ConfigSetProcessorInterface::class)
62+
->getMockForAbstractClass();
63+
64+
$this->configSetProcessorFactoryMock->expects($this->any())
65+
->method('create')
66+
->willReturn($this->processorMock);
67+
68+
$this->model = new ProcessorFacade(
69+
$this->scopeValidatorMock,
70+
$this->pathValidatorMock,
71+
$this->configSetProcessorFactoryMock
72+
);
73+
}
74+
75+
public function testProcess()
76+
{
77+
$this->scopeValidatorMock->expects($this->once())
78+
->method('isValid')
79+
->willReturn(true);
80+
$this->configSetProcessorFactoryMock->expects($this->once())
81+
->method('create')
82+
->with(ConfigSetProcessorFactory::TYPE_DEFAULT)
83+
->willReturn($this->processorMock);
84+
$this->processorMock->expects($this->once())
85+
->method('process')
86+
->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
87+
88+
$this->assertSame(
89+
'Value was saved.',
90+
$this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, false)
91+
);
92+
}
93+
94+
public function testExecuteLock()
95+
{
96+
$this->scopeValidatorMock->expects($this->once())
97+
->method('isValid')
98+
->willReturn(true);
99+
$this->configSetProcessorFactoryMock->expects($this->once())
100+
->method('create')
101+
->with(ConfigSetProcessorFactory::TYPE_LOCK)
102+
->willReturn($this->processorMock);
103+
$this->processorMock->expects($this->once())
104+
->method('process')
105+
->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
106+
107+
$this->assertSame(
108+
'Value was saved and locked.',
109+
$this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, true)
110+
);
111+
}
112+
}

0 commit comments

Comments
 (0)