-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #911 from magento-falcons/MAGETWO-65701
Bugs - MAGETWO-65308 CLI command config:set fails on configurations which requires session - MAGETWO-62560 Catalog Module UpgradeData to 2.1.3 breaks when cost attribute is deleted #7804 - for 2.2.0 Task - MAGETWO-65208 Store checksum for every section of configuration file & change behavior on read-only FS & add sorting of importers
- Loading branch information
Showing
30 changed files
with
886 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
app/code/Magento/Config/Console/Command/ConfigSet/ProcessorFacade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Config\Console\Command\ConfigSet; | ||
|
||
use Magento\Config\Console\Command\ConfigSetCommand; | ||
use Magento\Framework\App\Scope\ValidatorInterface; | ||
use Magento\Config\Model\Config\PathValidator; | ||
use Magento\Framework\Exception\ConfigurationMismatchException; | ||
use Magento\Framework\Exception\CouldNotSaveException; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Exception\ValidatorException; | ||
|
||
/** | ||
* Processor facade for config:set command. | ||
* | ||
* @see ConfigSetCommand | ||
*/ | ||
class ProcessorFacade | ||
{ | ||
/** | ||
* The scope validator. | ||
* | ||
* @var ValidatorInterface | ||
*/ | ||
private $scopeValidator; | ||
|
||
/** | ||
* The path validator. | ||
* | ||
* @var PathValidator | ||
*/ | ||
private $pathValidator; | ||
|
||
/** | ||
* The factory for config:set processors. | ||
* | ||
* @var ConfigSetProcessorFactory | ||
*/ | ||
private $configSetProcessorFactory; | ||
|
||
/** | ||
* @param ValidatorInterface $scopeValidator The scope validator | ||
* @param PathValidator $pathValidator The path validator | ||
* @param ConfigSetProcessorFactory $configSetProcessorFactory The factory for config:set processors | ||
*/ | ||
public function __construct( | ||
ValidatorInterface $scopeValidator, | ||
PathValidator $pathValidator, | ||
ConfigSetProcessorFactory $configSetProcessorFactory | ||
) { | ||
$this->scopeValidator = $scopeValidator; | ||
$this->pathValidator = $pathValidator; | ||
$this->configSetProcessorFactory = $configSetProcessorFactory; | ||
} | ||
|
||
/** | ||
* Processes config:set command. | ||
* | ||
* @param string $path The configuration path in format group/section/field_name | ||
* @param string $value The configuration value | ||
* @param string $scope The configuration scope (default, website, or store) | ||
* @param string $scopeCode The scope code | ||
* @param boolean $lock The lock flag | ||
* @return string Processor response message | ||
* @throws LocalizedException If scope validation failed | ||
* @throws ValidatorException If path validation failed | ||
* @throws CouldNotSaveException If processing failed | ||
* @throws ConfigurationMismatchException If processor can not be instantiated | ||
*/ | ||
public function process($path, $value, $scope, $scopeCode, $lock) | ||
{ | ||
$this->scopeValidator->isValid($scope, $scopeCode); | ||
$this->pathValidator->validate($path); | ||
|
||
$processor = $lock | ||
? $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK) | ||
: $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_DEFAULT); | ||
$message = $lock | ||
? 'Value was saved and locked.' | ||
: 'Value was saved.'; | ||
|
||
// The processing flow depends on --lock option. | ||
$processor->process($path, $value, $scope, $scopeCode); | ||
|
||
return $message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/ProcessorFacadeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Config\Test\Unit\Console\Command\ConfigSet; | ||
|
||
use Magento\Config\Console\Command\ConfigSet\ConfigSetProcessorFactory; | ||
use Magento\Config\Console\Command\ConfigSet\ConfigSetProcessorInterface; | ||
use Magento\Config\Console\Command\ConfigSet\ProcessorFacade; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\Scope\ValidatorInterface; | ||
use Magento\Config\Model\Config\PathValidator; | ||
use PHPUnit_Framework_MockObject_MockObject as Mock; | ||
|
||
/** | ||
* Test for ProcessorFacade. | ||
* | ||
* @see ProcessorFacade | ||
*/ | ||
class ProcessorFacadeTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ProcessorFacade | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var ValidatorInterface|Mock | ||
*/ | ||
private $scopeValidatorMock; | ||
|
||
/** | ||
* @var PathValidator|Mock | ||
*/ | ||
private $pathValidatorMock; | ||
|
||
/** | ||
* @var ConfigSetProcessorFactory|Mock | ||
*/ | ||
private $configSetProcessorFactoryMock; | ||
|
||
/** | ||
* @var ConfigSetProcessorInterface|Mock | ||
*/ | ||
private $processorMock; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->scopeValidatorMock = $this->getMockBuilder(ValidatorInterface::class) | ||
->getMockForAbstractClass(); | ||
$this->pathValidatorMock = $this->getMockBuilder(PathValidator::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->configSetProcessorFactoryMock = $this->getMockBuilder(ConfigSetProcessorFactory::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->processorMock = $this->getMockBuilder(ConfigSetProcessorInterface::class) | ||
->getMockForAbstractClass(); | ||
|
||
$this->configSetProcessorFactoryMock->expects($this->any()) | ||
->method('create') | ||
->willReturn($this->processorMock); | ||
|
||
$this->model = new ProcessorFacade( | ||
$this->scopeValidatorMock, | ||
$this->pathValidatorMock, | ||
$this->configSetProcessorFactoryMock | ||
); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
$this->scopeValidatorMock->expects($this->once()) | ||
->method('isValid') | ||
->willReturn(true); | ||
$this->configSetProcessorFactoryMock->expects($this->once()) | ||
->method('create') | ||
->with(ConfigSetProcessorFactory::TYPE_DEFAULT) | ||
->willReturn($this->processorMock); | ||
$this->processorMock->expects($this->once()) | ||
->method('process') | ||
->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null); | ||
|
||
$this->assertSame( | ||
'Value was saved.', | ||
$this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, false) | ||
); | ||
} | ||
|
||
public function testExecuteLock() | ||
{ | ||
$this->scopeValidatorMock->expects($this->once()) | ||
->method('isValid') | ||
->willReturn(true); | ||
$this->configSetProcessorFactoryMock->expects($this->once()) | ||
->method('create') | ||
->with(ConfigSetProcessorFactory::TYPE_LOCK) | ||
->willReturn($this->processorMock); | ||
$this->processorMock->expects($this->once()) | ||
->method('process') | ||
->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null); | ||
|
||
$this->assertSame( | ||
'Value was saved and locked.', | ||
$this->model->process('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, true) | ||
); | ||
} | ||
} |
Oops, something went wrong.