From 2247c8304ab620aeaf625532c576b5ca6fffa9e6 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Mon, 2 Mar 2015 18:43:07 -0600 Subject: [PATCH 001/214] MAGETWO-34507: Create OptionsInterface, Option - added Option class and OptionsInterface --- .../Magento/Framework/Setup/Option.php | 89 +++++++++++++++++++ .../Framework/Setup/OptionsInterface.php | 24 +++++ 2 files changed, 113 insertions(+) create mode 100644 lib/internal/Magento/Framework/Setup/Option.php create mode 100644 lib/internal/Magento/Framework/Setup/OptionsInterface.php diff --git a/lib/internal/Magento/Framework/Setup/Option.php b/lib/internal/Magento/Framework/Setup/Option.php new file mode 100644 index 0000000000000..4d47af664e6a2 --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/Option.php @@ -0,0 +1,89 @@ +frontendType = $frontendType; + $this->selectOptions = $selectOptions; + parent::__construct($name, $shortcut = null, $mode = null, $description = '', $default = null); + } + + /** + * Get frontend input type + * + * @return string + */ + public function getFrontendInput() + { + $this->frontendType; + } + + /** + * Get available options + * + * @return array + */ + public function getSelectOptions() + { + $this->selectOptions; + } +} diff --git a/lib/internal/Magento/Framework/Setup/OptionsInterface.php b/lib/internal/Magento/Framework/Setup/OptionsInterface.php new file mode 100644 index 0000000000000..d7958841cd580 --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/OptionsInterface.php @@ -0,0 +1,24 @@ + Date: Tue, 3 Mar 2015 10:21:23 -0600 Subject: [PATCH 002/214] MAGETWO-34507: Create OptionsInterface, Option - renamed classes and methods --- .../Setup/{Option.php => ConfigOption.php} | 5 ++++- ...ionsInterface.php => ConfigOptionsInterface.php} | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) rename lib/internal/Magento/Framework/Setup/{Option.php => ConfigOption.php} (95%) rename lib/internal/Magento/Framework/Setup/{OptionsInterface.php => ConfigOptionsInterface.php} (56%) diff --git a/lib/internal/Magento/Framework/Setup/Option.php b/lib/internal/Magento/Framework/Setup/ConfigOption.php similarity index 95% rename from lib/internal/Magento/Framework/Setup/Option.php rename to lib/internal/Magento/Framework/Setup/ConfigOption.php index 4d47af664e6a2..a94ccb768e06b 100644 --- a/lib/internal/Magento/Framework/Setup/Option.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOption.php @@ -7,7 +7,10 @@ use Symfony\Component\Console\Input\InputOption; -class Option extends InputOption +/** + * An option in a segment of the deployment configuration + */ +class ConfigOption extends InputOption { /**#@+ * Frontend input types diff --git a/lib/internal/Magento/Framework/Setup/OptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php similarity index 56% rename from lib/internal/Magento/Framework/Setup/OptionsInterface.php rename to lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php index d7958841cd580..ac384cc539839 100644 --- a/lib/internal/Magento/Framework/Setup/OptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php @@ -5,14 +5,17 @@ */ namespace Magento\Framework\Setup; -interface OptionsInterface +/** + * Interface for segment in deployment configuration + */ +interface ConfigOptionsInterface { /** - * Gets deployment configuration options of a module + * Gets deployment configuration options of a segment * - * @return Option[] + * @return ConfigOption[] */ - public function getDeploymentConfigOptions(); + public function getOptions(); /** * Creates deployment configuration options array that will be stored in deployment config file @@ -20,5 +23,5 @@ public function getDeploymentConfigOptions(); * @param array $options * @return array */ - public function createDeploymentConfig(array $options); + public function createConfig(array $options); } From f5e168efd6784dcfebcc6b4fe5a3a2a3e9406557 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 3 Mar 2015 10:48:45 -0600 Subject: [PATCH 003/214] MAGETWO-34507: Create OptionsInterface, Option - added test --- .../Framework/Setup/ConfigOptionTest.php | 30 +++++++++++++++++++ .../Magento/Framework/Setup/ConfigOption.php | 14 ++++----- 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Setup/ConfigOptionTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/ConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/ConfigOptionTest.php new file mode 100644 index 0000000000000..6ff432c3b7982 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/ConfigOptionTest.php @@ -0,0 +1,30 @@ +assertEquals(ConfigOption::FRONTEND_WIZARD_TEXT, $option->getFrontendInput()); + } + + public function testGetSelectOptions() + { + $option = new ConfigOption('test', ConfigOption::FRONTEND_WIZARD_SELECT, '', ['option1', 'option2', 'option3']); + $this->assertEquals(['option1', 'option2', 'option3'], $option->getSelectOptions()); + } +} diff --git a/lib/internal/Magento/Framework/Setup/ConfigOption.php b/lib/internal/Magento/Framework/Setup/ConfigOption.php index a94ccb768e06b..ff16737c2f3db 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOption.php @@ -42,8 +42,8 @@ class ConfigOption extends InputOption * Constructor * * @param string $name - * @param string $description * @param string $frontendType + * @param string $description * @param array $selectOptions * @param string|null $default * @param int|null $mode @@ -51,16 +51,16 @@ class ConfigOption extends InputOption */ public function __construct( $name, - $description = '', $frontendType, + $description = '', array $selectOptions = [], $default = null, $mode = null, $shortcut = null ) { - if ($frontendType != self::FRONTEND_WIZARD_TEXT || $frontendType != self::FRONTEND_WIZARD_CHECKBOX || - $frontendType != self::FRONTEND_WIZARD_MULTISELECT || $frontendType != self::FRONTEND_WIZARD_PASSWORD || - $frontendType != self::FRONTEND_WIZARD_RADIO || $frontendType != self::FRONTEND_WIZARD_SELECT || + if ($frontendType != self::FRONTEND_WIZARD_TEXT && $frontendType != self::FRONTEND_WIZARD_CHECKBOX && + $frontendType != self::FRONTEND_WIZARD_MULTISELECT && $frontendType != self::FRONTEND_WIZARD_PASSWORD && + $frontendType != self::FRONTEND_WIZARD_RADIO && $frontendType != self::FRONTEND_WIZARD_SELECT && $frontendType != self::FRONTEND_WIZARD_TEXTAREA ) { throw new \InvalidArgumentException('Unknown frontend input type.'); @@ -77,7 +77,7 @@ public function __construct( */ public function getFrontendInput() { - $this->frontendType; + return $this->frontendType; } /** @@ -87,6 +87,6 @@ public function getFrontendInput() */ public function getSelectOptions() { - $this->selectOptions; + return $this->selectOptions; } } From 9228f8f0c140fc58f24972ad8d14fb1bb65bc0eb Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Tue, 3 Mar 2015 12:09:28 -0600 Subject: [PATCH 004/214] MAGETWO-34656: Implement config options for 'backend' segment - added ConfigOptions - replaced old constant for path in the config with new one in the new class --- .../Backend/App/Area/FrontNameResolver.php | 5 +- .../Magento/Backend/Setup/ConfigOptions.php | 61 ++++++++++++++ .../Test/Legacy/_files/obsolete_constants.php | 5 ++ .../App/Area/FrontNameResolverTest.php | 4 +- .../Backend/Setup/ConfigOptionsTest.php | 81 +++++++++++++++++++ 5 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 app/code/Magento/Backend/Setup/ConfigOptions.php create mode 100644 dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php diff --git a/app/code/Magento/Backend/App/Area/FrontNameResolver.php b/app/code/Magento/Backend/App/Area/FrontNameResolver.php index 2dea792cea907..761714b025d38 100644 --- a/app/code/Magento/Backend/App/Area/FrontNameResolver.php +++ b/app/code/Magento/Backend/App/Area/FrontNameResolver.php @@ -7,6 +7,7 @@ */ namespace Magento\Backend\App\Area; +use Magento\Backend\Setup\ConfigOptions; use Magento\Framework\App\DeploymentConfig; class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolverInterface @@ -15,8 +16,6 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver const XML_PATH_CUSTOM_ADMIN_PATH = 'admin/url/custom_path'; - const PARAM_BACKEND_FRONT_NAME = 'backend/frontName'; - /** * Backend area code */ @@ -46,7 +45,7 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver public function __construct(\Magento\Backend\App\Config $config, DeploymentConfig $deploymentConfig) { $this->config = $config; - $this->defaultFrontName = $deploymentConfig->get(self::PARAM_BACKEND_FRONT_NAME); + $this->defaultFrontName = $deploymentConfig->get(ConfigOptions::CONFIG_PATH_BACKEND_FRONTNAME); } /** diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php new file mode 100644 index 0000000000000..06f003253ee1d --- /dev/null +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -0,0 +1,61 @@ +getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false); $deploymentConfigMock->expects($this->once()) ->method('get') - ->with(FrontNameResolver::PARAM_BACKEND_FRONT_NAME) + ->with(ConfigOptions::CONFIG_PATH_BACKEND_FRONTNAME) ->will($this->returnValue($this->_defaultFrontName)); $this->_configMock = $this->getMock('\Magento\Backend\App\Config', [], [], '', false); $this->_model = new \Magento\Backend\App\Area\FrontNameResolver($this->_configMock, $deploymentConfigMock); diff --git a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php new file mode 100644 index 0000000000000..6b6031d7b5ba3 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php @@ -0,0 +1,81 @@ +object = new ConfigOptions(); + } + + public function testGetOptions() + { + $options = $this->object->getOptions(); + foreach ($options as $option) { + $this->assertInstanceOf('\Magento\Framework\Setup\ConfigOption', $option); + } + } + + public function testCreateConfig() + { + $options = [ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; + $expected = ['backend' => ['frontName' => 'admin']]; + $this->assertSame($expected, $this->object->createConfig($options)); + } + + /** + * @param array $options + * + * @dataProvider createConfigNoFrontnameDataProvider + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage No backend frontname provided + */ + public function testCreateConfigNoFrontname(array $options) + { + $this->object->createConfig($options); + } + + /** + * @return array + */ + public function createConfigNoFrontnameDataProvider() + { + return [ + 'no data' => [[]], + 'no frontName' => [['something_else' => 'something']], + 'empty frontName' => [[ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => '']], + ]; + } + + /** + * @param array $options + * + * @dataProvider createConfigInvalidFrontnameDataProvider + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid backend frontname + */ + public function testCreateConfigInvalidFrontname(array $options) + { + $this->object->createConfig($options); + } + + /** + * @return array + */ + public function createConfigInvalidFrontnameDataProvider() + { + return [ + [[ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => '**']], + [[ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'invalid frontname']], + ]; + } +} From e0d47cd6d877df84c14b55f56857595c866be3af Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Tue, 3 Mar 2015 12:25:24 -0600 Subject: [PATCH 005/214] MAGETWO-34655: Implement config options for 'install' segment - added ConfigOptions in Setup application - replaced old constant for path to install date in config with new one from new class --- .../Magento/AdminNotification/Model/Feed.php | 3 +- .../Magento/Backend/Helper/Dashboard/Data.php | 8 +--- .../AdminNotification/Model/FeedTest.php | 4 +- .../Magento/Setup/ConfigOptionsTest.php | 25 ++++++++++++ setup/src/Magento/Setup/ConfigOptions.php | 38 +++++++++++++++++++ 5 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php create mode 100644 setup/src/Magento/Setup/ConfigOptions.php diff --git a/app/code/Magento/AdminNotification/Model/Feed.php b/app/code/Magento/AdminNotification/Model/Feed.php index e9416028a9aa9..4d72c32d53415 100644 --- a/app/code/Magento/AdminNotification/Model/Feed.php +++ b/app/code/Magento/AdminNotification/Model/Feed.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\AdminNotification\Model; +use Magento\Setup\ConfigOptions; /** * AdminNotification Feed model @@ -135,7 +136,7 @@ public function checkUpdate() $feedXml = $this->getFeedData(); - $installDate = strtotime($this->_deploymentConfig->get('install/date')); + $installDate = strtotime($this->_deploymentConfig->get(ConfigOptions::CONFIG_PATH_INSTALL_DATE)); if ($feedXml && $feedXml->channel && $feedXml->channel->item) { foreach ($feedXml->channel->item as $item) { diff --git a/app/code/Magento/Backend/Helper/Dashboard/Data.php b/app/code/Magento/Backend/Helper/Dashboard/Data.php index c72171c9199e6..0224102dadd38 100644 --- a/app/code/Magento/Backend/Helper/Dashboard/Data.php +++ b/app/code/Magento/Backend/Helper/Dashboard/Data.php @@ -6,6 +6,7 @@ namespace Magento\Backend\Helper\Dashboard; use Magento\Framework\App\DeploymentConfig; +use Magento\Setup\ConfigOptions; /** * Data helper for dashboard @@ -22,11 +23,6 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper */ protected $_installDate; - /** - * Configuration key to installation date - */ - const INSTALL_DATE = 'install/date'; - /** * @var \Magento\Store\Model\StoreManagerInterface */ @@ -45,7 +41,7 @@ public function __construct( parent::__construct( $context ); - $this->_installDate = $deploymentConfig->get(self::INSTALL_DATE); + $this->_installDate = $deploymentConfig->get(ConfigOptions::CONFIG_PATH_INSTALL_DATE); $this->_storeManager = $storeManager; } diff --git a/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php b/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php index 0a0744d8b5724..cc607eea3f487 100644 --- a/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php +++ b/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php @@ -6,6 +6,7 @@ namespace Magento\AdminNotification\Model; +use Magento\Setup\ConfigOptions; use Magento\TestFramework\Helper\ObjectManager as ObjectManagerHelper; /** @@ -140,7 +141,8 @@ public function testCheckUpdate($callInbox, $curlRequest) $this->backendConfig->expects($this->at(1))->method('getValue') ->will($this->returnValue('http://feed.magento.com')); $this->deploymentConfig->expects($this->once())->method('get') - ->with('install/date')->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); + ->with(ConfigOptions::CONFIG_PATH_INSTALL_DATE) + ->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create') ->will(($this->returnValue($this->inboxModel))); diff --git a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php new file mode 100644 index 0000000000000..26543bc097577 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php @@ -0,0 +1,25 @@ +object = new ConfigOptions(); + } + + public function testCreateConfig() + { + $config = $this->object->createConfig([]); + $this->assertNotEmpty($config['install']['date']); + } +} diff --git a/setup/src/Magento/Setup/ConfigOptions.php b/setup/src/Magento/Setup/ConfigOptions.php new file mode 100644 index 0000000000000..5571ad7698dec --- /dev/null +++ b/setup/src/Magento/Setup/ConfigOptions.php @@ -0,0 +1,38 @@ + Date: Tue, 3 Mar 2015 14:40:00 -0600 Subject: [PATCH 006/214] MAGETWO-34656: Implement config options for 'backend' segment - fixed constant in DI config --- app/etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/etc/di.xml b/app/etc/di.xml index 5695d82507c11..7ff78d50fa663 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -216,7 +216,7 @@ - Magento\Backend\App\Area\FrontNameResolver::PARAM_BACKEND_FRONT_NAME + Magento\Backend\Setup\ConfigOptions::CONFIG_PATH_BACKEND_FRONTNAME From 09c94be3b740098c1a76070b678054c93ce6a010 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 3 Mar 2015 14:49:40 -0600 Subject: [PATCH 007/214] MAGETWO-34509: Collector for OptionsInterfaces - implemented ConfigOptionsCollector --- .../Setup/Model/ConfigOptionsCollector.php | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 setup/src/Magento/Setup/Model/ConfigOptionsCollector.php diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php new file mode 100644 index 0000000000000..a0bc5c67b2068 --- /dev/null +++ b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php @@ -0,0 +1,147 @@ +directoryList = $directoryList; + $this->filesystem = $filesystem; + $this->fullModuleList = $fullModuleList; + $this->moduleList = $moduleList; + } + + /** + * Auto discover Options class and collect their options + * + * @return array + */ + public function collectOptions() + { + $optionsList = []; + + // go through modules + foreach ($this->moduleList->getNames() as $moduleName) { + $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptions'; + if (class_exists($optionsClassName)) { + $optionsClass = new $optionsClassName(); + if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { + $optionsList[$optionsClassName] = [ + 'options' => $optionsClass->getOptions(), + 'enabled' => $this->moduleList->has($moduleName), + ]; + } + } + } + + // go through framework + $frameworkOptionsFiles = []; + $this->collectRecursively( + $this->filesystem->getDirectoryRead(DirectoryList::LIB_INTERNAL), + 'Magento/Framework', + $frameworkOptionsFiles + ); + foreach ($frameworkOptionsFiles as $frameworkOptionsFile) { + // remove .php + $frameworkOptionsFile = substr($frameworkOptionsFile, 0, -4); + $frameworkOptionsClassName = str_replace('/', '\\', $frameworkOptionsFile); + $optionsClass = new $frameworkOptionsClassName(); + if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { + $optionsList[$frameworkOptionsClassName] = [ + 'options' => $optionsClass->getOptions(), + 'enabled' => true, + ]; + } + } + + // go through setup + $setupOptionsFiles = []; + $this->collectRecursively( + $this->filesystem->getDirectoryRead(DirectoryList::ROOT), + 'setup/src', + $setupOptionsFiles + ); + foreach ($setupOptionsFiles as $setupOptionsFile) { + // remove setup/src/ and .php + $setupOptionsFile = substr($setupOptionsFile, 10, -4); + $setupOptionsClassName = str_replace('/', '\\', $setupOptionsFile); + $optionsClass = new $setupOptionsClassName(); + if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { + $optionsList[$setupOptionsClassName] = [ + 'options' => $optionsClass->getOptions(), + 'enabled' => true, + ]; + } + } + + return $optionsList; + } + + /** + * Collects Options files recursively + * + * @param Filesystem\Directory\ReadInterface $dir + * @param string $path + * @param array $result + */ + private function collectRecursively(\Magento\Framework\Filesystem\Directory\ReadInterface $dir, $path, &$result) + { + $localResult = $dir->search($path . '/Setup/ConfigOptions.php'); + foreach ($localResult as $optionFile) { + $result[] = $optionFile; + } + + // goes deeper if current search is successful or next depth level exists + if ($localResult || $dir->search($path . '/*')) { + $this->collectRecursively($dir, $path . '/*', $result); + } + } +} From 2826eacebc98d04e9badb5719ad0b93208f23ea6 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 3 Mar 2015 15:06:12 -0600 Subject: [PATCH 008/214] MAGETWO-34509: Collector for OptionsInterfaces - change manual object creation to using ObjectManagerProvider --- .../Setup/Model/ConfigOptionsCollector.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php index a0bc5c67b2068..baff4f7dcb622 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php @@ -39,6 +39,13 @@ class ConfigOptionsCollector */ private $moduleList; + /** + * Object manager provider + * + * @var ObjectManagerProvider + */ + private $objectManagerProvider; + /** * Constructor * @@ -51,12 +58,14 @@ public function __construct( DirectoryList $directoryList, Filesystem $filesystem, FullModuleList $fullModuleList, - ModuleList $moduleList + ModuleList $moduleList, + ObjectManagerProvider $objectManagerProvider ) { $this->directoryList = $directoryList; $this->filesystem = $filesystem; $this->fullModuleList = $fullModuleList; $this->moduleList = $moduleList; + $this->objectManagerProvider = $objectManagerProvider; } /** @@ -72,7 +81,7 @@ public function collectOptions() foreach ($this->moduleList->getNames() as $moduleName) { $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptions'; if (class_exists($optionsClassName)) { - $optionsClass = new $optionsClassName(); + $optionsClass = $this->objectManagerProvider->get()->create($optionsClassName); if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { $optionsList[$optionsClassName] = [ 'options' => $optionsClass->getOptions(), @@ -93,7 +102,7 @@ public function collectOptions() // remove .php $frameworkOptionsFile = substr($frameworkOptionsFile, 0, -4); $frameworkOptionsClassName = str_replace('/', '\\', $frameworkOptionsFile); - $optionsClass = new $frameworkOptionsClassName(); + $optionsClass = $this->objectManagerProvider->get()->create($frameworkOptionsClassName); if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { $optionsList[$frameworkOptionsClassName] = [ 'options' => $optionsClass->getOptions(), @@ -113,7 +122,7 @@ public function collectOptions() // remove setup/src/ and .php $setupOptionsFile = substr($setupOptionsFile, 10, -4); $setupOptionsClassName = str_replace('/', '\\', $setupOptionsFile); - $optionsClass = new $setupOptionsClassName(); + $optionsClass = $this->objectManagerProvider->get()->create($setupOptionsClassName); if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { $optionsList[$setupOptionsClassName] = [ 'options' => $optionsClass->getOptions(), From e4fa89142d47d0ad92aa8750fcaa749b4bcab22a Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 3 Mar 2015 16:33:52 -0600 Subject: [PATCH 009/214] MAGETWO-34507: Create OptionsInterface, Option - split ConfigOption class --- .../Framework/Setup/ConfigOptionTest.php | 30 ----------- .../Framework/Setup/FlagConfigOptionTest.php | 21 ++++++++ .../Setup/MultiSelectConfigOptionTest.php | 39 +++++++++++++++ .../Setup/SelectConfigOptionTest.php | 39 +++++++++++++++ .../Framework/Setup/TextConfigOptionTest.php | 30 +++++++++++ ...figOption.php => AbstractConfigOption.php} | 29 ++--------- .../Framework/Setup/FlagConfigOption.php | 30 +++++++++++ .../Setup/MultiSelectConfigOption.php | 50 +++++++++++++++++++ .../Framework/Setup/SelectConfigOption.php | 50 +++++++++++++++++++ .../Framework/Setup/TextConfigOption.php | 40 +++++++++++++++ 10 files changed, 304 insertions(+), 54 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Framework/Setup/ConfigOptionTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php rename lib/internal/Magento/Framework/Setup/{ConfigOption.php => AbstractConfigOption.php} (52%) create mode 100644 lib/internal/Magento/Framework/Setup/FlagConfigOption.php create mode 100644 lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php create mode 100644 lib/internal/Magento/Framework/Setup/SelectConfigOption.php create mode 100644 lib/internal/Magento/Framework/Setup/TextConfigOption.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/ConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/ConfigOptionTest.php deleted file mode 100644 index 6ff432c3b7982..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Setup/ConfigOptionTest.php +++ /dev/null @@ -1,30 +0,0 @@ -assertEquals(ConfigOption::FRONTEND_WIZARD_TEXT, $option->getFrontendInput()); - } - - public function testGetSelectOptions() - { - $option = new ConfigOption('test', ConfigOption::FRONTEND_WIZARD_SELECT, '', ['option1', 'option2', 'option3']); - $this->assertEquals(['option1', 'option2', 'option3'], $option->getSelectOptions()); - } -} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php new file mode 100644 index 0000000000000..1f5d91fbdcad4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php @@ -0,0 +1,21 @@ +assertEquals(FlagConfigOption::FRONTEND_WIZARD_FLAG, $option->getFrontendInput()); + } + + public function testGetSelectOptions() + { + $option = new FlagConfigOption('test', FlagConfigOption::FRONTEND_WIZARD_FLAG); + $this->assertEquals([], $option->getSelectOptions()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php new file mode 100644 index 0000000000000..58ef19969f856 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php @@ -0,0 +1,39 @@ +assertEquals(MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, $option->getFrontendInput()); + } + + public function testGetSelectOptions() + { + $option = new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, ['a', 'b']); + $this->assertEquals(['a', 'b'], $option->getSelectOptions()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php new file mode 100644 index 0000000000000..94503315dd9ae --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php @@ -0,0 +1,39 @@ +assertEquals(SelectConfigOption::FRONTEND_WIZARD_SELECT, $option->getFrontendInput()); + } + + public function testGetSelectOptions() + { + $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); + $this->assertEquals(['a', 'b'], $option->getSelectOptions()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php new file mode 100644 index 0000000000000..756cf687fa3cb --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php @@ -0,0 +1,30 @@ +assertEquals(TextConfigOption::FRONTEND_WIZARD_TEXT, $option->getFrontendInput()); + } + + public function testGetSelectOptions() + { + $option = new TextConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT); + $this->assertEquals([], $option->getSelectOptions()); + } +} diff --git a/lib/internal/Magento/Framework/Setup/ConfigOption.php b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php similarity index 52% rename from lib/internal/Magento/Framework/Setup/ConfigOption.php rename to lib/internal/Magento/Framework/Setup/AbstractConfigOption.php index ff16737c2f3db..a688dc0ee0c69 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php @@ -8,22 +8,10 @@ use Symfony\Component\Console\Input\InputOption; /** - * An option in a segment of the deployment configuration + * Abstract Option class in a segment of the deployment configuration */ -class ConfigOption extends InputOption +abstract class AbstractConfigOption extends InputOption { - /**#@+ - * Frontend input types - */ - const FRONTEND_WIZARD_TEXT = 'text'; - const FRONTEND_WIZARD_PASSWORD = 'password'; - const FRONTEND_WIZARD_RADIO = 'radio'; - const FRONTEND_WIZARD_CHECKBOX = 'checkbox'; - const FRONTEND_WIZARD_SELECT = 'select'; - const FRONTEND_WIZARD_MULTISELECT = 'multiselect'; - const FRONTEND_WIZARD_TEXTAREA = 'textarea'; - /**#@- */ - /** * Frontend input type * @@ -46,7 +34,7 @@ class ConfigOption extends InputOption * @param string $description * @param array $selectOptions * @param string|null $default - * @param int|null $mode + * @param int $mode * @param string|null $shortcut */ public function __construct( @@ -55,19 +43,12 @@ public function __construct( $description = '', array $selectOptions = [], $default = null, - $mode = null, + $mode, $shortcut = null ) { - if ($frontendType != self::FRONTEND_WIZARD_TEXT && $frontendType != self::FRONTEND_WIZARD_CHECKBOX && - $frontendType != self::FRONTEND_WIZARD_MULTISELECT && $frontendType != self::FRONTEND_WIZARD_PASSWORD && - $frontendType != self::FRONTEND_WIZARD_RADIO && $frontendType != self::FRONTEND_WIZARD_SELECT && - $frontendType != self::FRONTEND_WIZARD_TEXTAREA - ) { - throw new \InvalidArgumentException('Unknown frontend input type.'); - } $this->frontendType = $frontendType; $this->selectOptions = $selectOptions; - parent::__construct($name, $shortcut = null, $mode = null, $description = '', $default = null); + parent::__construct($name, $shortcut, $mode, $description, $default); } /** diff --git a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php new file mode 100644 index 0000000000000..34cee9c4e451f --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php @@ -0,0 +1,30 @@ + Date: Tue, 3 Mar 2015 22:08:15 -0600 Subject: [PATCH 010/214] MAGETWO-34656: Implement config options for 'backend' segment - updated creation of options to usage of new classes - added default value --- app/code/Magento/Backend/Setup/ConfigOptions.php | 13 +++++-------- .../Magento/Backend/Setup/ConfigOptionsTest.php | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php index 06f003253ee1d..0d157a3d410ea 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -5,9 +5,8 @@ */ namespace Magento\Backend\Setup; -use Magento\Framework\Setup\ConfigOption; use Magento\Framework\Setup\ConfigOptionsInterface; -use Symfony\Component\Console\Input\InputOption; +use Magento\Framework\Setup\TextConfigOption; /* * Deployment configuration options needed for Backend module @@ -30,13 +29,11 @@ class ConfigOptions implements ConfigOptionsInterface public function getOptions() { return [ - new ConfigOption( + new TextConfigOption( self::INPUT_KEY_BACKEND_FRONTNAME, - ConfigOption::FRONTEND_WIZARD_TEXT, - 'Backenad frontname (e.g., "backend" or "admin")', - [], - '', - InputOption::VALUE_REQUIRED + TextConfigOption::FRONTEND_WIZARD_TEXT, + 'Backend frontname', + 'admin' ) ]; } diff --git a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php index 6b6031d7b5ba3..48b4d4a258399 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php @@ -21,7 +21,7 @@ public function testGetOptions() { $options = $this->object->getOptions(); foreach ($options as $option) { - $this->assertInstanceOf('\Magento\Framework\Setup\ConfigOption', $option); + $this->assertInstanceOf('\Magento\Framework\Setup\AbstractConfigOption', $option); } } From 993ce78ebcce04aa7a08deefb21708d1644d0930 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 11:41:29 -0600 Subject: [PATCH 011/214] MAGETWO-34693: Implement config options for 'crypt' segment - implemented crypt ConfigOptions - added tests --- app/code/Magento/Core/Setup/ConfigOptions.php | 44 +++++++++++ .../Magento/Core/Setup/ConfigOptionsTest.php | 73 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 app/code/Magento/Core/Setup/ConfigOptions.php create mode 100644 dev/tests/unit/testsuite/Magento/Core/Setup/ConfigOptionsTest.php diff --git a/app/code/Magento/Core/Setup/ConfigOptions.php b/app/code/Magento/Core/Setup/ConfigOptions.php new file mode 100644 index 0000000000000..1f3cf18dcb0d2 --- /dev/null +++ b/app/code/Magento/Core/Setup/ConfigOptions.php @@ -0,0 +1,44 @@ +object = new ConfigOptions(); + } + + public function testGetOptions() + { + $options = $this->object->getOptions(); + foreach ($options as $option) { + $this->assertInstanceOf('\Magento\Framework\Setup\TextConfigOption', $option); + } + } + + /** + * @param array $options + * + * @dataProvider createConfigNoKeyDataProvider + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage No encryption key provided. + */ + public function testCreateConfigNoKey(array $options) + { + $this->object->createConfig($options); + } + + /** + * @return array + */ + public function createConfigNoKeyDataProvider() + { + return [ + 'no data' => [[]], + 'no frontName' => [['something_else' => 'something']], + ]; + } + + /** + * @param array $options + * + * @dataProvider createConfigInvalidKeyDataProvider + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid encryption key. + */ + public function testCreateConfigInvalidKey(array $options) + { + $this->object->createConfig($options); + } + + /** + * @return array + */ + public function createConfigInvalidKeyDataProvider() + { + return [ + [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '']], + [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '0']], + ]; + } +} From 4771307f316ba9262868518e996a4d0b912bff51 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 4 Mar 2015 12:25:24 -0600 Subject: [PATCH 012/214] MAGETWO-34511: Process config options. - added ConfigFilePool and ConfigDada --- .../Framework/Config/Options/ConfigDada.php | 79 +++++++++++++++++++ .../Config/Options/ConfigFilePool.php | 55 +++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 lib/internal/Magento/Framework/Config/Options/ConfigDada.php create mode 100644 lib/internal/Magento/Framework/Config/Options/ConfigFilePool.php diff --git a/lib/internal/Magento/Framework/Config/Options/ConfigDada.php b/lib/internal/Magento/Framework/Config/Options/ConfigDada.php new file mode 100644 index 0000000000000..d7f145d4beec5 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Options/ConfigDada.php @@ -0,0 +1,79 @@ +fileKey = $fileKey; + $this->segmentKey = $segmentKey; + $this->data = $data; + } + + /** + * Gets File Key + * + * @return string + */ + public function getFileKey() + { + return $this->fileKey; + } + + /** + * Gets Segment Key + * + * @return string + */ + public function getSegmentKey() + { + return $this->segmentKey; + } + + /** + * Gets Data + * + * @return string + */ + public function getData() + { + return $this->data; + } +} + diff --git a/lib/internal/Magento/Framework/Config/Options/ConfigFilePool.php b/lib/internal/Magento/Framework/Config/Options/ConfigFilePool.php new file mode 100644 index 0000000000000..bf45b9ae8c87d --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Options/ConfigFilePool.php @@ -0,0 +1,55 @@ + 'app/etc/config.php' + ]; + + public function __construct($additionalConfigFiles) + { + // TODO: implement it + } + + /** + * Returns application config files + * + * @return array + */ + public function getPaths() + { + return $this->applicationConfigFiles; + } + + /** + * Returns file path by config key + * + * @param string $key + * @return string + * @throws Exception + */ + public function getPath($key) + { + if (!isset($this->applicationConfigFiles[$key])) { + throw new \Exception(''); + } + return $this->applicationConfigFiles[$key]; + } + +} \ No newline at end of file From 362c3fd980fa17e4efe77b7634ccf297be41cca8 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 4 Mar 2015 12:28:42 -0600 Subject: [PATCH 013/214] MAGETWO-34511: Process config options. - added new line to the end of file. --- .../Magento/Framework/Config/Options/ConfigFilePool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Config/Options/ConfigFilePool.php b/lib/internal/Magento/Framework/Config/Options/ConfigFilePool.php index bf45b9ae8c87d..52432d454c1e1 100644 --- a/lib/internal/Magento/Framework/Config/Options/ConfigFilePool.php +++ b/lib/internal/Magento/Framework/Config/Options/ConfigFilePool.php @@ -52,4 +52,4 @@ public function getPath($key) return $this->applicationConfigFiles[$key]; } -} \ No newline at end of file +} From 6f218dfa8165b7945515b328e538ab3cd0f953ed Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Wed, 4 Mar 2015 12:47:20 -0600 Subject: [PATCH 014/214] MAGETWO-34691: Implement config options for definitions segment - added options validation --- .../Framework/Setup/AbstractConfigOption.php | 10 ++++++++++ .../Setup/ConfigOptionsInterface.php | 2 +- .../Setup/MultiSelectConfigOption.php | 20 +++++++++++++++++++ .../Framework/Setup/SelectConfigOption.php | 14 +++++++++++++ .../Framework/Setup/TextConfigOption.php | 14 +++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php index a688dc0ee0c69..0a5a7df6a06a8 100644 --- a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php @@ -70,4 +70,14 @@ public function getSelectOptions() { return $this->selectOptions; } + + /** + * No base validation + * + * @param mixed $data + * @return void + */ + public function validate($data) + { + } } diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php index ac384cc539839..220eb1ec915da 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php @@ -13,7 +13,7 @@ interface ConfigOptionsInterface /** * Gets deployment configuration options of a segment * - * @return ConfigOption[] + * @return AbstractConfigOption[] */ public function getOptions(); diff --git a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php index ff93fe9ffd6c9..47df4ddc7c8f7 100644 --- a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php @@ -47,4 +47,24 @@ public function __construct( $shortCut ); } + + /** + * Validates input data + * + * @param mixed $data + * @return void + */ + public function validate($data) + { + if (is_array($data)) { + foreach ($data as $value) { + if (!in_array($value, $this->getSelectOptions())) { + throw new \InvalidArgumentException( + "Value specified for '{$this->getName()}' is not supported: '{$value}'" + ); + } + } + } + parent::validate($data); + } } diff --git a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/SelectConfigOption.php index dd7d94809d0d9..cb0197b83b122 100644 --- a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/SelectConfigOption.php @@ -47,4 +47,18 @@ public function __construct( $shortCut ); } + + /** + * Validates input data + * + * @param mixed $data + * @return void + */ + public function validate($data) + { + if (!in_array($data, $this->getSelectOptions())) { + throw new \InvalidArgumentException("Value specified for '{$this->getName()}' is not supported: '{$data}'"); + } + parent::validate($data); + } } diff --git a/lib/internal/Magento/Framework/Setup/TextConfigOption.php b/lib/internal/Magento/Framework/Setup/TextConfigOption.php index b945dd9f17ec6..50c8d1fd6f2e7 100644 --- a/lib/internal/Magento/Framework/Setup/TextConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/TextConfigOption.php @@ -37,4 +37,18 @@ public function __construct( } parent::__construct($name, $frontendType, $description, [], $default, self::VALUE_REQUIRED, $shortCut); } + + /** + * Validates input data + * + * @param mixed $data + * @return void + */ + public function validate($data) + { + if (!is_string($data)) { + throw new \InvalidArgumentException("'{$this->getName()}' must be a string"); + } + parent::validate($data); + } } From 28ddba2d8a6514a0e50435a52e40bbf9ae5a084e Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 13:56:25 -0600 Subject: [PATCH 015/214] MAGETWO-34507: Create OptionsInterface, Option - changed according to CR - added tests for validate method --- .../Framework/Setup/FlagConfigOptionTest.php | 6 ------ .../Setup/MultiSelectConfigOptionTest.php | 10 ++++++++++ .../Setup/SelectConfigOptionTest.php | 10 ++++++++++ .../Framework/Setup/TextConfigOptionTest.php | 8 ++++++-- .../Framework/Setup/AbstractConfigOption.php | 20 ------------------- .../Framework/Setup/FlagConfigOption.php | 2 +- .../Setup/MultiSelectConfigOption.php | 19 +++++++++++++++++- .../Framework/Setup/SelectConfigOption.php | 19 +++++++++++++++++- .../Framework/Setup/TextConfigOption.php | 2 +- 9 files changed, 64 insertions(+), 32 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php index 1f5d91fbdcad4..9cf7c23767274 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php @@ -12,10 +12,4 @@ public function testGetFrontendInput() $option = new FlagConfigOption('test', FlagConfigOption::FRONTEND_WIZARD_FLAG); $this->assertEquals(FlagConfigOption::FRONTEND_WIZARD_FLAG, $option->getFrontendInput()); } - - public function testGetSelectOptions() - { - $option = new FlagConfigOption('test', FlagConfigOption::FRONTEND_WIZARD_FLAG); - $this->assertEquals([], $option->getSelectOptions()); - } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php index 58ef19969f856..046d11ef07fad 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php @@ -36,4 +36,14 @@ public function testGetSelectOptions() $option = new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, ['a', 'b']); $this->assertEquals(['a', 'b'], $option->getSelectOptions()); } + + /** + * @expectedException \InvalidArgumentException + * @expectedMessage Frontend input type has to be text, textarea or password. + */ + public function testValidateException() + { + $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); + $option->validate('c'); + } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php index 94503315dd9ae..27c7465a4ca4e 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php @@ -36,4 +36,14 @@ public function testGetSelectOptions() $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); $this->assertEquals(['a', 'b'], $option->getSelectOptions()); } + + /** + * @expectedException \InvalidArgumentException + * @expectedMessage Frontend input type has to be text, textarea or password. + */ + public function testValidateException() + { + $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); + $option->validate('c'); + } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php b/dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php index 756cf687fa3cb..83cae1dc0b29d 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php @@ -22,9 +22,13 @@ public function testGetFrontendInput() $this->assertEquals(TextConfigOption::FRONTEND_WIZARD_TEXT, $option->getFrontendInput()); } - public function testGetSelectOptions() + /** + * @expectedException \InvalidArgumentException + * @expectedMessage must be a string + */ + public function testValidateException() { $option = new TextConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT); - $this->assertEquals([], $option->getSelectOptions()); + $option->validate(1); } } diff --git a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php index 0a5a7df6a06a8..3ee81533de821 100644 --- a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php @@ -19,20 +19,12 @@ abstract class AbstractConfigOption extends InputOption */ private $frontendType; - /** - * Available options - * - * @var array - */ - private $selectOptions; - /** * Constructor * * @param string $name * @param string $frontendType * @param string $description - * @param array $selectOptions * @param string|null $default * @param int $mode * @param string|null $shortcut @@ -41,13 +33,11 @@ public function __construct( $name, $frontendType, $description = '', - array $selectOptions = [], $default = null, $mode, $shortcut = null ) { $this->frontendType = $frontendType; - $this->selectOptions = $selectOptions; parent::__construct($name, $shortcut, $mode, $description, $default); } @@ -61,16 +51,6 @@ public function getFrontendInput() return $this->frontendType; } - /** - * Get available options - * - * @return array - */ - public function getSelectOptions() - { - return $this->selectOptions; - } - /** * No base validation * diff --git a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php index 34cee9c4e451f..af72c685349f7 100644 --- a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php @@ -25,6 +25,6 @@ public function __construct( $default = '', $shortCut = null ) { - parent::__construct($name, self::FRONTEND_WIZARD_FLAG, $description, [], null, self::VALUE_NONE, $shortCut); + parent::__construct($name, self::FRONTEND_WIZARD_FLAG, $description, null, self::VALUE_NONE, $shortCut); } } diff --git a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php index 47df4ddc7c8f7..9820a74e348bc 100644 --- a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php @@ -13,6 +13,13 @@ class MultiSelectConfigOption extends AbstractConfigOption const FRONTEND_WIZARD_MULTISELECT = 'multiselect'; /**#@- */ + /** + * Available options + * + * @var array + */ + private $selectOptions; + /** * Constructor * @@ -37,17 +44,27 @@ public function __construct( if (!$selectOptions) { throw new \InvalidArgumentException('Select options can\'t be empty.'); } + $this->selectOptions = $selectOptions; parent::__construct( $name, $frontendType, $description, - $selectOptions, $default, self::VALUE_REQUIRED, $shortCut ); } + /** + * Get available options + * + * @return array + */ + public function getSelectOptions() + { + return $this->selectOptions; + } + /** * Validates input data * diff --git a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/SelectConfigOption.php index cb0197b83b122..48a7a53d0acdc 100644 --- a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/SelectConfigOption.php @@ -13,6 +13,13 @@ class SelectConfigOption extends AbstractConfigOption const FRONTEND_WIZARD_SELECT = 'select'; /**#@- */ + /** + * Available options + * + * @var array + */ + private $selectOptions; + /** * Constructor * @@ -37,17 +44,27 @@ public function __construct( if (!$selectOptions) { throw new \InvalidArgumentException('Select options can\'t be empty.'); } + $this->selectOptions = $selectOptions; parent::__construct( $name, $frontendType, $description, - $selectOptions, $default, self::VALUE_REQUIRED, $shortCut ); } + /** + * Get available options + * + * @return array + */ + public function getSelectOptions() + { + return $this->selectOptions; + } + /** * Validates input data * diff --git a/lib/internal/Magento/Framework/Setup/TextConfigOption.php b/lib/internal/Magento/Framework/Setup/TextConfigOption.php index 50c8d1fd6f2e7..b6e366479e7a3 100644 --- a/lib/internal/Magento/Framework/Setup/TextConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/TextConfigOption.php @@ -35,7 +35,7 @@ public function __construct( ) { throw new \InvalidArgumentException('Frontend input type has to be text, textarea or password.'); } - parent::__construct($name, $frontendType, $description, [], $default, self::VALUE_REQUIRED, $shortCut); + parent::__construct($name, $frontendType, $description, $default, self::VALUE_REQUIRED, $shortCut); } /** From 7bd01d7bbc81532bf9cf804104bc43f474454d6f Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 14:06:37 -0600 Subject: [PATCH 016/214] MAGETWO-34507: Create OptionsInterface, Option - moved tests to correct directory --- .../testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php | 0 .../Magento/Framework/Setup/MultiSelectConfigOptionTest.php | 0 .../testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php | 0 .../testsuite/Magento/Framework/Setup/TextConfigOptionTest.php | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename dev/tests/{integration => unit}/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php (100%) rename dev/tests/{integration => unit}/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php (100%) rename dev/tests/{integration => unit}/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php (100%) rename dev/tests/{integration => unit}/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php (100%) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php similarity index 100% rename from dev/tests/integration/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php similarity index 100% rename from dev/tests/integration/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php similarity index 100% rename from dev/tests/integration/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php diff --git a/dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php similarity index 100% rename from dev/tests/integration/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php From cb5882d30450bd741a020aa769481fa6e1a81b60 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 4 Mar 2015 14:09:53 -0600 Subject: [PATCH 017/214] MAGETWO-34511: Process config options - fixed typo and moved files to better place. --- .../Config/{Options/ConfigDada.php => Data/ConfigData.php} | 5 ++--- .../Framework/Config/{Options => File}/ConfigFilePool.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) rename lib/internal/Magento/Framework/Config/{Options/ConfigDada.php => Data/ConfigData.php} (95%) rename lib/internal/Magento/Framework/Config/{Options => File}/ConfigFilePool.php (96%) diff --git a/lib/internal/Magento/Framework/Config/Options/ConfigDada.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php similarity index 95% rename from lib/internal/Magento/Framework/Config/Options/ConfigDada.php rename to lib/internal/Magento/Framework/Config/Data/ConfigData.php index d7f145d4beec5..d887e5515f419 100644 --- a/lib/internal/Magento/Framework/Config/Options/ConfigDada.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -1,14 +1,13 @@ Date: Wed, 4 Mar 2015 15:02:22 -0600 Subject: [PATCH 018/214] MAGETWO-34507: Create OptionsInterface, Option - added @throws annotation in docblock --- .../Magento/Framework/Setup/ConfigOptionsInterface.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php index 220eb1ec915da..83100ca0be5dc 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php @@ -11,7 +11,7 @@ interface ConfigOptionsInterface { /** - * Gets deployment configuration options of a segment + * Gets user input options to a segment in deployment configuration * * @return AbstractConfigOption[] */ @@ -22,6 +22,7 @@ public function getOptions(); * * @param array $options * @return array + * @throws \InvalidArgumentException */ public function createConfig(array $options); } From 22eb4e216cad492d74364148ddc78d7215a0c2de Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 15:06:29 -0600 Subject: [PATCH 019/214] MAGETWO-34693: Implement config options for 'crypt' segment - moved ConfigOptions from core to setup --- app/code/Magento/Core/Setup/ConfigOptions.php | 44 ----------- .../Magento/Core/Setup/ConfigOptionsTest.php | 73 ------------------- .../Magento/Setup/ConfigOptionsTest.php | 55 +++++++++++++- setup/src/Magento/Setup/ConfigOptions.php | 29 +++++++- 4 files changed, 81 insertions(+), 120 deletions(-) delete mode 100644 app/code/Magento/Core/Setup/ConfigOptions.php delete mode 100644 dev/tests/unit/testsuite/Magento/Core/Setup/ConfigOptionsTest.php diff --git a/app/code/Magento/Core/Setup/ConfigOptions.php b/app/code/Magento/Core/Setup/ConfigOptions.php deleted file mode 100644 index 1f3cf18dcb0d2..0000000000000 --- a/app/code/Magento/Core/Setup/ConfigOptions.php +++ /dev/null @@ -1,44 +0,0 @@ -object = new ConfigOptions(); - } - - public function testGetOptions() - { - $options = $this->object->getOptions(); - foreach ($options as $option) { - $this->assertInstanceOf('\Magento\Framework\Setup\TextConfigOption', $option); - } - } - - /** - * @param array $options - * - * @dataProvider createConfigNoKeyDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage No encryption key provided. - */ - public function testCreateConfigNoKey(array $options) - { - $this->object->createConfig($options); - } - - /** - * @return array - */ - public function createConfigNoKeyDataProvider() - { - return [ - 'no data' => [[]], - 'no frontName' => [['something_else' => 'something']], - ]; - } - - /** - * @param array $options - * - * @dataProvider createConfigInvalidKeyDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid encryption key. - */ - public function testCreateConfigInvalidKey(array $options) - { - $this->object->createConfig($options); - } - - /** - * @return array - */ - public function createConfigInvalidKeyDataProvider() - { - return [ - [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '']], - [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '0']], - ]; - } -} diff --git a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php index 26543bc097577..d867568f07118 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php @@ -17,9 +17,62 @@ protected function setUp() $this->object = new ConfigOptions(); } + public function testGetOptions() + { + $options = $this->object->getOptions(); + $this->assertInstanceOf('\Magento\Framework\Setup\TextConfigOption', $options[0]); + $this->assertEquals(1, count($options)); + } + public function testCreateConfig() { - $config = $this->object->createConfig([]); + $config = $this->object->createConfig([ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key']); $this->assertNotEmpty($config['install']['date']); } + + /** + * @param array $options + * + * @dataProvider createConfigNoKeyDataProvider + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage No encryption key provided. + */ + public function testCreateConfigNoKey(array $options) + { + $this->object->createConfig($options); + } + + /** + * @return array + */ + public function createConfigNoKeyDataProvider() + { + return [ + 'no data' => [[]], + 'no frontName' => [['something_else' => 'something']], + ]; + } + + /** + * @param array $options + * + * @dataProvider createConfigInvalidKeyDataProvider + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid encryption key. + */ + public function testCreateConfigInvalidKey(array $options) + { + $this->object->createConfig($options); + } + + /** + * @return array + */ + public function createConfigInvalidKeyDataProvider() + { + return [ + [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '']], + [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '0']], + ]; + } } diff --git a/setup/src/Magento/Setup/ConfigOptions.php b/setup/src/Magento/Setup/ConfigOptions.php index 5571ad7698dec..baffade993479 100644 --- a/setup/src/Magento/Setup/ConfigOptions.php +++ b/setup/src/Magento/Setup/ConfigOptions.php @@ -6,6 +6,7 @@ namespace Magento\Setup; use Magento\Framework\Setup\ConfigOptionsInterface; +use Magento\Framework\Setup\TextConfigOption; /** * Deployment configuration options needed for Setup application @@ -17,13 +18,30 @@ class ConfigOptions implements ConfigOptionsInterface */ const CONFIG_PATH_INSTALL_DATE = 'install/date'; + /** + * Input key for encryption key + */ + const INPUT_KEY_CRYPT_KEY = 'key'; + + /** + * @var array + */ + private $options; + + /** + * Constructor + */ + public function __construct() + { + $this->options = [new TextConfigOption('key', TextConfigOption::FRONTEND_WIZARD_TEXT, 'encryption key')]; + } + /** * {@inheritdoc} */ public function getOptions() { - // No user input is required - return []; + return $this->options; } /** @@ -33,6 +51,13 @@ public function createConfig(array $data) { $config = []; $config['install']['date'] = date('r'); + if (!isset($data[self::INPUT_KEY_CRYPT_KEY])) { + throw new \InvalidArgumentException('No encryption key provided.'); + } + if (!$data[self::INPUT_KEY_CRYPT_KEY]) { + throw new \InvalidArgumentException('Invalid encryption key.'); + } + $config['crypt']['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; return $config; } } From 043261e3c2867c34a228fbd26c127fac15604c66 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 15:19:08 -0600 Subject: [PATCH 020/214] MAGETWO-34693: Implement config options for 'crypt' segment - added one more assertion --- dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php index d867568f07118..0745b63fe7c5b 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php @@ -28,6 +28,7 @@ public function testCreateConfig() { $config = $this->object->createConfig([ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key']); $this->assertNotEmpty($config['install']['date']); + $this->assertEquals('key', $config['crypt']['key']); } /** From 0c65008b1bef4050fd9c98b6706c6843e8131b57 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 4 Mar 2015 15:30:26 -0600 Subject: [PATCH 021/214] MAGETWO-34511: Process config options - added DirectoryList into ConfigFilePool - code formatting --- .../Framework/Config/Data/ConfigData.php | 6 ++-- .../Framework/Config/File/ConfigFilePool.php | 35 +++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index d887e5515f419..6e78bcd90fdc8 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -3,7 +3,9 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework\Config\Data; + /** * Data transfer object to store config data for config options */ @@ -27,7 +29,7 @@ class ConfigData /** * Data * - * @var [] + * @var array */ private $data; @@ -36,7 +38,7 @@ class ConfigData * * @param string $fileKey * @param string $segmentKey - * @param [] $data + * @param array $data */ public function __construct($fileKey, $segmentKey, $data) { diff --git a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php index 2909ab0abe7fe..0c84a37fbcc1d 100644 --- a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php +++ b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php @@ -3,12 +3,15 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework\Config\File; +use Magento\Framework\App\Filesystem\DirectoryList; + /** * Stores file key to file name config */ -class ConfigFilePool +class ConfigFilePool { const APP_CONFIG = 'app_config'; @@ -18,13 +21,23 @@ class ConfigFilePool * @var array */ private $applicationConfigFiles = [ - // TODO: add DirectoryList - self::APP_CONFIG => 'app/etc/config.php' + self::APP_CONFIG => 'config.php' ]; - public function __construct($additionalConfigFiles) + /** + * Constructor + * + * @param DirectoryList $directoryList + * @param array $additionalConfigFiles + */ + public function __construct(DirectoryList $directoryList, $additionalConfigFiles = []) { - // TODO: implement it + $this->applicationConfigFiles = array_merge($this->applicationConfigFiles, $additionalConfigFiles); + $configurationDirectory = $directoryList->getPath(DirectoryList::CONFIG); + foreach ($this->applicationConfigFiles as $fileKey=>$filePath) { + $this->applicationConfigFiles[$fileKey] = $configurationDirectory . '/' . $filePath; + } + } /** @@ -40,16 +53,16 @@ public function getPaths() /** * Returns file path by config key * - * @param string $key + * @param string $fileKey * @return string - * @throws Exception + * @throws \Exception */ - public function getPath($key) + public function getPath($fileKey) { - if (!isset($this->applicationConfigFiles[$key])) { - throw new \Exception(''); + if (!isset($this->applicationConfigFiles[$fileKey])) { + throw new \Exception('File config key does not exist.'); } - return $this->applicationConfigFiles[$key]; + return $this->applicationConfigFiles[$fileKey]; } } From bfabbab255e378c8c2e0e252fb0c1d1b3d5211be Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 16:11:36 -0600 Subject: [PATCH 022/214] MAGETWO-34693: Implement config options for 'crypt' segment - implemented auto generate encryption key --- .../Magento/Setup/ConfigOptionsTest.php | 10 ++++----- setup/src/Magento/Setup/ConfigOptions.php | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php index 0745b63fe7c5b..b7220971c657d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php @@ -14,7 +14,9 @@ class ConfigOptionsTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->object = new ConfigOptions(); + $random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); + $random->expects($this->any())->method('getRandomString')->willReturn('key'); + $this->object = new ConfigOptions($random); } public function testGetOptions() @@ -33,14 +35,12 @@ public function testCreateConfig() /** * @param array $options - * * @dataProvider createConfigNoKeyDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage No encryption key provided. */ public function testCreateConfigNoKey(array $options) { - $this->object->createConfig($options); + $config = $this->object->createConfig($options); + $this->assertEquals(md5('key'), $config['crypt']['key']); } /** diff --git a/setup/src/Magento/Setup/ConfigOptions.php b/setup/src/Magento/Setup/ConfigOptions.php index baffade993479..7dcb5139796c1 100644 --- a/setup/src/Magento/Setup/ConfigOptions.php +++ b/setup/src/Magento/Setup/ConfigOptions.php @@ -5,6 +5,7 @@ */ namespace Magento\Setup; +use Magento\Framework\Math\Random; use Magento\Framework\Setup\ConfigOptionsInterface; use Magento\Framework\Setup\TextConfigOption; @@ -28,11 +29,19 @@ class ConfigOptions implements ConfigOptionsInterface */ private $options; + /** + * @var Random + */ + private $random; + /** * Constructor + * + * @param Random $random */ - public function __construct() + public function __construct(Random $random) { + $this->random = $random; $this->options = [new TextConfigOption('key', TextConfigOption::FRONTEND_WIZARD_TEXT, 'encryption key')]; } @@ -51,13 +60,14 @@ public function createConfig(array $data) { $config = []; $config['install']['date'] = date('r'); - if (!isset($data[self::INPUT_KEY_CRYPT_KEY])) { - throw new \InvalidArgumentException('No encryption key provided.'); - } - if (!$data[self::INPUT_KEY_CRYPT_KEY]) { + if (isset($data[self::INPUT_KEY_CRYPT_KEY]) && !$data[self::INPUT_KEY_CRYPT_KEY]) { throw new \InvalidArgumentException('Invalid encryption key.'); } - $config['crypt']['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; + if (!isset($data[self::INPUT_KEY_CRYPT_KEY])) { + $config['crypt']['key'] = md5($this->random->getRandomString(10)); + } else { + $config['crypt']['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; + } return $config; } } From 3e07d79d1892d95e28c4a4e161c6f059b570e9ca Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 4 Mar 2015 16:16:57 -0600 Subject: [PATCH 023/214] MAGETWO-34694: Implement config options for 'modules' segment - moved class to Model --- setup/src/Magento/Setup/{ => Model}/ConfigOptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename setup/src/Magento/Setup/{ => Model}/ConfigOptions.php (98%) diff --git a/setup/src/Magento/Setup/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php similarity index 98% rename from setup/src/Magento/Setup/ConfigOptions.php rename to setup/src/Magento/Setup/Model/ConfigOptions.php index 7dcb5139796c1..5fc7dc6edbc00 100644 --- a/setup/src/Magento/Setup/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup; +namespace Magento\Setup\Model; use Magento\Framework\Math\Random; use Magento\Framework\Setup\ConfigOptionsInterface; From aa914fa0da6dfc02a21ed9dbeafd8862eb7d8405 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 16:53:09 -0600 Subject: [PATCH 024/214] MAGETWO-34507: Create OptionsInterface, Option - updated docblocks --- .../Magento/Framework/Setup/AbstractConfigOption.php | 2 +- .../Magento/Framework/Setup/ConfigOptionsInterface.php | 7 ++++--- lib/internal/Magento/Framework/Setup/FlagConfigOption.php | 2 +- .../Magento/Framework/Setup/MultiSelectConfigOption.php | 2 +- .../Magento/Framework/Setup/SelectConfigOption.php | 2 +- lib/internal/Magento/Framework/Setup/TextConfigOption.php | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php index 3ee81533de821..995574ab07af5 100644 --- a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php @@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputOption; /** - * Abstract Option class in a segment of the deployment configuration + * Abstract Option class in deployment configuration tool */ abstract class AbstractConfigOption extends InputOption { diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php index 83100ca0be5dc..3140ac86f290f 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php @@ -6,19 +6,20 @@ namespace Magento\Framework\Setup; /** - * Interface for segment in deployment configuration + * Interface for handling options in deployment configuration tool */ interface ConfigOptionsInterface { /** - * Gets user input options to a segment in deployment configuration + * Gets a list of input options so that user can provide required + * information that will be used in deployment config file * * @return AbstractConfigOption[] */ public function getOptions(); /** - * Creates deployment configuration options array that will be stored in deployment config file + * Creates config array from user inputted data. This array will be stored in deployment config file * * @param array $options * @return array diff --git a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php index af72c685349f7..e02b6e99df11c 100644 --- a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php @@ -2,7 +2,7 @@ namespace Magento\Framework\Setup; /** - * Flag config option in deployment config + * Flag option in deployment config tool */ class FlagConfigOption extends AbstractConfigOption { diff --git a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php index 9820a74e348bc..a186af22c2bcb 100644 --- a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php @@ -2,7 +2,7 @@ namespace Magento\Framework\Setup; /** - * Multi-select config option in deployment config + * Multi-select option in deployment config tool */ class MultiSelectConfigOption extends AbstractConfigOption { diff --git a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/SelectConfigOption.php index 48a7a53d0acdc..fc986c275973f 100644 --- a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/SelectConfigOption.php @@ -2,7 +2,7 @@ namespace Magento\Framework\Setup; /** - * Select config option in deployment config + * Select option in deployment config tool */ class SelectConfigOption extends AbstractConfigOption { diff --git a/lib/internal/Magento/Framework/Setup/TextConfigOption.php b/lib/internal/Magento/Framework/Setup/TextConfigOption.php index b6e366479e7a3..5c021ae984f27 100644 --- a/lib/internal/Magento/Framework/Setup/TextConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/TextConfigOption.php @@ -2,7 +2,7 @@ namespace Magento\Framework\Setup; /** - * Text config option in deployment config + * Text option in deployment config tool */ class TextConfigOption extends AbstractConfigOption { From 87bf9a3d6f2beab3147d4c021ac46d3a70f85f0f Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 4 Mar 2015 17:11:06 -0600 Subject: [PATCH 025/214] MAGETWO-34694: Implement config options for 'modules' segment - added options related to modules --- .../Setup/{ => Model}/ConfigOptionsTest.php | 11 +++++-- .../src/Magento/Setup/Model/ConfigOptions.php | 33 +++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) rename dev/tests/unit/testsuite/Magento/Setup/{ => Model}/ConfigOptionsTest.php (78%) diff --git a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php similarity index 78% rename from dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php rename to dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index b7220971c657d..280dad26538c3 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup; +namespace Magento\Setup\Model; class ConfigOptionsTest extends \PHPUnit_Framework_TestCase { @@ -16,14 +16,17 @@ protected function setUp() { $random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); $random->expects($this->any())->method('getRandomString')->willReturn('key'); - $this->object = new ConfigOptions($random); + $loader = $this->getMock('\Magento\Framework\Module\ModuleList\Loader', [], [], '', false); + $loader->expects($this->any())->method('load')->willReturn(['module1', 'module2']); + $this->object = new ConfigOptions($random, $loader); } public function testGetOptions() { $options = $this->object->getOptions(); $this->assertInstanceOf('\Magento\Framework\Setup\TextConfigOption', $options[0]); - $this->assertEquals(1, count($options)); + $this->assertInstanceOf('\Magento\Framework\Setup\MultiSelectConfigOption', $options[1]); + $this->assertEquals(2, count($options)); } public function testCreateConfig() @@ -31,6 +34,8 @@ public function testCreateConfig() $config = $this->object->createConfig([ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key']); $this->assertNotEmpty($config['install']['date']); $this->assertEquals('key', $config['crypt']['key']); + $this->assertNotEmpty($config['modules']); + $this->assertEquals(2, count($config['modules'])); } /** diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 5fc7dc6edbc00..f67ef7ef821a9 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -8,6 +8,8 @@ use Magento\Framework\Math\Random; use Magento\Framework\Setup\ConfigOptionsInterface; use Magento\Framework\Setup\TextConfigOption; +use Magento\Framework\Setup\MultiSelectConfigOption; +use Magento\Framework\Module\ModuleList\Loader; /** * Deployment configuration options needed for Setup application @@ -24,6 +26,16 @@ class ConfigOptions implements ConfigOptionsInterface */ const INPUT_KEY_CRYPT_KEY = 'key'; + /** + * Path to modules in the deployment config + */ + const CONFIG_PATH_MODULES = 'modules'; + + /** + * @var array + */ + private $moduleList; + /** * @var array */ @@ -38,11 +50,12 @@ class ConfigOptions implements ConfigOptionsInterface * Constructor * * @param Random $random + * @param Loader $moduleLoader */ - public function __construct(Random $random) + public function __construct(Random $random, Loader $moduleLoader) { $this->random = $random; - $this->options = [new TextConfigOption('key', TextConfigOption::FRONTEND_WIZARD_TEXT, 'encryption key')]; + $this->moduleList = $moduleLoader->load(); } /** @@ -50,7 +63,16 @@ public function __construct(Random $random) */ public function getOptions() { - return $this->options; + return [ + new TextConfigOption('key', TextConfigOption::FRONTEND_WIZARD_TEXT, 'encryption key'), + new MultiSelectConfigOption( + 'modules', + MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, + $this->moduleList, + 'modules list', + $this->moduleList + ), + ]; } /** @@ -68,6 +90,11 @@ public function createConfig(array $data) } else { $config['crypt']['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; } + + foreach ($this->moduleList as $key) { + $config['modules'][$key] = 1; + } + return $config; } } From cc88c5faf007cdc4298f958498609f83cdec58f5 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 4 Mar 2015 17:23:42 -0600 Subject: [PATCH 026/214] MAGETWO-34694: Implement config options for 'modules' segment - use constants instead of string --- setup/src/Magento/Setup/Model/ConfigOptions.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index f67ef7ef821a9..df3502bb45e2c 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -36,11 +36,6 @@ class ConfigOptions implements ConfigOptionsInterface */ private $moduleList; - /** - * @var array - */ - private $options; - /** * @var Random */ @@ -64,9 +59,12 @@ public function __construct(Random $random, Loader $moduleLoader) public function getOptions() { return [ - new TextConfigOption('key', TextConfigOption::FRONTEND_WIZARD_TEXT, 'encryption key'), + new TextConfigOption(self::INPUT_KEY_CRYPT_KEY, + TextConfigOption::FRONTEND_WIZARD_TEXT, + 'encryption key' + ), new MultiSelectConfigOption( - 'modules', + self::CONFIG_PATH_MODULES, MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, $this->moduleList, 'modules list', From 7400a9530036e50bce2bdf7724c3c1e3a31ab4f8 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 17:45:20 -0600 Subject: [PATCH 027/214] MAGETWO-34507: Create OptionsInterface, Option - made changes according to CR feedback --- .../Magento/Framework/Setup/FlagConfigOptionTest.php | 4 ++-- .../Framework/Setup/MultiSelectConfigOptionTest.php | 4 ++-- .../Magento/Framework/Setup/SelectConfigOptionTest.php | 4 ++-- .../Magento/Framework/Setup/TextConfigOptionTest.php | 4 ++-- .../Magento/Framework/Setup/AbstractConfigOption.php | 6 +++--- lib/internal/Magento/Framework/Setup/FlagConfigOption.php | 6 +++++- .../Magento/Framework/Setup/MultiSelectConfigOption.php | 8 +++++++- .../Magento/Framework/Setup/SelectConfigOption.php | 8 +++++++- lib/internal/Magento/Framework/Setup/TextConfigOption.php | 8 +++++++- 9 files changed, 37 insertions(+), 15 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php index 9cf7c23767274..9c79e3ef5b9c1 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php @@ -7,9 +7,9 @@ class FlagConfigOptionTest extends \PHPUnit_Framework_TestCase { - public function testGetFrontendInput() + public function testGetFrontendType() { $option = new FlagConfigOption('test', FlagConfigOption::FRONTEND_WIZARD_FLAG); - $this->assertEquals(FlagConfigOption::FRONTEND_WIZARD_FLAG, $option->getFrontendInput()); + $this->assertEquals(FlagConfigOption::FRONTEND_WIZARD_FLAG, $option->getFrontendType()); } } diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php index 046d11ef07fad..ff5c390c5a947 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php @@ -25,10 +25,10 @@ public function testConstructNoOptions() new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, []); } - public function testGetFrontendInput() + public function testGetFrontendType() { $option = new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, ['a', 'b']); - $this->assertEquals(MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, $option->getFrontendInput()); + $this->assertEquals(MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, $option->getFrontendType()); } public function testGetSelectOptions() diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php index 27c7465a4ca4e..2efd73a15d1de 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php @@ -25,10 +25,10 @@ public function testConstructNoOptions() new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, []); } - public function testGetFrontendInput() + public function testGetFrontendType() { $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); - $this->assertEquals(SelectConfigOption::FRONTEND_WIZARD_SELECT, $option->getFrontendInput()); + $this->assertEquals(SelectConfigOption::FRONTEND_WIZARD_SELECT, $option->getFrontendType()); } public function testGetSelectOptions() diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php index 83cae1dc0b29d..b445ef112c641 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php @@ -16,10 +16,10 @@ public function testConstructInvalidFrontendType() new TextConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT); } - public function testGetFrontendInput() + public function testGetFrontendType() { $option = new TextConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT); - $this->assertEquals(TextConfigOption::FRONTEND_WIZARD_TEXT, $option->getFrontendInput()); + $this->assertEquals(TextConfigOption::FRONTEND_WIZARD_TEXT, $option->getFrontendType()); } /** diff --git a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php index 995574ab07af5..ecaf9e4392275 100644 --- a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php @@ -25,16 +25,16 @@ abstract class AbstractConfigOption extends InputOption * @param string $name * @param string $frontendType * @param string $description - * @param string|null $default * @param int $mode + * @param string|null $default * @param string|null $shortcut */ public function __construct( $name, $frontendType, $description = '', - $default = null, $mode, + $default = null, $shortcut = null ) { $this->frontendType = $frontendType; @@ -46,7 +46,7 @@ public function __construct( * * @return string */ - public function getFrontendInput() + public function getFrontendType() { return $this->frontendType; } diff --git a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php index e02b6e99df11c..6d267a561a12d 100644 --- a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php @@ -1,4 +1,8 @@ Date: Wed, 4 Mar 2015 18:11:16 -0600 Subject: [PATCH 028/214] MAGETWO-34507: Create OptionsInterface, Option - made more changes according to CR feedback --- .../Framework/Setup/MultiSelectConfigOptionTest.php | 6 +++--- .../Magento/Framework/Setup/SelectConfigOptionTest.php | 6 +++--- .../Magento/Framework/Setup/TextConfigOptionTest.php | 4 ++-- .../Magento/Framework/Setup/AbstractConfigOption.php | 6 +++--- .../Magento/Framework/Setup/FlagConfigOption.php | 2 -- .../Framework/Setup/MultiSelectConfigOption.php | 10 ++++++---- .../Magento/Framework/Setup/SelectConfigOption.php | 8 ++++---- .../Magento/Framework/Setup/TextConfigOption.php | 8 ++++---- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php index ff5c390c5a947..6baa7b0256ec1 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php @@ -9,7 +9,7 @@ class MultiSelectConfigOptionTest extends \PHPUnit_Framework_TestCase { /** * @expectedException \InvalidArgumentException - * @expectedMessage Frontend input type has to be select or radio. + * @expectedExceptionMessage Frontend input type has to be 'multiselect', 'textarea' or 'checkbox'. */ public function testConstructInvalidFrontendType() { @@ -18,7 +18,7 @@ public function testConstructInvalidFrontendType() /** * @expectedException \InvalidArgumentException - * @expectedMessage Select options can't be empty. + * @expectedExceptionMessage Select options can't be empty. */ public function testConstructNoOptions() { @@ -39,7 +39,7 @@ public function testGetSelectOptions() /** * @expectedException \InvalidArgumentException - * @expectedMessage Frontend input type has to be text, textarea or password. + * @expectedExceptionMessage Value specified for */ public function testValidateException() { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php index 2efd73a15d1de..589f8a3ebfd2d 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php @@ -9,7 +9,7 @@ class SelectConfigOptionTest extends \PHPUnit_Framework_TestCase { /** * @expectedException \InvalidArgumentException - * @expectedMessage Frontend input type has to be select or radio. + * @expectedExceptionMessage Frontend input type has to be 'select' or 'radio'. */ public function testConstructInvalidFrontendType() { @@ -18,7 +18,7 @@ public function testConstructInvalidFrontendType() /** * @expectedException \InvalidArgumentException - * @expectedMessage Select options can't be empty. + * @expectedExceptionMessage Select options can't be empty. */ public function testConstructNoOptions() { @@ -39,7 +39,7 @@ public function testGetSelectOptions() /** * @expectedException \InvalidArgumentException - * @expectedMessage Frontend input type has to be text, textarea or password. + * @expectedExceptionMessage Value specified for */ public function testValidateException() { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php index b445ef112c641..2a7ea40621ea7 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php @@ -9,7 +9,7 @@ class TextConfigOptionTest extends \PHPUnit_Framework_TestCase { /** * @expectedException \InvalidArgumentException - * @expectedMessage Frontend input type has to be text, textarea or password. + * @expectedExceptionMessage Frontend input type has to be 'text', 'textarea' or 'password'. */ public function testConstructInvalidFrontendType() { @@ -24,7 +24,7 @@ public function testGetFrontendType() /** * @expectedException \InvalidArgumentException - * @expectedMessage must be a string + * @expectedExceptionMessage must be a string */ public function testValidateException() { diff --git a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php index ecaf9e4392275..e4540f9120293 100644 --- a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php @@ -26,7 +26,7 @@ abstract class AbstractConfigOption extends InputOption * @param string $frontendType * @param string $description * @param int $mode - * @param string|null $default + * @param string|null $defaultValue * @param string|null $shortcut */ public function __construct( @@ -34,11 +34,11 @@ public function __construct( $frontendType, $description = '', $mode, - $default = null, + $defaultValue = null, $shortcut = null ) { $this->frontendType = $frontendType; - parent::__construct($name, $shortcut, $mode, $description, $default); + parent::__construct($name, $shortcut, $mode, $description, $defaultValue); } /** diff --git a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php index 6d267a561a12d..2ee87626b5fd0 100644 --- a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/FlagConfigOption.php @@ -20,13 +20,11 @@ class FlagConfigOption extends AbstractConfigOption * * @param string $name * @param string $description - * @param string $default * @param string|null $shortCut */ public function __construct( $name, $description = '', - $default = '', $shortCut = null ) { parent::__construct($name, self::FRONTEND_WIZARD_FLAG, $description, self::VALUE_NONE, null, $shortCut); diff --git a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php index 3c6cfea41e1b8..4aa12dfae471f 100644 --- a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php @@ -31,7 +31,7 @@ class MultiSelectConfigOption extends AbstractConfigOption * @param string $frontendType * @param array $selectOptions * @param string $description - * @param string $default + * @param string $defaultValue * @param string|null $shortCut * @throws \InvalidArgumentException */ @@ -40,11 +40,13 @@ public function __construct( $frontendType, array $selectOptions, $description = '', - $default = '', + $defaultValue = '', $shortCut = null ) { if ($frontendType != self::FRONTEND_WIZARD_MULTISELECT && $frontendType != self::FRONTEND_WIZARD_CHECKBOX) { - throw new \InvalidArgumentException('Frontend input type has to be multiselect, textarea or checkbox.'); + throw new \InvalidArgumentException( + "Frontend input type has to be 'multiselect', 'textarea' or 'checkbox'." + ); } if (!$selectOptions) { throw new \InvalidArgumentException('Select options can\'t be empty.'); @@ -55,7 +57,7 @@ public function __construct( $frontendType, $description, self::VALUE_REQUIRED, - $default, + $defaultValue, $shortCut ); } diff --git a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/SelectConfigOption.php index 2a19957175dbb..882857056508e 100644 --- a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/SelectConfigOption.php @@ -31,7 +31,7 @@ class SelectConfigOption extends AbstractConfigOption * @param string $frontendType * @param array $selectOptions * @param string $description - * @param string $default + * @param string $defaultValue * @param string|null $shortCut * @throws \InvalidArgumentException */ @@ -40,11 +40,11 @@ public function __construct( $frontendType, array $selectOptions, $description = '', - $default = '', + $defaultValue = '', $shortCut = null ) { if ($frontendType != self::FRONTEND_WIZARD_SELECT && $frontendType != self::FRONTEND_WIZARD_RADIO) { - throw new \InvalidArgumentException('Frontend input type has to be select or radio.'); + throw new \InvalidArgumentException("Frontend input type has to be 'select' or 'radio'."); } if (!$selectOptions) { throw new \InvalidArgumentException('Select options can\'t be empty.'); @@ -55,7 +55,7 @@ public function __construct( $frontendType, $description, self::VALUE_REQUIRED, - $default, + $defaultValue, $shortCut ); } diff --git a/lib/internal/Magento/Framework/Setup/TextConfigOption.php b/lib/internal/Magento/Framework/Setup/TextConfigOption.php index 023f18af52343..be9db04b14435 100644 --- a/lib/internal/Magento/Framework/Setup/TextConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/TextConfigOption.php @@ -24,7 +24,7 @@ class TextConfigOption extends AbstractConfigOption * @param string $name * @param string $frontendType * @param string $description - * @param string|null $default + * @param string|null $defaultValue * @param string|null $shortCut * @throws \InvalidArgumentException */ @@ -32,15 +32,15 @@ public function __construct( $name, $frontendType, $description = '', - $default = null, + $defaultValue = null, $shortCut = null ) { if ($frontendType != self::FRONTEND_WIZARD_TEXT && $frontendType != self::FRONTEND_WIZARD_PASSWORD && $frontendType != self::FRONTEND_WIZARD_TEXTAREA ) { - throw new \InvalidArgumentException('Frontend input type has to be text, textarea or password.'); + throw new \InvalidArgumentException("Frontend input type has to be 'text', 'textarea' or 'password'."); } - parent::__construct($name, $frontendType, $description, self::VALUE_REQUIRED, $default, $shortCut); + parent::__construct($name, $frontendType, $description, self::VALUE_REQUIRED, $defaultValue, $shortCut); } /** From eb92872aad30ef198edc926003ded94b979b20f8 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 4 Mar 2015 18:20:52 -0600 Subject: [PATCH 029/214] MAGETWO-34509: Collector for OptionsInterfaces - removed recursive searching logic - added integration test --- .../Model/ConfigOptionsCollectorTest.php | 82 +++++++++++++++++++ .../Setup/Model/ConfigOptionsCollector.php | 69 +++------------- 2 files changed, 95 insertions(+), 56 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php new file mode 100644 index 0000000000000..6f339e1a77f29 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php @@ -0,0 +1,82 @@ +objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false); + $this->objectManagerProvider + ->expects($this->any()) + ->method('get') + ->willReturn(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()); + $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get('Magento\Setup\Model\ConfigOptions'); + $backendOptions = new \Magento\Backend\Setup\ConfigOptions(); + $this->expected = [ + 'Magento\Setup\Model\ConfigOptions' => ['options' => $setupOptions->getOptions(), 'enabled' => true], + 'Magento\Backend\Setup\ConfigOptions' => ['options' => $backendOptions->getOptions()], + ]; + } + + public function testCollectOptions() + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + /** @var \Magento\Setup\Model\ConfigOptionsCollector $object */ + $object = $objectManager->create( + 'Magento\Setup\Model\ConfigOptionsCollector', + ['objectManagerProvider' => $this->objectManagerProvider] + ); + $result = $object->collectOptions(); + $this->assertOptions($result, true); + + } + + public function testCollectOptionsDisabledModules() + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $moduleListMock->expects($this->any())->method('has')->willReturn(false); + $object = $objectManager->create( + 'Magento\Setup\Model\ConfigOptionsCollector', + [ + 'objectManagerProvider' => $this->objectManagerProvider, + 'moduleList' => $moduleListMock, + ] + ); + $result = $object->collectOptions(); + $this->assertOptions($result, false); + } + + /** + * Assert options array + * + * @param $actual + * @param $enabled + */ + private function assertOptions($actual, $enabled) + { + $expected = []; + foreach ($this->expected as $key => $value) { + $expected[$key] = $value; + if (!isset($value['enabled'])) { + $expected[$key]['enabled'] = $enabled; + } + } + $this->assertEquals($expected, $actual); + } +} diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php index baff4f7dcb622..f75c04a77ba89 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php @@ -1,4 +1,8 @@ moduleList->getNames() as $moduleName) { + foreach ($this->fullModuleList->getNames() as $moduleName) { $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptions'; if (class_exists($optionsClassName)) { $optionsClass = $this->objectManagerProvider->get()->create($optionsClassName); @@ -91,41 +96,13 @@ public function collectOptions() } } - // go through framework - $frameworkOptionsFiles = []; - $this->collectRecursively( - $this->filesystem->getDirectoryRead(DirectoryList::LIB_INTERNAL), - 'Magento/Framework', - $frameworkOptionsFiles - ); - foreach ($frameworkOptionsFiles as $frameworkOptionsFile) { - // remove .php - $frameworkOptionsFile = substr($frameworkOptionsFile, 0, -4); - $frameworkOptionsClassName = str_replace('/', '\\', $frameworkOptionsFile); - $optionsClass = $this->objectManagerProvider->get()->create($frameworkOptionsClassName); - if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { - $optionsList[$frameworkOptionsClassName] = [ - 'options' => $optionsClass->getOptions(), - 'enabled' => true, - ]; - } - } - - // go through setup - $setupOptionsFiles = []; - $this->collectRecursively( - $this->filesystem->getDirectoryRead(DirectoryList::ROOT), - 'setup/src', - $setupOptionsFiles - ); - foreach ($setupOptionsFiles as $setupOptionsFile) { - // remove setup/src/ and .php - $setupOptionsFile = substr($setupOptionsFile, 10, -4); - $setupOptionsClassName = str_replace('/', '\\', $setupOptionsFile); - $optionsClass = $this->objectManagerProvider->get()->create($setupOptionsClassName); - if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { + // check setup + $setupOptionsClassName = 'Magento\Setup\Model\ConfigOptions'; + if (class_exists($setupOptionsClassName)) { + $setupOptionsClass = $this->objectManagerProvider->get()->create($setupOptionsClassName); + if ($setupOptionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { $optionsList[$setupOptionsClassName] = [ - 'options' => $optionsClass->getOptions(), + 'options' => $setupOptionsClass->getOptions(), 'enabled' => true, ]; } @@ -133,24 +110,4 @@ public function collectOptions() return $optionsList; } - - /** - * Collects Options files recursively - * - * @param Filesystem\Directory\ReadInterface $dir - * @param string $path - * @param array $result - */ - private function collectRecursively(\Magento\Framework\Filesystem\Directory\ReadInterface $dir, $path, &$result) - { - $localResult = $dir->search($path . '/Setup/ConfigOptions.php'); - foreach ($localResult as $optionFile) { - $result[] = $optionFile; - } - - // goes deeper if current search is successful or next depth level exists - if ($localResult || $dir->search($path . '/*')) { - $this->collectRecursively($dir, $path . '/*', $result); - } - } } From 2f2e4ecca26b907d3f15a25b14e69b63c65fb8a8 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Thu, 5 Mar 2015 01:04:04 -0600 Subject: [PATCH 030/214] MAGETWO-34511: Process config options - added console application --- setup/cli.php | 27 ++++++ .../src/Magento/Setup/Console/Application.php | 66 +++++++++++++++ .../Console/Command/ConfigInstallCommand.php | 64 ++++++++++++++ setup/src/Magento/Setup/Model/ConfigModel.php | 83 +++++++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 setup/cli.php create mode 100644 setup/src/Magento/Setup/Console/Application.php create mode 100644 setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php create mode 100644 setup/src/Magento/Setup/Model/ConfigModel.php diff --git a/setup/cli.php b/setup/cli.php new file mode 100644 index 0000000000000..859538a034421 --- /dev/null +++ b/setup/cli.php @@ -0,0 +1,27 @@ +getMessage(); + } else { + echo << +
+

+ Autoload error

+
+

{$e->getMessage()}

+ +HTML; + } + exit(1); +} + +$application = new Magento\Setup\Console\Application('Magento2 CLI', '0.0.1'); +$application->run(); diff --git a/setup/src/Magento/Setup/Console/Application.php b/setup/src/Magento/Setup/Console/Application.php new file mode 100644 index 0000000000000..4e4e024165a10 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Application.php @@ -0,0 +1,66 @@ +getApplicationCommands() as $command) { + $commands[] = $this->add($command); + } + + return $commands; + } + + /** + * Gets application commands + * + * @return array + */ + protected function getApplicationCommands() + { + $commandsList = []; + + $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')->getServiceManager(); + $setupFiles = glob(BP . '/setup/src/Magento/Setup/Console/Command/*Command.php'); + if ($setupFiles) { + foreach ($setupFiles as $file) { + if (preg_match("#(Magento/Setup/Console/Command/.*Command).php#", $file, $parts)) { + $class = str_replace('/', '\\', $parts[1]); + $commandObject = null; + try { + $commandObject = $serviceManager->create($class); + } catch (\Exception $e) { + try { + echo "Could not create command using service manager: " . $e->getMessage() . "\n"; + $commandObject = new $class(); + } catch (\Exception $e) { + } + } + if (null !== $commandObject) { + $commandsList[] = $commandObject; + } + } + } + } + + return $commandsList; + } +} diff --git a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php new file mode 100644 index 0000000000000..4cc1b9cce2a3f --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php @@ -0,0 +1,64 @@ +configModel = $configModel; + parent::__construct(); + } + + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $options = $this->configModel->getAvailableOptions(); + + $this + ->setName('config:install') + ->setDescription('Install deployment configuration') + ->setDefinition($options); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + // TODO: wrap into try catch + // TODO: think about error and log message processing + $this->configModel->process($input->getOptions()); + + } + + +} diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php new file mode 100644 index 0000000000000..5c0e6153d21b0 --- /dev/null +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -0,0 +1,83 @@ +configFilePool = $configFilePool; + $this->collector = $collector; + } + + /** + * Gets available config options + * + * @return array + */ + public function getAvailableOptions() + { + $optionCollection = []; + $options = $this->collector->collectOptions(); + + foreach ($options as $option) { + // TODO: we need to get rid of keys here + if ($option['enabled']) { + $optionCollection = array_merge($optionCollection, $option['options']); + } + } + + return $optionCollection; + } + + /** + * Process input options + * + * @param array $inputOptions + */ + public function process($inputOptions) + { + $fileConfigStorage = []; + + $options = $this->collector->collectOptions(); + foreach ($options as $option) { + if ($option['enabled']) { + // TODO: add isset and check of instance here + $conf = $option['configOption']->createConfig($inputOptions); + + // TODO: this file should be returned by ConfigOption + $defaultConfigFile = ConfigFilePool::APP_CONFIG; + + if (isset($fileConfigStorage[$defaultConfigFile])) { + $fileConfigStorage[$defaultConfigFile] = array_merge( + $fileConfigStorage[$defaultConfigFile], + $conf + ); + } else { + $fileConfigStorage[$defaultConfigFile] = $conf; + } + } + } + + var_dump($fileConfigStorage); + + } + +} From ab2383129e0f22e04c1d92f8d4a84b2c7f61b248 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 5 Mar 2015 10:16:37 -0600 Subject: [PATCH 031/214] MAGETWO-34694: Implement config options for 'modules' segment - Changes based on CR --- setup/src/Magento/Setup/Model/ConfigOptions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index df3502bb45e2c..4268a26975e30 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -89,8 +89,10 @@ public function createConfig(array $data) $config['crypt']['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; } - foreach ($this->moduleList as $key) { - $config['modules'][$key] = 1; + if (isset($this->moduleList)) { + foreach ($this->moduleList as $key) { + $config['modules'][$key] = 1; + } } return $config; From fb3495b709118f09a12169e1880cfc811d06e319 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 10:48:47 -0600 Subject: [PATCH 032/214] MAGETWO-34507: Create OptionsInterface, Option - made changes according to CR feedback --- app/code/Magento/Backend/Setup/ConfigOptions.php | 2 +- .../Framework/Setup/{ => Option}/FlagConfigOptionTest.php | 2 +- .../Setup/{ => Option}/MultiSelectConfigOptionTest.php | 2 +- .../Framework/Setup/{ => Option}/SelectConfigOptionTest.php | 2 +- .../Framework/Setup/{ => Option}/TextConfigOptionTest.php | 2 +- .../Framework/Setup/{ => Option}/AbstractConfigOption.php | 2 +- .../Magento/Framework/Setup/{ => Option}/FlagConfigOption.php | 2 +- .../Framework/Setup/{ => Option}/MultiSelectConfigOption.php | 4 ++-- .../Framework/Setup/{ => Option}/SelectConfigOption.php | 2 +- .../Magento/Framework/Setup/{ => Option}/TextConfigOption.php | 2 +- setup/src/Magento/Setup/Model/ConfigOptions.php | 4 ++-- 11 files changed, 13 insertions(+), 13 deletions(-) rename dev/tests/unit/testsuite/Magento/Framework/Setup/{ => Option}/FlagConfigOptionTest.php (90%) rename dev/tests/unit/testsuite/Magento/Framework/Setup/{ => Option}/MultiSelectConfigOptionTest.php (97%) rename dev/tests/unit/testsuite/Magento/Framework/Setup/{ => Option}/SelectConfigOptionTest.php (97%) rename dev/tests/unit/testsuite/Magento/Framework/Setup/{ => Option}/TextConfigOptionTest.php (96%) rename lib/internal/Magento/Framework/Setup/{ => Option}/AbstractConfigOption.php (96%) rename lib/internal/Magento/Framework/Setup/{ => Option}/FlagConfigOption.php (94%) rename lib/internal/Magento/Framework/Setup/{ => Option}/MultiSelectConfigOption.php (95%) rename lib/internal/Magento/Framework/Setup/{ => Option}/SelectConfigOption.php (98%) rename lib/internal/Magento/Framework/Setup/{ => Option}/TextConfigOption.php (97%) diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php index 0d157a3d410ea..4d1b7e21d43d1 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -6,7 +6,7 @@ namespace Magento\Backend\Setup; use Magento\Framework\Setup\ConfigOptionsInterface; -use Magento\Framework\Setup\TextConfigOption; +use Magento\Framework\Setup\Option\TextConfigOption; /* * Deployment configuration options needed for Backend module diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/FlagConfigOptionTest.php similarity index 90% rename from dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Setup/Option/FlagConfigOptionTest.php index 9c79e3ef5b9c1..6f53c498f2c08 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/FlagConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/FlagConfigOptionTest.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; class FlagConfigOptionTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/MultiSelectConfigOptionTest.php similarity index 97% rename from dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Setup/Option/MultiSelectConfigOptionTest.php index 6baa7b0256ec1..d43e86c4a8083 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/MultiSelectConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/MultiSelectConfigOptionTest.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; class MultiSelectConfigOptionTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/SelectConfigOptionTest.php similarity index 97% rename from dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Setup/Option/SelectConfigOptionTest.php index 589f8a3ebfd2d..b308068bbf9f3 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/SelectConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/SelectConfigOptionTest.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; class SelectConfigOptionTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/TextConfigOptionTest.php similarity index 96% rename from dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Setup/Option/TextConfigOptionTest.php index 2a7ea40621ea7..9721acf83d88c 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/TextConfigOptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/TextConfigOptionTest.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; class TextConfigOptionTest extends \PHPUnit_Framework_TestCase { diff --git a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php similarity index 96% rename from lib/internal/Magento/Framework/Setup/AbstractConfigOption.php rename to lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php index e4540f9120293..fe65a9d504cb4 100644 --- a/lib/internal/Magento/Framework/Setup/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; use Symfony\Component\Console\Input\InputOption; diff --git a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php similarity index 94% rename from lib/internal/Magento/Framework/Setup/FlagConfigOption.php rename to lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php index 2ee87626b5fd0..e3cc8a175680c 100644 --- a/lib/internal/Magento/Framework/Setup/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; /** * Flag option in deployment config tool diff --git a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php similarity index 95% rename from lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php rename to lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php index 4aa12dfae471f..c36d461e4d4a4 100644 --- a/lib/internal/Magento/Framework/Setup/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; /** * Multi-select option in deployment config tool @@ -56,7 +56,7 @@ public function __construct( $name, $frontendType, $description, - self::VALUE_REQUIRED, + self::VALUE_REQUIRED | self::VALUE_IS_ARRAY, $defaultValue, $shortCut ); diff --git a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php similarity index 98% rename from lib/internal/Magento/Framework/Setup/SelectConfigOption.php rename to lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php index 882857056508e..42a42704a47ce 100644 --- a/lib/internal/Magento/Framework/Setup/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; /** * Select option in deployment config tool diff --git a/lib/internal/Magento/Framework/Setup/TextConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php similarity index 97% rename from lib/internal/Magento/Framework/Setup/TextConfigOption.php rename to lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php index be9db04b14435..82eaf2b4fa738 100644 --- a/lib/internal/Magento/Framework/Setup/TextConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\Setup\Option; /** * Text option in deployment config tool diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 4268a26975e30..2a9c947b5ca95 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -7,8 +7,8 @@ use Magento\Framework\Math\Random; use Magento\Framework\Setup\ConfigOptionsInterface; -use Magento\Framework\Setup\TextConfigOption; -use Magento\Framework\Setup\MultiSelectConfigOption; +use Magento\Framework\Setup\Option\TextConfigOption; +use Magento\Framework\Setup\Option\MultiSelectConfigOption; use Magento\Framework\Module\ModuleList\Loader; /** From 19e6123d046da072085803114b4842884d7ac268 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 11:10:42 -0600 Subject: [PATCH 033/214] MAGETWO-34507: Create OptionsInterface, Option - changed default value to array type in MultiselectConfigOption --- .../Framework/Setup/Option/MultiSelectConfigOption.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php index c36d461e4d4a4..0133a03300732 100644 --- a/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php @@ -31,7 +31,7 @@ class MultiSelectConfigOption extends AbstractConfigOption * @param string $frontendType * @param array $selectOptions * @param string $description - * @param string $defaultValue + * @param array $defaultValue * @param string|null $shortCut * @throws \InvalidArgumentException */ @@ -40,7 +40,7 @@ public function __construct( $frontendType, array $selectOptions, $description = '', - $defaultValue = '', + array $defaultValue = [], $shortCut = null ) { if ($frontendType != self::FRONTEND_WIZARD_MULTISELECT && $frontendType != self::FRONTEND_WIZARD_CHECKBOX) { From 42c63b994d76bdc060330a0542cbdbea9936fdfd Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 11:41:21 -0600 Subject: [PATCH 034/214] MAGETWO-34507: Create OptionsInterface, Option - corrected docblock --- .../Magento/Framework/Setup/ConfigOptionsInterface.php | 4 ++-- .../Magento/Framework/Setup/Option/AbstractConfigOption.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php index 3140ac86f290f..271afd7f48d45 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php @@ -14,7 +14,7 @@ interface ConfigOptionsInterface * Gets a list of input options so that user can provide required * information that will be used in deployment config file * - * @return AbstractConfigOption[] + * @return Option\AbstractConfigOption[] */ public function getOptions(); @@ -22,7 +22,7 @@ public function getOptions(); * Creates config array from user inputted data. This array will be stored in deployment config file * * @param array $options - * @return array + * @return \Magento\Framework\Config\Data\ConfigData[] * @throws \InvalidArgumentException */ public function createConfig(array $options); diff --git a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php index fe65a9d504cb4..963496eb87be2 100644 --- a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php @@ -26,7 +26,7 @@ abstract class AbstractConfigOption extends InputOption * @param string $frontendType * @param string $description * @param int $mode - * @param string|null $defaultValue + * @param string|array|null $defaultValue * @param string|null $shortcut */ public function __construct( From 5825b9742d6ab9a15e45553abada333c0c96d771 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 12:06:08 -0600 Subject: [PATCH 035/214] MAGETWO-34658: Implement config options for 'session' segment - added session_save option - changed Setup\Model\ConfigOptions class to return ConfigData[] --- .../Magento/Setup/Model/ConfigOptionsTest.php | 40 ++++++++++++--- .../Framework/Config/Data/ConfigData.php | 4 ++ .../src/Magento/Setup/Model/ConfigOptions.php | 50 ++++++++++++++++--- 3 files changed, 79 insertions(+), 15 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 280dad26538c3..d801020a3cc29 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -24,18 +24,42 @@ protected function setUp() public function testGetOptions() { $options = $this->object->getOptions(); - $this->assertInstanceOf('\Magento\Framework\Setup\TextConfigOption', $options[0]); - $this->assertInstanceOf('\Magento\Framework\Setup\MultiSelectConfigOption', $options[1]); - $this->assertEquals(2, count($options)); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[0]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\MultiSelectConfigOption', $options[1]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\SelectConfigOption', $options[2]); + $this->assertEquals(3, count($options)); } public function testCreateConfig() { - $config = $this->object->createConfig([ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key']); - $this->assertNotEmpty($config['install']['date']); - $this->assertEquals('key', $config['crypt']['key']); + $config = $this->object->createConfig([ + ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key', + ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db' + ]); + $this->assertEquals(4, count($config)); + $this->assertNotEmpty($config['install']); + $this->assertNotEmpty($config['crypt']); + $this->assertEquals('key', $config['crypt']->getData()['key']); $this->assertNotEmpty($config['modules']); - $this->assertEquals(2, count($config['modules'])); + $this->assertEquals(2, count($config['modules']->getData())); + $this->assertNotEmpty($config['session']); + $this->assertEquals('db', $config['session']->getData()['save']); + } + + public function testCreateConfigNoSessionSave() + { + $config = $this->object->createConfig([ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key']); + $this->assertNotEmpty($config['session']); + $this->assertEquals('files', $config['session']->getData()['save']); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid session save location. + */ + public function testCreateConfigInvalidSessionSave() + { + $this->object->createConfig([ConfigOptions::INPUT_KEY_SESSION_SAVE => 'invalid']); } /** @@ -45,7 +69,7 @@ public function testCreateConfig() public function testCreateConfigNoKey(array $options) { $config = $this->object->createConfig($options); - $this->assertEquals(md5('key'), $config['crypt']['key']); + $this->assertEquals(md5('key'), $config['crypt']->getData()['key']); } /** diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index 6e78bcd90fdc8..54332a6499adc 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -11,6 +11,10 @@ */ class ConfigData { + /** + * Default file key + */ + const DEFAULT_FILE_KEY = 'config.php'; /** * File key diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 2a9c947b5ca95..67460eaf7772f 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -5,8 +5,10 @@ */ namespace Magento\Setup\Model; +use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Math\Random; use Magento\Framework\Setup\ConfigOptionsInterface; +use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; use Magento\Framework\Setup\Option\MultiSelectConfigOption; use Magento\Framework\Module\ModuleList\Loader; @@ -26,6 +28,11 @@ class ConfigOptions implements ConfigOptionsInterface */ const INPUT_KEY_CRYPT_KEY = 'key'; + /** + * Input key for session save + */ + const INPUT_KEY_SESSION_SAVE = 'session_save'; + /** * Path to modules in the deployment config */ @@ -59,7 +66,8 @@ public function __construct(Random $random, Loader $moduleLoader) public function getOptions() { return [ - new TextConfigOption(self::INPUT_KEY_CRYPT_KEY, + new TextConfigOption( + self::INPUT_KEY_CRYPT_KEY, TextConfigOption::FRONTEND_WIZARD_TEXT, 'encryption key' ), @@ -70,6 +78,13 @@ public function getOptions() 'modules list', $this->moduleList ), + new SelectConfigOption( + self::INPUT_KEY_SESSION_SAVE, + SelectConfigOption::FRONTEND_WIZARD_SELECT, + ['files', 'db'], + 'session save location', + 'files' + ), ]; } @@ -78,23 +93,44 @@ public function getOptions() */ public function createConfig(array $data) { - $config = []; - $config['install']['date'] = date('r'); + $configData = []; + // install segment + $installData['date'] = date('r'); + $configData['install'] = new ConfigData(ConfigData::DEFAULT_FILE_KEY, 'install', $installData); + + // crypt segment if (isset($data[self::INPUT_KEY_CRYPT_KEY]) && !$data[self::INPUT_KEY_CRYPT_KEY]) { throw new \InvalidArgumentException('Invalid encryption key.'); } + $cryptData = []; if (!isset($data[self::INPUT_KEY_CRYPT_KEY])) { - $config['crypt']['key'] = md5($this->random->getRandomString(10)); + $cryptData['key'] = md5($this->random->getRandomString(10)); } else { - $config['crypt']['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; + $cryptData['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; } + $configData['crypt'] = new ConfigData(ConfigData::DEFAULT_FILE_KEY, 'crypt', $cryptData); + // module segment + $modulesData = []; if (isset($this->moduleList)) { foreach ($this->moduleList as $key) { - $config['modules'][$key] = 1; + $modulesData[$key] = 1; } } + $configData['modules'] = new ConfigData(ConfigData::DEFAULT_FILE_KEY, 'modules', $modulesData); + + // session segment + $sessionData = []; + if (isset($data[self::INPUT_KEY_SESSION_SAVE])) { + if ($data[self::INPUT_KEY_SESSION_SAVE] != 'files' && $data[self::INPUT_KEY_SESSION_SAVE] != 'db') { + throw new \InvalidArgumentException('Invalid session save location.'); + } + $sessionData['save'] = $data[self::INPUT_KEY_SESSION_SAVE]; + } else { + $sessionData['save'] = 'files'; + } + $configData['session'] = new ConfigData(ConfigData::DEFAULT_FILE_KEY, 'session', $sessionData); - return $config; + return $configData; } } From 1eddf91e7981c90565e6c1d021b2be11da149061 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 5 Mar 2015 12:25:53 -0600 Subject: [PATCH 036/214] MAGETWO-34656: Implement config options for 'backend' segment - changed returned array to array of ConfigData objects --- .../Magento/Backend/Setup/ConfigOptions.php | 9 ++++++--- .../Backend/Setup/ConfigOptionsTest.php | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php index 4d1b7e21d43d1..5d4e9985eacdf 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -5,6 +5,7 @@ */ namespace Magento\Backend\Setup; +use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Setup\ConfigOptionsInterface; use Magento\Framework\Setup\Option\TextConfigOption; @@ -43,7 +44,6 @@ public function getOptions() */ public function createConfig(array $options) { - $config = []; if (empty($options[self::INPUT_KEY_BACKEND_FRONTNAME])) { throw new \InvalidArgumentException('No backend frontname provided.'); } @@ -52,7 +52,10 @@ public function createConfig(array $options) "Invalid backend frontname {$options[self::INPUT_KEY_BACKEND_FRONTNAME]}" ); } - $config['backend']['frontName'] = $options[self::INPUT_KEY_BACKEND_FRONTNAME]; - return $config; + return [new ConfigData( + ConfigData::DEFAULT_FILE_KEY, + 'backend', + ['frontName' => $options[self::INPUT_KEY_BACKEND_FRONTNAME]] + )]; } } diff --git a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php index 48b4d4a258399..71df758ba10e9 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Backend\Setup; +use Magento\Framework\Config\Data\ConfigData; + class ConfigOptionsTest extends \PHPUnit_Framework_TestCase { /** @@ -20,16 +22,27 @@ protected function setUp() public function testGetOptions() { $options = $this->object->getOptions(); + $this->assertInternalType('array', $options); foreach ($options as $option) { - $this->assertInstanceOf('\Magento\Framework\Setup\AbstractConfigOption', $option); + $this->assertInstanceOf('\Magento\Framework\Setup\Option\AbstractConfigOption', $option); } } public function testCreateConfig() { $options = [ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; - $expected = ['backend' => ['frontName' => 'admin']]; - $this->assertSame($expected, $this->object->createConfig($options)); + $actualConfig = $this->object->createConfig($options); + $expectedData = [ + ['file' => ConfigData::DEFAULT_FILE_KEY, 'segment' => 'backend', 'data' => ['frontName' => 'admin']] + ]; + $this->assertInternalType('array', $actualConfig); + /** @var \Magento\Framework\Config\Data\ConfigData $config */ + foreach ($actualConfig as $i => $config) { + $this->assertInstanceOf('\Magento\Framework\Config\Data\ConfigData', $config); + $this->assertSame($expectedData[$i]['file'], $config->getFileKey()); + $this->assertSame($expectedData[$i]['segment'], $config->getSegmentKey()); + $this->assertSame($expectedData[$i]['data'], $config->getData()); + } } /** From fd02c5c8b8552bbb69590012a9e9e7ff25f819f3 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 5 Mar 2015 12:58:40 -0600 Subject: [PATCH 037/214] MAGETWO-34657: Implement config options for 'resource' segment - adding config options for config module --- .../Magento/Config/Setup/ConfigOptions.php | 46 +++++++++++++++++++ .../Config/Setup/ConfigOptionsTest.php | 40 ++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 app/code/Magento/Config/Setup/ConfigOptions.php create mode 100644 dev/tests/unit/testsuite/Magento/Config/Setup/ConfigOptionsTest.php diff --git a/app/code/Magento/Config/Setup/ConfigOptions.php b/app/code/Magento/Config/Setup/ConfigOptions.php new file mode 100644 index 0000000000000..957ebeac42a45 --- /dev/null +++ b/app/code/Magento/Config/Setup/ConfigOptions.php @@ -0,0 +1,46 @@ + ['connection' => 'default']]; + } + return $config; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Config/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Config/Setup/ConfigOptionsTest.php new file mode 100644 index 0000000000000..4e8f3afc45efc --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Config/Setup/ConfigOptionsTest.php @@ -0,0 +1,40 @@ +object = new ConfigOptions(); + } + + public function testGetOptions() + { + $options = $this->object->getOptions(); + $this->assertEquals(0, count($options)); + } + + public function testDefaultCreateConfig() + { + $options = []; + $expected = [ConfigOptions::CONFIG_PATH_RESOURCE =>['default_setup' => ['connection' => 'default']]]; + $this->assertSame($expected, $this->object->createConfig($options)); + } + + public function testCreateConfigWithInput() + { + $options[ConfigOptions::INPUT_KEY_RESOURCE] = ['test' => ['name' =>'test', 'connection' => 'test']]; + $expected = $options; + $this->assertSame($expected, $this->object->createConfig($options)); + } + +} From 21b2ccd966476fa9d26fb6af2f12de5d745768fe Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 5 Mar 2015 12:59:54 -0600 Subject: [PATCH 038/214] MAGETWO-34655: Implement config options for 'install' segment - added definitions format option - fixed usage of file constant for ConfigData object - fixed options description to use first capital letter --- .../Magento/Backend/Setup/ConfigOptions.php | 3 +- .../Backend/Setup/ConfigOptionsTest.php | 4 +- .../Framework/App/ObjectManagerFactory.php | 7 ++- .../Framework/Config/Data/ConfigData.php | 5 --- .../ObjectManager/DefinitionFactory.php | 14 +++++- .../src/Magento/Setup/Model/ConfigOptions.php | 44 ++++++++++++------- 6 files changed, 49 insertions(+), 28 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php index 5d4e9985eacdf..15f397c0d919f 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -6,6 +6,7 @@ namespace Magento\Backend\Setup; use Magento\Framework\Config\Data\ConfigData; +use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Setup\ConfigOptionsInterface; use Magento\Framework\Setup\Option\TextConfigOption; @@ -53,7 +54,7 @@ public function createConfig(array $options) ); } return [new ConfigData( - ConfigData::DEFAULT_FILE_KEY, + ConfigFilePool::APP_CONFIG, 'backend', ['frontName' => $options[self::INPUT_KEY_BACKEND_FRONTNAME]] )]; diff --git a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php index 71df758ba10e9..d5776b3b48902 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php @@ -5,7 +5,7 @@ */ namespace Magento\Backend\Setup; -use Magento\Framework\Config\Data\ConfigData; +use Magento\Framework\Config\File\ConfigFilePool; class ConfigOptionsTest extends \PHPUnit_Framework_TestCase { @@ -33,7 +33,7 @@ public function testCreateConfig() $options = [ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; $actualConfig = $this->object->createConfig($options); $expectedData = [ - ['file' => ConfigData::DEFAULT_FILE_KEY, 'segment' => 'backend', 'data' => ['frontName' => 'admin']] + ['file' => ConfigFilePool::APP_CONFIG, 'segment' => 'backend', 'data' => ['frontName' => 'admin']] ]; $this->assertInternalType('array', $actualConfig); /** @var \Magento\Framework\Config\Data\ConfigData $config */ diff --git a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php index 1ebedf86043fd..6e7046e08e62a 100644 --- a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php +++ b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php @@ -21,6 +21,11 @@ */ class ObjectManagerFactory { + /** + * Path to definitions format in deployment configuration + */ + const CONFIG_PATH_DEFINITION_FORMAT = 'definition/format'; + /** * Initialization parameter for a custom deployment configuration file */ @@ -101,7 +106,7 @@ public function create(array $arguments) $this->driverPool->getDriver(DriverPool::FILE), $this->directoryList->getPath(DirectoryList::DI), $this->directoryList->getPath(DirectoryList::GENERATION), - $deploymentConfig->get('definition/format', Serialized::MODE_NAME) + $deploymentConfig->get(self::CONFIG_PATH_DEFINITION_FORMAT, Serialized::MODE_NAME) ); $definitions = $definitionFactory->createClassDefinition($deploymentConfig->get('definitions')); diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index 54332a6499adc..9a421427aadce 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -11,11 +11,6 @@ */ class ConfigData { - /** - * Default file key - */ - const DEFAULT_FILE_KEY = 'config.php'; - /** * File key * diff --git a/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php b/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php index b2aa552b499e5..638295a03a2a3 100644 --- a/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php +++ b/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php @@ -62,7 +62,7 @@ class DefinitionFactory * * @var array */ - protected $_definitionClasses = [ + protected static $definitionClasses = [ Binary::MODE_NAME => '\Magento\Framework\ObjectManager\Definition\Compiled\Binary', Serialized::MODE_NAME => '\Magento\Framework\ObjectManager\Definition\Compiled\Serialized', ]; @@ -93,7 +93,7 @@ public function createClassDefinition($definitions = false) if (is_string($definitions)) { $definitions = $this->_unpack($definitions); } - $definitionModel = $this->_definitionClasses[$this->_definitionFormat]; + $definitionModel = self::$definitionClasses[$this->_definitionFormat]; $result = new $definitionModel($definitions); } else { $generatorIo = new \Magento\Framework\Code\Generator\Io( @@ -159,6 +159,16 @@ public function createRelations() } } + /** + * Gets supported definition formats + * + * @return array + */ + public static function getSupportedFormats() + { + return array_keys(self::$definitionClasses); + } + /** * Un-compress definitions * diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 67460eaf7772f..175159a645ee1 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -6,7 +6,9 @@ namespace Magento\Setup\Model; use Magento\Framework\Config\Data\ConfigData; +use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Math\Random; +use Magento\Framework\ObjectManager\DefinitionFactory; use Magento\Framework\Setup\ConfigOptionsInterface; use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; @@ -22,21 +24,14 @@ class ConfigOptions implements ConfigOptionsInterface * Path to the values in the deployment config */ const CONFIG_PATH_INSTALL_DATE = 'install/date'; + const CONFIG_PATH_MODULES = 'modules'; /** - * Input key for encryption key + * Input keys for the options */ const INPUT_KEY_CRYPT_KEY = 'key'; - - /** - * Input key for session save - */ const INPUT_KEY_SESSION_SAVE = 'session_save'; - - /** - * Path to modules in the deployment config - */ - const CONFIG_PATH_MODULES = 'modules'; + const INPUT_KEY_DEFINITION_FORMAT = 'definition_format'; /** * @var array @@ -69,7 +64,7 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_CRYPT_KEY, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'encryption key' + 'Encryption key' ), new MultiSelectConfigOption( self::CONFIG_PATH_MODULES, @@ -82,9 +77,15 @@ public function getOptions() self::INPUT_KEY_SESSION_SAVE, SelectConfigOption::FRONTEND_WIZARD_SELECT, ['files', 'db'], - 'session save location', + 'Session save location', 'files' ), + new SelectConfigOption( + self::INPUT_KEY_DEFINITION_FORMAT, + SelectConfigOption::FRONTEND_WIZARD_SELECT, + DefinitionFactory::getSupportedFormats(), + 'Type of definitions used by Object Manager' + ), ]; } @@ -95,8 +96,7 @@ public function createConfig(array $data) { $configData = []; // install segment - $installData['date'] = date('r'); - $configData['install'] = new ConfigData(ConfigData::DEFAULT_FILE_KEY, 'install', $installData); + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'install', ['data' => date('r')]); // crypt segment if (isset($data[self::INPUT_KEY_CRYPT_KEY]) && !$data[self::INPUT_KEY_CRYPT_KEY]) { @@ -108,7 +108,7 @@ public function createConfig(array $data) } else { $cryptData['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; } - $configData['crypt'] = new ConfigData(ConfigData::DEFAULT_FILE_KEY, 'crypt', $cryptData); + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); // module segment $modulesData = []; @@ -117,7 +117,7 @@ public function createConfig(array $data) $modulesData[$key] = 1; } } - $configData['modules'] = new ConfigData(ConfigData::DEFAULT_FILE_KEY, 'modules', $modulesData); + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'modules', $modulesData); // session segment $sessionData = []; @@ -129,7 +129,17 @@ public function createConfig(array $data) } else { $sessionData['save'] = 'files'; } - $configData['session'] = new ConfigData(ConfigData::DEFAULT_FILE_KEY, 'session', $sessionData); + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); + + // definitions segment + if (!empty($data[self::INPUT_KEY_DEFINITION_FORMAT])) { + $config['definition']['format'] = $data[self::INPUT_KEY_DEFINITION_FORMAT]; + $configData[] = new ConfigData( + ConfigFilePool::APP_CONFIG, + 'definition', + ['format' => $data[self::INPUT_KEY_DEFINITION_FORMAT]] + ); + } return $configData; } From 1ab1ca2869be17ab80725f46427b5e25dcc70a4d Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 13:58:14 -0600 Subject: [PATCH 039/214] MAGETWO-34658: Implement config options for 'session' segment - updated tests --- .../Magento/Setup/Model/ConfigOptionsTest.php | 21 +++++++++---------- .../src/Magento/Setup/Model/ConfigOptions.php | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index d801020a3cc29..25f8e6de9a7ae 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -27,7 +27,7 @@ public function testGetOptions() $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[0]); $this->assertInstanceOf('Magento\Framework\Setup\Option\MultiSelectConfigOption', $options[1]); $this->assertInstanceOf('Magento\Framework\Setup\Option\SelectConfigOption', $options[2]); - $this->assertEquals(3, count($options)); + $this->assertEquals(4, count($options)); } public function testCreateConfig() @@ -37,20 +37,19 @@ public function testCreateConfig() ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db' ]); $this->assertEquals(4, count($config)); - $this->assertNotEmpty($config['install']); - $this->assertNotEmpty($config['crypt']); - $this->assertEquals('key', $config['crypt']->getData()['key']); - $this->assertNotEmpty($config['modules']); - $this->assertEquals(2, count($config['modules']->getData())); - $this->assertNotEmpty($config['session']); - $this->assertEquals('db', $config['session']->getData()['save']); + $this->assertNotEmpty($config[0]->getData()['date']); + $this->assertNotEmpty($config[1]->getData()['key']); + $this->assertEquals('key', $config[1]->getData()['key']); + $this->assertEquals(2, count($config[2]->getData())); + $this->assertNotEmpty($config[3]->getData()['save']); + $this->assertEquals('db', $config[3]->getData()['save']); } public function testCreateConfigNoSessionSave() { $config = $this->object->createConfig([ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key']); - $this->assertNotEmpty($config['session']); - $this->assertEquals('files', $config['session']->getData()['save']); + $this->assertNotEmpty($config[3]); + $this->assertEquals('files', $config[3]->getData()['save']); } /** @@ -69,7 +68,7 @@ public function testCreateConfigInvalidSessionSave() public function testCreateConfigNoKey(array $options) { $config = $this->object->createConfig($options); - $this->assertEquals(md5('key'), $config['crypt']->getData()['key']); + $this->assertEquals(md5('key'), $config[1]->getData()['key']); } /** diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 175159a645ee1..315535b49443c 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -96,7 +96,7 @@ public function createConfig(array $data) { $configData = []; // install segment - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'install', ['data' => date('r')]); + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'install', ['date' => date('r')]); // crypt segment if (isset($data[self::INPUT_KEY_CRYPT_KEY]) && !$data[self::INPUT_KEY_CRYPT_KEY]) { From 920bcc1670da781d43048e1d07c264709223f069 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 14:04:24 -0600 Subject: [PATCH 040/214] MAGETWO-34507: Create OptionsInterface, Option - updated docblock --- .../Magento/Framework/Setup/ConfigOptionsInterface.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php index 271afd7f48d45..bcaef2f366ca2 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php @@ -19,7 +19,8 @@ interface ConfigOptionsInterface public function getOptions(); /** - * Creates config array from user inputted data. This array will be stored in deployment config file + * Creates array of ConfigData objects from user inputted data. + * Data in these objects will be stored in array form in deployment config file. * * @param array $options * @return \Magento\Framework\Config\Data\ConfigData[] From 91e76e6f1a8e74e64d094a0cda6531ec7dd746a6 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 5 Mar 2015 14:07:37 -0600 Subject: [PATCH 041/214] MAGETWO-34691: Implement config options for definitions segment - added tests for getter of supported definition formats --- .../ObjectManager/DefinitionFactoryTest.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php index 6580e7448d7e3..4376f7abfed4b 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php @@ -16,7 +16,7 @@ class DefinitionFactoryTest extends \PHPUnit_Framework_TestCase protected $filesystemDriverMock; /** - * @var \Magento\Framework\ObjectManager\DefinitionFactory + * @var DefinitionFactory */ protected $model; @@ -35,7 +35,7 @@ protected function setUp() '', false ); - $this->model = new \Magento\Framework\ObjectManager\DefinitionFactory( + $this->model = new DefinitionFactory( $this->filesystemDriverMock, 'DefinitionDir', 'GenerationDir', @@ -113,4 +113,13 @@ public function createPluginsAndRelationsNotReadableDataProvider() ], ]; } + + public function testGetSupportedFormats() + { + $actual = DefinitionFactory::getSupportedFormats(); + $this->assertInternalType('array', $actual); + foreach ($actual as $className) { + $this->assertInternalType('string', $className); + } + } } From a2560e4d27c8a211b0bdd578086cf42400e47dd1 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 14:20:01 -0600 Subject: [PATCH 042/214] MAGETWO-34509: Collector for OptionsInterfaces - modified Collector to return ConfigOptions array - modified integration test --- .../Model/ConfigOptionsCollectorTest.php | 57 +++++++------------ .../Setup/Model/ConfigOptionsCollector.php | 21 ++++--- 2 files changed, 32 insertions(+), 46 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php index 6f339e1a77f29..9e16052ab77fa 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php @@ -12,11 +12,6 @@ class ConfigOptionsCollectorTest extends \PHPUnit_Framework_TestCase */ private $objectManagerProvider; - /** - * @var array - */ - private $expected; - public function setUp() { $this->objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false); @@ -24,16 +19,9 @@ public function setUp() ->expects($this->any()) ->method('get') ->willReturn(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()); - $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get('Magento\Setup\Model\ConfigOptions'); - $backendOptions = new \Magento\Backend\Setup\ConfigOptions(); - $this->expected = [ - 'Magento\Setup\Model\ConfigOptions' => ['options' => $setupOptions->getOptions(), 'enabled' => true], - 'Magento\Backend\Setup\ConfigOptions' => ['options' => $backendOptions->getOptions()], - ]; } - public function testCollectOptions() + public function testCollectOptionsAllModules() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var \Magento\Setup\Model\ConfigOptionsCollector $object */ @@ -41,12 +29,23 @@ public function testCollectOptions() 'Magento\Setup\Model\ConfigOptionsCollector', ['objectManagerProvider' => $this->objectManagerProvider] ); - $result = $object->collectOptions(); - $this->assertOptions($result, true); + $result = $object->collectOptions(true); + + $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get('Magento\Setup\Model\ConfigOptions'); + $backendOptions = new \Magento\Backend\Setup\ConfigOptions(); + $configOptions = new \Magento\Config\Setup\ConfigOptions(); + $expected = [ + 'setup' => $setupOptions, + 'Magento_Backend' => $backendOptions, + 'Magento_Config' => $configOptions, + ]; + + $this->assertEquals($expected, $result); } - public function testCollectOptionsDisabledModules() + public function testCollectOptionsEnabledModules() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); @@ -58,25 +57,13 @@ public function testCollectOptionsDisabledModules() 'moduleList' => $moduleListMock, ] ); - $result = $object->collectOptions(); - $this->assertOptions($result, false); - } + $result = $object->collectOptions(false); - /** - * Assert options array - * - * @param $actual - * @param $enabled - */ - private function assertOptions($actual, $enabled) - { - $expected = []; - foreach ($this->expected as $key => $value) { - $expected[$key] = $value; - if (!isset($value['enabled'])) { - $expected[$key]['enabled'] = $enabled; - } - } - $this->assertEquals($expected, $actual); + $expected = [ + 'setup' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get('Magento\Setup\Model\ConfigOptions'), + ]; + + $this->assertEquals($expected, $result); } } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php index f75c04a77ba89..6952da1bfe6e8 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php @@ -74,11 +74,14 @@ public function __construct( } /** - * Auto discover Options class and collect their options + * Auto discover ConfigOptions class and collect them. These classes should reside in /Setup directories. + * If $collectAll is true, all modules' ConfigOptions classes will be collected. + * Otherwise, only enabled modules' ConfigOptions classes will be collected. * - * @return array + * @param bool $collectAll + * @return \Magento\Framework\Setup\ConfigOptionsInterface[] */ - public function collectOptions() + public function collectOptions($collectAll) { $optionsList = []; @@ -88,10 +91,9 @@ public function collectOptions() if (class_exists($optionsClassName)) { $optionsClass = $this->objectManagerProvider->get()->create($optionsClassName); if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { - $optionsList[$optionsClassName] = [ - 'options' => $optionsClass->getOptions(), - 'enabled' => $this->moduleList->has($moduleName), - ]; + if ($this->moduleList->has($moduleName) || $collectAll) { + $optionsList[$moduleName] = $optionsClass; + } } } } @@ -101,10 +103,7 @@ public function collectOptions() if (class_exists($setupOptionsClassName)) { $setupOptionsClass = $this->objectManagerProvider->get()->create($setupOptionsClassName); if ($setupOptionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { - $optionsList[$setupOptionsClassName] = [ - 'options' => $setupOptionsClass->getOptions(), - 'enabled' => true, - ]; + $optionsList['setup'] = $setupOptionsClass; } } From 71921b5632b16ecda2e20ae11eedd0c125d52c92 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 5 Mar 2015 14:20:42 -0600 Subject: [PATCH 043/214] MAGETWO-34691: Implement config options for definitions segment - fixed default value of Select option to be avoid default value "" in case the option is not required --- .../Magento/Framework/Setup/Option/SelectConfigOption.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php index 42a42704a47ce..c6beb6b29d3a8 100644 --- a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php @@ -40,7 +40,7 @@ public function __construct( $frontendType, array $selectOptions, $description = '', - $defaultValue = '', + $defaultValue = null, $shortCut = null ) { if ($frontendType != self::FRONTEND_WIZARD_SELECT && $frontendType != self::FRONTEND_WIZARD_RADIO) { From 78e3fd9458b3e0318bf90d37cb472b347ae1976d Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 14:40:27 -0600 Subject: [PATCH 044/214] MAGETWO-34509: Collector for OptionsInterfaces - changed collector logic --- .../Magento/Setup/Model/ConfigOptionsCollectorTest.php | 2 +- setup/src/Magento/Setup/Model/ConfigOptionsCollector.php | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php index 9e16052ab77fa..9d0a52b56373e 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php @@ -49,7 +49,7 @@ public function testCollectOptionsEnabledModules() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); - $moduleListMock->expects($this->any())->method('has')->willReturn(false); + $moduleListMock->expects($this->once())->method('getNames')->willReturn([]); $object = $objectManager->create( 'Magento\Setup\Model\ConfigOptionsCollector', [ diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php index 6952da1bfe6e8..5fe655a576a15 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php @@ -85,15 +85,14 @@ public function collectOptions($collectAll) { $optionsList = []; + $moduleList = $collectAll ? $this->fullModuleList : $this->moduleList; // go through modules - foreach ($this->fullModuleList->getNames() as $moduleName) { + foreach ($moduleList->getNames() as $moduleName) { $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptions'; if (class_exists($optionsClassName)) { $optionsClass = $this->objectManagerProvider->get()->create($optionsClassName); if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { - if ($this->moduleList->has($moduleName) || $collectAll) { - $optionsList[$moduleName] = $optionsClass; - } + $optionsList[$moduleName] = $optionsClass; } } } From c927c782245456c6793e5f54154715fe6eb0547c Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Thu, 5 Mar 2015 16:32:15 -0600 Subject: [PATCH 045/214] MAGETWO-34692: Implement config options for 'db' segment - Implemented the feature. --- .../src/Magento/Setup/Model/ConfigOptions.php | 84 ++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 315535b49443c..aca459eb49973 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -14,24 +14,34 @@ use Magento\Framework\Setup\Option\TextConfigOption; use Magento\Framework\Setup\Option\MultiSelectConfigOption; use Magento\Framework\Module\ModuleList\Loader; +use Magento\Framework\App\DeploymentConfig\DbConfig; /** * Deployment configuration options needed for Setup application */ class ConfigOptions implements ConfigOptionsInterface { - /** + /**#@+ * Path to the values in the deployment config */ const CONFIG_PATH_INSTALL_DATE = 'install/date'; const CONFIG_PATH_MODULES = 'modules'; + /**#@-*/ - /** + /**#@+ * Input keys for the options */ const INPUT_KEY_CRYPT_KEY = 'key'; const INPUT_KEY_SESSION_SAVE = 'session_save'; const INPUT_KEY_DEFINITION_FORMAT = 'definition_format'; + const INPUT_KEY_DB_HOST = 'db_host'; + const INPUT_KEY_DB_NAME = 'db_name'; + const INPUT_KEY_DB_USER = 'db_user'; + const INPUT_KEY_DB_PASS = 'db_pass'; + const INPUT_KEY_DB_PREFIX = 'db_prefix'; + const INPUT_KEY_DB_MODEL = 'db_model'; + const INPUT_KEY_DB_INIT_STATEMENTS = 'db_init_statements'; + /**#@-*/ /** * @var array @@ -43,6 +53,21 @@ class ConfigOptions implements ConfigOptionsInterface */ private $random; + /** + * Maps configuration parameters to array keys in deployment config file + * + * @var array + */ + public static $paramMap = [ + self::INPUT_KEY_DB_HOST => DbConfig::KEY_HOST, + self::INPUT_KEY_DB_NAME => DbConfig::KEY_NAME, + self::INPUT_KEY_DB_USER => DbConfig::KEY_USER, + self::INPUT_KEY_DB_PASS => DbConfig::KEY_PASS, + self::INPUT_KEY_DB_PREFIX => DbConfig::KEY_PREFIX, + self::INPUT_KEY_DB_MODEL => DbConfig::KEY_MODEL, + self::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, + ]; + /** * Constructor * @@ -86,6 +111,41 @@ public function getOptions() DefinitionFactory::getSupportedFormats(), 'Type of definitions used by Object Manager' ), + new TextConfigOption( + self::INPUT_KEY_DB_HOST, + TextConfigOption::FRONTEND_WIZARD_TEXT, + 'Database server host' + ), + new TextConfigOption( + self::INPUT_KEY_DB_NAME, + TextConfigOption::FRONTEND_WIZARD_TEXT, + 'Database name' + ), + new TextConfigOption( + self::INPUT_KEY_DB_USER, + TextConfigOption::FRONTEND_WIZARD_TEXT, + 'Database server username' + ), + new TextConfigOption( + self::INPUT_KEY_DB_PASS, + TextConfigOption::FRONTEND_WIZARD_PASSWORD, + 'Database server password' + ), + new TextConfigOption( + self::INPUT_KEY_DB_PREFIX, + TextConfigOption::FRONTEND_WIZARD_TEXT, + 'Database table prefix' + ), + new TextConfigOption( + self::INPUT_KEY_DB_MODEL, + TextConfigOption::FRONTEND_WIZARD_TEXT, + 'Database type' + ), + new TextConfigOption( + self::INPUT_KEY_DB_INIT_STATEMENTS, + TextConfigOption::FRONTEND_WIZARD_TEXT, + 'Database initial set of commands' + ), ]; } @@ -141,6 +201,26 @@ public function createConfig(array $data) ); } + // db segment + $connection = []; + $required = [self::INPUT_KEY_DB_HOST, self::INPUT_KEY_DB_NAME, self::INPUT_KEY_DB_USER]; + foreach ($required as $key) { + if (!isset($data[$key])) { + throw new \InvalidArgumentException("Missing value for db configuration: {$key}"); + } + $connection[self::$paramMap[$key]] = $data[$key]; + } + $optional = [self::INPUT_KEY_DB_INIT_STATEMENTS, self::INPUT_KEY_DB_MODEL, self::INPUT_KEY_DB_PASS]; + foreach ($optional as $key) { + $connection[self::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : null; + } + $prefixKey = self::INPUT_KEY_DB_PREFIX; + $dbData = [ + DeploymentConfigMapper::$paramMap[$prefixKey] => isset($data[$prefixKey]) ? $data[$prefixKey] : null, + 'connection' => ['default' => $connection], + ]; + $configData['db'] = new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); + return $configData; } } From d6ba1762ffcd3f3601079fc7c6d0a275cca77d14 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 5 Mar 2015 16:47:42 -0600 Subject: [PATCH 046/214] MAGETWO-34694: Implement config options for 'modules' segment - changes based on discussion of how modules list is to be implemented --- dev/tests/unit/filename | 0 dev/tests/unit/filename.csv | 0 dev/tests/unit/filename.invalid_type | 0 .../src/Magento/Setup/Model/ConfigOptions.php | 33 ++++++++++--------- 4 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 dev/tests/unit/filename create mode 100644 dev/tests/unit/filename.csv create mode 100644 dev/tests/unit/filename.invalid_type diff --git a/dev/tests/unit/filename b/dev/tests/unit/filename new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/dev/tests/unit/filename.csv b/dev/tests/unit/filename.csv new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/dev/tests/unit/filename.invalid_type b/dev/tests/unit/filename.invalid_type new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index aca459eb49973..d661d8cee6028 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -12,8 +12,8 @@ use Magento\Framework\Setup\ConfigOptionsInterface; use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; -use Magento\Framework\Setup\Option\MultiSelectConfigOption; use Magento\Framework\Module\ModuleList\Loader; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\DeploymentConfig\DbConfig; /** @@ -25,7 +25,6 @@ class ConfigOptions implements ConfigOptionsInterface * Path to the values in the deployment config */ const CONFIG_PATH_INSTALL_DATE = 'install/date'; - const CONFIG_PATH_MODULES = 'modules'; /**#@-*/ /**#@+ @@ -43,6 +42,11 @@ class ConfigOptions implements ConfigOptionsInterface const INPUT_KEY_DB_INIT_STATEMENTS = 'db_init_statements'; /**#@-*/ + /** + * @var DeploymentConfig + */ + private $deploymentConfig; + /** * @var array */ @@ -73,11 +77,13 @@ class ConfigOptions implements ConfigOptionsInterface * * @param Random $random * @param Loader $moduleLoader + * @param DeploymentConfig $deploymentConfig */ - public function __construct(Random $random, Loader $moduleLoader) + public function __construct(Random $random, Loader $moduleLoader, DeploymentConfig $deploymentConfig) { $this->random = $random; - $this->moduleList = $moduleLoader->load(); + $this->deploymentConfig = $deploymentConfig; + $this->moduleList = array_keys($moduleLoader->load()); } /** @@ -91,13 +97,6 @@ public function getOptions() TextConfigOption::FRONTEND_WIZARD_TEXT, 'Encryption key' ), - new MultiSelectConfigOption( - self::CONFIG_PATH_MODULES, - MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, - $this->moduleList, - 'modules list', - $this->moduleList - ), new SelectConfigOption( self::INPUT_KEY_SESSION_SAVE, SelectConfigOption::FRONTEND_WIZARD_SELECT, @@ -171,13 +170,15 @@ public function createConfig(array $data) $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); // module segment - $modulesData = []; - if (isset($this->moduleList)) { - foreach ($this->moduleList as $key) { - $modulesData[$key] = 1; + if (!$this->deploymentConfig->isAvailable()) { + $modulesData = []; + if (isset($this->moduleList)) { + foreach (array_values($this->moduleList) as $key) { + $modulesData[$key] = 1; + } } + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'modules', $modulesData); } - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'modules', $modulesData); // session segment $sessionData = []; From f7896f4f1ff31a6db54d2a5d31c5b22fcbd1e4b6 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 16:55:43 -0600 Subject: [PATCH 047/214] MAGETWO-34509: Collector for OptionsInterfaces - added auto detect module list in collector logic --- .../Model/ConfigOptionsCollectorTest.php | 28 +++++++++++++------ .../Framework/Module/ModuleListTest.php | 12 ++++++++ .../Magento/Framework/Module/ModuleList.php | 14 ++++++++++ .../Setup/Model/ConfigOptionsCollector.php | 10 +++---- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php index 9d0a52b56373e..42d48359e9c20 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php @@ -21,35 +21,43 @@ public function setUp() ->willReturn(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()); } - public function testCollectOptionsAllModules() + public function testCollectOptionsDeploymentConfigAvailable() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $moduleListMock->expects($this->once())->method('isModuleInfoAvailable')->willReturn(true); + $moduleListMock->expects($this->once())->method('getNames')->willReturn(['Magento_Backend']); + $fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); + $fullModuleListMock->expects($this->never())->method('getNames'); /** @var \Magento\Setup\Model\ConfigOptionsCollector $object */ $object = $objectManager->create( 'Magento\Setup\Model\ConfigOptionsCollector', - ['objectManagerProvider' => $this->objectManagerProvider] + [ + 'objectManagerProvider' => $this->objectManagerProvider, + 'moduleList' => $moduleListMock, + 'fullModuleList' => $fullModuleListMock, + ] ); - $result = $object->collectOptions(true); + $result = $object->collectOptions(); $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('Magento\Setup\Model\ConfigOptions'); $backendOptions = new \Magento\Backend\Setup\ConfigOptions(); - $configOptions = new \Magento\Config\Setup\ConfigOptions(); $expected = [ 'setup' => $setupOptions, 'Magento_Backend' => $backendOptions, - 'Magento_Config' => $configOptions, ]; $this->assertEquals($expected, $result); } - public function testCollectOptionsEnabledModules() + public function testCollectOptionsDeploymentConfigUnavailable() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); - $moduleListMock->expects($this->once())->method('getNames')->willReturn([]); + $moduleListMock->expects($this->once())->method('isModuleInfoAvailable')->willReturn(false); + $moduleListMock->expects($this->never())->method('getNames'); $object = $objectManager->create( 'Magento\Setup\Model\ConfigOptionsCollector', [ @@ -57,11 +65,15 @@ public function testCollectOptionsEnabledModules() 'moduleList' => $moduleListMock, ] ); - $result = $object->collectOptions(false); + $result = $object->collectOptions(); + $backendOptions = new \Magento\Backend\Setup\ConfigOptions(); + $configOptions = new \Magento\Config\Setup\ConfigOptions(); $expected = [ 'setup' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('Magento\Setup\Model\ConfigOptions'), + 'Magento_Backend' => $backendOptions, + 'Magento_Config' => $configOptions, ]; $this->assertEquals($expected, $result); diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ModuleListTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ModuleListTest.php index 23c62e6505aa2..a617e567488f4 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ModuleListTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ModuleListTest.php @@ -84,6 +84,18 @@ public function testHas() $this->assertFalse($this->model->has('bar')); } + public function testIsModuleInfoAvailable() + { + $this->setLoadConfigExpectation(true); + $this->assertTrue($this->model->isModuleInfoAvailable()); + } + + public function testIsModuleInfoAvailableNoConfig() + { + $this->config->expects($this->once())->method('getSegment')->willReturn(null); + $this->assertFalse($this->model->isModuleInfoAvailable()); + } + /** * Prepares expectation for loading deployment configuration * diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php index 7fb7e1d8b6458..f04e60f3e26c6 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/ModuleList.php @@ -117,6 +117,20 @@ public function has($name) return !empty($this->configData[$name]); } + /** + * Checks if module list information is available. + * + * @return bool + */ + public function isModuleInfoAvailable() + { + $this->loadConfigData(); + if ($this->configData) { + return true; + } + return false; + } + /** * Loads configuration data only * diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php index 5fe655a576a15..d0e904b65a66a 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php @@ -5,6 +5,7 @@ */ namespace Magento\Setup\Model; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Framework\Module\FullModuleList; @@ -75,17 +76,16 @@ public function __construct( /** * Auto discover ConfigOptions class and collect them. These classes should reside in /Setup directories. - * If $collectAll is true, all modules' ConfigOptions classes will be collected. - * Otherwise, only enabled modules' ConfigOptions classes will be collected. + * If deployment config is not available, all modules will be searched. Otherwise, only enabled modules + * will be searched. * - * @param bool $collectAll * @return \Magento\Framework\Setup\ConfigOptionsInterface[] */ - public function collectOptions($collectAll) + public function collectOptions() { $optionsList = []; - $moduleList = $collectAll ? $this->fullModuleList : $this->moduleList; + $moduleList = $this->moduleList->isModuleInfoAvailable() ? $this->moduleList : $this->fullModuleList; // go through modules foreach ($moduleList->getNames() as $moduleName) { $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptions'; From 051b9a024a8fbf55e4d1cc7a5515340cba477c71 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Thu, 5 Mar 2015 16:59:47 -0600 Subject: [PATCH 048/214] MAGETWO-34692: Implement config options for 'db' segment - Fixing an error. --- setup/src/Magento/Setup/Model/ConfigOptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index d661d8cee6028..ed426bd064a4d 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -220,7 +220,7 @@ public function createConfig(array $data) DeploymentConfigMapper::$paramMap[$prefixKey] => isset($data[$prefixKey]) ? $data[$prefixKey] : null, 'connection' => ['default' => $connection], ]; - $configData['db'] = new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); return $configData; } From bd05d9b858e6dd81186c3a35ab690bdef2f984bd Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Thu, 5 Mar 2015 17:25:22 -0600 Subject: [PATCH 049/214] MAGETWO-34692: Implement config options for 'db' segment - Fixed the realted test. --- .../Magento/Setup/Model/ConfigOptionsTest.php | 58 +++++++++++++++---- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 25f8e6de9a7ae..63aa73923e5b3 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -16,27 +16,31 @@ protected function setUp() { $random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); $random->expects($this->any())->method('getRandomString')->willReturn('key'); - $loader = $this->getMock('\Magento\Framework\Module\ModuleList\Loader', [], [], '', false); + $loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); $loader->expects($this->any())->method('load')->willReturn(['module1', 'module2']); - $this->object = new ConfigOptions($random, $loader); + $deployConfig= $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $deployConfig->expects($this->any())->method('isAvailable')->willReturn(false); + $this->object = new ConfigOptions($random, $loader, $deployConfig); } public function testGetOptions() { $options = $this->object->getOptions(); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[0]); - $this->assertInstanceOf('Magento\Framework\Setup\Option\MultiSelectConfigOption', $options[1]); - $this->assertInstanceOf('Magento\Framework\Setup\Option\SelectConfigOption', $options[2]); - $this->assertEquals(4, count($options)); + $this->assertInstanceOf('Magento\Framework\Setup\Option\SelectConfigOption', $options[1]); + $this->assertEquals(10, count($options)); } public function testCreateConfig() { $config = $this->object->createConfig([ ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key', - ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db' + ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db', + ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', + ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', + ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', ]); - $this->assertEquals(4, count($config)); + $this->assertEquals(5, count($config)); $this->assertNotEmpty($config[0]->getData()['date']); $this->assertNotEmpty($config[1]->getData()['key']); $this->assertEquals('key', $config[1]->getData()['key']); @@ -47,7 +51,12 @@ public function testCreateConfig() public function testCreateConfigNoSessionSave() { - $config = $this->object->createConfig([ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key']); + $config = $this->object->createConfig([ + ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key', + ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', + ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', + ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ]); $this->assertNotEmpty($config[3]); $this->assertEquals('files', $config[3]->getData()['save']); } @@ -58,7 +67,12 @@ public function testCreateConfigNoSessionSave() */ public function testCreateConfigInvalidSessionSave() { - $this->object->createConfig([ConfigOptions::INPUT_KEY_SESSION_SAVE => 'invalid']); + $this->object->createConfig([ + ConfigOptions::INPUT_KEY_SESSION_SAVE => 'invalid', + ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', + ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', + ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ]); } /** @@ -77,8 +91,17 @@ public function testCreateConfigNoKey(array $options) public function createConfigNoKeyDataProvider() { return [ - 'no data' => [[]], - 'no frontName' => [['something_else' => 'something']], + 'no key data' => [[ + ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', + ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', + ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ]], + 'no frontName' => [[ + 'something_else' => 'something', + ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', + ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', + ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ]], ]; } @@ -104,4 +127,17 @@ public function createConfigInvalidKeyDataProvider() [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '0']], ]; } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Missing value for db configuration: db_user + */ + public function testCreateConfigInvalidDB() + { + $data = [ + ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', + ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', + ]; + $this->object->createConfig($data); + } } From 7eb986df82a2486ffc8255a4c976539263a0396d Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 17:02:14 -0600 Subject: [PATCH 050/214] MAGETWO-34509: Collector for OptionsInterfaces - removed unused imports --- setup/src/Magento/Setup/Model/ConfigOptionsCollector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php index d0e904b65a66a..0e96dfb95672f 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php @@ -5,7 +5,6 @@ */ namespace Magento\Setup\Model; -use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Framework\Module\FullModuleList; From e4c0cef4b64fd8402caa2d0138f9746cb441cb8d Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 17:52:17 -0600 Subject: [PATCH 051/214] MAGETWO-34658: Implement config options for 'session' segment - changed hardcoded array index to constant --- .../src/Magento/Setup/Model/ConfigOptions.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index ed426bd064a4d..0bfbfa7a0381d 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -15,6 +15,8 @@ use Magento\Framework\Module\ModuleList\Loader; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\DeploymentConfig\DbConfig; +use Magento\Framework\App\DeploymentConfig\EncryptConfig; +use Magento\Framework\App\DeploymentConfig\SessionConfig; /** * Deployment configuration options needed for Setup application @@ -155,7 +157,11 @@ public function createConfig(array $data) { $configData = []; // install segment - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'install', ['date' => date('r')]); + $configData[] = new ConfigData( + ConfigFilePool::APP_CONFIG, + 'install', + [DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DATE] => date('r')] + ); // crypt segment if (isset($data[self::INPUT_KEY_CRYPT_KEY]) && !$data[self::INPUT_KEY_CRYPT_KEY]) { @@ -163,9 +169,10 @@ public function createConfig(array $data) } $cryptData = []; if (!isset($data[self::INPUT_KEY_CRYPT_KEY])) { - $cryptData['key'] = md5($this->random->getRandomString(10)); + $cryptData[DeploymentConfigMapper::$paramMap[self::INPUT_KEY_CRYPT_KEY]] = + md5($this->random->getRandomString(10)); } else { - $cryptData['key'] = $data[self::INPUT_KEY_CRYPT_KEY]; + $cryptData[DeploymentConfigMapper::$paramMap[self::INPUT_KEY_CRYPT_KEY]] = $data[self::INPUT_KEY_CRYPT_KEY]; } $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); @@ -186,9 +193,10 @@ public function createConfig(array $data) if ($data[self::INPUT_KEY_SESSION_SAVE] != 'files' && $data[self::INPUT_KEY_SESSION_SAVE] != 'db') { throw new \InvalidArgumentException('Invalid session save location.'); } - $sessionData['save'] = $data[self::INPUT_KEY_SESSION_SAVE]; + $sessionData[DeploymentConfigMapper::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = + $data[self::INPUT_KEY_SESSION_SAVE]; } else { - $sessionData['save'] = 'files'; + $sessionData[DeploymentConfigMapper::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = 'files'; } $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); From 2ca54b48923583fe86600be170074eafbee82688 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 5 Mar 2015 18:02:08 -0600 Subject: [PATCH 052/214] MAGETWO-34658: Implement config options for 'session' segment - use own's paramMap instead of old DeploymentConfigMapper --- .../src/Magento/Setup/Model/ConfigOptions.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 0bfbfa7a0381d..432e234a09742 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -16,6 +16,7 @@ use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\DeploymentConfig\DbConfig; use Magento\Framework\App\DeploymentConfig\EncryptConfig; +use Magento\Framework\App\DeploymentConfig\InstallConfig; use Magento\Framework\App\DeploymentConfig\SessionConfig; /** @@ -72,6 +73,8 @@ class ConfigOptions implements ConfigOptionsInterface self::INPUT_KEY_DB_PREFIX => DbConfig::KEY_PREFIX, self::INPUT_KEY_DB_MODEL => DbConfig::KEY_MODEL, self::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, + self::INPUT_KEY_CRYPT_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, + self::INPUT_KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, ]; /** @@ -157,11 +160,7 @@ public function createConfig(array $data) { $configData = []; // install segment - $configData[] = new ConfigData( - ConfigFilePool::APP_CONFIG, - 'install', - [DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DATE] => date('r')] - ); + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'install', [InstallConfig::KEY_DATE => date('r')]); // crypt segment if (isset($data[self::INPUT_KEY_CRYPT_KEY]) && !$data[self::INPUT_KEY_CRYPT_KEY]) { @@ -169,10 +168,9 @@ public function createConfig(array $data) } $cryptData = []; if (!isset($data[self::INPUT_KEY_CRYPT_KEY])) { - $cryptData[DeploymentConfigMapper::$paramMap[self::INPUT_KEY_CRYPT_KEY]] = - md5($this->random->getRandomString(10)); + $cryptData[self::$paramMap[self::INPUT_KEY_CRYPT_KEY]] = md5($this->random->getRandomString(10)); } else { - $cryptData[DeploymentConfigMapper::$paramMap[self::INPUT_KEY_CRYPT_KEY]] = $data[self::INPUT_KEY_CRYPT_KEY]; + $cryptData[self::$paramMap[self::INPUT_KEY_CRYPT_KEY]] = $data[self::INPUT_KEY_CRYPT_KEY]; } $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); @@ -193,10 +191,10 @@ public function createConfig(array $data) if ($data[self::INPUT_KEY_SESSION_SAVE] != 'files' && $data[self::INPUT_KEY_SESSION_SAVE] != 'db') { throw new \InvalidArgumentException('Invalid session save location.'); } - $sessionData[DeploymentConfigMapper::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = + $sessionData[self::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = $data[self::INPUT_KEY_SESSION_SAVE]; } else { - $sessionData[DeploymentConfigMapper::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = 'files'; + $sessionData[self::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = 'files'; } $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); From ed1146ddaf17435c32fc454f427083664290bc03 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Thu, 5 Mar 2015 18:17:17 -0600 Subject: [PATCH 053/214] MAGETWO-34511: Process config options - added collction of options and config from ConfigOption --- setup/src/Magento/Setup/Model/ConfigModel.php | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 5c0e6153d21b0..4bc6cc7f80bed 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -7,6 +7,8 @@ namespace Magento\Setup\Model; use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\Setup\ConfigOptionsInterface; +use Magento\Framework\Config\Data\ConfigData; class ConfigModel { @@ -39,9 +41,7 @@ public function getAvailableOptions() foreach ($options as $option) { // TODO: we need to get rid of keys here - if ($option['enabled']) { - $optionCollection = array_merge($optionCollection, $option['options']); - } + $optionCollection = array_merge($optionCollection, $option->getOptions()); } return $optionCollection; @@ -54,26 +54,47 @@ public function getAvailableOptions() */ public function process($inputOptions) { + // TODO: add error processing and refactor $fileConfigStorage = []; $options = $this->collector->collectOptions(); - foreach ($options as $option) { - if ($option['enabled']) { - // TODO: add isset and check of instance here - $conf = $option['configOption']->createConfig($inputOptions); - - // TODO: this file should be returned by ConfigOption - $defaultConfigFile = ConfigFilePool::APP_CONFIG; - - if (isset($fileConfigStorage[$defaultConfigFile])) { - $fileConfigStorage[$defaultConfigFile] = array_merge( - $fileConfigStorage[$defaultConfigFile], - $conf - ); + + foreach ($options as $moduleName => $option) { + + if (!$option instanceof ConfigOptionsInterface) { + // TODO: ROMOVE IT! + echo "FIX IT!: " . 'ConfigOption for module:' . $moduleName . ' does not implement ConfigOptionsInterface' . PHP_EOL; + continue; + throw new \Exception( + 'ConfigOption for module:' . $moduleName . ' does not implement ConfigOptionsInterface' + ); + } + + $configData = $option->createConfig($inputOptions); + foreach ($configData as $config) { + + if (!$config instanceof ConfigData) { + // TODO: ROMOVE IT! + echo "FIX IT!: " . 'In module : ' .$moduleName . 'ConfigOption::createConfig should return instance of ConfigData' . PHP_EOL; + continue; + throw new \Exception( + 'In module : ' .$moduleName . 'ConfigOption::createConfig should return instance of ConfigData' + ); + } + + if ( + isset($fileConfigStorage[$config->getFileKey()]) + && isset($fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()]) + ) { + $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_merge( + $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()], + $config->getData() + ); } else { - $fileConfigStorage[$defaultConfigFile] = $conf; + $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = $config->getData(); } } + } var_dump($fileConfigStorage); From e298dcfac4102b1cc6f5fe5d5df67b9291cb13e1 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 6 Mar 2015 09:58:52 -0600 Subject: [PATCH 054/214] MAGETWO-34692: Implement config options for 'db' segment - Fixed an inconsistency based on CR feedback. --- setup/src/Magento/Setup/Model/ConfigOptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 432e234a09742..b47dff0a6566b 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -223,7 +223,7 @@ public function createConfig(array $data) } $prefixKey = self::INPUT_KEY_DB_PREFIX; $dbData = [ - DeploymentConfigMapper::$paramMap[$prefixKey] => isset($data[$prefixKey]) ? $data[$prefixKey] : null, + self::$paramMap[$prefixKey] => isset($data[$prefixKey]) ? $data[$prefixKey] : null, 'connection' => ['default' => $connection], ]; $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); From d6ff684affe17b113f2fa1b8297f794c674882b4 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Fri, 6 Mar 2015 09:30:59 -0600 Subject: [PATCH 055/214] MAGETWO-34691: Implement config options for definitions segment - fixed code style --- .../Magento/Framework/Setup/Option/SelectConfigOption.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php index c6beb6b29d3a8..6f72c4065c69e 100644 --- a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php @@ -31,7 +31,7 @@ class SelectConfigOption extends AbstractConfigOption * @param string $frontendType * @param array $selectOptions * @param string $description - * @param string $defaultValue + * @param string|null $defaultValue * @param string|null $shortCut * @throws \InvalidArgumentException */ From ab368a9d52751673e27710a82ebf3a399ec480c0 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Fri, 6 Mar 2015 11:31:42 -0600 Subject: [PATCH 056/214] MAGETWO-34655: Implement config options for 'install' segment - fixed usages of moved class --- app/code/Magento/AdminNotification/Model/Feed.php | 2 +- app/code/Magento/Backend/Helper/Dashboard/Data.php | 2 +- .../unit/testsuite/Magento/AdminNotification/Model/FeedTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/AdminNotification/Model/Feed.php b/app/code/Magento/AdminNotification/Model/Feed.php index 4d72c32d53415..b975adc8f85fc 100644 --- a/app/code/Magento/AdminNotification/Model/Feed.php +++ b/app/code/Magento/AdminNotification/Model/Feed.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\AdminNotification\Model; -use Magento\Setup\ConfigOptions; +use Magento\Setup\Model\ConfigOptions; /** * AdminNotification Feed model diff --git a/app/code/Magento/Backend/Helper/Dashboard/Data.php b/app/code/Magento/Backend/Helper/Dashboard/Data.php index 0224102dadd38..1e4040b57bf40 100644 --- a/app/code/Magento/Backend/Helper/Dashboard/Data.php +++ b/app/code/Magento/Backend/Helper/Dashboard/Data.php @@ -6,7 +6,7 @@ namespace Magento\Backend\Helper\Dashboard; use Magento\Framework\App\DeploymentConfig; -use Magento\Setup\ConfigOptions; +use Magento\Setup\Model\ConfigOptions; /** * Data helper for dashboard diff --git a/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php b/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php index cc607eea3f487..ff16495547976 100644 --- a/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php +++ b/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php @@ -6,7 +6,7 @@ namespace Magento\AdminNotification\Model; -use Magento\Setup\ConfigOptions; +use Magento\Setup\Model\ConfigOptions; use Magento\TestFramework\Helper\ObjectManager as ObjectManagerHelper; /** From 956049903b30b06dca9ec1e46e019822b21c0a88 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 6 Mar 2015 11:31:49 -0600 Subject: [PATCH 057/214] MAGETWO-34657: Implement config options for 'resource' segment - moving to setup's ConfigOptions --- .../Magento/Config/Setup/ConfigOptions.php | 46 ------------------- .../Config/Setup/ConfigOptionsTest.php | 40 ---------------- .../Magento/Setup/Model/ConfigOptionsTest.php | 10 ++++ .../Magento/Framework/App/Bootstrap.php | 1 + .../src/Magento/Setup/Model/ConfigOptions.php | 7 +++ 5 files changed, 18 insertions(+), 86 deletions(-) delete mode 100644 app/code/Magento/Config/Setup/ConfigOptions.php delete mode 100644 dev/tests/unit/testsuite/Magento/Config/Setup/ConfigOptionsTest.php diff --git a/app/code/Magento/Config/Setup/ConfigOptions.php b/app/code/Magento/Config/Setup/ConfigOptions.php deleted file mode 100644 index 957ebeac42a45..0000000000000 --- a/app/code/Magento/Config/Setup/ConfigOptions.php +++ /dev/null @@ -1,46 +0,0 @@ - ['connection' => 'default']]; - } - return $config; - } -} diff --git a/dev/tests/unit/testsuite/Magento/Config/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Config/Setup/ConfigOptionsTest.php deleted file mode 100644 index 4e8f3afc45efc..0000000000000 --- a/dev/tests/unit/testsuite/Magento/Config/Setup/ConfigOptionsTest.php +++ /dev/null @@ -1,40 +0,0 @@ -object = new ConfigOptions(); - } - - public function testGetOptions() - { - $options = $this->object->getOptions(); - $this->assertEquals(0, count($options)); - } - - public function testDefaultCreateConfig() - { - $options = []; - $expected = [ConfigOptions::CONFIG_PATH_RESOURCE =>['default_setup' => ['connection' => 'default']]]; - $this->assertSame($expected, $this->object->createConfig($options)); - } - - public function testCreateConfigWithInput() - { - $options[ConfigOptions::INPUT_KEY_RESOURCE] = ['test' => ['name' =>'test', 'connection' => 'test']]; - $expected = $options; - $this->assertSame($expected, $this->object->createConfig($options)); - } - -} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 63aa73923e5b3..89b02d552c80b 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Setup\Model; +use Magento\Framework\App\DeploymentConfig\ResourceConfig; + class ConfigOptionsTest extends \PHPUnit_Framework_TestCase { /** @@ -140,4 +142,12 @@ public function testCreateConfigInvalidDB() ]; $this->object->createConfig($data); } + + public function testCreateResourceConfig() + { + $options = []; + $expected = [ConfigOptions::INPUT_KEY_RESOURCE =>['default_setup' => ['connection' => 'default']]]; + $this->assertSame($expected, $this->object->createConfig($options)); + } + } diff --git a/lib/internal/Magento/Framework/App/Bootstrap.php b/lib/internal/Magento/Framework/App/Bootstrap.php index 2099ee76e92d7..e0cc0d9076218 100644 --- a/lib/internal/Magento/Framework/App/Bootstrap.php +++ b/lib/internal/Magento/Framework/App/Bootstrap.php @@ -407,6 +407,7 @@ protected function terminate(\Exception $e) echo $e; } else { $message = "An error has happened during application run. See debug log for details.\n"; + echo $e; try { if (!$this->objectManager) { throw new \DomainException(); diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index b47dff0a6566b..c51a73159a08f 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -18,6 +18,7 @@ use Magento\Framework\App\DeploymentConfig\EncryptConfig; use Magento\Framework\App\DeploymentConfig\InstallConfig; use Magento\Framework\App\DeploymentConfig\SessionConfig; +use Magento\Framework\App\DeploymentConfig\ResourceConfig; /** * Deployment configuration options needed for Setup application @@ -43,6 +44,7 @@ class ConfigOptions implements ConfigOptionsInterface const INPUT_KEY_DB_PREFIX = 'db_prefix'; const INPUT_KEY_DB_MODEL = 'db_model'; const INPUT_KEY_DB_INIT_STATEMENTS = 'db_init_statements'; + const INPUT_KEY_RESOURCE = 'resource'; /**#@-*/ /** @@ -75,6 +77,7 @@ class ConfigOptions implements ConfigOptionsInterface self::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, self::INPUT_KEY_CRYPT_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, self::INPUT_KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, + self::INPUT_KEY_RESOURCE => ResourceConfig::CONFIG_KEY, ]; /** @@ -228,6 +231,10 @@ public function createConfig(array $data) ]; $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); + //resource segment + $resourceData[self::$paramMap[self::INPUT_KEY_RESOURCE]] = ['default_setup' => ['connection' => 'default']]; + $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'resource', $resourceData); + return $configData; } } From d6df1285bca062956a1279b2bc930e40f3c417ce Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 6 Mar 2015 11:54:30 -0600 Subject: [PATCH 058/214] MAGETWO-34657: Implement config options for 'resource' segment - reverting debugging echo --- lib/internal/Magento/Framework/App/Bootstrap.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Bootstrap.php b/lib/internal/Magento/Framework/App/Bootstrap.php index e0cc0d9076218..2099ee76e92d7 100644 --- a/lib/internal/Magento/Framework/App/Bootstrap.php +++ b/lib/internal/Magento/Framework/App/Bootstrap.php @@ -407,7 +407,6 @@ protected function terminate(\Exception $e) echo $e; } else { $message = "An error has happened during application run. See debug log for details.\n"; - echo $e; try { if (!$this->objectManager) { throw new \DomainException(); From 26fa1e63f45b3ffc25a772eaf745a59d9ebde451 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 6 Mar 2015 13:49:42 -0600 Subject: [PATCH 059/214] MAGETWO-34658: Implement config options for 'session' segment - use constant as param value instead of string --- setup/src/Magento/Setup/Model/ConfigOptions.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index c51a73159a08f..35c3e2a0a5379 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -47,6 +47,13 @@ class ConfigOptions implements ConfigOptionsInterface const INPUT_KEY_RESOURCE = 'resource'; /**#@-*/ + /**#@+ + * Values for session_save + */ + const SESSION_SAVE_FILES = 'files'; + const SESSION_SAVE_DB = 'db'; + /**#@-*/ + /** * @var DeploymentConfig */ @@ -108,9 +115,9 @@ public function getOptions() new SelectConfigOption( self::INPUT_KEY_SESSION_SAVE, SelectConfigOption::FRONTEND_WIZARD_SELECT, - ['files', 'db'], + [self::SESSION_SAVE_FILES, self::SESSION_SAVE_DB], 'Session save location', - 'files' + self::SESSION_SAVE_FILES ), new SelectConfigOption( self::INPUT_KEY_DEFINITION_FORMAT, @@ -191,13 +198,15 @@ public function createConfig(array $data) // session segment $sessionData = []; if (isset($data[self::INPUT_KEY_SESSION_SAVE])) { - if ($data[self::INPUT_KEY_SESSION_SAVE] != 'files' && $data[self::INPUT_KEY_SESSION_SAVE] != 'db') { + if ($data[self::INPUT_KEY_SESSION_SAVE] != self::SESSION_SAVE_FILES && + $data[self::INPUT_KEY_SESSION_SAVE] != self::SESSION_SAVE_DB + ) { throw new \InvalidArgumentException('Invalid session save location.'); } $sessionData[self::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = $data[self::INPUT_KEY_SESSION_SAVE]; } else { - $sessionData[self::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = 'files'; + $sessionData[self::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = self::SESSION_SAVE_FILES; } $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); From 3aa4df90d87101f6ea276273086d5e805db81d6b Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 6 Mar 2015 14:37:08 -0600 Subject: [PATCH 060/214] MAGETWO-34507: Create OptionsInterface, Option - corrected docblock --- .../Magento/Framework/Setup/Option/AbstractConfigOption.php | 2 +- .../Magento/Framework/Setup/Option/FlagConfigOption.php | 2 +- .../Magento/Framework/Setup/Option/MultiSelectConfigOption.php | 2 +- .../Magento/Framework/Setup/Option/SelectConfigOption.php | 2 +- .../Magento/Framework/Setup/Option/TextConfigOption.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php index 963496eb87be2..beaec5d21ac63 100644 --- a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php @@ -27,7 +27,7 @@ abstract class AbstractConfigOption extends InputOption * @param string $description * @param int $mode * @param string|array|null $defaultValue - * @param string|null $shortcut + * @param string|array|null $shortcut */ public function __construct( $name, diff --git a/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php index e3cc8a175680c..f52edf8e18002 100644 --- a/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php @@ -20,7 +20,7 @@ class FlagConfigOption extends AbstractConfigOption * * @param string $name * @param string $description - * @param string|null $shortCut + * @param string|array|null $shortCut */ public function __construct( $name, diff --git a/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php index 0133a03300732..efc8ffea4d249 100644 --- a/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php @@ -32,7 +32,7 @@ class MultiSelectConfigOption extends AbstractConfigOption * @param array $selectOptions * @param string $description * @param array $defaultValue - * @param string|null $shortCut + * @param string|array|null $shortCut * @throws \InvalidArgumentException */ public function __construct( diff --git a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php index 6f72c4065c69e..05149154c6265 100644 --- a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php @@ -32,7 +32,7 @@ class SelectConfigOption extends AbstractConfigOption * @param array $selectOptions * @param string $description * @param string|null $defaultValue - * @param string|null $shortCut + * @param string|array|null $shortCut * @throws \InvalidArgumentException */ public function __construct( diff --git a/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php index 82eaf2b4fa738..3a6ec95d8b333 100644 --- a/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php @@ -25,7 +25,7 @@ class TextConfigOption extends AbstractConfigOption * @param string $frontendType * @param string $description * @param string|null $defaultValue - * @param string|null $shortCut + * @param string|array|null $shortCut * @throws \InvalidArgumentException */ public function __construct( From 66d04cfb00f21c347c6bd34722f18a45517c9567 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 6 Mar 2015 15:30:01 -0600 Subject: [PATCH 061/214] MAGETWO-34657: Implement config options for 'resource' segment - removing unused code. --- .../unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 89b02d552c80b..8161197fb2f96 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -5,8 +5,6 @@ */ namespace Magento\Setup\Model; -use Magento\Framework\App\DeploymentConfig\ResourceConfig; - class ConfigOptionsTest extends \PHPUnit_Framework_TestCase { /** From ef7d65b2db06c7850f3d60fb8827f77ab1ae68ac Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 6 Mar 2015 16:54:44 -0600 Subject: [PATCH 062/214] MAGETWO-34692: Implement config options for 'db' segment - Changes based on code review feedback. --- .../Magento/Setup/Model/ConfigOptionsTest.php | 19 ++++++++++------- .../src/Magento/Setup/Model/ConfigOptions.php | 21 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 8161197fb2f96..0e12badc97e61 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -38,9 +38,9 @@ public function testCreateConfig() ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db', ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', ]); - $this->assertEquals(5, count($config)); + $this->assertEquals(6, count($config)); $this->assertNotEmpty($config[0]->getData()['date']); $this->assertNotEmpty($config[1]->getData()['key']); $this->assertEquals('key', $config[1]->getData()['key']); @@ -55,7 +55,7 @@ public function testCreateConfigNoSessionSave() ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key', ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', ]); $this->assertNotEmpty($config[3]); $this->assertEquals('files', $config[3]->getData()['save']); @@ -71,7 +71,7 @@ public function testCreateConfigInvalidSessionSave() ConfigOptions::INPUT_KEY_SESSION_SAVE => 'invalid', ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', ]); } @@ -94,13 +94,13 @@ public function createConfigNoKeyDataProvider() 'no key data' => [[ ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', ]], 'no frontName' => [[ 'something_else' => 'something', ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbPass', + ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', ]], ]; } @@ -143,9 +143,12 @@ public function testCreateConfigInvalidDB() public function testCreateResourceConfig() { - $options = []; + $options = [ + ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', + ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', + ConfigOptions::INPUT_KEY_DB_USER => 'dbUser' + ]; $expected = [ConfigOptions::INPUT_KEY_RESOURCE =>['default_setup' => ['connection' => 'default']]]; $this->assertSame($expected, $this->object->createConfig($options)); } - } diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 35c3e2a0a5379..9fbb9ce8e13b0 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -44,6 +44,7 @@ class ConfigOptions implements ConfigOptionsInterface const INPUT_KEY_DB_PREFIX = 'db_prefix'; const INPUT_KEY_DB_MODEL = 'db_model'; const INPUT_KEY_DB_INIT_STATEMENTS = 'db_init_statements'; + const INPUT_KEY_ACTIVE = 'active'; const INPUT_KEY_RESOURCE = 'resource'; /**#@-*/ @@ -82,6 +83,7 @@ class ConfigOptions implements ConfigOptionsInterface self::INPUT_KEY_DB_PREFIX => DbConfig::KEY_PREFIX, self::INPUT_KEY_DB_MODEL => DbConfig::KEY_MODEL, self::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, + self::INPUT_KEY_ACTIVE => DbConfig::KEY_ACTIVE, self::INPUT_KEY_CRYPT_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, self::INPUT_KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, self::INPUT_KEY_RESOURCE => ResourceConfig::CONFIG_KEY, @@ -229,15 +231,16 @@ public function createConfig(array $data) } $connection[self::$paramMap[$key]] = $data[$key]; } - $optional = [self::INPUT_KEY_DB_INIT_STATEMENTS, self::INPUT_KEY_DB_MODEL, self::INPUT_KEY_DB_PASS]; - foreach ($optional as $key) { - $connection[self::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : null; - } - $prefixKey = self::INPUT_KEY_DB_PREFIX; - $dbData = [ - self::$paramMap[$prefixKey] => isset($data[$prefixKey]) ? $data[$prefixKey] : null, - 'connection' => ['default' => $connection], - ]; + $connection[self::$paramMap[self::INPUT_KEY_DB_PASS]] = isset($data[self::INPUT_KEY_DB_PASS]) ? + $data[self::INPUT_KEY_DB_PASS] : ''; + $connection[self::$paramMap[self::INPUT_KEY_DB_MODEL]] = isset($data[self::INPUT_KEY_DB_MODEL]) ? + $data[self::INPUT_KEY_DB_MODEL] : 'mysql4'; + $connection[self::$paramMap[self::INPUT_KEY_DB_INIT_STATEMENTS]] = + isset($data[self::INPUT_KEY_DB_INIT_STATEMENTS]) ? $data[self::INPUT_KEY_DB_INIT_STATEMENTS] + : 'SET NAMES utf8;'; + $connection[self::$paramMap[self::INPUT_KEY_ACTIVE]] = '1'; + $prefixKey = isset($data[self::INPUT_KEY_DB_PREFIX]) ? $data[self::INPUT_KEY_DB_PREFIX] : ''; + $dbData = [ $prefixKey, 'connection' => ['default' => $connection]]; $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); //resource segment From b28731c149e42b7787ed8072639e85fb6e3942f5 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 6 Mar 2015 17:28:38 -0600 Subject: [PATCH 063/214] MAGETWO-34692: Implement config options for 'db' segment - Fixed a bug in the code. --- setup/src/Magento/Setup/Model/ConfigOptions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 9fbb9ce8e13b0..192b4fa20c652 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -240,7 +240,10 @@ public function createConfig(array $data) : 'SET NAMES utf8;'; $connection[self::$paramMap[self::INPUT_KEY_ACTIVE]] = '1'; $prefixKey = isset($data[self::INPUT_KEY_DB_PREFIX]) ? $data[self::INPUT_KEY_DB_PREFIX] : ''; - $dbData = [ $prefixKey, 'connection' => ['default' => $connection]]; + $dbData = [ + self::$paramMap[self::INPUT_KEY_DB_PREFIX] => $prefixKey, + 'connection' => ['default' => $connection] + ]; $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); //resource segment From e627a15d350e39270ad0a5d40a31cff6a431ecd7 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 6 Mar 2015 18:52:47 -0600 Subject: [PATCH 064/214] MAGETWO-34855: Split createConfig in ConfigOptions into smaller functions - adding ConfigDataGenerator for first time - modifying tests --- .../Setup/Model/ConfigDataGeneratorTest.php | 132 +++++++++++++ .../Magento/Setup/Model/ConfigOptionsTest.php | 149 +++----------- .../Setup/Model/ConfigDataGenerator.php | 187 ++++++++++++++++++ .../src/Magento/Setup/Model/ConfigOptions.php | 138 ++----------- 4 files changed, 356 insertions(+), 250 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php create mode 100644 setup/src/Magento/Setup/Model/ConfigDataGenerator.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php new file mode 100644 index 0000000000000..e4953b6a8ff4c --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php @@ -0,0 +1,132 @@ +getMock('Magento\Framework\Math\Random', [], [], '', false); + $random->expects($this->any())->method('getRandomString')->willReturn('key'); + $loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); + $loader->expects($this->any())->method('load')->willReturn(['module1', 'module2']); + $deployConfig= $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $deployConfig->expects($this->any())->method('isAvailable')->willReturn(false); + $this->object = new ConfigDataGenerator($random, $loader, $deployConfig); + } + + public function testCreateInstallConfig() + { + $returnValue = $this->object->createInstallConfig(); + $this->assertInstanceOf('Magento\Framework\Config\Data\ConfigData', $returnValue); + $this->assertEquals('install', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + } + + public function testCreateCryptConfigWithInput() + { + $testData = [ConfigOptions::INPUT_KEY_CRYPT_KEY => 'some-test_key']; + $returnValue = $this->object->createCryptConfig($testData); + $this->assertEquals('crypt', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(['key' => 'some-test_key'], $returnValue->getData()); + } + + public function testCreateCryptConfigWithoutInput() + { + $returnValue = $this->object->createCryptConfig([]); + $this->assertEquals('crypt', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(['key' => md5('key')], $returnValue->getData()); + } + + public function testCreateModuleConfig() + { + $returnValue = $this->object->createModuleConfig(); + $this->assertEquals('modules', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(['module1' => 1, 'module2' => 1], $returnValue->getData()); + } + + public function testCreateSessionConfigWithInput() + { + $testData = [ConfigOptions::INPUT_KEY_SESSION_SAVE => 'files']; + $returnValue = $this->object->createSessionConfig($testData); + $this->assertEquals('session', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_FILES], $returnValue->getData()); + + $testData = [ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db']; + $returnValue = $this->object->createSessionConfig($testData); + $this->assertEquals('session', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_DB], $returnValue->getData()); + } + + public function testCreateSessionConfigWithoutInput() + { + $returnValue = $this->object->createSessionConfig([]); + $this->assertEquals('session', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_FILES], $returnValue->getData()); + } + + public function testCreateDefinitionsConfig() + { + $testData = [ConfigOptions::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; + $returnValue = $this->object->createDefinitionsConfig($testData); + $this->assertEquals('definition', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(['format' => 'test-format'], $returnValue->getData()); + } + + public function testCreateDbConfig() + { + $testData = [ + ConfigOptions::INPUT_KEY_DB_HOST => 'testLocalhost', + ConfigOptions::INPUT_KEY_DB_NAME => 'testDbName', + ConfigOptions::INPUT_KEY_DB_USER => 'testDbUser', + ConfigOptions::INPUT_KEY_DB_PREFIX => 'testSomePrefix', + ]; + $returnValue = $this->object->createDbConfig($testData); + $this->assertEquals('db', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $dbData = $returnValue->getData(); + $this->assertArrayHasKey('table_prefix', $dbData); + $this->assertSame('testSomePrefix', $dbData['table_prefix']); + $this->assertArrayHasKey('connection', $dbData); + $this->assertArrayHasKey('default', $dbData['connection']); + $this->assertArrayHasKey('host', $dbData['connection']['default']); + $this->assertSame('testLocalhost', $dbData['connection']['default']['host']); + $this->assertArrayHasKey('dbname', $dbData['connection']['default']); + $this->assertSame('testDbName', $dbData['connection']['default']['dbname']); + $this->assertArrayHasKey('username', $dbData['connection']['default']); + $this->assertSame('testDbUser', $dbData['connection']['default']['username']); + $this->assertArrayHasKey('password', $dbData['connection']['default']); + $this->assertSame('', $dbData['connection']['default']['password']); + $this->assertArrayHasKey('model', $dbData['connection']['default']); + $this->assertSame('mysql4', $dbData['connection']['default']['model']); + $this->assertArrayHasKey('initStatements', $dbData['connection']['default']); + $this->assertSame('SET NAMES utf8;', $dbData['connection']['default']['initStatements']); + $this->assertArrayHasKey('active', $dbData['connection']['default']); + $this->assertSame('1', $dbData['connection']['default']['active']); + } + + public function testCreateResourceConfig() + { + $returnValue = $this->object->createResourceConfig(); + $this->assertEquals('resource', $returnValue->getSegmentKey()); + $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); + $this->assertEquals(['resource' => ['default_setup' => ['connection' => 'default']]], $returnValue->getData()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 0e12badc97e61..03824e33690b8 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -12,15 +12,15 @@ class ConfigOptionsTest extends \PHPUnit_Framework_TestCase */ private $object; + /** + * @var ConfigDataGenerator|\PHPUnit_Framework_MockObject_MockObject + */ + private $generator; + protected function setUp() { - $random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); - $random->expects($this->any())->method('getRandomString')->willReturn('key'); - $loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); - $loader->expects($this->any())->method('load')->willReturn(['module1', 'module2']); - $deployConfig= $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $deployConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $this->object = new ConfigOptions($random, $loader, $deployConfig); + $this->generator = $this->getMock('\Magento\Setup\Model\ConfigDataGenerator', [], [], '', false); + $this->object = new ConfigOptions($this->generator); } public function testGetOptions() @@ -28,127 +28,26 @@ public function testGetOptions() $options = $this->object->getOptions(); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[0]); $this->assertInstanceOf('Magento\Framework\Setup\Option\SelectConfigOption', $options[1]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\SelectConfigOption', $options[2]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[3]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[4]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[5]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[6]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[7]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[8]); + $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[9]); $this->assertEquals(10, count($options)); } - public function testCreateConfig() - { - $config = $this->object->createConfig([ - ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key', - ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db', - ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', - ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', - ]); - $this->assertEquals(6, count($config)); - $this->assertNotEmpty($config[0]->getData()['date']); - $this->assertNotEmpty($config[1]->getData()['key']); - $this->assertEquals('key', $config[1]->getData()['key']); - $this->assertEquals(2, count($config[2]->getData())); - $this->assertNotEmpty($config[3]->getData()['save']); - $this->assertEquals('db', $config[3]->getData()['save']); - } - - public function testCreateConfigNoSessionSave() - { - $config = $this->object->createConfig([ - ConfigOptions::INPUT_KEY_CRYPT_KEY => 'key', - ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', - ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', - ]); - $this->assertNotEmpty($config[3]); - $this->assertEquals('files', $config[3]->getData()['save']); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid session save location. - */ - public function testCreateConfigInvalidSessionSave() - { - $this->object->createConfig([ - ConfigOptions::INPUT_KEY_SESSION_SAVE => 'invalid', - ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', - ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', - ]); - } - - /** - * @param array $options - * @dataProvider createConfigNoKeyDataProvider - */ - public function testCreateConfigNoKey(array $options) - { - $config = $this->object->createConfig($options); - $this->assertEquals(md5('key'), $config[1]->getData()['key']); - } - - /** - * @return array - */ - public function createConfigNoKeyDataProvider() - { - return [ - 'no key data' => [[ - ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', - ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', - ]], - 'no frontName' => [[ - 'something_else' => 'something', - ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', - ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbUser', - ]], - ]; - } - - /** - * @param array $options - * - * @dataProvider createConfigInvalidKeyDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid encryption key. - */ - public function testCreateConfigInvalidKey(array $options) - { - $this->object->createConfig($options); - } - - /** - * @return array - */ - public function createConfigInvalidKeyDataProvider() - { - return [ - [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '']], - [[ConfigOptions::INPUT_KEY_CRYPT_KEY => '0']], - ]; - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Missing value for db configuration: db_user - */ - public function testCreateConfigInvalidDB() - { - $data = [ - ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', - ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ]; - $this->object->createConfig($data); - } - - public function testCreateResourceConfig() + public function testCreateOptions() { - $options = [ - ConfigOptions::INPUT_KEY_DB_HOST => 'localhost', - ConfigOptions::INPUT_KEY_DB_NAME => 'dbName', - ConfigOptions::INPUT_KEY_DB_USER => 'dbUser' - ]; - $expected = [ConfigOptions::INPUT_KEY_RESOURCE =>['default_setup' => ['connection' => 'default']]]; - $this->assertSame($expected, $this->object->createConfig($options)); + $this->generator->expects($this->once())->method('createInstallConfig'); + $this->generator->expects($this->once())->method('createCryptConfig'); + $this->generator->expects($this->once())->method('createModuleConfig'); + $this->generator->expects($this->once())->method('createSessionConfig'); + $this->generator->expects($this->once())->method('createDefinitionsConfig'); + $this->generator->expects($this->once())->method('createDbConfig'); + $this->generator->expects($this->once())->method('createResourceConfig'); + $this->object->createConfig([]); } } diff --git a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php b/setup/src/Magento/Setup/Model/ConfigDataGenerator.php new file mode 100644 index 0000000000000..1482deb15a3e2 --- /dev/null +++ b/setup/src/Magento/Setup/Model/ConfigDataGenerator.php @@ -0,0 +1,187 @@ + DbConfig::KEY_HOST, + ConfigOptions::INPUT_KEY_DB_NAME => DbConfig::KEY_NAME, + ConfigOptions::INPUT_KEY_DB_USER => DbConfig::KEY_USER, + ConfigOptions::INPUT_KEY_DB_PASS => DbConfig::KEY_PASS, + ConfigOptions::INPUT_KEY_DB_PREFIX => DbConfig::KEY_PREFIX, + ConfigOptions::INPUT_KEY_DB_MODEL => DbConfig::KEY_MODEL, + ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, + ConfigOptions::INPUT_KEY_ACTIVE => DbConfig::KEY_ACTIVE, + ConfigOptions::INPUT_KEY_CRYPT_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, + ConfigOptions::INPUT_KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, + ConfigOptions::INPUT_KEY_RESOURCE => ResourceConfig::CONFIG_KEY, + ]; + + public function __construct(Random $random, Loader $moduleLoader, DeploymentConfig $deploymentConfig) + { + $this->random = $random; + $this->deploymentConfig = $deploymentConfig; + $this->moduleList = array_values($moduleLoader->load()); + } + + /** + * Creates install segment config data + * + * @return ConfigData + */ + public function createInstallConfig() + { + return new ConfigData(ConfigFilePool::APP_CONFIG, 'install', [InstallConfig::KEY_DATE => date('r')]); + } + + /** + * Creates encryption key config data + * @param array $data + * @return ConfigData + * @throws \InvalidArgumentException + */ + public function createCryptConfig(array $data) + { + if (isset($data[ConfigOptions::INPUT_KEY_CRYPT_KEY]) && !$data[ConfigOptions::INPUT_KEY_CRYPT_KEY]) { + throw new \InvalidArgumentException('Invalid encryption key.'); + } + $cryptData = []; + if (!isset($data[ConfigOptions::INPUT_KEY_CRYPT_KEY])) { + $cryptData[self::$paramMap[ConfigOptions::INPUT_KEY_CRYPT_KEY]] = md5($this->random->getRandomString(10)); + } else { + $cryptData[self::$paramMap[ConfigOptions::INPUT_KEY_CRYPT_KEY]] = $data[ConfigOptions::INPUT_KEY_CRYPT_KEY]; + } + return new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); + } + + /** + * Creates module config data + * + * @return ConfigData + */ + public function createModuleConfig() + { + if (!$this->deploymentConfig->isAvailable()) { + $modulesData = []; + if (isset($this->moduleList)) { + foreach (array_values($this->moduleList) as $key) { + $modulesData[$key] = 1; + } + } + return new ConfigData(ConfigFilePool::APP_CONFIG, 'modules', $modulesData); + } + } + + /** + * Creates session config data + * + * @param array $data + * @return ConfigData + * @throws \InvalidArgumentException + */ + public function createSessionConfig(array $data) + { + $sessionData = []; + if (isset($data[ConfigOptions::INPUT_KEY_SESSION_SAVE])) { + if ($data[ConfigOptions::INPUT_KEY_SESSION_SAVE] != ConfigOptions::SESSION_SAVE_FILES && + $data[ConfigOptions::INPUT_KEY_SESSION_SAVE] != ConfigOptions::SESSION_SAVE_DB + ) { + throw new \InvalidArgumentException('Invalid session save location.'); + } + $sessionData[self::$paramMap[ConfigOptions::INPUT_KEY_SESSION_SAVE]] = + $data[ConfigOptions::INPUT_KEY_SESSION_SAVE]; + } else { + $sessionData[self::$paramMap[ConfigOptions::INPUT_KEY_SESSION_SAVE]] = ConfigOptions::SESSION_SAVE_FILES; + } + return new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); + } + + /** + * Creates definitions config data + * + * @param array $data + * @return ConfigData + */ + public function createDefinitionsConfig(array $data) + { + // definitions segment + if (!empty($data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT])) { + $config['definition']['format'] = $data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT]; + return new ConfigData( + ConfigFilePool::APP_CONFIG, + 'definition', + ['format' => $data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT]] + ); + } + } + + /** + * Creates db config data + * + * @param array $data + * @return ConfigData + * @throws \InvalidArgumentException + */ + public function createDbConfig(array $data) + { + // db segment + $connection = []; + $required = [ + ConfigOptions::INPUT_KEY_DB_HOST, + ConfigOptions::INPUT_KEY_DB_NAME, + ConfigOptions::INPUT_KEY_DB_USER + ]; + foreach ($required as $key) { + if (!isset($data[$key])) { + throw new \InvalidArgumentException("Missing value for db configuration: {$key}"); + } + $connection[self::$paramMap[$key]] = $data[$key]; + } + $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_PASS]] = + isset($data[ConfigOptions::INPUT_KEY_DB_PASS]) ? $data[ConfigOptions::INPUT_KEY_DB_PASS] : ''; + $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_MODEL]] = + isset($data[ConfigOptions::INPUT_KEY_DB_MODEL]) ? $data[ConfigOptions::INPUT_KEY_DB_MODEL] : 'mysql4'; + $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS]] = + isset($data[ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS]) ? + $data[ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS] : 'SET NAMES utf8;'; + $connection[self::$paramMap[ConfigOptions::INPUT_KEY_ACTIVE]] = '1'; + $prefixKey = isset($data[ConfigOptions::INPUT_KEY_DB_PREFIX]) ? $data[ConfigOptions::INPUT_KEY_DB_PREFIX] : ''; + $dbData = [ + self::$paramMap[ConfigOptions::INPUT_KEY_DB_PREFIX] => $prefixKey, + 'connection' => ['default' => $connection] + ]; + return new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); + } + + /** + * Creates resource config data + * + * @return ConfigData + */ + public function createResourceConfig() + { + $resourceData[self::$paramMap[ConfigOptions::INPUT_KEY_RESOURCE]] = + ['default_setup' => ['connection' => 'default']]; + return new ConfigData(ConfigFilePool::APP_CONFIG, 'resource', $resourceData); + } +} diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 192b4fa20c652..a0b1c2cf24622 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -5,20 +5,11 @@ */ namespace Magento\Setup\Model; -use Magento\Framework\Config\Data\ConfigData; -use Magento\Framework\Config\File\ConfigFilePool; -use Magento\Framework\Math\Random; use Magento\Framework\ObjectManager\DefinitionFactory; use Magento\Framework\Setup\ConfigOptionsInterface; use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; -use Magento\Framework\Module\ModuleList\Loader; use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\App\DeploymentConfig\DbConfig; -use Magento\Framework\App\DeploymentConfig\EncryptConfig; -use Magento\Framework\App\DeploymentConfig\InstallConfig; -use Magento\Framework\App\DeploymentConfig\SessionConfig; -use Magento\Framework\App\DeploymentConfig\ResourceConfig; /** * Deployment configuration options needed for Setup application @@ -56,51 +47,20 @@ class ConfigOptions implements ConfigOptionsInterface /**#@-*/ /** - * @var DeploymentConfig - */ - private $deploymentConfig; - - /** - * @var array - */ - private $moduleList; - - /** - * @var Random - */ - private $random; - - /** - * Maps configuration parameters to array keys in deployment config file + * Generate config data for individual segments * - * @var array + * @var ConfigDataGenerator */ - public static $paramMap = [ - self::INPUT_KEY_DB_HOST => DbConfig::KEY_HOST, - self::INPUT_KEY_DB_NAME => DbConfig::KEY_NAME, - self::INPUT_KEY_DB_USER => DbConfig::KEY_USER, - self::INPUT_KEY_DB_PASS => DbConfig::KEY_PASS, - self::INPUT_KEY_DB_PREFIX => DbConfig::KEY_PREFIX, - self::INPUT_KEY_DB_MODEL => DbConfig::KEY_MODEL, - self::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, - self::INPUT_KEY_ACTIVE => DbConfig::KEY_ACTIVE, - self::INPUT_KEY_CRYPT_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, - self::INPUT_KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, - self::INPUT_KEY_RESOURCE => ResourceConfig::CONFIG_KEY, - ]; + private $configDataGenerator; /** * Constructor * - * @param Random $random - * @param Loader $moduleLoader - * @param DeploymentConfig $deploymentConfig + * @param ConfigDataGenerator $configDataGenerator */ - public function __construct(Random $random, Loader $moduleLoader, DeploymentConfig $deploymentConfig) + public function __construct(ConfigDataGenerator $configDataGenerator) { - $this->random = $random; - $this->deploymentConfig = $deploymentConfig; - $this->moduleList = array_keys($moduleLoader->load()); + $this->configDataGenerator = $configDataGenerator; } /** @@ -171,85 +131,13 @@ public function getOptions() public function createConfig(array $data) { $configData = []; - // install segment - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'install', [InstallConfig::KEY_DATE => date('r')]); - - // crypt segment - if (isset($data[self::INPUT_KEY_CRYPT_KEY]) && !$data[self::INPUT_KEY_CRYPT_KEY]) { - throw new \InvalidArgumentException('Invalid encryption key.'); - } - $cryptData = []; - if (!isset($data[self::INPUT_KEY_CRYPT_KEY])) { - $cryptData[self::$paramMap[self::INPUT_KEY_CRYPT_KEY]] = md5($this->random->getRandomString(10)); - } else { - $cryptData[self::$paramMap[self::INPUT_KEY_CRYPT_KEY]] = $data[self::INPUT_KEY_CRYPT_KEY]; - } - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); - - // module segment - if (!$this->deploymentConfig->isAvailable()) { - $modulesData = []; - if (isset($this->moduleList)) { - foreach (array_values($this->moduleList) as $key) { - $modulesData[$key] = 1; - } - } - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'modules', $modulesData); - } - - // session segment - $sessionData = []; - if (isset($data[self::INPUT_KEY_SESSION_SAVE])) { - if ($data[self::INPUT_KEY_SESSION_SAVE] != self::SESSION_SAVE_FILES && - $data[self::INPUT_KEY_SESSION_SAVE] != self::SESSION_SAVE_DB - ) { - throw new \InvalidArgumentException('Invalid session save location.'); - } - $sessionData[self::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = - $data[self::INPUT_KEY_SESSION_SAVE]; - } else { - $sessionData[self::$paramMap[self::INPUT_KEY_SESSION_SAVE]] = self::SESSION_SAVE_FILES; - } - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); - - // definitions segment - if (!empty($data[self::INPUT_KEY_DEFINITION_FORMAT])) { - $config['definition']['format'] = $data[self::INPUT_KEY_DEFINITION_FORMAT]; - $configData[] = new ConfigData( - ConfigFilePool::APP_CONFIG, - 'definition', - ['format' => $data[self::INPUT_KEY_DEFINITION_FORMAT]] - ); - } - - // db segment - $connection = []; - $required = [self::INPUT_KEY_DB_HOST, self::INPUT_KEY_DB_NAME, self::INPUT_KEY_DB_USER]; - foreach ($required as $key) { - if (!isset($data[$key])) { - throw new \InvalidArgumentException("Missing value for db configuration: {$key}"); - } - $connection[self::$paramMap[$key]] = $data[$key]; - } - $connection[self::$paramMap[self::INPUT_KEY_DB_PASS]] = isset($data[self::INPUT_KEY_DB_PASS]) ? - $data[self::INPUT_KEY_DB_PASS] : ''; - $connection[self::$paramMap[self::INPUT_KEY_DB_MODEL]] = isset($data[self::INPUT_KEY_DB_MODEL]) ? - $data[self::INPUT_KEY_DB_MODEL] : 'mysql4'; - $connection[self::$paramMap[self::INPUT_KEY_DB_INIT_STATEMENTS]] = - isset($data[self::INPUT_KEY_DB_INIT_STATEMENTS]) ? $data[self::INPUT_KEY_DB_INIT_STATEMENTS] - : 'SET NAMES utf8;'; - $connection[self::$paramMap[self::INPUT_KEY_ACTIVE]] = '1'; - $prefixKey = isset($data[self::INPUT_KEY_DB_PREFIX]) ? $data[self::INPUT_KEY_DB_PREFIX] : ''; - $dbData = [ - self::$paramMap[self::INPUT_KEY_DB_PREFIX] => $prefixKey, - 'connection' => ['default' => $connection] - ]; - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); - - //resource segment - $resourceData[self::$paramMap[self::INPUT_KEY_RESOURCE]] = ['default_setup' => ['connection' => 'default']]; - $configData[] = new ConfigData(ConfigFilePool::APP_CONFIG, 'resource', $resourceData); - + $configData[] = $this->configDataGenerator->createInstallConfig(); + $configData[] = $this->configDataGenerator->createCryptConfig($data); + $configData[] = $this->configDataGenerator->createModuleConfig(); + $configData[] = $this->configDataGenerator->createSessionConfig($data); + $configData[] = $this->configDataGenerator->createDefinitionsConfig($data); + $configData[] = $this->configDataGenerator->createDbConfig($data); + $configData[] = $this->configDataGenerator->createResourceConfig(); return $configData; } } From c009f4070e360a3a0d9c818ee6d12bd4565caa2a Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 08:55:22 -0500 Subject: [PATCH 065/214] MAGETWO-34511: Process config options - added validate() to ConfigOptions inteface - implemented initialize() in ConfigInstallCommand --- .../Magento/Backend/Setup/ConfigOptions.php | 21 +++++++++------ .../Setup/ConfigOptionsInterface.php | 9 ++++++- .../Console/Command/ConfigInstallCommand.php | 27 +++++++++++++++++++ .../Setup/Model/ConfigDataGenerator.php | 2 +- setup/src/Magento/Setup/Model/ConfigModel.php | 18 +++++++------ .../src/Magento/Setup/Model/ConfigOptions.php | 8 ++++++ 6 files changed, 67 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php index 15f397c0d919f..280c973fa2a7e 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -45,18 +45,23 @@ public function getOptions() */ public function createConfig(array $options) { - if (empty($options[self::INPUT_KEY_BACKEND_FRONTNAME])) { - throw new \InvalidArgumentException('No backend frontname provided.'); - } - if (!preg_match('/^[a-zA-Z0-9_]+$/', $options[self::INPUT_KEY_BACKEND_FRONTNAME])) { - throw new \InvalidArgumentException( - "Invalid backend frontname {$options[self::INPUT_KEY_BACKEND_FRONTNAME]}" - ); - } return [new ConfigData( ConfigFilePool::APP_CONFIG, 'backend', ['frontName' => $options[self::INPUT_KEY_BACKEND_FRONTNAME]] )]; } + + /** + * {@inheritdoc} + */ + public function validate(array $options) + { + $errors = []; + if (!preg_match('/^[a-zA-Z0-9_]+$/', $options[self::INPUT_KEY_BACKEND_FRONTNAME])) { + $errors[] = "Invalid backend frontname {$options[self::INPUT_KEY_BACKEND_FRONTNAME]}"; + } + + return $errors; + } } diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php index bcaef2f366ca2..8e1abb67218b3 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php @@ -24,7 +24,14 @@ public function getOptions(); * * @param array $options * @return \Magento\Framework\Config\Data\ConfigData[] - * @throws \InvalidArgumentException */ public function createConfig(array $options); + + /** + * Validates user input option values and returns error messages + * + * @param array $options + * @return array + */ + public function validate(array $options); } diff --git a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php index 4cc1b9cce2a3f..b7be95accf231 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php @@ -23,6 +23,11 @@ class ConfigInstallCommand extends Command */ protected $configFilePool; + /** + * @var array + */ + protected $errors; + /** * Constructor *s @@ -47,6 +52,8 @@ protected function configure() ->setName('config:install') ->setDescription('Install deployment configuration') ->setDefinition($options); + + $this->ignoreValidationErrors(); } /** @@ -60,5 +67,25 @@ protected function execute(InputInterface $input, OutputInterface $output) } + /** + * {@inheritdoc} + */ + public function initialize(InputInterface $input, OutputInterface $output) + { + $inputOptions = $input->getOptions(); + + $errors = []; + + $options = $this->configModel->getAvailableOptions(); + foreach ($options as $option) { + try { + $option->validate($inputOptions[$option->getName()]); + } catch (\InvalidArgumentException $e) { + $errors[] = $e->getMessage(); + } + + } + $this->errors = $errors; + } } diff --git a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php b/setup/src/Magento/Setup/Model/ConfigDataGenerator.php index 1482deb15a3e2..6582e4fcfdcd6 100644 --- a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigDataGenerator.php @@ -41,7 +41,7 @@ public function __construct(Random $random, Loader $moduleLoader, DeploymentConf { $this->random = $random; $this->deploymentConfig = $deploymentConfig; - $this->moduleList = array_values($moduleLoader->load()); + $this->moduleList = array_keys($moduleLoader->load()); } /** diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 4bc6cc7f80bed..17518af2a6bf6 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -40,7 +40,6 @@ public function getAvailableOptions() $options = $this->collector->collectOptions(); foreach ($options as $option) { - // TODO: we need to get rid of keys here $optionCollection = array_merge($optionCollection, $option->getOptions()); } @@ -62,21 +61,24 @@ public function process($inputOptions) foreach ($options as $moduleName => $option) { if (!$option instanceof ConfigOptionsInterface) { - // TODO: ROMOVE IT! - echo "FIX IT!: " . 'ConfigOption for module:' . $moduleName . ' does not implement ConfigOptionsInterface' . PHP_EOL; - continue; throw new \Exception( 'ConfigOption for module:' . $moduleName . ' does not implement ConfigOptionsInterface' ); } - $configData = $option->createConfig($inputOptions); + $errors = $option->validate($inputOptions); + if ($errors) { + var_dump($errors); + die('______'); + } else { + $configData = $option->createConfig($inputOptions); + } + + + foreach ($configData as $config) { if (!$config instanceof ConfigData) { - // TODO: ROMOVE IT! - echo "FIX IT!: " . 'In module : ' .$moduleName . 'ConfigOption::createConfig should return instance of ConfigData' . PHP_EOL; - continue; throw new \Exception( 'In module : ' .$moduleName . 'ConfigOption::createConfig should return instance of ConfigData' ); diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index a0b1c2cf24622..b8fd28db4d3c4 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -140,4 +140,12 @@ public function createConfig(array $data) $configData[] = $this->configDataGenerator->createResourceConfig(); return $configData; } + + /** + * {@inheritdoc} + */ + public function validate(array $options) + { + return []; + } } From 0900cdc363a259f30551e7ab2a2838c59a563e38 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 9 Mar 2015 09:19:30 -0500 Subject: [PATCH 066/214] MAGETWO-34855: Split createConfig in ConfigOptions into smaller functions - fixed for optional items --- setup/src/Magento/Setup/Model/ConfigOptions.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index b8fd28db4d3c4..ff6207a9a6d1f 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -133,9 +133,15 @@ public function createConfig(array $data) $configData = []; $configData[] = $this->configDataGenerator->createInstallConfig(); $configData[] = $this->configDataGenerator->createCryptConfig($data); - $configData[] = $this->configDataGenerator->createModuleConfig(); + $modulesConfig = $this->configDataGenerator->createModuleConfig(); + if (isset($modulesConfig)) { + $configData[] = $modulesConfig; + } $configData[] = $this->configDataGenerator->createSessionConfig($data); - $configData[] = $this->configDataGenerator->createDefinitionsConfig($data); + $definitionConfig = $this->configDataGenerator->createDefinitionsConfig($data); + if (isset($definitionConfig)) { + $configData[] = $definitionConfig; + } $configData[] = $this->configDataGenerator->createDbConfig($data); $configData[] = $this->configDataGenerator->createResourceConfig(); return $configData; From 33b114ba385e71e62b7ab6e8810e3390f71a065b Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 9 Mar 2015 09:54:06 -0500 Subject: [PATCH 067/214] MAGETWO-34855: Split createConfig in ConfigOptions into smaller functions - fixing tests --- .../Magento/Setup/Model/ConfigOptionsTest.php | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 03824e33690b8..04880f2bfe6fc 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -19,7 +19,7 @@ class ConfigOptionsTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->generator = $this->getMock('\Magento\Setup\Model\ConfigDataGenerator', [], [], '', false); + $this->generator = $this->getMock('Magento\Setup\Model\ConfigDataGenerator', [], [], '', false); $this->object = new ConfigOptions($this->generator); } @@ -27,27 +27,53 @@ public function testGetOptions() { $options = $this->object->getOptions(); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[0]); + $this->assertSame('Encryption key', $options[0]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\SelectConfigOption', $options[1]); + $this->assertSame('Session save location', $options[1]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\SelectConfigOption', $options[2]); + $this->assertSame('Type of definitions used by Object Manager', $options[2]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[3]); + $this->assertSame('Database server host', $options[3]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[4]); + $this->assertSame('Database name', $options[4]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[5]); + $this->assertSame('Database server username', $options[5]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[6]); + $this->assertSame('Database server password', $options[6]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[7]); + $this->assertSame('Database table prefix', $options[7]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[8]); + $this->assertSame('Database type', $options[8]->getDescription()); $this->assertInstanceOf('Magento\Framework\Setup\Option\TextConfigOption', $options[9]); + $this->assertSame('Database initial set of commands', $options[9]->getDescription()); $this->assertEquals(10, count($options)); } public function testCreateOptions() { - $this->generator->expects($this->once())->method('createInstallConfig'); - $this->generator->expects($this->once())->method('createCryptConfig'); - $this->generator->expects($this->once())->method('createModuleConfig'); - $this->generator->expects($this->once())->method('createSessionConfig'); - $this->generator->expects($this->once())->method('createDefinitionsConfig'); - $this->generator->expects($this->once())->method('createDbConfig'); - $this->generator->expects($this->once())->method('createResourceConfig'); - $this->object->createConfig([]); + $configDataMock = $this->getMock('Magento\Framework\Config\Data\ConfigData', [], [], '', false); + $this->generator->expects($this->once())->method('createInstallConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createCryptConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createModuleConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createSessionConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createDefinitionsConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); + $configData = $this->object->createConfig([]); + $this->assertEquals(7 ,count($configData)); + } + + public function testCreateOptionsWithOptionalNull() + { + $configDataMock = $this->getMock('Magento\Framework\Config\Data\ConfigData', [], [], '', false); + $this->generator->expects($this->once())->method('createInstallConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createCryptConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createModuleConfig')->willReturn(null); + $this->generator->expects($this->once())->method('createSessionConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createDefinitionsConfig')->willReturn(null); + $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); + $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); + $configData = $this->object->createConfig([]); + $this->assertEquals(5 ,count($configData)); } } From 055f2d6ebac54aa8fc24d173575f5c04cea49d07 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 09:57:09 -0500 Subject: [PATCH 068/214] MAGETWO-34511: Process config options - moved validation from ConfigDataGenerator to ConfigOptions->validate() --- .../Setup/Model/ConfigDataGenerator.php | 23 +-------------- setup/src/Magento/Setup/Model/ConfigModel.php | 5 ++++ .../src/Magento/Setup/Model/ConfigOptions.php | 29 ++++++++++++++++++- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php b/setup/src/Magento/Setup/Model/ConfigDataGenerator.php index 6582e4fcfdcd6..df3b7fb8d7178 100644 --- a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigDataGenerator.php @@ -58,13 +58,9 @@ public function createInstallConfig() * Creates encryption key config data * @param array $data * @return ConfigData - * @throws \InvalidArgumentException */ public function createCryptConfig(array $data) { - if (isset($data[ConfigOptions::INPUT_KEY_CRYPT_KEY]) && !$data[ConfigOptions::INPUT_KEY_CRYPT_KEY]) { - throw new \InvalidArgumentException('Invalid encryption key.'); - } $cryptData = []; if (!isset($data[ConfigOptions::INPUT_KEY_CRYPT_KEY])) { $cryptData[self::$paramMap[ConfigOptions::INPUT_KEY_CRYPT_KEY]] = md5($this->random->getRandomString(10)); @@ -97,17 +93,11 @@ public function createModuleConfig() * * @param array $data * @return ConfigData - * @throws \InvalidArgumentException */ public function createSessionConfig(array $data) { $sessionData = []; if (isset($data[ConfigOptions::INPUT_KEY_SESSION_SAVE])) { - if ($data[ConfigOptions::INPUT_KEY_SESSION_SAVE] != ConfigOptions::SESSION_SAVE_FILES && - $data[ConfigOptions::INPUT_KEY_SESSION_SAVE] != ConfigOptions::SESSION_SAVE_DB - ) { - throw new \InvalidArgumentException('Invalid session save location.'); - } $sessionData[self::$paramMap[ConfigOptions::INPUT_KEY_SESSION_SAVE]] = $data[ConfigOptions::INPUT_KEY_SESSION_SAVE]; } else { @@ -140,23 +130,12 @@ public function createDefinitionsConfig(array $data) * * @param array $data * @return ConfigData - * @throws \InvalidArgumentException */ public function createDbConfig(array $data) { // db segment $connection = []; - $required = [ - ConfigOptions::INPUT_KEY_DB_HOST, - ConfigOptions::INPUT_KEY_DB_NAME, - ConfigOptions::INPUT_KEY_DB_USER - ]; - foreach ($required as $key) { - if (!isset($data[$key])) { - throw new \InvalidArgumentException("Missing value for db configuration: {$key}"); - } - $connection[self::$paramMap[$key]] = $data[$key]; - } + $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_PASS]] = isset($data[ConfigOptions::INPUT_KEY_DB_PASS]) ? $data[ConfigOptions::INPUT_KEY_DB_PASS] : ''; $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_MODEL]] = diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 17518af2a6bf6..13ccac6951f51 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -103,4 +103,9 @@ public function process($inputOptions) } + public function validate() + { + + } + } diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index ff6207a9a6d1f..9826ca8759a34 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -152,6 +152,33 @@ public function createConfig(array $data) */ public function validate(array $options) { - return []; + $errors = []; + + $required = [ + ConfigOptions::INPUT_KEY_DB_HOST, + ConfigOptions::INPUT_KEY_DB_NAME, + ConfigOptions::INPUT_KEY_DB_USER + ]; + + foreach ($required as $key) { + if (!isset($options[$key]) || empty($options[$key])) { + $errors[] = "Missing value for db configuration: {$key}"; + } + $connection[ConfigDataGenerator::$paramMap[$key]] = $options[$key]; + } + + if (isset($options[ConfigOptions::INPUT_KEY_CRYPT_KEY]) && !$options[ConfigOptions::INPUT_KEY_CRYPT_KEY]) { + $errors[] = 'Invalid encryption key.'; + } + + if (isset($options[ConfigOptions::INPUT_KEY_SESSION_SAVE])) { + if ($options[ConfigOptions::INPUT_KEY_SESSION_SAVE] != ConfigOptions::SESSION_SAVE_FILES && + $options[ConfigOptions::INPUT_KEY_SESSION_SAVE] != ConfigOptions::SESSION_SAVE_DB + ) { + $errors[] = 'Invalid session save location.'; + } + } + + return $errors; } } From 88894e0f7318c13d3b2aa0968d54cc013a447351 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 10:58:16 -0500 Subject: [PATCH 069/214] MAGETWO-34511: Process config options - fixed db config. --- setup/src/Magento/Setup/Model/ConfigDataGenerator.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php b/setup/src/Magento/Setup/Model/ConfigDataGenerator.php index df3b7fb8d7178..a8ff39c074c2a 100644 --- a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigDataGenerator.php @@ -136,6 +136,16 @@ public function createDbConfig(array $data) // db segment $connection = []; + $required = [ + ConfigOptions::INPUT_KEY_DB_HOST, + ConfigOptions::INPUT_KEY_DB_NAME, + ConfigOptions::INPUT_KEY_DB_USER + ]; + + foreach ($required as $key) { + $connection[ConfigDataGenerator::$paramMap[$key]] = $data[$key]; + } + $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_PASS]] = isset($data[ConfigOptions::INPUT_KEY_DB_PASS]) ? $data[ConfigOptions::INPUT_KEY_DB_PASS] : ''; $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_MODEL]] = From d190a1e3a6e57c67a3cb4234e31ff4ec4ee08e12 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 9 Mar 2015 11:00:37 -0500 Subject: [PATCH 070/214] MAGETWO-34855: Split createConfig in ConfigOptions into smaller functions - CR fixes --- .../Setup/Model/ConfigDataGeneratorTest.php | 32 +++++++++++-------- .../Magento/Setup/Model/ConfigOptionsTest.php | 6 ++-- ...gDataGenerator.php => ConfigGenerator.php} | 16 +++++++--- .../src/Magento/Setup/Model/ConfigOptions.php | 8 ++--- 4 files changed, 37 insertions(+), 25 deletions(-) rename setup/src/Magento/Setup/Model/{ConfigDataGenerator.php => ConfigGenerator.php} (95%) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php index e4953b6a8ff4c..3cc45a9dc6b2a 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php @@ -10,24 +10,28 @@ class ConfigDataGeneratorTest extends \PHPUnit_Framework_TestCase { /** - * @var ConfigDataGenerator + * @var ConfigGenerator */ - private $object; + private $configGeneratorObject; protected function setUp() { $random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); $random->expects($this->any())->method('getRandomString')->willReturn('key'); $loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); - $loader->expects($this->any())->method('load')->willReturn(['module1', 'module2']); + $loader->expects($this->any())->method('load')->willReturn([ + 'module1' => ['name' => 'module_one', 'version' => '1.0.0'], + 'module2' => ['name' => 'module_two', 'version' => '1.0.0'] + ] + ); $deployConfig= $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $deployConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $this->object = new ConfigDataGenerator($random, $loader, $deployConfig); + $this->configGeneratorObject = new ConfigGenerator($random, $loader, $deployConfig); } public function testCreateInstallConfig() { - $returnValue = $this->object->createInstallConfig(); + $returnValue = $this->configGeneratorObject->createInstallConfig(); $this->assertInstanceOf('Magento\Framework\Config\Data\ConfigData', $returnValue); $this->assertEquals('install', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); @@ -36,7 +40,7 @@ public function testCreateInstallConfig() public function testCreateCryptConfigWithInput() { $testData = [ConfigOptions::INPUT_KEY_CRYPT_KEY => 'some-test_key']; - $returnValue = $this->object->createCryptConfig($testData); + $returnValue = $this->configGeneratorObject->createCryptConfig($testData); $this->assertEquals('crypt', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['key' => 'some-test_key'], $returnValue->getData()); @@ -44,7 +48,7 @@ public function testCreateCryptConfigWithInput() public function testCreateCryptConfigWithoutInput() { - $returnValue = $this->object->createCryptConfig([]); + $returnValue = $this->configGeneratorObject->createCryptConfig([]); $this->assertEquals('crypt', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['key' => md5('key')], $returnValue->getData()); @@ -52,7 +56,7 @@ public function testCreateCryptConfigWithoutInput() public function testCreateModuleConfig() { - $returnValue = $this->object->createModuleConfig(); + $returnValue = $this->configGeneratorObject->createModuleConfig(); $this->assertEquals('modules', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['module1' => 1, 'module2' => 1], $returnValue->getData()); @@ -61,13 +65,13 @@ public function testCreateModuleConfig() public function testCreateSessionConfigWithInput() { $testData = [ConfigOptions::INPUT_KEY_SESSION_SAVE => 'files']; - $returnValue = $this->object->createSessionConfig($testData); + $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_FILES], $returnValue->getData()); $testData = [ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db']; - $returnValue = $this->object->createSessionConfig($testData); + $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_DB], $returnValue->getData()); @@ -75,7 +79,7 @@ public function testCreateSessionConfigWithInput() public function testCreateSessionConfigWithoutInput() { - $returnValue = $this->object->createSessionConfig([]); + $returnValue = $this->configGeneratorObject->createSessionConfig([]); $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_FILES], $returnValue->getData()); @@ -84,7 +88,7 @@ public function testCreateSessionConfigWithoutInput() public function testCreateDefinitionsConfig() { $testData = [ConfigOptions::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; - $returnValue = $this->object->createDefinitionsConfig($testData); + $returnValue = $this->configGeneratorObject->createDefinitionsConfig($testData); $this->assertEquals('definition', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['format' => 'test-format'], $returnValue->getData()); @@ -98,7 +102,7 @@ public function testCreateDbConfig() ConfigOptions::INPUT_KEY_DB_USER => 'testDbUser', ConfigOptions::INPUT_KEY_DB_PREFIX => 'testSomePrefix', ]; - $returnValue = $this->object->createDbConfig($testData); + $returnValue = $this->configGeneratorObject->createDbConfig($testData); $this->assertEquals('db', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $dbData = $returnValue->getData(); @@ -124,7 +128,7 @@ public function testCreateDbConfig() public function testCreateResourceConfig() { - $returnValue = $this->object->createResourceConfig(); + $returnValue = $this->configGeneratorObject->createResourceConfig(); $this->assertEquals('resource', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['resource' => ['default_setup' => ['connection' => 'default']]], $returnValue->getData()); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 04880f2bfe6fc..3064b47abd156 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -13,7 +13,7 @@ class ConfigOptionsTest extends \PHPUnit_Framework_TestCase private $object; /** - * @var ConfigDataGenerator|\PHPUnit_Framework_MockObject_MockObject + * @var ConfigGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $generator; @@ -60,7 +60,7 @@ public function testCreateOptions() $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); $configData = $this->object->createConfig([]); - $this->assertEquals(7 ,count($configData)); + $this->assertEquals(7, count($configData)); } public function testCreateOptionsWithOptionalNull() @@ -74,6 +74,6 @@ public function testCreateOptionsWithOptionalNull() $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); $configData = $this->object->createConfig([]); - $this->assertEquals(5 ,count($configData)); + $this->assertEquals(5, count($configData)); } } diff --git a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php similarity index 95% rename from setup/src/Magento/Setup/Model/ConfigDataGenerator.php rename to setup/src/Magento/Setup/Model/ConfigGenerator.php index a8ff39c074c2a..1d279dc989e12 100644 --- a/setup/src/Magento/Setup/Model/ConfigDataGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -16,7 +16,10 @@ use Magento\Framework\App\DeploymentConfig\SessionConfig; use Magento\Framework\App\DeploymentConfig\ResourceConfig; -class ConfigDataGenerator +/** + * Creates deployment config data based on user input array + */ +class ConfigGenerator { /** * Maps configuration parameters to array keys in deployment config file @@ -37,6 +40,13 @@ class ConfigDataGenerator ConfigOptions::INPUT_KEY_RESOURCE => ResourceConfig::CONFIG_KEY, ]; + /** + * Constructor + * + * @param Random $random + * @param Loader $moduleLoader + * @param DeploymentConfig $deploymentConfig + */ public function __construct(Random $random, Loader $moduleLoader, DeploymentConfig $deploymentConfig) { $this->random = $random; @@ -80,7 +90,7 @@ public function createModuleConfig() if (!$this->deploymentConfig->isAvailable()) { $modulesData = []; if (isset($this->moduleList)) { - foreach (array_values($this->moduleList) as $key) { + foreach ($this->moduleList as $key) { $modulesData[$key] = 1; } } @@ -114,7 +124,6 @@ public function createSessionConfig(array $data) */ public function createDefinitionsConfig(array $data) { - // definitions segment if (!empty($data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT])) { $config['definition']['format'] = $data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT]; return new ConfigData( @@ -133,7 +142,6 @@ public function createDefinitionsConfig(array $data) */ public function createDbConfig(array $data) { - // db segment $connection = []; $required = [ diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 9826ca8759a34..4cc8970210496 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -49,16 +49,16 @@ class ConfigOptions implements ConfigOptionsInterface /** * Generate config data for individual segments * - * @var ConfigDataGenerator + * @var ConfigGenerator */ private $configDataGenerator; /** * Constructor * - * @param ConfigDataGenerator $configDataGenerator + * @param ConfigGenerator $configDataGenerator */ - public function __construct(ConfigDataGenerator $configDataGenerator) + public function __construct(ConfigGenerator $configDataGenerator) { $this->configDataGenerator = $configDataGenerator; } @@ -164,7 +164,7 @@ public function validate(array $options) if (!isset($options[$key]) || empty($options[$key])) { $errors[] = "Missing value for db configuration: {$key}"; } - $connection[ConfigDataGenerator::$paramMap[$key]] = $options[$key]; + $connection[ConfigGenerator::$paramMap[$key]] = $options[$key]; } if (isset($options[ConfigOptions::INPUT_KEY_CRYPT_KEY]) && !$options[ConfigOptions::INPUT_KEY_CRYPT_KEY]) { From eba2a4e230084223d016e2a72b3925852d2ae064 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 9 Mar 2015 11:21:23 -0500 Subject: [PATCH 071/214] MAGETWO-34855: Split createConfig in ConfigOptions into smaller functions - renaming test --- .../{ConfigDataGeneratorTest.php => ConfigGeneratorTest.php} | 2 +- setup/src/Magento/Setup/Model/ConfigGenerator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename dev/tests/unit/testsuite/Magento/Setup/Model/{ConfigDataGeneratorTest.php => ConfigGeneratorTest.php} (99%) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php similarity index 99% rename from dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php rename to dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php index 3cc45a9dc6b2a..2778325cf1d8c 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigDataGeneratorTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php @@ -7,7 +7,7 @@ use Magento\Framework\Config\File\ConfigFilePool; -class ConfigDataGeneratorTest extends \PHPUnit_Framework_TestCase +class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase { /** * @var ConfigGenerator diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 1d279dc989e12..8fe7f3d80aee0 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -151,7 +151,7 @@ public function createDbConfig(array $data) ]; foreach ($required as $key) { - $connection[ConfigDataGenerator::$paramMap[$key]] = $data[$key]; + $connection[ConfigGenerator::$paramMap[$key]] = $data[$key]; } $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_PASS]] = From 318c27a9ca505c5e73d9ef4b068b7fc77d98c3d3 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 9 Mar 2015 11:39:50 -0500 Subject: [PATCH 072/214] MAGETWO-34855: Split createConfig in ConfigOptions into smaller functions - fix renaming --- .../Magento/Setup/Model/ConfigOptionsTest.php | 2 +- .../src/Magento/Setup/Model/ConfigOptions.php | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index 3064b47abd156..a0c2b522e99af 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -19,7 +19,7 @@ class ConfigOptionsTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->generator = $this->getMock('Magento\Setup\Model\ConfigDataGenerator', [], [], '', false); + $this->generator = $this->getMock('Magento\Setup\Model\ConfigGenerator', [], [], '', false); $this->object = new ConfigOptions($this->generator); } diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index 4cc8970210496..e43d37758e943 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -51,16 +51,16 @@ class ConfigOptions implements ConfigOptionsInterface * * @var ConfigGenerator */ - private $configDataGenerator; + private $configGenerator; /** * Constructor * - * @param ConfigGenerator $configDataGenerator + * @param ConfigGenerator $configGenerator */ - public function __construct(ConfigGenerator $configDataGenerator) + public function __construct(ConfigGenerator $configGenerator) { - $this->configDataGenerator = $configDataGenerator; + $this->configGenerator = $configGenerator; } /** @@ -131,19 +131,19 @@ public function getOptions() public function createConfig(array $data) { $configData = []; - $configData[] = $this->configDataGenerator->createInstallConfig(); - $configData[] = $this->configDataGenerator->createCryptConfig($data); - $modulesConfig = $this->configDataGenerator->createModuleConfig(); + $configData[] = $this->configGenerator->createInstallConfig(); + $configData[] = $this->configGenerator->createCryptConfig($data); + $modulesConfig = $this->configGenerator->createModuleConfig(); if (isset($modulesConfig)) { $configData[] = $modulesConfig; } - $configData[] = $this->configDataGenerator->createSessionConfig($data); - $definitionConfig = $this->configDataGenerator->createDefinitionsConfig($data); + $configData[] = $this->configGenerator->createSessionConfig($data); + $definitionConfig = $this->configGenerator->createDefinitionsConfig($data); if (isset($definitionConfig)) { $configData[] = $definitionConfig; } - $configData[] = $this->configDataGenerator->createDbConfig($data); - $configData[] = $this->configDataGenerator->createResourceConfig(); + $configData[] = $this->configGenerator->createDbConfig($data); + $configData[] = $this->configGenerator->createResourceConfig(); return $configData; } From b19e8bb78803ab56f64bb5fa643ea54f965ff29d Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 12:15:30 -0500 Subject: [PATCH 073/214] MAGETWO-34511: Process config options - added options and configOptions validation. --- .../Console/Command/ConfigInstallCommand.php | 18 ++----- setup/src/Magento/Setup/Model/ConfigModel.php | 48 +++++++++++-------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php index b7be95accf231..f6ead304fa9c6 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php @@ -61,10 +61,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - // TODO: wrap into try catch - // TODO: think about error and log message processing $this->configModel->process($input->getOptions()); - } /** @@ -74,18 +71,13 @@ public function initialize(InputInterface $input, OutputInterface $output) { $inputOptions = $input->getOptions(); - $errors = []; + $errors = $this->configModel->validate($inputOptions); - $options = $this->configModel->getAvailableOptions(); - foreach ($options as $option) { - try { - $option->validate($inputOptions[$option->getName()]); - } catch (\InvalidArgumentException $e) { - $errors[] = $e->getMessage(); + if (!empty($errors)) { + foreach ($errors as $error) { + $output->writeln("$error"); } - + exit(1); } - - $this->errors = $errors; } } diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 13ccac6951f51..4e6b054cea194 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -53,28 +53,13 @@ public function getAvailableOptions() */ public function process($inputOptions) { - // TODO: add error processing and refactor $fileConfigStorage = []; $options = $this->collector->collectOptions(); foreach ($options as $moduleName => $option) { - if (!$option instanceof ConfigOptionsInterface) { - throw new \Exception( - 'ConfigOption for module:' . $moduleName . ' does not implement ConfigOptionsInterface' - ); - } - - $errors = $option->validate($inputOptions); - if ($errors) { - var_dump($errors); - die('______'); - } else { - $configData = $option->createConfig($inputOptions); - } - - + $configData = $option->createConfig($inputOptions); foreach ($configData as $config) { @@ -100,12 +85,37 @@ public function process($inputOptions) } var_dump($fileConfigStorage); - } - public function validate() + /** + * Validates Input Options + * + * @param array $inputOptions + * @return array + */ + public function validate(array $inputOptions) { + $errors = []; - } + //Basic types validation + $options = $this->getAvailableOptions(); + foreach ($options as $option) { + try { + if ($inputOptions[$option->getName()] !== NULL) { + $option->validate($inputOptions[$option->getName()]); + } + } catch (\InvalidArgumentException $e) { + $errors[] = $e->getMessage(); + } + } + // validate ConfigOptions + $options = $this->collector->collectOptions(); + + foreach ($options as $moduleName => $option) { + $errors = array_merge($errors, $option->validate($inputOptions)); + } + + return $errors; + } } From 05e3b59b4fb1571da33ea4559f898c195476bc1a Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 14:40:24 -0500 Subject: [PATCH 074/214] MAGETWO-34511: Process config options - added method to save config --- .../Framework/App/DeploymentConfig/Writer.php | 34 +++++++++++++++++-- .../Framework/Config/File/ConfigFilePool.php | 6 ++-- .../Console/Command/ConfigInstallCommand.php | 20 ++++++++--- setup/src/Magento/Setup/Model/ConfigModel.php | 21 ++++++++---- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index 4c6281d72f3fd..cfca03d666cc0 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -8,6 +8,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; +use Magento\Framework\Config\File\ConfigFilePool; /** * Deployment configuration writer @@ -35,18 +36,29 @@ class Writer */ private $formatter; + /** + * @var ConfigFilePool + */ + private $configFilePool; + /** * Constructor * * @param Reader $reader * @param Filesystem $filesystem + * @param ConfigFilePool $configFilePool * @param Writer\FormatterInterface $formatter */ - public function __construct(Reader $reader, Filesystem $filesystem, Writer\FormatterInterface $formatter = null) - { + public function __construct( + Reader $reader, + Filesystem $filesystem, + ConfigFilePool $configFilePool, + Writer\FormatterInterface $formatter = null + ) { $this->reader = $reader; $this->filesystem = $filesystem; $this->formatter = $formatter ?: new Writer\PhpFormatter(); + $this->configFilePool = $configFilePool; } /** @@ -98,6 +110,24 @@ public function checkIfWritable() return false; } + /** + * Saves config + * + * @param array $data + * @return void + */ + public function saveConfig(array $data) + { + $paths = $this->configFilePool->getPaths(); + + foreach ($data as $fileKey => $config) { + if (isset($paths[$fileKey])) { + $contents = $this->formatter->format($config); + $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents); + } + } + } + /** * Persists the data into file * diff --git a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php index 0c84a37fbcc1d..6c44762545366 100644 --- a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php +++ b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php @@ -27,15 +27,13 @@ class ConfigFilePool /** * Constructor * - * @param DirectoryList $directoryList * @param array $additionalConfigFiles */ - public function __construct(DirectoryList $directoryList, $additionalConfigFiles = []) + public function __construct($additionalConfigFiles = []) { $this->applicationConfigFiles = array_merge($this->applicationConfigFiles, $additionalConfigFiles); - $configurationDirectory = $directoryList->getPath(DirectoryList::CONFIG); foreach ($this->applicationConfigFiles as $fileKey=>$filePath) { - $this->applicationConfigFiles[$fileKey] = $configurationDirectory . '/' . $filePath; + $this->applicationConfigFiles[$fileKey] = $filePath; } } diff --git a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php index f6ead304fa9c6..49d1dc537d4dd 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Magento\Setup\Model\ConfigModel; +use Magento\Framework\Module\ModuleList; class ConfigInstallCommand extends Command { @@ -24,18 +25,22 @@ class ConfigInstallCommand extends Command protected $configFilePool; /** - * @var array + * Enabled module list + * + * @var ModuleList */ - protected $errors; + private $moduleList; /** * Constructor - *s + * * @param \Magento\Setup\Model\ConfigModel $configModel + * @param ModuleList $moduleList */ - public function __construct(ConfigModel $configModel) + public function __construct(ConfigModel $configModel, ModuleList $moduleList) { $this->configModel = $configModel; + $this->moduleList = $moduleList; parent::__construct(); } @@ -62,6 +67,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $this->configModel->process($input->getOptions()); + $output->writeln('Deployment config has been saved.'); } /** @@ -69,6 +75,12 @@ protected function execute(InputInterface $input, OutputInterface $output) */ public function initialize(InputInterface $input, OutputInterface $output) { + if (!$this->moduleList->isModuleInfoAvailable()) { + $output->writeln( + 'There is no module configuration settings available, so all modules are enabled.' + ); + } + $inputOptions = $input->getOptions(); $errors = $this->configModel->validate($inputOptions); diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 4e6b054cea194..6dea2e20803f8 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -7,8 +7,8 @@ namespace Magento\Setup\Model; use Magento\Framework\Config\File\ConfigFilePool; -use Magento\Framework\Setup\ConfigOptionsInterface; use Magento\Framework\Config\Data\ConfigData; +use Magento\Framework\App\DeploymentConfig\Writer; class ConfigModel { @@ -17,16 +17,23 @@ class ConfigModel */ protected $collector; + /** + * @var \Magento\Framework\App\DeploymentConfig\Writer + */ + protected $writer; + /** * Constructor * * @param ConfigOptionsCollector $collector - * @param \Magento\Framework\Config\File\ConfigFilePool $configFilePool + * @param Writer $writer */ - public function __construct(ConfigOptionsCollector $collector, ConfigFilePool $configFilePool) - { - $this->configFilePool = $configFilePool; + public function __construct( + ConfigOptionsCollector $collector, + Writer $writer + ) { $this->collector = $collector; + $this->writer = $writer; } /** @@ -50,6 +57,7 @@ public function getAvailableOptions() * Process input options * * @param array $inputOptions + * @throws \Exception */ public function process($inputOptions) { @@ -84,7 +92,8 @@ public function process($inputOptions) } - var_dump($fileConfigStorage); + $this->writer->saveConfig($fileConfigStorage); + } /** From adb496226cbc3d9a27df4f648996cf22f061b9f6 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 15:02:54 -0500 Subject: [PATCH 075/214] MAGETWO-34511: Process config options - fixed save file logic (not it merges not rewrites) --- .../Magento/Framework/App/DeploymentConfig/Reader.php | 10 ++++++++-- .../Magento/Framework/App/DeploymentConfig/Writer.php | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php index 41e6decf37b7e..de210b4287105 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php @@ -65,11 +65,17 @@ public function getFile() /** * Loads the configuration file * + * @param string $configFile * @return array */ - public function load() + public function load($configFile = null) { - $file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $this->file; + if ($configFile) { + $file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $configFile; + } else { + $file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $this->file; + } + $result = @include $file; return $result ?: []; } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index cfca03d666cc0..9bd8e9d8bd4d7 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -122,6 +122,12 @@ public function saveConfig(array $data) foreach ($data as $fileKey => $config) { if (isset($paths[$fileKey])) { + + if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) { + $currentData = $this->reader->load($paths[$fileKey]); + $config = array_merge($currentData, $config); + } + $contents = $this->formatter->format($config); $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents); } From 0da6d333834bc6bb26be5307e33c33d9f36ec305 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 15:18:38 -0500 Subject: [PATCH 076/214] MAGETWO-34511: Process config options - fixed code standard issue --- setup/src/Magento/Setup/Console/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Console/Application.php b/setup/src/Magento/Setup/Console/Application.php index 4e4e024165a10..0a350f87ae0ca 100644 --- a/setup/src/Magento/Setup/Console/Application.php +++ b/setup/src/Magento/Setup/Console/Application.php @@ -38,7 +38,8 @@ protected function getApplicationCommands() { $commandsList = []; - $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')->getServiceManager(); + $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') + ->getServiceManager(); $setupFiles = glob(BP . '/setup/src/Magento/Setup/Console/Command/*Command.php'); if ($setupFiles) { foreach ($setupFiles as $file) { From 215ec1e8fffd5d16543b8db8341f4a9f5a4d84de Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 16:41:47 -0500 Subject: [PATCH 077/214] MAGETWO-34511: Process config options - changes according to CR --- .../Magento/Framework/Config/Data/ConfigData.php | 4 ++-- .../Framework/Setup/ConfigOptionsInterface.php | 2 +- setup/cli.php | 14 ++------------ .../Setup/Console/Command/ConfigInstallCommand.php | 2 +- setup/src/Magento/Setup/Model/ConfigModel.php | 4 +--- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index 9a421427aadce..95db7eade3a66 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -39,7 +39,7 @@ class ConfigData * @param string $segmentKey * @param array $data */ - public function __construct($fileKey, $segmentKey, $data) + public function __construct($fileKey, $segmentKey, array $data) { $this->fileKey = $fileKey; $this->segmentKey = $segmentKey; @@ -69,7 +69,7 @@ public function getSegmentKey() /** * Gets Data * - * @return string + * @return array */ public function getData() { diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php index 8e1abb67218b3..4e0481cf3a0bc 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php @@ -31,7 +31,7 @@ public function createConfig(array $options); * Validates user input option values and returns error messages * * @param array $options - * @return array + * @return string[] */ public function validate(array $options); } diff --git a/setup/cli.php b/setup/cli.php index 859538a034421..8592fdd637824 100644 --- a/setup/cli.php +++ b/setup/cli.php @@ -6,22 +6,12 @@ try { require __DIR__ . '/../app/bootstrap.php'; + $application = new Magento\Setup\Console\Application('Magento CLI'); + $application->run(); } catch (\Exception $e) { if (PHP_SAPI == 'cli') { echo 'Autoload error: ' . $e->getMessage(); - } else { - echo << -
-

- Autoload error

-
-

{$e->getMessage()}

- -HTML; } exit(1); } -$application = new Magento\Setup\Console\Application('Magento2 CLI', '0.0.1'); -$application->run(); diff --git a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php index 49d1dc537d4dd..0ba8954c5d8fa 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php @@ -77,7 +77,7 @@ public function initialize(InputInterface $input, OutputInterface $output) { if (!$this->moduleList->isModuleInfoAvailable()) { $output->writeln( - 'There is no module configuration settings available, so all modules are enabled.' + 'There is no module configuration available, so all modules are enabled.' ); } diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 6dea2e20803f8..ab52b45317976 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -70,15 +70,13 @@ public function process($inputOptions) $configData = $option->createConfig($inputOptions); foreach ($configData as $config) { - if (!$config instanceof ConfigData) { throw new \Exception( 'In module : ' .$moduleName . 'ConfigOption::createConfig should return instance of ConfigData' ); } - if ( - isset($fileConfigStorage[$config->getFileKey()]) + if (isset($fileConfigStorage[$config->getFileKey()]) && isset($fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()]) ) { $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_merge( From c3805771f7f51ba76021d33c968ff2933b5af4cd Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 16:56:29 -0500 Subject: [PATCH 078/214] MAGETWO-34511: Process config options -fixed config merge --- lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index 9bd8e9d8bd4d7..4779b40d88aa3 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -125,7 +125,7 @@ public function saveConfig(array $data) if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) { $currentData = $this->reader->load($paths[$fileKey]); - $config = array_merge($currentData, $config); + $config = array_merge_recursive($currentData, $config); } $contents = $this->formatter->format($config); From bc147738be6185feb42f912cc1c16b6e4460310f Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 17:10:41 -0500 Subject: [PATCH 079/214] MAGETWO-34511: Process config options - fixed merge in config. --- setup/src/Magento/Setup/Model/ConfigModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index ab52b45317976..7f81485ad37f3 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -79,7 +79,7 @@ public function process($inputOptions) if (isset($fileConfigStorage[$config->getFileKey()]) && isset($fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()]) ) { - $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_merge( + $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_merge_recursive( $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()], $config->getData() ); From 52fc99fc8fd120e7f60958a799d51c72ca0c3996 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 17:24:21 -0500 Subject: [PATCH 080/214] MAGETWO-34511: Process config options - fixed error message. --- setup/src/Magento/Setup/Model/ConfigModel.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 7f81485ad37f3..2ee941e7fa9be 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -72,7 +72,9 @@ public function process($inputOptions) foreach ($configData as $config) { if (!$config instanceof ConfigData) { throw new \Exception( - 'In module : ' .$moduleName . 'ConfigOption::createConfig should return instance of ConfigData' + 'In module : ' + . $moduleName + . 'ConfigOption::createConfig should return an array of ConfigData instances' ); } From decbebc62fd6a9efc4732bc71ea891d4c57fa8f7 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Mon, 9 Mar 2015 17:25:11 -0500 Subject: [PATCH 081/214] MAGETWO-34511: Process config options - implemented test for validation of backend frontname --- .../Magento/Backend/Setup/ConfigOptions.php | 2 +- .../Backend/Setup/ConfigOptionsTest.php | 45 +++++++------------ 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php index 280c973fa2a7e..9b3ce1e54b71d 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -59,7 +59,7 @@ public function validate(array $options) { $errors = []; if (!preg_match('/^[a-zA-Z0-9_]+$/', $options[self::INPUT_KEY_BACKEND_FRONTNAME])) { - $errors[] = "Invalid backend frontname {$options[self::INPUT_KEY_BACKEND_FRONTNAME]}"; + $errors[] = "Invalid backend frontname '{$options[self::INPUT_KEY_BACKEND_FRONTNAME]}'"; } return $errors; diff --git a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php index d5776b3b48902..7fd932ac0a393 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php @@ -45,50 +45,35 @@ public function testCreateConfig() } } - /** - * @param array $options - * - * @dataProvider createConfigNoFrontnameDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage No backend frontname provided - */ - public function testCreateConfigNoFrontname(array $options) - { - $this->object->createConfig($options); - } - - /** - * @return array - */ - public function createConfigNoFrontnameDataProvider() + public function testValidate() { - return [ - 'no data' => [[]], - 'no frontName' => [['something_else' => 'something']], - 'empty frontName' => [[ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => '']], - ]; + $options = [ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; + $errors = $this->object->validate($options); + $this->assertEmpty($errors); } /** * @param array $options - * - * @dataProvider createConfigInvalidFrontnameDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid backend frontname + * @param string $expectedError + * @dataProvider validateInvalidDataProvider */ - public function testCreateConfigInvalidFrontname(array $options) + public function testValidateInvalid(array $options, $expectedError) { - $this->object->createConfig($options); + $errors = $this->object->validate($options); + $this->assertSame([$expectedError], $errors); } /** * @return array */ - public function createConfigInvalidFrontnameDataProvider() + public function validateInvalidDataProvider() { return [ - [[ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => '**']], - [[ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'invalid frontname']], + [[ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => '**'], "Invalid backend frontname '**'"], + [ + [ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'invalid frontname'], + "Invalid backend frontname 'invalid frontname'" + ], ]; } } From 913b61c4543e32f1a727ed0d4cc557fd79b167bb Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Mon, 9 Mar 2015 17:32:17 -0500 Subject: [PATCH 082/214] MAGETWO-34511: Process config options - removed temporary files --- dev/tests/unit/filename | 0 dev/tests/unit/filename.csv | 0 dev/tests/unit/filename.invalid_type | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 dev/tests/unit/filename delete mode 100644 dev/tests/unit/filename.csv delete mode 100644 dev/tests/unit/filename.invalid_type diff --git a/dev/tests/unit/filename b/dev/tests/unit/filename deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/dev/tests/unit/filename.csv b/dev/tests/unit/filename.csv deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/dev/tests/unit/filename.invalid_type b/dev/tests/unit/filename.invalid_type deleted file mode 100644 index e69de29bb2d1d..0000000000000 From 4e4f15b2f4b8cec2126c09227d4c3d8a24b7f39d Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 9 Mar 2015 17:52:41 -0500 Subject: [PATCH 083/214] MAGETWO-34511: Process config options -fixed WriterTest --- .../Magento/Framework/App/DeploymentConfig/WriterTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php index 8ff1f55b39ee6..629ccd11e30c6 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php @@ -7,6 +7,7 @@ namespace Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Config\File\ConfigFilePool; class WriterTest extends \PHPUnit_Framework_TestCase { @@ -37,7 +38,8 @@ protected function setUp() $this->formatter = $this->getMockForAbstractClass( 'Magento\Framework\App\DeploymentConfig\Writer\FormatterInterface' ); - $this->object = new Writer($this->reader, $filesystem, $this->formatter); + $configFilePool = new ConfigFilePool(); + $this->object = new Writer($this->reader, $filesystem, $configFilePool, $this->formatter); $this->reader->expects($this->any())->method('getFile')->willReturn('test.php'); $this->dirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $filesystem->expects($this->any()) From a7200988d082069c6c14351c7ad45bc2e66f72d9 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 00:10:32 -0500 Subject: [PATCH 084/214] MAGETWO-34511: Process config options -added test for ConfigModel -modified test for Writer -reverted array_merge_recursive to array-merge --- .../App/DeploymentConfig/WriterTest.php | 33 +++++- .../Magento/Setup/Model/ConfigModelTest.php | 111 ++++++++++++++++++ .../Framework/App/DeploymentConfig/Writer.php | 2 +- setup/src/Magento/Setup/Model/ConfigModel.php | 4 +- 4 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php index 629ccd11e30c6..7b0975919cc2c 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php @@ -31,6 +31,11 @@ class WriterTest extends \PHPUnit_Framework_TestCase */ protected $formatter; + /** + * @var ConfigFilePool + */ + private $configFilePool; + protected function setUp() { $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); @@ -38,8 +43,8 @@ protected function setUp() $this->formatter = $this->getMockForAbstractClass( 'Magento\Framework\App\DeploymentConfig\Writer\FormatterInterface' ); - $configFilePool = new ConfigFilePool(); - $this->object = new Writer($this->reader, $filesystem, $configFilePool, $this->formatter); + $this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); + $this->object = new Writer($this->reader, $filesystem, $this->configFilePool, $this->formatter); $this->reader->expects($this->any())->method('getFile')->willReturn('test.php'); $this->dirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $filesystem->expects($this->any()) @@ -80,6 +85,30 @@ public function testUpdate() $this->object->update($segment); } + public function testSaveConfig() + { + $configFiles = [ + ConfigFilePool::APP_CONFIG => 'test_conf.php', + 'test_key' => 'test2_conf.php' + ]; + + $testSet = [ + ConfigFilePool::APP_CONFIG => ['foo' => 'bar', 'key' => 'value', 'baz' => 1], + ]; + + $this->configFilePool->expects($this->once())->method('getPaths')->willReturn($configFiles); + $this->dirWrite->expects($this->any())->method('isExist')->willReturn(true); + $this->reader->expects($this->once())->method('load')->willReturn($testSet[ConfigFilePool::APP_CONFIG]); + $this->formatter + ->expects($this->once()) + ->method('format') + ->with($testSet[ConfigFilePool::APP_CONFIG]) + ->willReturn([]); + $this->dirWrite->expects($this->once())->method('writeFile')->with('test_conf.php', []); + + $this->object->saveConfig($testSet); + } + /** * Creates a segment mock * diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php new file mode 100644 index 0000000000000..a6a817b264308 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php @@ -0,0 +1,111 @@ +collector = $this->getMock('Magento\Setup\Model\ConfigOptionsCollector', [], [], '', false); + $this->writer = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); + $this->configOptions = $this->getMock('Magento\Backend\Setup\ConfigOptions', [], [], '', false); + $this->configData = $this->getMock('Magento\Framework\Config\Data\ConfigData', [], [], '', false); + + $this->configModel = new ConfigModel($this->collector, $this->writer); + } + + public function testValidate() + { + $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option->expects($this->exactly(3))->method('getName')->willReturn('Fake'); + $optionsSet = [ + $option, + $option, + $option + ]; + $configOption = $this->configOptions; + $configOption->expects($this->once())->method('getOptions')->will($this->returnValue($optionsSet)); + $configOption->expects($this->once())->method('validate')->will($this->returnValue([])); + + $this->collector + ->expects($this->exactly(2)) + ->method('collectOptions') + ->will($this->returnValue([$configOption])); + + $this->configModel->validate(['Fake'=>null]); + } + + public function testProcess() + { + $dataSet = [ + 'test' => 'fake' + ]; + $configData = $this->configData; + $configData->expects($this->once())->method('getData')->will($this->returnValue($dataSet)); + + $configOption = $this->configOptions; + $configOption->expects($this->once()) + ->method('createConfig') + ->will($this->returnValue([$configData])); + + $configOptions = [ + 'Fake_Module' => $configOption + ]; + + $this->collector->expects($this->once())->method('collectOptions')->will($this->returnValue($configOptions)); + $this->writer->expects($this->once())->method('saveConfig'); + + $this->configModel->process([]); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage In module : Fake_ModuleConfigOption::createConfig + */ + public function testProcessException() + { + $configOption = $this->configOptions; + $configOption->expects($this->once()) + ->method('createConfig') + ->will($this->returnValue([null])); + + $wrongData = [ + 'Fake_Module' => $configOption + ]; + + $this->collector->expects($this->once())->method('collectOptions')->will($this->returnValue($wrongData)); + + $this->configModel->process([]); + } +} diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index 4779b40d88aa3..9bd8e9d8bd4d7 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -125,7 +125,7 @@ public function saveConfig(array $data) if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) { $currentData = $this->reader->load($paths[$fileKey]); - $config = array_merge_recursive($currentData, $config); + $config = array_merge($currentData, $config); } $contents = $this->formatter->format($config); diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 2ee941e7fa9be..491c388cf9c3f 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -6,7 +6,6 @@ namespace Magento\Setup\Model; -use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\App\DeploymentConfig\Writer; @@ -81,7 +80,7 @@ public function process($inputOptions) if (isset($fileConfigStorage[$config->getFileKey()]) && isset($fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()]) ) { - $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_merge_recursive( + $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_merge( $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()], $config->getData() ); @@ -93,7 +92,6 @@ public function process($inputOptions) } $this->writer->saveConfig($fileConfigStorage); - } /** From 9fbf0a0781c3c4f217ced17db194c448fe1a3297 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 10:03:21 -0500 Subject: [PATCH 085/214] MAGETWO-34511: Process config options - changed array_merge to array_replace_recursive --- lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php | 2 +- setup/src/Magento/Setup/Model/ConfigModel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index 9bd8e9d8bd4d7..a2b48b1b39306 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -125,7 +125,7 @@ public function saveConfig(array $data) if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) { $currentData = $this->reader->load($paths[$fileKey]); - $config = array_merge($currentData, $config); + $config = array_replace_recursive($currentData, $config); } $contents = $this->formatter->format($config); diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 491c388cf9c3f..8cc7acaa1fe00 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -80,7 +80,7 @@ public function process($inputOptions) if (isset($fileConfigStorage[$config->getFileKey()]) && isset($fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()]) ) { - $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_merge( + $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_replace_recursive( $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()], $config->getData() ); From 954704a25c463df3990817c3949d179354dda978 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 10 Mar 2015 10:10:06 -0500 Subject: [PATCH 086/214] MAGETWO-34511: Process config options - static test fixes --- .../Magento/AdminNotification/Model/Feed.php | 1 + .../Magento/Backend/Setup/ConfigOptions.php | 4 ++-- .../Setup/Model/ConfigGeneratorTest.php | 3 ++- .../Framework/Config/Data/ConfigData.php | 1 - .../Framework/Config/File/ConfigFilePool.php | 3 +-- .../Setup/Option/AbstractConfigOption.php | 2 +- .../Setup/Option/FlagConfigOption.php | 2 +- .../Setup/Option/MultiSelectConfigOption.php | 2 +- .../Setup/Option/SelectConfigOption.php | 2 +- .../Setup/Option/TextConfigOption.php | 2 +- setup/cli.php | 1 - .../Magento/Setup/Model/ConfigGenerator.php | 18 ++++++++++-------- setup/src/Magento/Setup/Model/ConfigModel.php | 5 +++-- 13 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/AdminNotification/Model/Feed.php b/app/code/Magento/AdminNotification/Model/Feed.php index b975adc8f85fc..6dbad7584b900 100644 --- a/app/code/Magento/AdminNotification/Model/Feed.php +++ b/app/code/Magento/AdminNotification/Model/Feed.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\AdminNotification\Model; + use Magento\Setup\Model\ConfigOptions; /** diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php index 9b3ce1e54b71d..b05cb95419e52 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -34,8 +34,8 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_BACKEND_FRONTNAME, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'Backend frontname', - 'admin' + 'admin', + 'Backend frontname' ) ]; } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php index 2778325cf1d8c..82a002dfebcaf 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php @@ -19,7 +19,8 @@ protected function setUp() $random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); $random->expects($this->any())->method('getRandomString')->willReturn('key'); $loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); - $loader->expects($this->any())->method('load')->willReturn([ + $loader->expects($this->any())->method('load')->willReturn( + [ 'module1' => ['name' => 'module_one', 'version' => '1.0.0'], 'module2' => ['name' => 'module_two', 'version' => '1.0.0'] ] diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index 95db7eade3a66..cdf323ac267b4 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -76,4 +76,3 @@ public function getData() return $this->data; } } - diff --git a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php index 6c44762545366..17c79659abae1 100644 --- a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php +++ b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php @@ -32,7 +32,7 @@ class ConfigFilePool public function __construct($additionalConfigFiles = []) { $this->applicationConfigFiles = array_merge($this->applicationConfigFiles, $additionalConfigFiles); - foreach ($this->applicationConfigFiles as $fileKey=>$filePath) { + foreach ($this->applicationConfigFiles as $fileKey => $filePath) { $this->applicationConfigFiles[$fileKey] = $filePath; } @@ -62,5 +62,4 @@ public function getPath($fileKey) } return $this->applicationConfigFiles[$fileKey]; } - } diff --git a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php index beaec5d21ac63..a8bed627aafa1 100644 --- a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php @@ -32,8 +32,8 @@ abstract class AbstractConfigOption extends InputOption public function __construct( $name, $frontendType, - $description = '', $mode, + $description = '', $defaultValue = null, $shortcut = null ) { diff --git a/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php index f52edf8e18002..9ffd5384eaa0d 100644 --- a/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php @@ -27,6 +27,6 @@ public function __construct( $description = '', $shortCut = null ) { - parent::__construct($name, self::FRONTEND_WIZARD_FLAG, $description, self::VALUE_NONE, null, $shortCut); + parent::__construct($name, self::FRONTEND_WIZARD_FLAG, self::VALUE_NONE, $description, null, $shortCut); } } diff --git a/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php index efc8ffea4d249..98c0953f16b5f 100644 --- a/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php @@ -55,8 +55,8 @@ public function __construct( parent::__construct( $name, $frontendType, - $description, self::VALUE_REQUIRED | self::VALUE_IS_ARRAY, + $description, $defaultValue, $shortCut ); diff --git a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php index 05149154c6265..a14de60ff9a74 100644 --- a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php @@ -53,8 +53,8 @@ public function __construct( parent::__construct( $name, $frontendType, - $description, self::VALUE_REQUIRED, + $description, $defaultValue, $shortCut ); diff --git a/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php index 3a6ec95d8b333..913ed46dc13c8 100644 --- a/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php @@ -40,7 +40,7 @@ public function __construct( ) { throw new \InvalidArgumentException("Frontend input type has to be 'text', 'textarea' or 'password'."); } - parent::__construct($name, $frontendType, $description, self::VALUE_REQUIRED, $defaultValue, $shortCut); + parent::__construct($name, $frontendType, self::VALUE_REQUIRED, $description, $defaultValue, $shortCut); } /** diff --git a/setup/cli.php b/setup/cli.php index 8592fdd637824..2e8d605451565 100644 --- a/setup/cli.php +++ b/setup/cli.php @@ -14,4 +14,3 @@ } exit(1); } - diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 8fe7f3d80aee0..018932fc95cb5 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -125,7 +125,6 @@ public function createSessionConfig(array $data) public function createDefinitionsConfig(array $data) { if (!empty($data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT])) { - $config['definition']['format'] = $data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT]; return new ConfigData( ConfigFilePool::APP_CONFIG, 'definition', @@ -154,13 +153,16 @@ public function createDbConfig(array $data) $connection[ConfigGenerator::$paramMap[$key]] = $data[$key]; } - $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_PASS]] = - isset($data[ConfigOptions::INPUT_KEY_DB_PASS]) ? $data[ConfigOptions::INPUT_KEY_DB_PASS] : ''; - $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_MODEL]] = - isset($data[ConfigOptions::INPUT_KEY_DB_MODEL]) ? $data[ConfigOptions::INPUT_KEY_DB_MODEL] : 'mysql4'; - $connection[self::$paramMap[ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS]] = - isset($data[ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS]) ? - $data[ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS] : 'SET NAMES utf8;'; + $optional = [ + [ConfigOptions::INPUT_KEY_DB_PASS => ''], + [ConfigOptions::INPUT_KEY_DB_MODEL => 'mysql4'], + [ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS => 'SET NAMES utf8;'] + ]; + + foreach ($optional as $key => $value) { + $connection[ConfigGenerator::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : $value; + } + $connection[self::$paramMap[ConfigOptions::INPUT_KEY_ACTIVE]] = '1'; $prefixKey = isset($data[ConfigOptions::INPUT_KEY_DB_PREFIX]) ? $data[ConfigOptions::INPUT_KEY_DB_PREFIX] : ''; $dbData = [ diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 8cc7acaa1fe00..ebe18d67aba60 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -56,6 +56,7 @@ public function getAvailableOptions() * Process input options * * @param array $inputOptions + * @returns void * @throws \Exception */ public function process($inputOptions) @@ -108,7 +109,7 @@ public function validate(array $inputOptions) $options = $this->getAvailableOptions(); foreach ($options as $option) { try { - if ($inputOptions[$option->getName()] !== NULL) { + if ($inputOptions[$option->getName()] !== null) { $option->validate($inputOptions[$option->getName()]); } } catch (\InvalidArgumentException $e) { @@ -119,7 +120,7 @@ public function validate(array $inputOptions) // validate ConfigOptions $options = $this->collector->collectOptions(); - foreach ($options as $moduleName => $option) { + foreach (array_values($options) as $option) { $errors = array_merge($errors, $option->validate($inputOptions)); } From 405b01d32786c46dea5dc6c0804b6bf5b1cfb6b8 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 10 Mar 2015 10:56:42 -0500 Subject: [PATCH 087/214] MAGETWO-34511: Process config options - fixed tests --- setup/src/Magento/Setup/Model/ConfigGenerator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 018932fc95cb5..90bcdd2661d1d 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -154,13 +154,13 @@ public function createDbConfig(array $data) } $optional = [ - [ConfigOptions::INPUT_KEY_DB_PASS => ''], - [ConfigOptions::INPUT_KEY_DB_MODEL => 'mysql4'], - [ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS => 'SET NAMES utf8;'] + ConfigOptions::INPUT_KEY_DB_PASS => '', + ConfigOptions::INPUT_KEY_DB_MODEL => 'mysql4', + ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS => 'SET NAMES utf8;' ]; foreach ($optional as $key => $value) { - $connection[ConfigGenerator::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : $value; + $connection[self::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : $value; } $connection[self::$paramMap[ConfigOptions::INPUT_KEY_ACTIVE]] = '1'; From 8696ecffafe4d700de00cf0b180c6e2f9e1f041f Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 10:59:43 -0500 Subject: [PATCH 088/214] MAGETWO-34511: Process config options - added test for ConfigInstallCommand - fixed issues according to CR --- .../Command/ConfigInstallCommandTest.php | 110 ++++++++++++++++++ .../Framework/Config/File/ConfigFilePool.php | 4 - .../Setup/Option/AbstractConfigOption.php | 2 +- .../Console/Command/ConfigInstallCommand.php | 5 +- .../src/Magento/Setup/Model/ConfigOptions.php | 1 - 5 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Command/ConfigInstallCommandTest.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Command/ConfigInstallCommandTest.php b/dev/tests/unit/testsuite/Magento/Setup/Command/ConfigInstallCommandTest.php new file mode 100644 index 0000000000000..5048f25ee8207 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Command/ConfigInstallCommandTest.php @@ -0,0 +1,110 @@ +configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); + $this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); + $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $this->input = $this->getMock('Symfony\Component\Console\Input\InputInterface', [], [], '', false); + $this->output = $this->getMock('Symfony\Component\Console\Output\OutputInterface', [], [], '', false); + } + + public function testInitialize() + { + $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $optionsSet = [ + $option + ]; + $this->input->expects($this->once())->method('getOptions')->will($this->returnValue([])); + + $this->moduleList->expects($this->once())->method('isModuleInfoAvailable')->will($this->returnValue(false)); + + $this->configModel->expects($this->once()) + ->method('validate') + ->will($this->returnValue([])); + $this->configModel + ->expects($this->once()) + ->method('getAvailableOptions') + ->will($this->returnValue($optionsSet)); + + $this->output->expects($this->once()) + ->method('writeln') + ->with('There is no module configuration available, so all modules are enabled.'); + + $command = new ConfigInstallCommand($this->configModel, $this->moduleList); + $command->initialize($this->input, $this->output); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Parameters validation is failed + */ + public function testInitializeFailedValidation() + { + $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $optionsSet = [ + $option + ]; + + $this->input->expects($this->once())->method('getOptions')->will($this->returnValue([])); + + $this->moduleList->expects($this->once())->method('isModuleInfoAvailable')->will($this->returnValue(true)); + + $this->configModel->expects($this->once()) + ->method('validate') + ->will($this->returnValue(['Error message'])); + + $this->output->expects($this->once())->method('writeln')->with('Error message'); + + $this->configModel + ->expects($this->once()) + ->method('getAvailableOptions') + ->will($this->returnValue($optionsSet)); + + $command = new ConfigInstallCommand($this->configModel, $this->moduleList); + $command->initialize($this->input, $this->output); + } +} diff --git a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php index 17c79659abae1..882e846ec144e 100644 --- a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php +++ b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php @@ -32,10 +32,6 @@ class ConfigFilePool public function __construct($additionalConfigFiles = []) { $this->applicationConfigFiles = array_merge($this->applicationConfigFiles, $additionalConfigFiles); - foreach ($this->applicationConfigFiles as $fileKey => $filePath) { - $this->applicationConfigFiles[$fileKey] = $filePath; - } - } /** diff --git a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php index a8bed627aafa1..3639b74625bb3 100644 --- a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php @@ -53,7 +53,7 @@ public function getFrontendType() /** * No base validation - * + * @SuppressWarnings(PHPMD.UnusedLocalVariable) * @param mixed $data * @return void */ diff --git a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php index 0ba8954c5d8fa..e84e5169ebef5 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php @@ -53,8 +53,7 @@ protected function configure() { $options = $this->configModel->getAvailableOptions(); - $this - ->setName('config:install') + $this->setName('config:install') ->setDescription('Install deployment configuration') ->setDefinition($options); @@ -89,7 +88,7 @@ public function initialize(InputInterface $input, OutputInterface $output) foreach ($errors as $error) { $output->writeln("$error"); } - exit(1); + throw new \InvalidArgumentException('Parameters validation is failed'); } } } diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptions.php index e43d37758e943..1614709150ed0 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptions.php @@ -164,7 +164,6 @@ public function validate(array $options) if (!isset($options[$key]) || empty($options[$key])) { $errors[] = "Missing value for db configuration: {$key}"; } - $connection[ConfigGenerator::$paramMap[$key]] = $options[$key]; } if (isset($options[ConfigOptions::INPUT_KEY_CRYPT_KEY]) && !$options[ConfigOptions::INPUT_KEY_CRYPT_KEY]) { From da16132318524ceafb2d2a47950be0d029bcfa07 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 10 Mar 2015 11:23:28 -0500 Subject: [PATCH 089/214] MAGETWO-34511: Process config options - typo in phpdocs --- setup/src/Magento/Setup/Model/ConfigModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index ebe18d67aba60..ed634d852934a 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -56,7 +56,7 @@ public function getAvailableOptions() * Process input options * * @param array $inputOptions - * @returns void + * @return void * @throws \Exception */ public function process($inputOptions) From 9e235769114986ddd9db4a3bb51e35ae749dab51 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 11:37:18 -0500 Subject: [PATCH 090/214] MAGETWO-34511: Process config options - added test for ConfigFilePool --- .../Config/File/ConfigFilePoolTest.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Config/File/ConfigFilePoolTest.php diff --git a/dev/tests/unit/testsuite/Magento/Framework/Config/File/ConfigFilePoolTest.php b/dev/tests/unit/testsuite/Magento/Framework/Config/File/ConfigFilePoolTest.php new file mode 100644 index 0000000000000..0a9bd2c14aec9 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Config/File/ConfigFilePoolTest.php @@ -0,0 +1,47 @@ + 'new_config.php' + ]; + $this->configFilePool = new ConfigFilePool($newPath); + } + + public function testGetPaths() + { + $expected['new_key'] = 'new_config.php'; + $expected[ConfigFilePool::APP_CONFIG] = 'config.php'; + + $this->assertEquals($expected, $this->configFilePool->getPaths()); + } + + public function testGetPath() + { + $expected = 'config.php'; + $this->assertEquals($expected, $this->configFilePool->getPath(ConfigFilePool::APP_CONFIG)); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage File config key does not exist. + */ + public function testGetPathException() + { + $fileKey = 'not_existing'; + $this->configFilePool->getPath($fileKey); + } +} From b0a7eb9e9471dfb3c8cb2858ae029d9e733d59ba Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 11:57:46 -0500 Subject: [PATCH 091/214] MAGETWO-34511: Process config options - fixed test according to CR --- .../App/DeploymentConfig/WriterTest.php | 34 ++++++++++++++++--- .../Magento/Setup/Model/ConfigModelTest.php | 2 +- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php index 7b0975919cc2c..1fbe8db16e460 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/DeploymentConfig/WriterTest.php @@ -92,21 +92,45 @@ public function testSaveConfig() 'test_key' => 'test2_conf.php' ]; - $testSet = [ - ConfigFilePool::APP_CONFIG => ['foo' => 'bar', 'key' => 'value', 'baz' => 1], + $testSetExisting = [ + ConfigFilePool::APP_CONFIG => [ + 'foo' => 'bar', + 'key' => 'value', + 'baz' => [ + 'test' => 'value' + ] + ], + ]; + + $testSetUpdate = [ + ConfigFilePool::APP_CONFIG => [ + 'baz' => [ + 'test' => 'value2' + ] + ], + ]; + + $testSetExpected = [ + ConfigFilePool::APP_CONFIG => [ + 'foo' => 'bar', + 'key' => 'value', + 'baz' => [ + 'test' => 'value2' + ] + ], ]; $this->configFilePool->expects($this->once())->method('getPaths')->willReturn($configFiles); $this->dirWrite->expects($this->any())->method('isExist')->willReturn(true); - $this->reader->expects($this->once())->method('load')->willReturn($testSet[ConfigFilePool::APP_CONFIG]); + $this->reader->expects($this->once())->method('load')->willReturn($testSetExisting[ConfigFilePool::APP_CONFIG]); $this->formatter ->expects($this->once()) ->method('format') - ->with($testSet[ConfigFilePool::APP_CONFIG]) + ->with($testSetExpected[ConfigFilePool::APP_CONFIG]) ->willReturn([]); $this->dirWrite->expects($this->once())->method('writeFile')->with('test_conf.php', []); - $this->object->saveConfig($testSet); + $this->object->saveConfig($testSetUpdate); } /** diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php index a6a817b264308..0012982b7dddd 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php @@ -63,7 +63,7 @@ public function testValidate() ->method('collectOptions') ->will($this->returnValue([$configOption])); - $this->configModel->validate(['Fake'=>null]); + $this->configModel->validate(['Fake' => null]); } public function testProcess() From 0110f45e29a78816c0b99508fbe3fe0d369d1a8b Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 10 Mar 2015 12:07:53 -0500 Subject: [PATCH 092/214] MAGETWO-34511: Process config options - fix since parent class changed --- app/code/Magento/Backend/Setup/ConfigOptions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptions.php index b05cb95419e52..9b3ce1e54b71d 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptions.php @@ -34,8 +34,8 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_BACKEND_FRONTNAME, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'admin', - 'Backend frontname' + 'Backend frontname', + 'admin' ) ]; } From 9b3ec17cd567a7bbc7149c227f8cead5ca068398 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 13:39:18 -0500 Subject: [PATCH 093/214] MAGETWO-34511: Process config options - fixed few minors in code style according to CR --- .../Magento/Framework/Setup/Option/AbstractConfigOption.php | 2 +- setup/src/Magento/Setup/Model/ConfigModel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php index 3639b74625bb3..c09cda4cc627e 100644 --- a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php @@ -24,8 +24,8 @@ abstract class AbstractConfigOption extends InputOption * * @param string $name * @param string $frontendType - * @param string $description * @param int $mode + * @param string $description * @param string|array|null $defaultValue * @param string|array|null $shortcut */ diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index ed634d852934a..b9a582cbb6cd4 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -120,7 +120,7 @@ public function validate(array $inputOptions) // validate ConfigOptions $options = $this->collector->collectOptions(); - foreach (array_values($options) as $option) { + foreach ($options as $option) { $errors = array_merge($errors, $option->validate($inputOptions)); } From 2e28990307f1541c28e56dbf84410776436046c8 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 13:44:26 -0500 Subject: [PATCH 094/214] MAGETWO-34511: Process config options - fixed cli check --- setup/cli.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup/cli.php b/setup/cli.php index 2e8d605451565..e82e4e4d255e2 100644 --- a/setup/cli.php +++ b/setup/cli.php @@ -6,8 +6,11 @@ try { require __DIR__ . '/../app/bootstrap.php'; - $application = new Magento\Setup\Console\Application('Magento CLI'); - $application->run(); + if (PHP_SAPI == 'cli') { + $application = new Magento\Setup\Console\Application('Magento CLI'); + $application->run(); + } + } catch (\Exception $e) { if (PHP_SAPI == 'cli') { echo 'Autoload error: ' . $e->getMessage(); From 3421e60a21b0783c5e43a18e73f5d5ff519a5193 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 14:46:21 -0500 Subject: [PATCH 095/214] MAGETWO-34511: Process config options - moved ConfigInstallCommandTest to mutch namespase --- .../Setup/{ => Console}/Command/ConfigInstallCommandTest.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dev/tests/unit/testsuite/Magento/Setup/{ => Console}/Command/ConfigInstallCommandTest.php (100%) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Command/ConfigInstallCommandTest.php b/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php similarity index 100% rename from dev/tests/unit/testsuite/Magento/Setup/Command/ConfigInstallCommandTest.php rename to dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php From 6a9a5ff9673d2e48fdeeeecbb411ed47108ced52 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 10 Mar 2015 15:20:44 -0500 Subject: [PATCH 096/214] MAGETWO-34509: Collector for OptionsInterfaces - fix integration test --- .../Magento/Setup/Model/ConfigOptionsCollectorTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php index 42d48359e9c20..0cf441b1725c6 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php @@ -68,12 +68,10 @@ public function testCollectOptionsDeploymentConfigUnavailable() $result = $object->collectOptions(); $backendOptions = new \Magento\Backend\Setup\ConfigOptions(); - $configOptions = new \Magento\Config\Setup\ConfigOptions(); $expected = [ 'setup' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('Magento\Setup\Model\ConfigOptions'), 'Magento_Backend' => $backendOptions, - 'Magento_Config' => $configOptions, ]; $this->assertEquals($expected, $result); From 054f17f52fed581fe50a0eaa5d54b79d1aacb51f Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 16:35:10 -0500 Subject: [PATCH 097/214] MAGETWO-34511: Process config options - added multi-level array check to ConfigModelTest::testProcess --- .../Magento/Setup/Model/ConfigModelTest.php | 52 ++++++++++++++++--- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php index 0012982b7dddd..7a269ee8569ab 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php @@ -6,7 +6,7 @@ namespace Magento\Setup\Model; -use Magento\Framework\Config\Data\ConfigData; +use Magento\Framework\Config\File\ConfigFilePool; class ConfigModelTest extends \PHPUnit_Framework_TestCase { @@ -68,23 +68,59 @@ public function testValidate() public function testProcess() { - $dataSet = [ - 'test' => 'fake' + $testSet1 = [ + ConfigFilePool::APP_CONFIG => [ + 'segment' => [ + 'someKey' => 'value', + 'test' => 'value1' + ] + ] ]; - $configData = $this->configData; - $configData->expects($this->once())->method('getData')->will($this->returnValue($dataSet)); + + $testSet2 = [ + ConfigFilePool::APP_CONFIG => [ + 'segment' => [ + 'test' => 'value2' + ] + ] + ]; + + $testSetExpected = [ + ConfigFilePool::APP_CONFIG => [ + 'segment' => [ + 'someKey' => 'value', + 'test' => 'value2' + ] + ] + ]; + + $configData1 = clone $this->configData; + $configData2 = clone $this->configData; + + $configData1->expects($this->any()) + ->method('getData') + ->will($this->returnValue($testSet1[ConfigFilePool::APP_CONFIG]['segment'])); + $configData1->expects($this->any())->method('getFileKey')->will($this->returnValue(ConfigFilePool::APP_CONFIG)); + $configData1->expects($this->any())->method('getSegmentKey')->will($this->returnValue('segment')); + + $configData2->expects($this->any()) + ->method('getData') + ->will($this->returnValue($testSet2[ConfigFilePool::APP_CONFIG]['segment'])); + $configData2->expects($this->any())->method('getFileKey')->will($this->returnValue(ConfigFilePool::APP_CONFIG)); + $configData2->expects($this->any())->method('getSegmentKey')->will($this->returnValue('segment')); $configOption = $this->configOptions; $configOption->expects($this->once()) ->method('createConfig') - ->will($this->returnValue([$configData])); + ->will($this->returnValue([$configData1, $configData2])); $configOptions = [ 'Fake_Module' => $configOption ]; - $this->collector->expects($this->once())->method('collectOptions')->will($this->returnValue($configOptions)); - $this->writer->expects($this->once())->method('saveConfig'); + + + $this->writer->expects($this->once())->method('saveConfig')->with($testSetExpected); $this->configModel->process([]); } From 5c78070241f8a41ececebf9958b708cef16d27e5 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 16:37:02 -0500 Subject: [PATCH 098/214] MAGETWO-34511: Process config options - removed unnesesary spase in ConfigModelTest --- dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php index 7a269ee8569ab..6c488725ad854 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php @@ -119,7 +119,6 @@ public function testProcess() ]; $this->collector->expects($this->once())->method('collectOptions')->will($this->returnValue($configOptions)); - $this->writer->expects($this->once())->method('saveConfig')->with($testSetExpected); $this->configModel->process([]); From f5967882b0a249612739088a2ac11bf35d505e3f Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 17:12:14 -0500 Subject: [PATCH 099/214] MAGETWO-34511: Process config options - removed unused property from test --- .../Setup/Console/Command/ConfigInstallCommandTest.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php b/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php index 5048f25ee8207..89a6cc222ae0c 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php @@ -27,12 +27,7 @@ class ConfigInstallCommandTest extends \PHPUnit_Framework_TestCase * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Module\ModuleList */ private $moduleList; - - /** - * @var ConfigInstallCommand - */ - private $configInstallCommand; - + /** * @var \PHPUnit_Framework_MockObject_MockObject|InputInterface */ From 4271db6ef00081f29bd3aa2a99445ec5d95e65f4 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 17:23:31 -0500 Subject: [PATCH 100/214] MAGETWO-34511: Process config options - changed messages accurding to feedback from Daniel --- .../Setup/Console/Command/ConfigInstallCommandTest.php | 4 ++-- .../Magento/Setup/Console/Command/ConfigInstallCommand.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php b/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php index 89a6cc222ae0c..0dd971c6475fd 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php @@ -27,7 +27,7 @@ class ConfigInstallCommandTest extends \PHPUnit_Framework_TestCase * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Module\ModuleList */ private $moduleList; - + /** * @var \PHPUnit_Framework_MockObject_MockObject|InputInterface */ @@ -67,7 +67,7 @@ public function testInitialize() $this->output->expects($this->once()) ->method('writeln') - ->with('There is no module configuration available, so all modules are enabled.'); + ->with('No module configuration is available, so all modules are enabled.'); $command = new ConfigInstallCommand($this->configModel, $this->moduleList); $command->initialize($this->input, $this->output); diff --git a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php index e84e5169ebef5..5d73562214a03 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php @@ -66,7 +66,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $this->configModel->process($input->getOptions()); - $output->writeln('Deployment config has been saved.'); + $output->writeln('You saved the deployment config.'); } /** @@ -76,7 +76,7 @@ public function initialize(InputInterface $input, OutputInterface $output) { if (!$this->moduleList->isModuleInfoAvailable()) { $output->writeln( - 'There is no module configuration available, so all modules are enabled.' + 'No module configuration is available, so all modules are enabled.' ); } From e44245f496735bea277e9f602bb86c67509536e0 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 17:57:26 -0500 Subject: [PATCH 101/214] MAGETWO-34916: Rename ConfigOptions to ConfigOptionsList and related chages - renamed --- .../Magento/AdminNotification/Model/Feed.php | 4 +- .../Backend/App/Area/FrontNameResolver.php | 4 +- .../Magento/Backend/Helper/Dashboard/Data.php | 4 +- ...onfigOptions.php => ConfigOptionsList.php} | 4 +- app/etc/di.xml | 2 +- .../Model/ConfigOptionsCollectorTest.php | 6 +- .../AdminNotification/Model/FeedTest.php | 4 +- .../App/Area/FrontNameResolverTest.php | 4 +- .../Backend/Setup/ConfigOptionsTest.php | 12 ++-- .../Setup/Model/ConfigGeneratorTest.php | 22 +++---- .../Magento/Setup/Model/ConfigModelTest.php | 22 +++---- .../Magento/Setup/Model/ConfigOptionsTest.php | 4 +- ...ace.php => ConfigOptionsListInterface.php} | 2 +- .../Magento/Setup/Model/ConfigGenerator.php | 60 +++++++++---------- setup/src/Magento/Setup/Model/ConfigModel.php | 8 +-- ...onfigOptions.php => ConfigOptionsList.php} | 18 +++--- ...tor.php => ConfigOptionsListCollector.php} | 16 ++--- 17 files changed, 99 insertions(+), 97 deletions(-) rename app/code/Magento/Backend/Setup/{ConfigOptions.php => ConfigOptionsList.php} (92%) rename lib/internal/Magento/Framework/Setup/{ConfigOptionsInterface.php => ConfigOptionsListInterface.php} (96%) rename setup/src/Magento/Setup/Model/{ConfigOptions.php => ConfigOptionsList.php} (88%) rename setup/src/Magento/Setup/Model/{ConfigOptionsCollector.php => ConfigOptionsListCollector.php} (87%) diff --git a/app/code/Magento/AdminNotification/Model/Feed.php b/app/code/Magento/AdminNotification/Model/Feed.php index 6dbad7584b900..98b59d00994d4 100644 --- a/app/code/Magento/AdminNotification/Model/Feed.php +++ b/app/code/Magento/AdminNotification/Model/Feed.php @@ -5,7 +5,7 @@ */ namespace Magento\AdminNotification\Model; -use Magento\Setup\Model\ConfigOptions; +use Magento\Setup\Model\ConfigOptionsList; /** * AdminNotification Feed model @@ -137,7 +137,7 @@ public function checkUpdate() $feedXml = $this->getFeedData(); - $installDate = strtotime($this->_deploymentConfig->get(ConfigOptions::CONFIG_PATH_INSTALL_DATE)); + $installDate = strtotime($this->_deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)); if ($feedXml && $feedXml->channel && $feedXml->channel->item) { foreach ($feedXml->channel->item as $item) { diff --git a/app/code/Magento/Backend/App/Area/FrontNameResolver.php b/app/code/Magento/Backend/App/Area/FrontNameResolver.php index 761714b025d38..f8fcd4a44ba38 100644 --- a/app/code/Magento/Backend/App/Area/FrontNameResolver.php +++ b/app/code/Magento/Backend/App/Area/FrontNameResolver.php @@ -7,7 +7,7 @@ */ namespace Magento\Backend\App\Area; -use Magento\Backend\Setup\ConfigOptions; +use Magento\Backend\Setup\ConfigOptionsList; use Magento\Framework\App\DeploymentConfig; class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolverInterface @@ -45,7 +45,7 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver public function __construct(\Magento\Backend\App\Config $config, DeploymentConfig $deploymentConfig) { $this->config = $config; - $this->defaultFrontName = $deploymentConfig->get(ConfigOptions::CONFIG_PATH_BACKEND_FRONTNAME); + $this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME); } /** diff --git a/app/code/Magento/Backend/Helper/Dashboard/Data.php b/app/code/Magento/Backend/Helper/Dashboard/Data.php index 1e4040b57bf40..84233cd1cb00d 100644 --- a/app/code/Magento/Backend/Helper/Dashboard/Data.php +++ b/app/code/Magento/Backend/Helper/Dashboard/Data.php @@ -6,7 +6,7 @@ namespace Magento\Backend\Helper\Dashboard; use Magento\Framework\App\DeploymentConfig; -use Magento\Setup\Model\ConfigOptions; +use Magento\Setup\Model\ConfigOptionsList; /** * Data helper for dashboard @@ -41,7 +41,7 @@ public function __construct( parent::__construct( $context ); - $this->_installDate = $deploymentConfig->get(ConfigOptions::CONFIG_PATH_INSTALL_DATE); + $this->_installDate = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE); $this->_storeManager = $storeManager; } diff --git a/app/code/Magento/Backend/Setup/ConfigOptions.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php similarity index 92% rename from app/code/Magento/Backend/Setup/ConfigOptions.php rename to app/code/Magento/Backend/Setup/ConfigOptionsList.php index 9b3ce1e54b71d..faf8a786f7830 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptions.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -7,13 +7,13 @@ use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Config\File\ConfigFilePool; -use Magento\Framework\Setup\ConfigOptionsInterface; +use Magento\Framework\Setup\ConfigOptionsListInterface; use Magento\Framework\Setup\Option\TextConfigOption; /* * Deployment configuration options needed for Backend module */ -class ConfigOptions implements ConfigOptionsInterface +class ConfigOptionsList implements ConfigOptionsListInterface { /** * Input key for the options diff --git a/app/etc/di.xml b/app/etc/di.xml index a637ef09d1653..b4a96e7186dbc 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -218,7 +218,7 @@
- Magento\Backend\Setup\ConfigOptions::CONFIG_PATH_BACKEND_FRONTNAME + Magento\Backend\Setup\ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php index 0cf441b1725c6..34c8d7ee718ae 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php @@ -29,7 +29,7 @@ public function testCollectOptionsDeploymentConfigAvailable() $moduleListMock->expects($this->once())->method('getNames')->willReturn(['Magento_Backend']); $fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); $fullModuleListMock->expects($this->never())->method('getNames'); - /** @var \Magento\Setup\Model\ConfigOptionsCollector $object */ + /** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */ $object = $objectManager->create( 'Magento\Setup\Model\ConfigOptionsCollector', [ @@ -42,7 +42,7 @@ public function testCollectOptionsDeploymentConfigAvailable() $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('Magento\Setup\Model\ConfigOptions'); - $backendOptions = new \Magento\Backend\Setup\ConfigOptions(); + $backendOptions = new \Magento\Backend\Setup\ConfigOptionsList(); $expected = [ 'setup' => $setupOptions, 'Magento_Backend' => $backendOptions, @@ -67,7 +67,7 @@ public function testCollectOptionsDeploymentConfigUnavailable() ); $result = $object->collectOptions(); - $backendOptions = new \Magento\Backend\Setup\ConfigOptions(); + $backendOptions = new \Magento\Backend\Setup\ConfigOptionsList(); $expected = [ 'setup' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('Magento\Setup\Model\ConfigOptions'), diff --git a/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php b/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php index ff16495547976..68d6bd5c5f340 100644 --- a/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php +++ b/dev/tests/unit/testsuite/Magento/AdminNotification/Model/FeedTest.php @@ -6,7 +6,7 @@ namespace Magento\AdminNotification\Model; -use Magento\Setup\Model\ConfigOptions; +use Magento\Setup\Model\ConfigOptionsList; use Magento\TestFramework\Helper\ObjectManager as ObjectManagerHelper; /** @@ -141,7 +141,7 @@ public function testCheckUpdate($callInbox, $curlRequest) $this->backendConfig->expects($this->at(1))->method('getValue') ->will($this->returnValue('http://feed.magento.com')); $this->deploymentConfig->expects($this->once())->method('get') - ->with(ConfigOptions::CONFIG_PATH_INSTALL_DATE) + ->with(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE) ->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create') diff --git a/dev/tests/unit/testsuite/Magento/Backend/App/Area/FrontNameResolverTest.php b/dev/tests/unit/testsuite/Magento/Backend/App/Area/FrontNameResolverTest.php index 989627432d7e2..24c6d60b3c6b5 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/App/Area/FrontNameResolverTest.php +++ b/dev/tests/unit/testsuite/Magento/Backend/App/Area/FrontNameResolverTest.php @@ -5,7 +5,7 @@ */ namespace Magento\Backend\App\Area; -use Magento\Backend\Setup\ConfigOptions; +use Magento\Backend\Setup\ConfigOptionsList; class FrontNameResolverTest extends \PHPUnit_Framework_TestCase { @@ -29,7 +29,7 @@ protected function setUp() $deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false); $deploymentConfigMock->expects($this->once()) ->method('get') - ->with(ConfigOptions::CONFIG_PATH_BACKEND_FRONTNAME) + ->with(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME) ->will($this->returnValue($this->_defaultFrontName)); $this->_configMock = $this->getMock('\Magento\Backend\App\Config', [], [], '', false); $this->_model = new \Magento\Backend\App\Area\FrontNameResolver($this->_configMock, $deploymentConfigMock); diff --git a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php index 7fd932ac0a393..e3e8a61ac64cc 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php @@ -10,13 +10,13 @@ class ConfigOptionsTest extends \PHPUnit_Framework_TestCase { /** - * @var ConfigOptions + * @var ConfigOptionsList */ private $object; protected function setUp() { - $this->object = new ConfigOptions(); + $this->object = new ConfigOptionsList(); } public function testGetOptions() @@ -30,7 +30,7 @@ public function testGetOptions() public function testCreateConfig() { - $options = [ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; + $options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; $actualConfig = $this->object->createConfig($options); $expectedData = [ ['file' => ConfigFilePool::APP_CONFIG, 'segment' => 'backend', 'data' => ['frontName' => 'admin']] @@ -47,7 +47,7 @@ public function testCreateConfig() public function testValidate() { - $options = [ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; + $options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; $errors = $this->object->validate($options); $this->assertEmpty($errors); } @@ -69,9 +69,9 @@ public function testValidateInvalid(array $options, $expectedError) public function validateInvalidDataProvider() { return [ - [[ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => '**'], "Invalid backend frontname '**'"], + [[ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => '**'], "Invalid backend frontname '**'"], [ - [ConfigOptions::INPUT_KEY_BACKEND_FRONTNAME => 'invalid frontname'], + [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'invalid frontname'], "Invalid backend frontname 'invalid frontname'" ], ]; diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php index 82a002dfebcaf..6361702e281b4 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php @@ -40,7 +40,7 @@ public function testCreateInstallConfig() public function testCreateCryptConfigWithInput() { - $testData = [ConfigOptions::INPUT_KEY_CRYPT_KEY => 'some-test_key']; + $testData = [ConfigOptionsList::INPUT_KEY_CRYPT_KEY => 'some-test_key']; $returnValue = $this->configGeneratorObject->createCryptConfig($testData); $this->assertEquals('crypt', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); @@ -65,17 +65,17 @@ public function testCreateModuleConfig() public function testCreateSessionConfigWithInput() { - $testData = [ConfigOptions::INPUT_KEY_SESSION_SAVE => 'files']; + $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_FILES], $returnValue->getData()); + $this->assertEquals(['save' => ConfigOptionsList::SESSION_SAVE_FILES], $returnValue->getData()); - $testData = [ConfigOptions::INPUT_KEY_SESSION_SAVE => 'db']; + $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_DB], $returnValue->getData()); + $this->assertEquals(['save' => ConfigOptionsList::SESSION_SAVE_DB], $returnValue->getData()); } public function testCreateSessionConfigWithoutInput() @@ -83,12 +83,12 @@ public function testCreateSessionConfigWithoutInput() $returnValue = $this->configGeneratorObject->createSessionConfig([]); $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['save' => ConfigOptions::SESSION_SAVE_FILES], $returnValue->getData()); + $this->assertEquals(['save' => ConfigOptionsList::SESSION_SAVE_FILES], $returnValue->getData()); } public function testCreateDefinitionsConfig() { - $testData = [ConfigOptions::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; + $testData = [ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; $returnValue = $this->configGeneratorObject->createDefinitionsConfig($testData); $this->assertEquals('definition', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); @@ -98,10 +98,10 @@ public function testCreateDefinitionsConfig() public function testCreateDbConfig() { $testData = [ - ConfigOptions::INPUT_KEY_DB_HOST => 'testLocalhost', - ConfigOptions::INPUT_KEY_DB_NAME => 'testDbName', - ConfigOptions::INPUT_KEY_DB_USER => 'testDbUser', - ConfigOptions::INPUT_KEY_DB_PREFIX => 'testSomePrefix', + ConfigOptionsList::INPUT_KEY_DB_HOST => 'testLocalhost', + ConfigOptionsList::INPUT_KEY_DB_NAME => 'testDbName', + ConfigOptionsList::INPUT_KEY_DB_USER => 'testDbUser', + ConfigOptionsList::INPUT_KEY_DB_PREFIX => 'testSomePrefix', ]; $returnValue = $this->configGeneratorObject->createDbConfig($testData); $this->assertEquals('db', $returnValue->getSegmentKey()); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php index 6c488725ad854..f0dec78b59873 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php @@ -16,7 +16,7 @@ class ConfigModelTest extends \PHPUnit_Framework_TestCase private $configModel; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ConfigOptionsCollector + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ConfigOptionsListCollector */ private $collector; @@ -31,15 +31,15 @@ class ConfigModelTest extends \PHPUnit_Framework_TestCase private $configData; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Setup\ConfigOptions + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Setup\ConfigOptionsList */ - private $configOptions; + private $configOptionsList; public function setUp() { - $this->collector = $this->getMock('Magento\Setup\Model\ConfigOptionsCollector', [], [], '', false); + $this->collector = $this->getMock('Magento\Setup\Model\ConfigOptionsListCollector', [], [], '', false); $this->writer = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); - $this->configOptions = $this->getMock('Magento\Backend\Setup\ConfigOptions', [], [], '', false); + $this->configOptionsList = $this->getMock('Magento\Backend\Setup\ConfigOptionsList', [], [], '', false); $this->configData = $this->getMock('Magento\Framework\Config\Data\ConfigData', [], [], '', false); $this->configModel = new ConfigModel($this->collector, $this->writer); @@ -54,7 +54,7 @@ public function testValidate() $option, $option ]; - $configOption = $this->configOptions; + $configOption = $this->configOptionsList; $configOption->expects($this->once())->method('getOptions')->will($this->returnValue($optionsSet)); $configOption->expects($this->once())->method('validate')->will($this->returnValue([])); @@ -109,15 +109,17 @@ public function testProcess() $configData2->expects($this->any())->method('getFileKey')->will($this->returnValue(ConfigFilePool::APP_CONFIG)); $configData2->expects($this->any())->method('getSegmentKey')->will($this->returnValue('segment')); - $configOption = $this->configOptions; + $configOption = $this->configOptionsList; $configOption->expects($this->once()) ->method('createConfig') ->will($this->returnValue([$configData1, $configData2])); - $configOptions = [ + $configOptionsList = [ 'Fake_Module' => $configOption ]; - $this->collector->expects($this->once())->method('collectOptions')->will($this->returnValue($configOptions)); + $this->collector->expects($this->once()) + ->method('collectOptions') + ->will($this->returnValue($configOptionsList)); $this->writer->expects($this->once())->method('saveConfig')->with($testSetExpected); @@ -130,7 +132,7 @@ public function testProcess() */ public function testProcessException() { - $configOption = $this->configOptions; + $configOption = $this->configOptionsList; $configOption->expects($this->once()) ->method('createConfig') ->will($this->returnValue([null])); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php index a0c2b522e99af..e0980aa85a0c3 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php @@ -8,7 +8,7 @@ class ConfigOptionsTest extends \PHPUnit_Framework_TestCase { /** - * @var ConfigOptions + * @var ConfigOptionsList */ private $object; @@ -20,7 +20,7 @@ class ConfigOptionsTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->generator = $this->getMock('Magento\Setup\Model\ConfigGenerator', [], [], '', false); - $this->object = new ConfigOptions($this->generator); + $this->object = new ConfigOptionsList($this->generator); } public function testGetOptions() diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php similarity index 96% rename from lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php rename to lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php index 4e0481cf3a0bc..9c618922255da 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php @@ -8,7 +8,7 @@ /** * Interface for handling options in deployment configuration tool */ -interface ConfigOptionsInterface +interface ConfigOptionsListInterface { /** * Gets a list of input options so that user can provide required diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 90bcdd2661d1d..ce6213282dc86 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -27,17 +27,17 @@ class ConfigGenerator * @var array */ public static $paramMap = [ - ConfigOptions::INPUT_KEY_DB_HOST => DbConfig::KEY_HOST, - ConfigOptions::INPUT_KEY_DB_NAME => DbConfig::KEY_NAME, - ConfigOptions::INPUT_KEY_DB_USER => DbConfig::KEY_USER, - ConfigOptions::INPUT_KEY_DB_PASS => DbConfig::KEY_PASS, - ConfigOptions::INPUT_KEY_DB_PREFIX => DbConfig::KEY_PREFIX, - ConfigOptions::INPUT_KEY_DB_MODEL => DbConfig::KEY_MODEL, - ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, - ConfigOptions::INPUT_KEY_ACTIVE => DbConfig::KEY_ACTIVE, - ConfigOptions::INPUT_KEY_CRYPT_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, - ConfigOptions::INPUT_KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, - ConfigOptions::INPUT_KEY_RESOURCE => ResourceConfig::CONFIG_KEY, + ConfigOptionsList::INPUT_KEY_DB_HOST => DbConfig::KEY_HOST, + ConfigOptionsList::INPUT_KEY_DB_NAME => DbConfig::KEY_NAME, + ConfigOptionsList::INPUT_KEY_DB_USER => DbConfig::KEY_USER, + ConfigOptionsList::INPUT_KEY_DB_PASS => DbConfig::KEY_PASS, + ConfigOptionsList::INPUT_KEY_DB_PREFIX => DbConfig::KEY_PREFIX, + ConfigOptionsList::INPUT_KEY_DB_MODEL => DbConfig::KEY_MODEL, + ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, + ConfigOptionsList::INPUT_KEY_ACTIVE => DbConfig::KEY_ACTIVE, + ConfigOptionsList::INPUT_KEY_CRYPT_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, + ConfigOptionsList::INPUT_KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, + ConfigOptionsList::INPUT_KEY_RESOURCE => ResourceConfig::CONFIG_KEY, ]; /** @@ -72,10 +72,10 @@ public function createInstallConfig() public function createCryptConfig(array $data) { $cryptData = []; - if (!isset($data[ConfigOptions::INPUT_KEY_CRYPT_KEY])) { - $cryptData[self::$paramMap[ConfigOptions::INPUT_KEY_CRYPT_KEY]] = md5($this->random->getRandomString(10)); + if (!isset($data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { + $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = md5($this->random->getRandomString(10)); } else { - $cryptData[self::$paramMap[ConfigOptions::INPUT_KEY_CRYPT_KEY]] = $data[ConfigOptions::INPUT_KEY_CRYPT_KEY]; + $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = $data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; } return new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); } @@ -107,11 +107,11 @@ public function createModuleConfig() public function createSessionConfig(array $data) { $sessionData = []; - if (isset($data[ConfigOptions::INPUT_KEY_SESSION_SAVE])) { - $sessionData[self::$paramMap[ConfigOptions::INPUT_KEY_SESSION_SAVE]] = - $data[ConfigOptions::INPUT_KEY_SESSION_SAVE]; + if (isset($data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { + $sessionData[self::$paramMap[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]] = + $data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]; } else { - $sessionData[self::$paramMap[ConfigOptions::INPUT_KEY_SESSION_SAVE]] = ConfigOptions::SESSION_SAVE_FILES; + $sessionData[self::$paramMap[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]] = ConfigOptionsList::SESSION_SAVE_FILES; } return new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); } @@ -124,11 +124,11 @@ public function createSessionConfig(array $data) */ public function createDefinitionsConfig(array $data) { - if (!empty($data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT])) { + if (!empty($data[ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT])) { return new ConfigData( ConfigFilePool::APP_CONFIG, 'definition', - ['format' => $data[ConfigOptions::INPUT_KEY_DEFINITION_FORMAT]] + ['format' => $data[ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT]] ); } } @@ -144,9 +144,9 @@ public function createDbConfig(array $data) $connection = []; $required = [ - ConfigOptions::INPUT_KEY_DB_HOST, - ConfigOptions::INPUT_KEY_DB_NAME, - ConfigOptions::INPUT_KEY_DB_USER + ConfigOptionsList::INPUT_KEY_DB_HOST, + ConfigOptionsList::INPUT_KEY_DB_NAME, + ConfigOptionsList::INPUT_KEY_DB_USER ]; foreach ($required as $key) { @@ -154,19 +154,19 @@ public function createDbConfig(array $data) } $optional = [ - ConfigOptions::INPUT_KEY_DB_PASS => '', - ConfigOptions::INPUT_KEY_DB_MODEL => 'mysql4', - ConfigOptions::INPUT_KEY_DB_INIT_STATEMENTS => 'SET NAMES utf8;' + ConfigOptionsList::INPUT_KEY_DB_PASS => '', + ConfigOptionsList::INPUT_KEY_DB_MODEL => 'mysql4', + ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS => 'SET NAMES utf8;' ]; foreach ($optional as $key => $value) { $connection[self::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : $value; } - $connection[self::$paramMap[ConfigOptions::INPUT_KEY_ACTIVE]] = '1'; - $prefixKey = isset($data[ConfigOptions::INPUT_KEY_DB_PREFIX]) ? $data[ConfigOptions::INPUT_KEY_DB_PREFIX] : ''; + $connection[self::$paramMap[ConfigOptionsList::INPUT_KEY_ACTIVE]] = '1'; + $prefixKey = isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]) ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] : ''; $dbData = [ - self::$paramMap[ConfigOptions::INPUT_KEY_DB_PREFIX] => $prefixKey, + self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX] => $prefixKey, 'connection' => ['default' => $connection] ]; return new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); @@ -179,7 +179,7 @@ public function createDbConfig(array $data) */ public function createResourceConfig() { - $resourceData[self::$paramMap[ConfigOptions::INPUT_KEY_RESOURCE]] = + $resourceData[self::$paramMap[ConfigOptionsList::INPUT_KEY_RESOURCE]] = ['default_setup' => ['connection' => 'default']]; return new ConfigData(ConfigFilePool::APP_CONFIG, 'resource', $resourceData); } diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index b9a582cbb6cd4..75bf45920bbcb 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -12,7 +12,7 @@ class ConfigModel { /** - * @var \Magento\Setup\Model\ConfigOptionsCollector + * @var \Magento\Setup\Model\ConfigOptionsListCollector */ protected $collector; @@ -24,11 +24,11 @@ class ConfigModel /** * Constructor * - * @param ConfigOptionsCollector $collector + * @param ConfigOptionsListCollector $collector * @param Writer $writer */ public function __construct( - ConfigOptionsCollector $collector, + ConfigOptionsListCollector $collector, Writer $writer ) { $this->collector = $collector; @@ -117,7 +117,7 @@ public function validate(array $inputOptions) } } - // validate ConfigOptions + // validate ConfigOptionsList $options = $this->collector->collectOptions(); foreach ($options as $option) { diff --git a/setup/src/Magento/Setup/Model/ConfigOptions.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php similarity index 88% rename from setup/src/Magento/Setup/Model/ConfigOptions.php rename to setup/src/Magento/Setup/Model/ConfigOptionsList.php index 1614709150ed0..d87d675c4cebc 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptions.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -6,7 +6,7 @@ namespace Magento\Setup\Model; use Magento\Framework\ObjectManager\DefinitionFactory; -use Magento\Framework\Setup\ConfigOptionsInterface; +use Magento\Framework\Setup\ConfigOptionsListInterface; use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; use Magento\Framework\App\DeploymentConfig; @@ -14,7 +14,7 @@ /** * Deployment configuration options needed for Setup application */ -class ConfigOptions implements ConfigOptionsInterface +class ConfigOptionsList implements ConfigOptionsListInterface { /**#@+ * Path to the values in the deployment config @@ -155,9 +155,9 @@ public function validate(array $options) $errors = []; $required = [ - ConfigOptions::INPUT_KEY_DB_HOST, - ConfigOptions::INPUT_KEY_DB_NAME, - ConfigOptions::INPUT_KEY_DB_USER + ConfigOptionsList::INPUT_KEY_DB_HOST, + ConfigOptionsList::INPUT_KEY_DB_NAME, + ConfigOptionsList::INPUT_KEY_DB_USER ]; foreach ($required as $key) { @@ -166,13 +166,13 @@ public function validate(array $options) } } - if (isset($options[ConfigOptions::INPUT_KEY_CRYPT_KEY]) && !$options[ConfigOptions::INPUT_KEY_CRYPT_KEY]) { + if (isset($options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) && !$options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) { $errors[] = 'Invalid encryption key.'; } - if (isset($options[ConfigOptions::INPUT_KEY_SESSION_SAVE])) { - if ($options[ConfigOptions::INPUT_KEY_SESSION_SAVE] != ConfigOptions::SESSION_SAVE_FILES && - $options[ConfigOptions::INPUT_KEY_SESSION_SAVE] != ConfigOptions::SESSION_SAVE_DB + if (isset($options[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { + if ($options[ConfigOptionsList::INPUT_KEY_SESSION_SAVE] != ConfigOptionsList::SESSION_SAVE_FILES && + $options[ConfigOptionsList::INPUT_KEY_SESSION_SAVE] != ConfigOptionsList::SESSION_SAVE_DB ) { $errors[] = 'Invalid session save location.'; } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php similarity index 87% rename from setup/src/Magento/Setup/Model/ConfigOptionsCollector.php rename to setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php index 0e96dfb95672f..36b8d123df5c7 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php @@ -11,9 +11,9 @@ use Magento\Framework\Module\ModuleList; /** - * Collects all ConfigOptions class in modules and setup + * Collects all ConfigOptionsList class in modules and setup */ -class ConfigOptionsCollector +class ConfigOptionsListCollector { /** * Directory List @@ -74,11 +74,11 @@ public function __construct( } /** - * Auto discover ConfigOptions class and collect them. These classes should reside in /Setup directories. + * Auto discover ConfigOptionsList class and collect them. These classes should reside in /Setup directories. * If deployment config is not available, all modules will be searched. Otherwise, only enabled modules * will be searched. * - * @return \Magento\Framework\Setup\ConfigOptionsInterface[] + * @return \Magento\Framework\Setup\ConfigOptionsListInterface[] */ public function collectOptions() { @@ -87,20 +87,20 @@ public function collectOptions() $moduleList = $this->moduleList->isModuleInfoAvailable() ? $this->moduleList : $this->fullModuleList; // go through modules foreach ($moduleList->getNames() as $moduleName) { - $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptions'; + $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptionsList'; if (class_exists($optionsClassName)) { $optionsClass = $this->objectManagerProvider->get()->create($optionsClassName); - if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { + if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsListInterface) { $optionsList[$moduleName] = $optionsClass; } } } // check setup - $setupOptionsClassName = 'Magento\Setup\Model\ConfigOptions'; + $setupOptionsClassName = 'Magento\Setup\Model\ConfigOptionsList'; if (class_exists($setupOptionsClassName)) { $setupOptionsClass = $this->objectManagerProvider->get()->create($setupOptionsClassName); - if ($setupOptionsClass instanceof \Magento\Framework\Setup\ConfigOptionsInterface) { + if ($setupOptionsClass instanceof \Magento\Framework\Setup\ConfigOptionsListInterface) { $optionsList['setup'] = $setupOptionsClass; } } From 982a91e892f57f0279bbc7e528b38d19dce329e8 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 18:20:57 -0500 Subject: [PATCH 102/214] MAGETWO-34916: Rename ConfigOptions to ConfigOptionsList and related chages - renamed tests --- ...ctorTest.php => ConfigOptionsListCollectorTest.php} | 10 +++++----- ...ConfigOptionsTest.php => ConfigOptionsListTest.php} | 2 +- ...ConfigOptionsTest.php => ConfigOptionsListTest.php} | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename dev/tests/integration/testsuite/Magento/Setup/Model/{ConfigOptionsCollectorTest.php => ConfigOptionsListCollectorTest.php} (90%) rename dev/tests/unit/testsuite/Magento/Backend/Setup/{ConfigOptionsTest.php => ConfigOptionsListTest.php} (97%) rename dev/tests/unit/testsuite/Magento/Setup/Model/{ConfigOptionsTest.php => ConfigOptionsListTest.php} (98%) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php similarity index 90% rename from dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php rename to dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php index 34c8d7ee718ae..85388215606bb 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php @@ -5,7 +5,7 @@ */ namespace Magento\Setup\Model; -class ConfigOptionsCollectorTest extends \PHPUnit_Framework_TestCase +class ConfigOptionsListCollectorTest extends \PHPUnit_Framework_TestCase { /** * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject @@ -31,7 +31,7 @@ public function testCollectOptionsDeploymentConfigAvailable() $fullModuleListMock->expects($this->never())->method('getNames'); /** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */ $object = $objectManager->create( - 'Magento\Setup\Model\ConfigOptionsCollector', + 'Magento\Setup\Model\ConfigOptionsListCollector', [ 'objectManagerProvider' => $this->objectManagerProvider, 'moduleList' => $moduleListMock, @@ -41,7 +41,7 @@ public function testCollectOptionsDeploymentConfigAvailable() $result = $object->collectOptions(); $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get('Magento\Setup\Model\ConfigOptions'); + ->get('Magento\Setup\Model\ConfigOptionsList'); $backendOptions = new \Magento\Backend\Setup\ConfigOptionsList(); $expected = [ 'setup' => $setupOptions, @@ -59,7 +59,7 @@ public function testCollectOptionsDeploymentConfigUnavailable() $moduleListMock->expects($this->once())->method('isModuleInfoAvailable')->willReturn(false); $moduleListMock->expects($this->never())->method('getNames'); $object = $objectManager->create( - 'Magento\Setup\Model\ConfigOptionsCollector', + 'Magento\Setup\Model\ConfigOptionsListCollector', [ 'objectManagerProvider' => $this->objectManagerProvider, 'moduleList' => $moduleListMock, @@ -70,7 +70,7 @@ public function testCollectOptionsDeploymentConfigUnavailable() $backendOptions = new \Magento\Backend\Setup\ConfigOptionsList(); $expected = [ 'setup' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get('Magento\Setup\Model\ConfigOptions'), + ->get('Magento\Setup\Model\ConfigOptionsList'), 'Magento_Backend' => $backendOptions, ]; diff --git a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsListTest.php similarity index 97% rename from dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php rename to dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsListTest.php index e3e8a61ac64cc..1603761b306a5 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsListTest.php @@ -7,7 +7,7 @@ use Magento\Framework\Config\File\ConfigFilePool; -class ConfigOptionsTest extends \PHPUnit_Framework_TestCase +class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase { /** * @var ConfigOptionsList diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsListTest.php similarity index 98% rename from dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php rename to dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsListTest.php index e0980aa85a0c3..69eca392d14c4 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsListTest.php @@ -5,7 +5,7 @@ */ namespace Magento\Setup\Model; -class ConfigOptionsTest extends \PHPUnit_Framework_TestCase +class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase { /** * @var ConfigOptionsList From 6f582677ee250c8f071dc7749865bd5260d42f5b Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 18:25:53 -0500 Subject: [PATCH 103/214] MAGETWO-34916: Rename ConfigOptions to ConfigOptionsList and related chages - fixed sanity tests --- setup/src/Magento/Setup/Model/ConfigGenerator.php | 13 +++++++++---- setup/src/Magento/Setup/Model/ConfigOptionsList.php | 3 ++- .../Setup/Model/ConfigOptionsListCollector.php | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index ce6213282dc86..5f8f323f271fb 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -73,9 +73,11 @@ public function createCryptConfig(array $data) { $cryptData = []; if (!isset($data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { - $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = md5($this->random->getRandomString(10)); + $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = + md5($this->random->getRandomString(10)); } else { - $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = $data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; + $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = + $data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; } return new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); } @@ -111,7 +113,8 @@ public function createSessionConfig(array $data) $sessionData[self::$paramMap[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]] = $data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]; } else { - $sessionData[self::$paramMap[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]] = ConfigOptionsList::SESSION_SAVE_FILES; + $sessionData[self::$paramMap[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]] = + ConfigOptionsList::SESSION_SAVE_FILES; } return new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); } @@ -164,7 +167,9 @@ public function createDbConfig(array $data) } $connection[self::$paramMap[ConfigOptionsList::INPUT_KEY_ACTIVE]] = '1'; - $prefixKey = isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]) ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] : ''; + $prefixKey = isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]) + ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] + : ''; $dbData = [ self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX] => $prefixKey, 'connection' => ['default' => $connection] diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index d87d675c4cebc..a8926ca783b85 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -166,7 +166,8 @@ public function validate(array $options) } } - if (isset($options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) && !$options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) { + if (isset($options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) + && !$options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) { $errors[] = 'Invalid encryption key.'; } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php index 36b8d123df5c7..92b35d718b83f 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php @@ -74,7 +74,8 @@ public function __construct( } /** - * Auto discover ConfigOptionsList class and collect them. These classes should reside in /Setup directories. + * Auto discover ConfigOptionsList class and collect them. + * These classes should reside in /Setup directories. * If deployment config is not available, all modules will be searched. Otherwise, only enabled modules * will be searched. * From def8fbf2302c4984c79b0653cb7d57ab00d93df1 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 10 Mar 2015 18:28:09 -0500 Subject: [PATCH 104/214] MAGETWO-34916: Rename ConfigOptions to ConfigOptionsList and related chages - fixed obsolite constant --- .../testsuite/Magento/Test/Legacy/_files/obsolete_constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php index 1e59c91c769ed..2cf84471410cd 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php @@ -709,6 +709,6 @@ [ 'PARAM_BACKEND_FRONT_NAME', 'Magento\Backend\App\Area\FrontNameResolver', - 'Magento\Backend\Setup\ConfigOptions::CONFIG_PATH_BACKEND_FRONTNAME' + 'Magento\Backend\Setup\ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME' ], ]; From e865565d901d7674a8d68568b6d84d3978507063 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Mon, 16 Mar 2015 11:04:17 -0500 Subject: [PATCH 105/214] MAGETWO-35132: Create console shell - added Symfony requirement to composer.json - changed cli.php to cli - added cli to access protection list --- composer.json | 3 ++- composer.lock | 12 ++++++------ setup/.htaccess | 5 +++++ setup/{cli.php => cli} | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) rename setup/{cli.php => cli} (95%) diff --git a/composer.json b/composer.json index c5d79f16eeebd..f1d8144bcaebb 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "composer/composer": "1.0.0-alpha8", "monolog/monolog": "1.11.0", "tubalmartin/cssmin": "2.4.8-p4", - "magento/magento-composer-installer": "*" + "magento/magento-composer-installer": "*", + "symfony/console": "~2.3" }, "require-dev": { "phpunit/phpunit": "4.1.0", diff --git a/composer.lock b/composer.lock index 46d8e23acef19..d813698126f13 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "4eaf34f33747b9344bfdf525a14e7767", + "hash": "6bba41553634b9f3b7d9b5163879eacf", "packages": [ { "name": "composer/composer", @@ -1941,16 +1941,16 @@ }, { "name": "fabpot/php-cs-fixer", - "version": "v1.5", + "version": "v1.5.1", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "2d6851520bf0250f668307ab2fd28cbb0b35d2b9" + "reference": "85777ebc6a1dac48c904acf9412b29b58b5dd592" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/2d6851520bf0250f668307ab2fd28cbb0b35d2b9", - "reference": "2d6851520bf0250f668307ab2fd28cbb0b35d2b9", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/85777ebc6a1dac48c904acf9412b29b58b5dd592", + "reference": "85777ebc6a1dac48c904acf9412b29b58b5dd592", "shasum": "" }, "require": { @@ -1990,7 +1990,7 @@ } ], "description": "A script to automatically fix Symfony Coding Standard", - "time": "2015-02-18 19:35:59" + "time": "2015-03-13 19:33:24" }, { "name": "league/climate", diff --git a/setup/.htaccess b/setup/.htaccess index 3e6764bf4bab2..5fdf63f4da9a6 100644 --- a/setup/.htaccess +++ b/setup/.htaccess @@ -3,3 +3,8 @@ Options -Indexes RewriteEngine Off + + + Order Allow,Deny + Deny from all + diff --git a/setup/cli.php b/setup/cli similarity index 95% rename from setup/cli.php rename to setup/cli index e82e4e4d255e2..6236a435ffaf8 100644 --- a/setup/cli.php +++ b/setup/cli @@ -1,3 +1,4 @@ +#!/usr/bin/env php Date: Mon, 16 Mar 2015 11:37:11 -0500 Subject: [PATCH 106/214] MAGETWO-35132: Create console shell - renamed cli to magento --- setup/.htaccess | 2 +- setup/{cli => magento} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename setup/{cli => magento} (100%) diff --git a/setup/.htaccess b/setup/.htaccess index 5fdf63f4da9a6..e988a7aca0784 100644 --- a/setup/.htaccess +++ b/setup/.htaccess @@ -4,7 +4,7 @@ Options -Indexes RewriteEngine Off - + Order Allow,Deny Deny from all diff --git a/setup/cli b/setup/magento similarity index 100% rename from setup/cli rename to setup/magento From c837a7903fd2bc6bdd9913e588eac0cffcf3a759 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 17 Mar 2015 14:03:16 -0500 Subject: [PATCH 107/214] MAGETWO-35132: Create console shell - moved script to bin directory --- bin/.htaccess | 2 ++ {setup => bin}/magento | 0 setup/.htaccess | 5 ----- 3 files changed, 2 insertions(+), 5 deletions(-) create mode 100644 bin/.htaccess rename {setup => bin}/magento (100%) diff --git a/bin/.htaccess b/bin/.htaccess new file mode 100644 index 0000000000000..896fbc5a341ea --- /dev/null +++ b/bin/.htaccess @@ -0,0 +1,2 @@ +Order deny,allow +Deny from all \ No newline at end of file diff --git a/setup/magento b/bin/magento similarity index 100% rename from setup/magento rename to bin/magento diff --git a/setup/.htaccess b/setup/.htaccess index e988a7aca0784..3e6764bf4bab2 100644 --- a/setup/.htaccess +++ b/setup/.htaccess @@ -3,8 +3,3 @@ Options -Indexes RewriteEngine Off - - - Order Allow,Deny - Deny from all - From ee87afb6bdd898ce35e3ed82d4220a54148887d0 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 18 Mar 2015 18:58:00 -0500 Subject: [PATCH 108/214] MAGETWO-35133: Search for Commands - added CommandList for Setup, Tools and Modules. - changed demo cli application to use CommandList --- .../Magento/Tools/Console/CommandList.php | 38 +++++++++++ .../Magento/Framework/App/Bootstrap.php | 2 +- .../Magento/Framework/Console/CommandList.php | 52 +++++++++++++++ .../src/Magento/Setup/Console/Application.php | 65 ++++++++++++------- .../src/Magento/Setup/Console/CommandList.php | 59 +++++++++++++++++ 5 files changed, 191 insertions(+), 25 deletions(-) create mode 100644 dev/tools/Magento/Tools/Console/CommandList.php create mode 100644 lib/internal/Magento/Framework/Console/CommandList.php create mode 100644 setup/src/Magento/Setup/Console/CommandList.php diff --git a/dev/tools/Magento/Tools/Console/CommandList.php b/dev/tools/Magento/Tools/Console/CommandList.php new file mode 100644 index 0000000000000..7782fa9522471 --- /dev/null +++ b/dev/tools/Magento/Tools/Console/CommandList.php @@ -0,0 +1,38 @@ +getCommandsClasses() as $class) { + if (class_exists($class)) { + $commands[] = new $class; + } + } + + return $commands; + } +} diff --git a/lib/internal/Magento/Framework/App/Bootstrap.php b/lib/internal/Magento/Framework/App/Bootstrap.php index 2099ee76e92d7..2edc1d162dab9 100644 --- a/lib/internal/Magento/Framework/App/Bootstrap.php +++ b/lib/internal/Magento/Framework/App/Bootstrap.php @@ -331,7 +331,7 @@ private function getIsExpected($key, $default) * * @return bool */ - private function isInstalled() + public function isInstalled() { $this->initObjectManager(); /** @var \Magento\Framework\App\DeploymentConfig $deploymentConfig */ diff --git a/lib/internal/Magento/Framework/Console/CommandList.php b/lib/internal/Magento/Framework/Console/CommandList.php new file mode 100644 index 0000000000000..99dea20d862b7 --- /dev/null +++ b/lib/internal/Magento/Framework/Console/CommandList.php @@ -0,0 +1,52 @@ +objectManager = $objectManager; + $this->commands = $commands; + } + + /** + * Gets list of command instances + * + * @return \Symfony\Component\Console\Command\Command[] + */ + public function getCommands() + { + $commands = []; + foreach ($this->commands as $class) { + if (class_exists($class)) { + $commands[] = $this->objectManager->get($class); + } + } + + return $commands; + } + +} diff --git a/setup/src/Magento/Setup/Console/Application.php b/setup/src/Magento/Setup/Console/Application.php index 0a350f87ae0ca..9274bd37acf09 100644 --- a/setup/src/Magento/Setup/Console/Application.php +++ b/setup/src/Magento/Setup/Console/Application.php @@ -7,7 +7,8 @@ namespace Magento\Setup\Console; use Symfony\Component\Console\Application as SymfonyApplication; -use \Magento\Framework\App\Bootstrap; +use Magento\Framework\App\Bootstrap; +use Magento\Framework\Shell\ComplexParameter; /** * Magento2 CLI Application @@ -36,32 +37,48 @@ protected function getDefaultCommands() */ protected function getApplicationCommands() { - $commandsList = []; + // TODO: this application class should be moved and probably refactored in scope of MAGETWO-35132 + + $setupCommands = []; + $toolsCommands = []; + $modulesCommands = []; + + $bootstrapParam = new ComplexParameter('bootstrap'); + $params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER); + $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; + $bootstrap = Bootstrap::create(BP, $params); + + if (class_exists('Magento\Setup\Console\CommandList')) { + $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') + ->getServiceManager(); + $setupCommandList = new \Magento\Setup\Console\CommandList($serviceManager); + $setupCommands = $setupCommandList->getCommands(); + } + + if (class_exists('Magento\Tools\Console\CommandList')) { + $toolsCommandList = new \Magento\Tools\Console\CommandList(); + $toolsCommands = $toolsCommandList->getCommands(); + } + + // TODO: do we need to change this for better solution? + if ($bootstrap->isInstalled()) { + + $objectManager = $bootstrap->getObjectManager(); + $commandList = $objectManager->create( + 'Magento\Framework\Console\CommandList', + ['objectManager'=>$objectManager] + ); + + $modulesCommands = $commandList->getCommands(); - $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') - ->getServiceManager(); - $setupFiles = glob(BP . '/setup/src/Magento/Setup/Console/Command/*Command.php'); - if ($setupFiles) { - foreach ($setupFiles as $file) { - if (preg_match("#(Magento/Setup/Console/Command/.*Command).php#", $file, $parts)) { - $class = str_replace('/', '\\', $parts[1]); - $commandObject = null; - try { - $commandObject = $serviceManager->create($class); - } catch (\Exception $e) { - try { - echo "Could not create command using service manager: " . $e->getMessage() . "\n"; - $commandObject = new $class(); - } catch (\Exception $e) { - } - } - if (null !== $commandObject) { - $commandsList[] = $commandObject; - } - } - } } + $commandsList = array_merge( + $setupCommands, + $toolsCommands, + $modulesCommands + ); + return $commandsList; } } diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php new file mode 100644 index 0000000000000..2339f4ed21290 --- /dev/null +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -0,0 +1,59 @@ +serviceManager = $serviceManager; + } + + /** + * Gets list of setup command classes + * + * @return string[] + */ + protected function getCommandsClasses() + { + return [ + 'Magento\Setup\Console\Command\ConfigInstallCommand' + ]; + } + + /** + * Gets list of command instances + * + * @return \Symfony\Component\Console\Command\Command[] + */ + public function getCommands() + { + $commands = []; + + foreach ($this->getCommandsClasses() as $class) { + if (class_exists($class)) { + $commands[] = $this->serviceManager->create($class); + } + } + + return $commands; + } +} From 42b8e55baafe0cea31c1aad04e88db7043b6c5b4 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 19 Mar 2015 13:58:40 -0500 Subject: [PATCH 109/214] MAGETWO-35132: Create console shell - moved Application class to framework --- bin/magento | 2 +- .../internal/Magento/Framework/Cli.php | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) rename setup/src/Magento/Setup/Console/Application.php => lib/internal/Magento/Framework/Cli.php (80%) diff --git a/bin/magento b/bin/magento index 6236a435ffaf8..9f0976b4d5f35 100644 --- a/bin/magento +++ b/bin/magento @@ -8,7 +8,7 @@ try { require __DIR__ . '/../app/bootstrap.php'; if (PHP_SAPI == 'cli') { - $application = new Magento\Setup\Console\Application('Magento CLI'); + $application = new Magento\Framework\Cli('Magento CLI'); $application->run(); } diff --git a/setup/src/Magento/Setup/Console/Application.php b/lib/internal/Magento/Framework/Cli.php similarity index 80% rename from setup/src/Magento/Setup/Console/Application.php rename to lib/internal/Magento/Framework/Cli.php index 9274bd37acf09..9db431ed7afdb 100644 --- a/setup/src/Magento/Setup/Console/Application.php +++ b/lib/internal/Magento/Framework/Cli.php @@ -4,18 +4,18 @@ * See COPYING.txt for license details. */ -namespace Magento\Setup\Console; +namespace Magento\Framework; use Symfony\Component\Console\Application as SymfonyApplication; use Magento\Framework\App\Bootstrap; use Magento\Framework\Shell\ComplexParameter; /** - * Magento2 CLI Application + * Magento2 CLI Application. This is the hood for all command line tools supported by Magento. * * {@inheritdoc} */ -class Application extends SymfonyApplication +class Cli extends SymfonyApplication { /** * {@inheritdoc} @@ -37,8 +37,6 @@ protected function getDefaultCommands() */ protected function getApplicationCommands() { - // TODO: this application class should be moved and probably refactored in scope of MAGETWO-35132 - $setupCommands = []; $toolsCommands = []; $modulesCommands = []; @@ -47,10 +45,10 @@ protected function getApplicationCommands() $params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER); $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; $bootstrap = Bootstrap::create(BP, $params); + $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') + ->getServiceManager(); if (class_exists('Magento\Setup\Console\CommandList')) { - $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') - ->getServiceManager(); $setupCommandList = new \Magento\Setup\Console\CommandList($serviceManager); $setupCommands = $setupCommandList->getCommands(); } @@ -60,9 +58,7 @@ protected function getApplicationCommands() $toolsCommands = $toolsCommandList->getCommands(); } - // TODO: do we need to change this for better solution? - if ($bootstrap->isInstalled()) { - + if ($serviceManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { $objectManager = $bootstrap->getObjectManager(); $commandList = $objectManager->create( 'Magento\Framework\Console\CommandList', From d7be6e78edb310b29e776432301cfa7c08d76204 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 19 Mar 2015 14:13:44 -0500 Subject: [PATCH 110/214] MAGETWO-35132: Create console shell - change to use ObjectManager --- lib/internal/Magento/Framework/Cli.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Cli.php b/lib/internal/Magento/Framework/Cli.php index 9db431ed7afdb..c6d64d5d5ae11 100644 --- a/lib/internal/Magento/Framework/Cli.php +++ b/lib/internal/Magento/Framework/Cli.php @@ -45,10 +45,11 @@ protected function getApplicationCommands() $params = $bootstrapParam->mergeFromArgv($_SERVER, $_SERVER); $params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null; $bootstrap = Bootstrap::create(BP, $params); - $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') - ->getServiceManager(); + $objectManager = $bootstrap->getObjectManager(); if (class_exists('Magento\Setup\Console\CommandList')) { + $serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php') + ->getServiceManager(); $setupCommandList = new \Magento\Setup\Console\CommandList($serviceManager); $setupCommands = $setupCommandList->getCommands(); } @@ -58,8 +59,7 @@ protected function getApplicationCommands() $toolsCommands = $toolsCommandList->getCommands(); } - if ($serviceManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { - $objectManager = $bootstrap->getObjectManager(); + if ($objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { $commandList = $objectManager->create( 'Magento\Framework\Console\CommandList', ['objectManager'=>$objectManager] From 981e51145b2a53893f909ad653a2e3e8a87e5128 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Thu, 19 Mar 2015 17:12:51 -0500 Subject: [PATCH 111/214] MAGETWO-35133: Search for Commands - changes according to CR - added unittests --- .../Magento/Tools/Console/CommandList.php | 7 +++- .../App/Test/Unit/Console/CommandListTest.php | 38 +++++++++++++++++++ .../Magento/Framework/Console/CommandList.php | 6 ++- .../Test/Unit/DefinitionFactoryTest.php | 2 +- .../src/Magento/Setup/Console/CommandList.php | 6 ++- .../Test/Unit/Console/CommandListTest.php | 36 ++++++++++++++++++ 6 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php create mode 100644 setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php diff --git a/dev/tools/Magento/Tools/Console/CommandList.php b/dev/tools/Magento/Tools/Console/CommandList.php index 7782fa9522471..7efc680566012 100644 --- a/dev/tools/Magento/Tools/Console/CommandList.php +++ b/dev/tools/Magento/Tools/Console/CommandList.php @@ -6,6 +6,8 @@ namespace Magento\Tools\Console; +use Symfony\Component\Console\Command\Command; + class CommandList { /** @@ -29,7 +31,10 @@ public function getCommands() foreach ($this->getCommandsClasses() as $class) { if (class_exists($class)) { - $commands[] = new $class; + $command = new $class;; + if ($command instanceof Command) { + $commands[] = $command; + } } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php new file mode 100644 index 0000000000000..276eb971e29bb --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php @@ -0,0 +1,38 @@ +objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false); + $this->commandList = new CommandList($this->objectManager, $commands); + } + + public function testGetCommands() + { + $this->objectManager->expects($this->once())->method('get')->with('Symfony\Component\Console\Command\Command'); + $this->commandList->getCommands(); + } +} diff --git a/lib/internal/Magento/Framework/Console/CommandList.php b/lib/internal/Magento/Framework/Console/CommandList.php index 99dea20d862b7..61caca54380cb 100644 --- a/lib/internal/Magento/Framework/Console/CommandList.php +++ b/lib/internal/Magento/Framework/Console/CommandList.php @@ -7,6 +7,7 @@ namespace Magento\Framework\Console; use Magento\Framework\ObjectManagerInterface; +use Symfony\Component\Console\Command\Command; class CommandList { @@ -42,7 +43,10 @@ public function getCommands() $commands = []; foreach ($this->commands as $class) { if (class_exists($class)) { - $commands[] = $this->objectManager->get($class); + $command = $this->objectManager->get($class); + if ($command instanceof Command) { + $commands[] = $command; + } } } diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php index ea32f1c5b5706..bf20a234e1eec 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php @@ -116,7 +116,7 @@ public function createPluginsAndRelationsNotReadableDataProvider() public function testGetSupportedFormats() { - $actual = DefinitionFactory::getSupportedFormats(); + $actual = \Magento\Framework\ObjectManager\DefinitionFactory::getSupportedFormats(); $this->assertInternalType('array', $actual); foreach ($actual as $className) { $this->assertInternalType('string', $className); diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php index 2339f4ed21290..2fb94d2eab11b 100644 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -7,6 +7,7 @@ namespace Magento\Setup\Console; use Zend\ServiceManager\ServiceManager; +use Symfony\Component\Console\Command\Command; class CommandList { @@ -50,7 +51,10 @@ public function getCommands() foreach ($this->getCommandsClasses() as $class) { if (class_exists($class)) { - $commands[] = $this->serviceManager->create($class); + $command = $this->serviceManager->create($class); + if ($command instanceof Command) { + $commands[] = $command; + } } } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php new file mode 100644 index 0000000000000..f16c0ecf7629b --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php @@ -0,0 +1,36 @@ +serviceManager = $this->getMock('\Zend\ServiceManager\ServiceManager', [], [], '', false); + $this->commandList = new CommandList($this->serviceManager); + } + + public function testGetCommands() + { + $this->serviceManager->expects($this->at(0)) + ->method('create') + ->with('Magento\Setup\Console\Command\ConfigInstallCommand'); + $this->commandList->getCommands(); + } +} From 233a8b63a72d876e535a07fc2d1b4ad573346c81 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 09:48:07 -0500 Subject: [PATCH 112/214] MAGETWO-35133: Search for Commands - changed back isInstalled() to private. --- lib/internal/Magento/Framework/App/Bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Bootstrap.php b/lib/internal/Magento/Framework/App/Bootstrap.php index 2edc1d162dab9..2099ee76e92d7 100644 --- a/lib/internal/Magento/Framework/App/Bootstrap.php +++ b/lib/internal/Magento/Framework/App/Bootstrap.php @@ -331,7 +331,7 @@ private function getIsExpected($key, $default) * * @return bool */ - public function isInstalled() + private function isInstalled() { $this->initObjectManager(); /** @var \Magento\Framework\App\DeploymentConfig $deploymentConfig */ From 346ef77de0c30f307e8b7b55c885ed100d264561 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 10:35:33 -0500 Subject: [PATCH 113/214] MAGETWO-35133: Search for Commands - removed redundand semicolons --- dev/tools/Magento/Tools/Console/CommandList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tools/Magento/Tools/Console/CommandList.php b/dev/tools/Magento/Tools/Console/CommandList.php index 7efc680566012..12a5344f56682 100644 --- a/dev/tools/Magento/Tools/Console/CommandList.php +++ b/dev/tools/Magento/Tools/Console/CommandList.php @@ -31,7 +31,7 @@ public function getCommands() foreach ($this->getCommandsClasses() as $class) { if (class_exists($class)) { - $command = new $class;; + $command = new $class; if ($command instanceof Command) { $commands[] = $command; } From ef5210c9d65d84559d4493e940e63e105c0f7476 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 11:02:55 -0500 Subject: [PATCH 114/214] MAGETWO-35133: Search for Commands - fixed aligment according to CR. --- lib/internal/Magento/Framework/Cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Cli.php b/lib/internal/Magento/Framework/Cli.php index c6d64d5d5ae11..d306535a568ba 100644 --- a/lib/internal/Magento/Framework/Cli.php +++ b/lib/internal/Magento/Framework/Cli.php @@ -63,7 +63,7 @@ protected function getApplicationCommands() $commandList = $objectManager->create( 'Magento\Framework\Console\CommandList', ['objectManager'=>$objectManager] - ); + ); $modulesCommands = $commandList->getCommands(); From adbc1cb66ab48b807095bfd84fc66be3d5b643df Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Fri, 20 Mar 2015 11:16:03 -0500 Subject: [PATCH 115/214] MAGETWO-35352: Move Unit-test According To New Design --- .../Backend/Test/Unit}/Setup/ConfigOptionsListTest.php | 3 ++- .../Framework/Config/Test/Unit}/File/ConfigFilePoolTest.php | 4 +++- .../Setup/Test/Unit}/Option/FlagConfigOptionTest.php | 4 +++- .../Setup/Test/Unit}/Option/MultiSelectConfigOptionTest.php | 6 +++++- .../Setup/Test/Unit}/Option/SelectConfigOptionTest.php | 5 ++++- .../Setup/Test/Unit}/Option/TextConfigOptionTest.php | 5 ++++- .../Test/Unit}/Console/Command/ConfigInstallCommandTest.php | 3 ++- .../Magento/Setup/Test/Unit}/Model/ConfigGeneratorTest.php | 4 +++- .../src/Magento/Setup/Test/Unit}/Model/ConfigModelTest.php | 3 ++- .../Setup/Test/Unit}/Model/ConfigOptionsListTest.php | 5 ++++- 10 files changed, 32 insertions(+), 10 deletions(-) rename {dev/tests/unit/testsuite/Magento/Backend => app/code/Magento/Backend/Test/Unit}/Setup/ConfigOptionsListTest.php (96%) rename {dev/tests/unit/testsuite/Magento/Framework/Config => lib/internal/Magento/Framework/Config/Test/Unit}/File/ConfigFilePoolTest.php (91%) rename {dev/tests/unit/testsuite/Magento/Framework/Setup => lib/internal/Magento/Framework/Setup/Test/Unit}/Option/FlagConfigOptionTest.php (79%) rename {dev/tests/unit/testsuite/Magento/Framework/Setup => lib/internal/Magento/Framework/Setup/Test/Unit}/Option/MultiSelectConfigOptionTest.php (88%) rename {dev/tests/unit/testsuite/Magento/Framework/Setup => lib/internal/Magento/Framework/Setup/Test/Unit}/Option/SelectConfigOptionTest.php (90%) rename {dev/tests/unit/testsuite/Magento/Framework/Setup => lib/internal/Magento/Framework/Setup/Test/Unit}/Option/TextConfigOptionTest.php (86%) rename {dev/tests/unit/testsuite/Magento/Setup => setup/src/Magento/Setup/Test/Unit}/Console/Command/ConfigInstallCommandTest.php (97%) rename {dev/tests/unit/testsuite/Magento/Setup => setup/src/Magento/Setup/Test/Unit}/Model/ConfigGeneratorTest.php (98%) rename {dev/tests/unit/testsuite/Magento/Setup => setup/src/Magento/Setup/Test/Unit}/Model/ConfigModelTest.php (98%) rename {dev/tests/unit/testsuite/Magento/Setup => setup/src/Magento/Setup/Test/Unit}/Model/ConfigOptionsListTest.php (97%) diff --git a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsListTest.php b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php similarity index 96% rename from dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsListTest.php rename to app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php index 1603761b306a5..d2a7c36e84954 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Setup/ConfigOptionsListTest.php +++ b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php @@ -3,8 +3,9 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Backend\Setup; +namespace Magento\Backend\Test\Unit\Setup; +use Magento\Backend\Setup\ConfigOptionsList; use Magento\Framework\Config\File\ConfigFilePool; class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase diff --git a/dev/tests/unit/testsuite/Magento/Framework/Config/File/ConfigFilePoolTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php similarity index 91% rename from dev/tests/unit/testsuite/Magento/Framework/Config/File/ConfigFilePoolTest.php rename to lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php index 0a9bd2c14aec9..52bc10dc59b89 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Config/File/ConfigFilePoolTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php @@ -4,7 +4,9 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\Config\File; +namespace Magento\Framework\Config\Test\Unit\File; + +use Magento\Framework\Config\File\ConfigFilePool; class ConfigFilePoolTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/FlagConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/FlagConfigOptionTest.php similarity index 79% rename from dev/tests/unit/testsuite/Magento/Framework/Setup/Option/FlagConfigOptionTest.php rename to lib/internal/Magento/Framework/Setup/Test/Unit/Option/FlagConfigOptionTest.php index 6f53c498f2c08..4f2d549820c22 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/FlagConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/FlagConfigOptionTest.php @@ -3,7 +3,9 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\Option; +namespace Magento\Framework\Setup\Test\Unit\Option; + +use Magento\Framework\Setup\Option\FlagConfigOption; class FlagConfigOptionTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/MultiSelectConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php similarity index 88% rename from dev/tests/unit/testsuite/Magento/Framework/Setup/Option/MultiSelectConfigOptionTest.php rename to lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php index d43e86c4a8083..b3de72651d8f8 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/MultiSelectConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php @@ -3,7 +3,11 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\Option; +namespace Magento\Framework\Setup\Test\Unit\Option; + +use Magento\Framework\Setup\Option\MultiSelectConfigOption; +use Magento\Framework\Setup\Option\SelectConfigOption; +use Magento\Framework\Setup\Option\TextConfigOption; class MultiSelectConfigOptionTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/SelectConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/SelectConfigOptionTest.php similarity index 90% rename from dev/tests/unit/testsuite/Magento/Framework/Setup/Option/SelectConfigOptionTest.php rename to lib/internal/Magento/Framework/Setup/Test/Unit/Option/SelectConfigOptionTest.php index b308068bbf9f3..a8fd1c3998be5 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/SelectConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/SelectConfigOptionTest.php @@ -3,7 +3,10 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\Option; +namespace Magento\Framework\Setup\Test\Unit\Option; + +use Magento\Framework\Setup\Option\SelectConfigOption; +use Magento\Framework\Setup\Option\TextConfigOption; class SelectConfigOptionTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/TextConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/TextConfigOptionTest.php similarity index 86% rename from dev/tests/unit/testsuite/Magento/Framework/Setup/Option/TextConfigOptionTest.php rename to lib/internal/Magento/Framework/Setup/Test/Unit/Option/TextConfigOptionTest.php index 9721acf83d88c..e5ee1cf748b0c 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Setup/Option/TextConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/TextConfigOptionTest.php @@ -3,7 +3,10 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\Option; +namespace Magento\Framework\Setup\Test\Unit\Option; + +use Magento\Framework\Setup\Option\SelectConfigOption; +use Magento\Framework\Setup\Option\TextConfigOption; class TextConfigOptionTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php similarity index 97% rename from dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php rename to setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php index 0dd971c6475fd..e52181b6010ca 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Console/Command/ConfigInstallCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php @@ -4,10 +4,11 @@ * See COPYING.txt for license details. */ -namespace Magento\Setup\Console\Command; +namespace Magento\Setup\Test\Unit\Console\Command; use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Module\ModuleList; +use Magento\Setup\Console\Command\ConfigInstallCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php similarity index 98% rename from dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php rename to setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 6361702e281b4..1307d5a8536eb 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -3,9 +3,11 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup\Model; +namespace Magento\Setup\Test\Unit\Model; use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Setup\Model\ConfigGenerator; +use Magento\Setup\Model\ConfigOptionsList; class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php similarity index 98% rename from dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php rename to setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php index f0dec78b59873..c3fa909427f01 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php @@ -4,9 +4,10 @@ * See COPYING.txt for license details. */ -namespace Magento\Setup\Model; +namespace Magento\Setup\Test\Unit\Model; use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Setup\Model\ConfigModel; class ConfigModelTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsListTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php similarity index 97% rename from dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsListTest.php rename to setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php index 69eca392d14c4..5f0d2bb78e6fb 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ConfigOptionsListTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php @@ -3,7 +3,10 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup\Model; +namespace Magento\Setup\Test\Unit\Model; + +use Magento\Setup\Model\ConfigGenerator; +use Magento\Setup\Model\ConfigOptionsList; class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase { From bdc10d654d66c93f300dd972c58c153e7fe8f2f9 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Fri, 20 Mar 2015 11:23:50 -0500 Subject: [PATCH 116/214] MAGETWO-35352: Move Unit-test According To New Design - fixed unit test --- .../Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php index b3de72651d8f8..74271a06c138a 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php @@ -6,7 +6,6 @@ namespace Magento\Framework\Setup\Test\Unit\Option; use Magento\Framework\Setup\Option\MultiSelectConfigOption; -use Magento\Framework\Setup\Option\SelectConfigOption; use Magento\Framework\Setup\Option\TextConfigOption; class MultiSelectConfigOptionTest extends \PHPUnit_Framework_TestCase @@ -47,7 +46,7 @@ public function testGetSelectOptions() */ public function testValidateException() { - $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); - $option->validate('c'); + $option = new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, ['a', 'b']); + $option->validate(['c', 'd']); } } From d66197fb37e89c75bc06a21e0aa6cf1e1394cae3 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Fri, 20 Mar 2015 11:48:56 -0500 Subject: [PATCH 117/214] MAGETWO-35352: Move Unit-test According To New Design - fixed code style --- lib/internal/Magento/Framework/Console/CommandList.php | 1 - .../Magento/Framework/Setup/Option/AbstractConfigOption.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Console/CommandList.php b/lib/internal/Magento/Framework/Console/CommandList.php index 61caca54380cb..7eaa7f7ec980b 100644 --- a/lib/internal/Magento/Framework/Console/CommandList.php +++ b/lib/internal/Magento/Framework/Console/CommandList.php @@ -52,5 +52,4 @@ public function getCommands() return $commands; } - } diff --git a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php index c09cda4cc627e..48ff2c3330e9e 100644 --- a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php @@ -53,7 +53,7 @@ public function getFrontendType() /** * No base validation - * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @param mixed $data * @return void */ From 1c89f071e7b54f32c3a37f6fa68d4b34d6306948 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 11:43:40 -0500 Subject: [PATCH 118/214] MAGETWO-35133: Search for Commands - fix accordong to CR. --- lib/internal/Magento/Framework/Cli.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Cli.php b/lib/internal/Magento/Framework/Cli.php index d306535a568ba..d5cac50aac0dc 100644 --- a/lib/internal/Magento/Framework/Cli.php +++ b/lib/internal/Magento/Framework/Cli.php @@ -60,10 +60,7 @@ protected function getApplicationCommands() } if ($objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { - $commandList = $objectManager->create( - 'Magento\Framework\Console\CommandList', - ['objectManager'=>$objectManager] - ); + $commandList = $objectManager->create('Magento\Framework\Console\CommandList'); $modulesCommands = $commandList->getCommands(); From 51ca4d9566d37bbb4ec701d2ff2fff5045adfed4 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 11:53:44 -0500 Subject: [PATCH 119/214] MAGETWO-35133: Search for Commands - added readme file to Framework/Comsole component. --- lib/internal/Magento/Framework/Console/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/internal/Magento/Framework/Console/README.md diff --git a/lib/internal/Magento/Framework/Console/README.md b/lib/internal/Magento/Framework/Console/README.md new file mode 100644 index 0000000000000..91d289b014e45 --- /dev/null +++ b/lib/internal/Magento/Framework/Console/README.md @@ -0,0 +1,3 @@ +# Console + +This component has a list of commands, which can be extended via DI configuration. \ No newline at end of file From 01e2ccfa95d0290d98cdc5598f26ef4a0af36fde Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 12:53:29 -0500 Subject: [PATCH 120/214] MAGETWO-35133: Search for Commands - changes in readme according to CR - throws exceprtion in case if command class does not exist and added testcase for that - added docbloc descriptions for classes --- dev/tools/Magento/Tools/Console/CommandList.php | 15 +++++++++------ .../App/Test/Unit/Console/CommandListTest.php | 13 +++++++++++++ .../Magento/Framework/Console/CommandList.php | 14 +++++++++----- lib/internal/Magento/Framework/Console/README.md | 15 ++++++++++++++- setup/src/Magento/Setup/Console/CommandList.php | 14 +++++++++----- 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/dev/tools/Magento/Tools/Console/CommandList.php b/dev/tools/Magento/Tools/Console/CommandList.php index 12a5344f56682..c86c0c11ca5c9 100644 --- a/dev/tools/Magento/Tools/Console/CommandList.php +++ b/dev/tools/Magento/Tools/Console/CommandList.php @@ -6,8 +6,11 @@ namespace Magento\Tools\Console; -use Symfony\Component\Console\Command\Command; - +/** + * Class CommandList contains predefined list of command classes for Tools + * + * @package Magento\Tools\Console + */ class CommandList { /** @@ -24,6 +27,7 @@ protected function getCommandsClasses() * Gets list of command instances * * @return \Symfony\Component\Console\Command\Command[] + * @throws \Exception */ public function getCommands() { @@ -31,10 +35,9 @@ public function getCommands() foreach ($this->getCommandsClasses() as $class) { if (class_exists($class)) { - $command = new $class; - if ($command instanceof Command) { - $commands[] = $command; - } + $commands[] = new $class; + } else { + throw new \Exception('Class ' . $class . ' does not exist'); } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php index 276eb971e29bb..a82804c49cb0a 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php @@ -35,4 +35,17 @@ public function testGetCommands() $this->objectManager->expects($this->once())->method('get')->with('Symfony\Component\Console\Command\Command'); $this->commandList->getCommands(); } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Class Symfony\Component\Console\Command\WrongCommand does not exist + */ + public function testGetCommandsException() + { + $wrongCommands =[ + 'Symfony\Component\Console\Command\WrongCommand' + ]; + $commandList = new CommandList($this->objectManager, $wrongCommands); + $commandList->getCommands(); + } } diff --git a/lib/internal/Magento/Framework/Console/CommandList.php b/lib/internal/Magento/Framework/Console/CommandList.php index 7eaa7f7ec980b..b40c82de4260e 100644 --- a/lib/internal/Magento/Framework/Console/CommandList.php +++ b/lib/internal/Magento/Framework/Console/CommandList.php @@ -7,8 +7,12 @@ namespace Magento\Framework\Console; use Magento\Framework\ObjectManagerInterface; -use Symfony\Component\Console\Command\Command; +/** + * Class CommandList has a list of commands, which can be extended via DI configuration. + * + * @package Magento\Framework\Console + */ class CommandList { /** @@ -37,16 +41,16 @@ public function __construct(ObjectManagerInterface $objectManager, array $comman * Gets list of command instances * * @return \Symfony\Component\Console\Command\Command[] + * @throws \Exception */ public function getCommands() { $commands = []; foreach ($this->commands as $class) { if (class_exists($class)) { - $command = $this->objectManager->get($class); - if ($command instanceof Command) { - $commands[] = $command; - } + $commands[] = $this->objectManager->get($class); + } else { + throw new \Exception('Class ' . $class . ' does not exist'); } } diff --git a/lib/internal/Magento/Framework/Console/README.md b/lib/internal/Magento/Framework/Console/README.md index 91d289b014e45..98920fa4b4bf7 100644 --- a/lib/internal/Magento/Framework/Console/README.md +++ b/lib/internal/Magento/Framework/Console/README.md @@ -1,3 +1,16 @@ # Console -This component has a list of commands, which can be extended via DI configuration. \ No newline at end of file +This component contains Magento Cli and can be extended via DI configuration. + +For example we can introduce new command in module using di.xml: + +``` + + + + Magento\MyModule\Console\TestMeCommand + + + +``` + diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php index 2fb94d2eab11b..4c51a62d6d25c 100644 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -7,8 +7,12 @@ namespace Magento\Setup\Console; use Zend\ServiceManager\ServiceManager; -use Symfony\Component\Console\Command\Command; +/** + * Class CommandList contains predefined list of commands for Setup + * + * @package Magento\Setup\Console + */ class CommandList { /** @@ -44,6 +48,7 @@ protected function getCommandsClasses() * Gets list of command instances * * @return \Symfony\Component\Console\Command\Command[] + * @throws \Exception */ public function getCommands() { @@ -51,10 +56,9 @@ public function getCommands() foreach ($this->getCommandsClasses() as $class) { if (class_exists($class)) { - $command = $this->serviceManager->create($class); - if ($command instanceof Command) { - $commands[] = $command; - } + $commands[] = $this->serviceManager->create($class); + } else { + throw new \Exception('Class ' . $class . ' does not exist'); } } From 506d7961aae1ff514b45227609f3c906d8202bc8 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 13:01:46 -0500 Subject: [PATCH 121/214] MAGETWO-35133: Search for Commands - fixed readme --- lib/internal/Magento/Framework/Console/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Console/README.md b/lib/internal/Magento/Framework/Console/README.md index 98920fa4b4bf7..8d77e82bdff72 100644 --- a/lib/internal/Magento/Framework/Console/README.md +++ b/lib/internal/Magento/Framework/Console/README.md @@ -8,7 +8,7 @@ For example we can introduce new command in module using di.xml: - Magento\MyModule\Console\TestMeCommand + Magento\MyModule\Console\TestMeCommand From 42710cfa184c216b8129275bda9cebd226c3827c Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 14:47:17 -0500 Subject: [PATCH 122/214] MAGETWO-35133: Search for Commands - moved Cli class to Console namespace. --- bin/magento | 2 +- lib/internal/Magento/Framework/{ => Console}/Cli.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename lib/internal/Magento/Framework/{ => Console}/Cli.php (98%) diff --git a/bin/magento b/bin/magento index 9f0976b4d5f35..728379e2a2bcf 100644 --- a/bin/magento +++ b/bin/magento @@ -8,7 +8,7 @@ try { require __DIR__ . '/../app/bootstrap.php'; if (PHP_SAPI == 'cli') { - $application = new Magento\Framework\Cli('Magento CLI'); + $application = new Magento\Framework\Console\Cli('Magento CLI'); $application->run(); } diff --git a/lib/internal/Magento/Framework/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php similarity index 98% rename from lib/internal/Magento/Framework/Cli.php rename to lib/internal/Magento/Framework/Console/Cli.php index d5cac50aac0dc..8d4b84e5c49ac 100644 --- a/lib/internal/Magento/Framework/Cli.php +++ b/lib/internal/Magento/Framework/Console/Cli.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework; +namespace Magento\Framework\Console; use Symfony\Component\Console\Application as SymfonyApplication; use Magento\Framework\App\Bootstrap; From d0f64210e14a83c3a72521b90d1e4e5acf7f85f1 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 14:58:01 -0500 Subject: [PATCH 123/214] MAGETWO-35133: Search for Commands - removed unnesesary lines --- lib/internal/Magento/Framework/Console/Cli.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Console/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php index 8d4b84e5c49ac..9d74f61e2495a 100644 --- a/lib/internal/Magento/Framework/Console/Cli.php +++ b/lib/internal/Magento/Framework/Console/Cli.php @@ -61,9 +61,7 @@ protected function getApplicationCommands() if ($objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { $commandList = $objectManager->create('Magento\Framework\Console\CommandList'); - $modulesCommands = $commandList->getCommands(); - } $commandsList = array_merge( From 9c93a1e6b0bc3cb07f41ceda97117547d5304a72 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 20 Mar 2015 15:59:26 -0500 Subject: [PATCH 124/214] MAGETWO-35133: Search for Commands - fixed comment --- dev/tools/Magento/Tools/Console/CommandList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tools/Magento/Tools/Console/CommandList.php b/dev/tools/Magento/Tools/Console/CommandList.php index c86c0c11ca5c9..a25d185b58c09 100644 --- a/dev/tools/Magento/Tools/Console/CommandList.php +++ b/dev/tools/Magento/Tools/Console/CommandList.php @@ -14,7 +14,7 @@ class CommandList { /** - * Gets list of setup command classes + * Gets list of tools command classes * * @return string[] */ From 317d281846a9b59686ff696f54d15d3b2a50172b Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Fri, 20 Mar 2015 18:38:40 -0500 Subject: [PATCH 125/214] MAGETWO-35135: Integrate config command - Initial code for renaming config:install to config:create --- ...allCommand.php => ConfigCreateCommand.php} | 27 ++++++++++---- .../src/Magento/Setup/Console/CommandList.php | 2 +- .../Command/ConfigInstallCommandTest.php | 36 +++++++++++++++++-- .../Test/Unit/Console/CommandListTest.php | 2 +- 4 files changed, 56 insertions(+), 11 deletions(-) rename setup/src/Magento/Setup/Console/Command/{ConfigInstallCommand.php => ConfigCreateCommand.php} (75%) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php similarity index 75% rename from setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php rename to setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php index 5d73562214a03..a505d35df87e1 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigInstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php @@ -6,13 +6,14 @@ namespace Magento\Setup\Console\Command; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Module\ModuleList; +use Magento\Setup\Model\ConfigModel; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Magento\Setup\Model\ConfigModel; -use Magento\Framework\Module\ModuleList; -class ConfigInstallCommand extends Command +class ConfigCreateCommand extends Command { /** * @var ConfigModel @@ -31,16 +32,26 @@ class ConfigInstallCommand extends Command */ private $moduleList; + /** + * Existing deployment config + */ + private $deploymentConfig; + /** * Constructor * * @param \Magento\Setup\Model\ConfigModel $configModel * @param ModuleList $moduleList + * @param DeploymentConfig $deploymentConfig */ - public function __construct(ConfigModel $configModel, ModuleList $moduleList) + public function __construct( + ConfigModel $configModel, + ModuleList $moduleList, + DeploymentConfig $deploymentConfig) { $this->configModel = $configModel; $this->moduleList = $moduleList; + $this->deploymentConfig = $deploymentConfig; parent::__construct(); } @@ -53,8 +64,8 @@ protected function configure() { $options = $this->configModel->getAvailableOptions(); - $this->setName('config:install') - ->setDescription('Install deployment configuration') + $this->setName('config:create') + ->setDescription('Create deployment configuration') ->setDefinition($options); $this->ignoreValidationErrors(); @@ -74,6 +85,10 @@ protected function execute(InputInterface $input, OutputInterface $output) */ public function initialize(InputInterface $input, OutputInterface $output) { + if ($this->deploymentConfig->isAvailable()) { + throw new \Exception('Deployment configuration already exists, cannot create a new one'); + } + if (!$this->moduleList->isModuleInfoAvailable()) { $output->writeln( 'No module configuration is available, so all modules are enabled.' diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php index 4c51a62d6d25c..a38e8f4cc16d9 100644 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -40,7 +40,7 @@ public function __construct(ServiceManager $serviceManager) protected function getCommandsClasses() { return [ - 'Magento\Setup\Console\Command\ConfigInstallCommand' + 'Magento\Setup\Console\Command\ConfigCreateCommand' ]; } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php index e52181b6010ca..c56e5d3d0b5b3 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php @@ -8,7 +8,7 @@ use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Module\ModuleList; -use Magento\Setup\Console\Command\ConfigInstallCommand; +use Magento\Setup\Console\Command\ConfigCreateCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -29,6 +29,11 @@ class ConfigInstallCommandTest extends \PHPUnit_Framework_TestCase */ private $moduleList; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig + */ + private $deploymentConfig; + /** * @var \PHPUnit_Framework_MockObject_MockObject|InputInterface */ @@ -44,6 +49,7 @@ public function setUp() $this->configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); $this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->input = $this->getMock('Symfony\Component\Console\Input\InputInterface', [], [], '', false); $this->output = $this->getMock('Symfony\Component\Console\Output\OutputInterface', [], [], '', false); } @@ -69,8 +75,9 @@ public function testInitialize() $this->output->expects($this->once()) ->method('writeln') ->with('No module configuration is available, so all modules are enabled.'); + $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $command = new ConfigInstallCommand($this->configModel, $this->moduleList); + $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $command->initialize($this->input, $this->output); } @@ -95,12 +102,35 @@ public function testInitializeFailedValidation() $this->output->expects($this->once())->method('writeln')->with('Error message'); + $this->configModel + ->expects($this->once()) + ->method('getAvailableOptions') + ->will($this->returnValue($optionsSet)); + $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(false); + + $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); + $command->initialize($this->input, $this->output); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Deployment configuration already exists + */ + public function testDeploymentConfigExists() + { + $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(true); + $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $optionsSet = [ + $option + ]; + $this->configModel ->expects($this->once()) ->method('getAvailableOptions') ->will($this->returnValue($optionsSet)); - $command = new ConfigInstallCommand($this->configModel, $this->moduleList); + $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $command->initialize($this->input, $this->output); } + } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php index f16c0ecf7629b..12c555953e9b4 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php @@ -30,7 +30,7 @@ public function testGetCommands() { $this->serviceManager->expects($this->at(0)) ->method('create') - ->with('Magento\Setup\Console\Command\ConfigInstallCommand'); + ->with('Magento\Setup\Console\Command\ConfigCreateCommand'); $this->commandList->getCommands(); } } From 11ebbe19eb2f96be6322833e74e075f67a7973af Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 23 Mar 2015 11:04:34 -0500 Subject: [PATCH 126/214] MAGETWO-35133: Search for Commands - optimized Framework CommandList, it does not require object manager now. --- .../App/Test/Unit/Console/CommandListTest.php | 31 ++++++------------- .../Magento/Framework/Console/CommandList.php | 21 ++----------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php index a82804c49cb0a..8e6d910c400ed 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php @@ -7,6 +7,7 @@ namespace Magento\Framework\App\Test\Unit\Console; use Magento\Framework\Console\CommandList; +use Symfony\Component\Console\Command\Command; class CommandListTest extends \PHPUnit_Framework_TestCase { @@ -16,36 +17,24 @@ class CommandListTest extends \PHPUnit_Framework_TestCase private $commandList; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface + * @var Symfony\Component\Console\Command\Command */ - private $objectManager; + private $testCommand; public function setUp() { - $commands =[ - 'Symfony\Component\Console\Command\Command' + $this->testCommand = new Command('Test'); + $commands = [ + $this->testCommand ]; - $this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false); - $this->commandList = new CommandList($this->objectManager, $commands); + $this->commandList = new CommandList($commands); } public function testGetCommands() { - $this->objectManager->expects($this->once())->method('get')->with('Symfony\Component\Console\Command\Command'); - $this->commandList->getCommands(); - } - - /** - * @expectedException \Exception - * @expectedExceptionMessage Class Symfony\Component\Console\Command\WrongCommand does not exist - */ - public function testGetCommandsException() - { - $wrongCommands =[ - 'Symfony\Component\Console\Command\WrongCommand' - ]; - $commandList = new CommandList($this->objectManager, $wrongCommands); - $commandList->getCommands(); + $commands = $this->commandList->getCommands(); + $this->assertEquals(1, count($commands)); + $this->assertEquals($this->testCommand, $commands[0]); } } diff --git a/lib/internal/Magento/Framework/Console/CommandList.php b/lib/internal/Magento/Framework/Console/CommandList.php index b40c82de4260e..a75d096466bf0 100644 --- a/lib/internal/Magento/Framework/Console/CommandList.php +++ b/lib/internal/Magento/Framework/Console/CommandList.php @@ -20,20 +20,13 @@ class CommandList */ protected $commands; - /** - * @var ObjectManagerInterface - */ - protected $objectManager; - /** * Constructor * - * @param ObjectManagerInterface $objectManager * @param array $commands */ - public function __construct(ObjectManagerInterface $objectManager, array $commands = []) + public function __construct(array $commands = []) { - $this->objectManager = $objectManager; $this->commands = $commands; } @@ -41,19 +34,9 @@ public function __construct(ObjectManagerInterface $objectManager, array $comman * Gets list of command instances * * @return \Symfony\Component\Console\Command\Command[] - * @throws \Exception */ public function getCommands() { - $commands = []; - foreach ($this->commands as $class) { - if (class_exists($class)) { - $commands[] = $this->objectManager->get($class); - } else { - throw new \Exception('Class ' . $class . ' does not exist'); - } - } - - return $commands; + return $this->commands; } } From d2685a843c1d171a8882a63de5309961e7630b26 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 23 Mar 2015 15:03:06 -0500 Subject: [PATCH 127/214] MAGETWO-35133: Search for Commands - fix in test according to CR. --- .../Magento/Framework/App/Test/Unit/Console/CommandListTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php index 8e6d910c400ed..7fffa7866da26 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Console/CommandListTest.php @@ -34,7 +34,7 @@ public function setUp() public function testGetCommands() { $commands = $this->commandList->getCommands(); + $this->assertSame([$this->testCommand], $commands); $this->assertEquals(1, count($commands)); - $this->assertEquals($this->testCommand, $commands[0]); } } From 642b94a351f8aa7e06dad12790047c5bc2945afb Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 24 Mar 2015 15:24:18 -0500 Subject: [PATCH 128/214] MAGETWO-35137: Add deployment configuration set command - added config path to config option - added read config value by path into ConfigModel --- .../Backend/Setup/ConfigOptionsList.php | 13 +++-- .../Framework/App/DeploymentConfig/Reader.php | 7 +++ .../Setup/ConfigOptionsListInterface.php | 3 +- .../Setup/Option/AbstractConfigOption.php | 20 +++++++ .../Setup/Option/SelectConfigOption.php | 3 ++ .../Setup/Option/TextConfigOption.php | 12 ++++- .../Console/Command/ConfigCreateCommand.php | 15 +++--- .../src/Magento/Setup/Console/CommandList.php | 2 +- .../Magento/Setup/Model/ConfigGenerator.php | 24 ++++----- setup/src/Magento/Setup/Model/ConfigModel.php | 53 ++++++++++++++++++- .../Magento/Setup/Model/ConfigOptionsList.php | 45 +++++++++------- 11 files changed, 150 insertions(+), 47 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php index faf8a786f7830..f306c860c5957 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -34,6 +34,7 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_BACKEND_FRONTNAME, TextConfigOption::FRONTEND_WIZARD_TEXT, + 'backend/frontName', 'Backend frontname', 'admin' ) @@ -43,12 +44,16 @@ public function getOptions() /** * {@inheritdoc} */ - public function createConfig(array $options) + public function createConfig(array $options, array $currentConfig = []) { + $data = []; + if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) { + $data = ['frontName' => $options[self::INPUT_KEY_BACKEND_FRONTNAME]]; + } return [new ConfigData( ConfigFilePool::APP_CONFIG, 'backend', - ['frontName' => $options[self::INPUT_KEY_BACKEND_FRONTNAME]] + $data )]; } @@ -58,7 +63,9 @@ public function createConfig(array $options) public function validate(array $options) { $errors = []; - if (!preg_match('/^[a-zA-Z0-9_]+$/', $options[self::INPUT_KEY_BACKEND_FRONTNAME])) { + if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME]) + && !preg_match('/^[a-zA-Z0-9_]+$/', $options[self::INPUT_KEY_BACKEND_FRONTNAME]) + ) { $errors[] = "Invalid backend frontname '{$options[self::INPUT_KEY_BACKEND_FRONTNAME]}'"; } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php index de210b4287105..a988374d93e3a 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php @@ -7,6 +7,7 @@ namespace Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Config\File\ConfigFilePool; /** * Deployment configuration reader @@ -79,4 +80,10 @@ public function load($configFile = null) $result = @include $file; return $result ?: []; } + + public function loadConfig() + { + // TODO: add multi config functionality here + return $this->load(); + } } diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php index 9c618922255da..a84578169b500 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php @@ -23,9 +23,10 @@ public function getOptions(); * Data in these objects will be stored in array form in deployment config file. * * @param array $options + * @param array $currentConfig * @return \Magento\Framework\Config\Data\ConfigData[] */ - public function createConfig(array $options); + public function createConfig(array $options, array $currentConfig = []); /** * Validates user input option values and returns error messages diff --git a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php index 48ff2c3330e9e..f2be8be82c27f 100644 --- a/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/AbstractConfigOption.php @@ -19,12 +19,20 @@ abstract class AbstractConfigOption extends InputOption */ private $frontendType; + /** + * Config path + * + * @var string + */ + private $configPath; + /** * Constructor * * @param string $name * @param string $frontendType * @param int $mode + * @param string $configPath * @param string $description * @param string|array|null $defaultValue * @param string|array|null $shortcut @@ -33,11 +41,13 @@ public function __construct( $name, $frontendType, $mode, + $configPath, $description = '', $defaultValue = null, $shortcut = null ) { $this->frontendType = $frontendType; + $this->configPath = $configPath; parent::__construct($name, $shortcut, $mode, $description, $defaultValue); } @@ -51,6 +61,16 @@ public function getFrontendType() return $this->frontendType; } + /** + * Get config path + * + * @return string + */ + public function getConfigPath() + { + return $this->configPath; + } + /** * No base validation * @SuppressWarnings(PHPMD.UnusedFormalParameter) diff --git a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php index a14de60ff9a74..0482be895e43c 100644 --- a/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/SelectConfigOption.php @@ -30,6 +30,7 @@ class SelectConfigOption extends AbstractConfigOption * @param string $name * @param string $frontendType * @param array $selectOptions + * @param string $configPath * @param string $description * @param string|null $defaultValue * @param string|array|null $shortCut @@ -39,6 +40,7 @@ public function __construct( $name, $frontendType, array $selectOptions, + $configPath, $description = '', $defaultValue = null, $shortCut = null @@ -54,6 +56,7 @@ public function __construct( $name, $frontendType, self::VALUE_REQUIRED, + $configPath, $description, $defaultValue, $shortCut diff --git a/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php index 913ed46dc13c8..e248e56854bd8 100644 --- a/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/TextConfigOption.php @@ -23,6 +23,7 @@ class TextConfigOption extends AbstractConfigOption * * @param string $name * @param string $frontendType + * @param string $configPath * @param string $description * @param string|null $defaultValue * @param string|array|null $shortCut @@ -31,6 +32,7 @@ class TextConfigOption extends AbstractConfigOption public function __construct( $name, $frontendType, + $configPath, $description = '', $defaultValue = null, $shortCut = null @@ -40,7 +42,15 @@ public function __construct( ) { throw new \InvalidArgumentException("Frontend input type has to be 'text', 'textarea' or 'password'."); } - parent::__construct($name, $frontendType, self::VALUE_REQUIRED, $description, $defaultValue, $shortCut); + parent::__construct( + $name, + $frontendType, + self::VALUE_REQUIRED, + $configPath, + $description, + $defaultValue, + $shortCut + ); } /** diff --git a/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php index a505d35df87e1..ae7faedb84019 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php @@ -64,7 +64,7 @@ protected function configure() { $options = $this->configModel->getAvailableOptions(); - $this->setName('config:create') + $this->setName('config:set') ->setDescription('Create deployment configuration') ->setDefinition($options); @@ -76,7 +76,14 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $this->configModel->process($input->getOptions()); + $inputOptions = $input->getOptions(); + + $inputOptions = array_filter($inputOptions, + function ($value) { + return $value !== null; + } + ); + $this->configModel->process($inputOptions); $output->writeln('You saved the deployment config.'); } @@ -85,10 +92,6 @@ protected function execute(InputInterface $input, OutputInterface $output) */ public function initialize(InputInterface $input, OutputInterface $output) { - if ($this->deploymentConfig->isAvailable()) { - throw new \Exception('Deployment configuration already exists, cannot create a new one'); - } - if (!$this->moduleList->isModuleInfoAvailable()) { $output->writeln( 'No module configuration is available, so all modules are enabled.' diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php index a38e8f4cc16d9..87b70b9dae3a5 100644 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -40,7 +40,7 @@ public function __construct(ServiceManager $serviceManager) protected function getCommandsClasses() { return [ - 'Magento\Setup\Console\Command\ConfigCreateCommand' + 'Magento\Setup\Console\Command\ConfigCreateCommand', ]; } diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 5f8f323f271fb..d8feeca2e4245 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -144,26 +144,22 @@ public function createDefinitionsConfig(array $data) */ public function createDbConfig(array $data) { + var_dump($data); $connection = []; - $required = [ + $optional = [ ConfigOptionsList::INPUT_KEY_DB_HOST, ConfigOptionsList::INPUT_KEY_DB_NAME, - ConfigOptionsList::INPUT_KEY_DB_USER + ConfigOptionsList::INPUT_KEY_DB_USER, + ConfigOptionsList::INPUT_KEY_DB_PASS, + ConfigOptionsList::INPUT_KEY_DB_MODEL, + ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS, ]; - foreach ($required as $key) { - $connection[ConfigGenerator::$paramMap[$key]] = $data[$key]; - } - - $optional = [ - ConfigOptionsList::INPUT_KEY_DB_PASS => '', - ConfigOptionsList::INPUT_KEY_DB_MODEL => 'mysql4', - ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS => 'SET NAMES utf8;' - ]; - - foreach ($optional as $key => $value) { - $connection[self::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : $value; + foreach ($optional as $key) { + if (isset($data[$key])) { + $connection[self::$paramMap[$key]] = $data[$key]; + } } $connection[self::$paramMap[ConfigOptionsList::INPUT_KEY_ACTIVE]] = '1'; diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 75bf45920bbcb..c55733d9e3afd 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -8,6 +8,7 @@ use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\App\DeploymentConfig\Reader; class ConfigModel { @@ -21,18 +22,32 @@ class ConfigModel */ protected $writer; + /** + * @var \Magento\Framework\App\DeploymentConfig\Reader + */ + protected $reader; + + /** + * @var array + */ + protected $currentConfig; + /** * Constructor * * @param ConfigOptionsListCollector $collector * @param Writer $writer + * @param Reader $reader */ public function __construct( ConfigOptionsListCollector $collector, - Writer $writer + Writer $writer, + Reader $reader ) { $this->collector = $collector; $this->writer = $writer; + $this->reader = $reader; + $this->currentConfig = $this->reader->loadConfig(); } /** @@ -49,6 +64,13 @@ public function getAvailableOptions() $optionCollection = array_merge($optionCollection, $option->getOptions()); } + foreach ($optionCollection as $option) { + $currentValue = $this->getConfigValueByPath($option->getConfigPath()); + if ($currentValue !== null) { + $option->setDefault(); + } + } + return $optionCollection; } @@ -67,7 +89,7 @@ public function process($inputOptions) foreach ($options as $moduleName => $option) { - $configData = $option->createConfig($inputOptions); + $configData = $option->createConfig($inputOptions, $this->currentConfig); foreach ($configData as $config) { if (!$config instanceof ConfigData) { @@ -126,4 +148,31 @@ public function validate(array $inputOptions) return $errors; } + + /** + * Gets config value by path + * + * @param string $path + * @return mixed + */ + public function getConfigValueByPath($path) + { + $currentConfig = $this->currentConfig; + $chunks = explode('/', $path); + if (!empty($chunks)) { + + $sizeOfPath = count($chunks); + for ($level = 0; $level < $sizeOfPath; $level++) { + if (isset($currentConfig[$chunks[$level]])) { + if ($level === $sizeOfPath-1) { + return $currentConfig[$chunks[$level]]; + } + + $currentConfig = $currentConfig[$chunks[$level]]; + } + } + } + + return null; + } } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index a8926ca783b85..5c5c843d20c5b 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -72,12 +72,17 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_CRYPT_KEY, TextConfigOption::FRONTEND_WIZARD_TEXT, + 'crypt/key', 'Encryption key' + // TODO: find right place for it + //md5($this->random->getRandomString(10)) + ), new SelectConfigOption( self::INPUT_KEY_SESSION_SAVE, SelectConfigOption::FRONTEND_WIZARD_SELECT, [self::SESSION_SAVE_FILES, self::SESSION_SAVE_DB], + 'session/save', 'Session save location', self::SESSION_SAVE_FILES ), @@ -85,42 +90,56 @@ public function getOptions() self::INPUT_KEY_DEFINITION_FORMAT, SelectConfigOption::FRONTEND_WIZARD_SELECT, DefinitionFactory::getSupportedFormats(), + 'definition/format', 'Type of definitions used by Object Manager' ), new TextConfigOption( self::INPUT_KEY_DB_HOST, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'Database server host' + 'db/connection/default/host', + 'Database server host', + 'localhost' ), new TextConfigOption( self::INPUT_KEY_DB_NAME, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'Database name' + 'db/connection/default/dbname', + 'Database name', + 'magento2' ), new TextConfigOption( self::INPUT_KEY_DB_USER, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'Database server username' + 'db/connection/default/username', + 'Database server username', + 'root' ), new TextConfigOption( self::INPUT_KEY_DB_PASS, TextConfigOption::FRONTEND_WIZARD_PASSWORD, - 'Database server password' + 'db/connection/default/password', + 'Database server password', + '' ), new TextConfigOption( self::INPUT_KEY_DB_PREFIX, TextConfigOption::FRONTEND_WIZARD_TEXT, + 'db/table_prefix', 'Database table prefix' ), new TextConfigOption( self::INPUT_KEY_DB_MODEL, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'Database type' + 'db/connection/default/model', + 'Database type', + 'mysql4' ), new TextConfigOption( self::INPUT_KEY_DB_INIT_STATEMENTS, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'Database initial set of commands' + 'db/connection/default/initStatements', + 'Database initial set of commands', + 'SET NAMES utf8;' ), ]; } @@ -128,7 +147,7 @@ public function getOptions() /** * {@inheritdoc} */ - public function createConfig(array $data) + public function createConfig(array $data, array $currentConfig = []) { $configData = []; $configData[] = $this->configGenerator->createInstallConfig(); @@ -154,18 +173,6 @@ public function validate(array $options) { $errors = []; - $required = [ - ConfigOptionsList::INPUT_KEY_DB_HOST, - ConfigOptionsList::INPUT_KEY_DB_NAME, - ConfigOptionsList::INPUT_KEY_DB_USER - ]; - - foreach ($required as $key) { - if (!isset($options[$key]) || empty($options[$key])) { - $errors[] = "Missing value for db configuration: {$key}"; - } - } - if (isset($options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) && !$options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) { $errors[] = 'Invalid encryption key.'; From c064ac4ac82c47b8cbb8df9cf36a4b59ca10cadf Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 24 Mar 2015 15:42:48 -0500 Subject: [PATCH 129/214] MAGETWO-35137: Add deployment configuration set command - removed var_dump and unnesesary usage. --- lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php | 1 - setup/src/Magento/Setup/Model/ConfigGenerator.php | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php index a988374d93e3a..c77db417513d1 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php @@ -7,7 +7,6 @@ namespace Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Config\File\ConfigFilePool; /** * Deployment configuration reader diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index d8feeca2e4245..9d39d67f582a7 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -144,7 +144,6 @@ public function createDefinitionsConfig(array $data) */ public function createDbConfig(array $data) { - var_dump($data); $connection = []; $optional = [ From bcbbaed2bcfae836aab3bc4b270743b83aa294e2 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 24 Mar 2015 16:28:18 -0500 Subject: [PATCH 130/214] MAGETWO-35137: Add deployment configuration set command - refactored ConfigOptionsList according to new interface --- .../Magento/Setup/Model/ConfigGenerator.php | 39 +++++++++++++------ .../Magento/Setup/Model/ConfigOptionsList.php | 7 +--- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 9d39d67f582a7..b1f76183a0e52 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -57,28 +57,47 @@ public function __construct(Random $random, Loader $moduleLoader, DeploymentConf /** * Creates install segment config data * + * @param array $currentConfig * @return ConfigData */ - public function createInstallConfig() + public function createInstallConfig(array $currentConfig) { - return new ConfigData(ConfigFilePool::APP_CONFIG, 'install', [InstallConfig::KEY_DATE => date('r')]); + $installConfig = []; + if (!isset($currentConfig['install']['date'])) { + $installConfig = [InstallConfig::KEY_DATE => date('r')]; + } + return new ConfigData(ConfigFilePool::APP_CONFIG, 'install', $installConfig); } /** * Creates encryption key config data * @param array $data + * @param array $currentData * @return ConfigData */ - public function createCryptConfig(array $data) + public function createCryptConfig(array $data, array $currentData) { + $currentKey = false; + if (isset($currentData['crypt'][ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { + $currentKey = $currentData['crypt'][ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; + } + $cryptData = []; - if (!isset($data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { - $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = - md5($this->random->getRandomString(10)); + if (isset($data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { + if ($currentKey) { + $key = $currentKey . "\n" . $data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; + } else { + $key = $data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; + } + + $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = $key; } else { - $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = - $data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; + if (!$currentKey) { + $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = + md5($this->random->getRandomString(10)); + } } + return new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); } @@ -112,10 +131,8 @@ public function createSessionConfig(array $data) if (isset($data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { $sessionData[self::$paramMap[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]] = $data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]; - } else { - $sessionData[self::$paramMap[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]] = - ConfigOptionsList::SESSION_SAVE_FILES; } + return new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index 5c5c843d20c5b..5652bdeccef2c 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -74,9 +74,6 @@ public function getOptions() TextConfigOption::FRONTEND_WIZARD_TEXT, 'crypt/key', 'Encryption key' - // TODO: find right place for it - //md5($this->random->getRandomString(10)) - ), new SelectConfigOption( self::INPUT_KEY_SESSION_SAVE, @@ -150,8 +147,8 @@ public function getOptions() public function createConfig(array $data, array $currentConfig = []) { $configData = []; - $configData[] = $this->configGenerator->createInstallConfig(); - $configData[] = $this->configGenerator->createCryptConfig($data); + $configData[] = $this->configGenerator->createInstallConfig($currentConfig); + $configData[] = $this->configGenerator->createCryptConfig($data, $currentConfig); $modulesConfig = $this->configGenerator->createModuleConfig(); if (isset($modulesConfig)) { $configData[] = $modulesConfig; From e41c22ecd20142c23adbbf1514b10a30680889c8 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 19 Mar 2015 12:45:57 -0500 Subject: [PATCH 131/214] MAGETWO-35136: Delete Segments - deleting BackendConfig - deleting session segment - deleting dbconfig - deleting dbConfig and EncryptConfig - deleting Cache and Db config - refactoring modules' config --- .../Backend/Setup/ConfigOptionsList.php | 5 + .../Config/Source/Storage/Media/Database.php | 21 ++- .../Source/Storage/Media/DatabaseTest.php | 21 +-- app/etc/di.xml | 1 - .../Magento/Mtf/App/State/AbstractState.php | 12 +- .../Magento/TestFramework/Application.php | 11 +- .../Model/Resource/Db/ProfilerTest.php | 8 +- .../Test/Legacy/_files/obsolete_classes.php | 6 + .../Framework/App/Cache/Frontend/Pool.php | 23 ++-- .../Framework/App/Cache/Type/FrontendPool.php | 18 +-- .../App/DeploymentConfig/BackendConfig.php | 45 ------ .../App/DeploymentConfig/CacheConfig.php | 88 ------------ .../App/DeploymentConfig/DbConfig.php | 116 ---------------- .../App/DeploymentConfig/EncryptConfig.php | 16 +-- .../App/DeploymentConfig/InstallConfig.php | 42 ------ .../Framework/App/DeploymentConfig/Reader.php | 15 ++ .../App/DeploymentConfig/ResourceConfig.php | 63 --------- .../App/DeploymentConfig/SessionConfig.php | 47 ------- .../Magento/Framework/App/Resource.php | 22 ++- .../Magento/Framework/App/Resource/Config.php | 7 +- .../App/Test/Unit/Cache/Frontend/PoolTest.php | 25 ++-- .../Test/Unit/Cache/Type/FrontendPoolTest.php | 21 ++- .../DeploymentConfig/BackendConfigTest.php | 64 --------- .../Unit/DeploymentConfig/CacheConfigTest.php | 70 ---------- .../Unit/DeploymentConfig/DbConfigTest.php | 128 ------------------ .../DeploymentConfig/InstallConfigTest.php | 34 ----- .../DeploymentConfig/ResourceConfigTest.php | 74 ---------- .../DeploymentConfig/SessionConfigTest.php | 47 ------- .../App/Test/Unit/Resource/ConfigTest.php | 16 +-- .../Framework/App/Test/Unit/ResourceTest.php | 16 ++- .../Magento/Framework/Module/ModuleList.php | 3 +- .../Module/ModuleList/DeploymentConfig.php | 8 +- pub/get.php | 1 - .../src/Magento/Setup/Controller/Install.php | 4 +- .../Magento/Setup/Model/ConfigGenerator.php | 27 ++-- .../Magento/Setup/Model/ConfigOptionsList.php | 57 ++++++++ .../Setup/Model/DeploymentConfigMapper.php | 27 ++-- setup/src/Magento/Setup/Model/Installer.php | 25 ++-- .../Magento/Setup/Model/InstallerFactory.php | 7 +- .../src/Magento/Setup/Model/ModuleStatus.php | 3 +- .../Magento/Setup/Module/ResourceFactory.php | 6 +- .../Test/Unit/Module/ResourceFactoryTest.php | 2 +- 42 files changed, 242 insertions(+), 1010 deletions(-) delete mode 100644 lib/internal/Magento/Framework/App/DeploymentConfig/BackendConfig.php delete mode 100644 lib/internal/Magento/Framework/App/DeploymentConfig/CacheConfig.php delete mode 100644 lib/internal/Magento/Framework/App/DeploymentConfig/DbConfig.php delete mode 100644 lib/internal/Magento/Framework/App/DeploymentConfig/InstallConfig.php delete mode 100644 lib/internal/Magento/Framework/App/DeploymentConfig/ResourceConfig.php delete mode 100644 lib/internal/Magento/Framework/App/DeploymentConfig/SessionConfig.php delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/BackendConfigTest.php delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/CacheConfigTest.php delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/DbConfigTest.php delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/InstallConfigTest.php delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ResourceConfigTest.php delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/SessionConfigTest.php diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php index f306c860c5957..1b5eb4481919e 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -25,6 +25,11 @@ class ConfigOptionsList implements ConfigOptionsListInterface */ const CONFIG_PATH_BACKEND_FRONTNAME = 'backend/frontName'; + /** + * Key for config + */ + const KEY_FRONTNAME = 'frontend'; + /** * {@inheritdoc} */ diff --git a/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php b/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php index f150f80ad8bac..66fc5d30cd075 100644 --- a/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php +++ b/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php @@ -9,22 +9,22 @@ */ namespace Magento\MediaStorage\Model\Config\Source\Storage\Media; -use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\App\DeploymentConfig\ResourceConfig; +use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Setup\Model\ConfigOptionsList; class Database implements \Magento\Framework\Option\ArrayInterface { /** - * @var DeploymentConfig + * @var Reader */ - protected $_deploymentConfig; + protected $reader; /** - * @param DeploymentConfig $deploymentConfig + * @param Reader $reader */ - public function __construct(DeploymentConfig $deploymentConfig) + public function __construct(Reader $reader) { - $this->_deploymentConfig = $deploymentConfig; + $this->reader = $reader; } /** @@ -35,10 +35,9 @@ public function __construct(DeploymentConfig $deploymentConfig) public function toOptionArray() { $resourceOptions = []; - $resourceInfo = $this->_deploymentConfig->getSegment(ResourceConfig::CONFIG_KEY); - if (null !== $resourceInfo) { - $resourceConfig = new ResourceConfig($resourceInfo); - foreach (array_keys($resourceConfig->getData()) as $resourceName) { + $resourceConfig = $this->reader->getConfigData(ConfigOptionsList::KEY_RESOURCE); + if (null !== $resourceConfig) { + foreach (array_keys($resourceConfig) as $resourceName) { $resourceOptions[] = ['value' => $resourceName, 'label' => $resourceName]; } sort($resourceOptions); diff --git a/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php b/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php index 5952cf065d017..3b3226dc6026c 100644 --- a/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php +++ b/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php @@ -8,7 +8,7 @@ namespace Magento\MediaStorage\Test\Unit\Model\Config\Source\Storage\Media; -use Magento\Framework\App\DeploymentConfig\ResourceConfig; +use Magento\Setup\Model\ConfigOptionsList; /** * Class DatabaseTest @@ -21,27 +21,28 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase protected $mediaDatabase; /** - * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject */ - protected $configMock; + protected $readerMock; protected function setUp() { - $this->configMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $this->configMock->expects( + $this->readerMock = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $this->readerMock->expects( $this->any() )->method( - 'getSegment' + 'getConfigData' )->with( - ResourceConfig::CONFIG_KEY + ConfigOptionsList::KEY_RESOURCE )->will( $this->returnValue( - ['default_setup' => ['name' => 'default_setup', ResourceConfig::KEY_CONNECTION => 'connect1'], - 'custom_resource' => ['name' => 'custom_resource', ResourceConfig::KEY_CONNECTION => 'connect2'], + [ + 'default_setup' => ['name' => 'default_setup', ConfigOptionsList::KEY_CONNECTION => 'connect1'], + 'custom_resource' => ['name' => 'custom_resource', ConfigOptionsList::KEY_CONNECTION => 'connect2'], ] ) ); - $this->mediaDatabase = new \Magento\MediaStorage\Model\Config\Source\Storage\Media\Database($this->configMock); + $this->mediaDatabase = new \Magento\MediaStorage\Model\Config\Source\Storage\Media\Database($this->readerMock); } /** diff --git a/app/etc/di.xml b/app/etc/di.xml index ae05cbce7e18b..9249d1d9dacc9 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -305,7 +305,6 @@ Magento\Framework\App\Resource\Config\Reader\Proxy Magento\Framework\App\Cache\Type\Config\Proxy - Magento\Framework\App\DeploymentConfig\ResourceConfig diff --git a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php index ef8d88494f1ae..06cd15d819529 100644 --- a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php +++ b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php @@ -6,8 +6,8 @@ namespace Magento\Mtf\App\State; -use Magento\Framework\App\DeploymentConfig\DbConfig; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Setup\Model\ConfigOptionsList; /** * Abstract class AbstractState @@ -41,12 +41,10 @@ public function clearInstance() { $dirList = \Magento\Mtf\ObjectManagerFactory::getObjectManager() ->get('Magento\Framework\Filesystem\DirectoryList'); - $deploymentConfig = new \Magento\Framework\App\DeploymentConfig( - new \Magento\Framework\App\DeploymentConfig\Reader($dirList), - [] - ); - $dbConfig = new DbConfig($deploymentConfig->getSegment(DbConfig::CONFIG_KEY)); - $dbInfo = $dbConfig->getConnection('default'); + + $reader = new \Magento\Framework\App\DeploymentConfig\Reader($dirList); + $dbConfig = $reader->getConfigData(ConfigOptionsList::CONFIG_KEY); + $dbInfo = $dbConfig['connection']['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; $password = $dbInfo['password']; diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index b8d9e4424ce95..98b636d630603 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -10,7 +10,7 @@ use Magento\Framework\Filesystem; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\App\DeploymentConfig\DbConfig; +use Magento\Setup\Model\ConfigOptionsList; /** * Encapsulates application installation, initialization and uninstall @@ -161,12 +161,9 @@ public function getDbInstance() { if (null === $this->_db) { if ($this->isInstalled()) { - $deploymentConfig = new DeploymentConfig( - new \Magento\Framework\App\DeploymentConfig\Reader($this->dirList), - [] - ); - $dbConfig = new DbConfig($deploymentConfig->getSegment(DbConfig::CONFIG_KEY)); - $dbInfo = $dbConfig->getConnection('default'); + $reader = new \Magento\Framework\App\DeploymentConfig\Reader($this->dirList); + $dbConfig = $reader->getConfigData(ConfigOptionsList::CONFIG_KEY); + $dbInfo = $dbConfig['connection']['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; $password = $dbInfo['password']; diff --git a/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php b/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php index 955772f912ce2..c93de0e670df0 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php @@ -7,7 +7,7 @@ */ namespace Magento\Framework\Model\Resource\Db; -use Magento\Framework\App\DeploymentConfig\DbConfig; +use Magento\Setup\Model\ConfigOptionsList; class ProfilerTest extends \PHPUnit_Framework_TestCase { @@ -45,9 +45,9 @@ protected function setUp() protected function _getConnectionRead() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $deploymentConfig = $objectManager->get('Magento\Framework\App\DeploymentConfig'); - $dbConfig = new DbConfig($deploymentConfig->getSegment(DbConfig::CONFIG_KEY)); - $connectionConfig = $dbConfig->getConnection('default'); + $reader = $objectManager->get('Magento\Framework\App\DeploymentConfig\Reader'); + $dbConfig = $reader->getConfigData(ConfigOptionsList::CONFIG_KEY); + $connectionConfig = $dbConfig['connection']['default']; $connectionConfig['profiler'] = [ 'class' => 'Magento\Framework\Model\Resource\Db\Profiler', 'enabled' => 'true', diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 2f915d7ffb489..016f703823479 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3117,4 +3117,10 @@ ['Magento\LocaleFactory'], ['Magento\Framework\LocaleFactory'], ['Magento\Core\Helper\Data', 'Magento\Framework\Json\Helper\Data'], + ['Magento\Framework\App\DeploymentConfig\BackendConfig'], + ['Magento\Framework\App\DeploymentConfig\DbConfig'], + ['Magento\Framework\App\DeploymentConfig\InstallConfig'], + ['Magento\Framework\App\DeploymentConfig\ResourceConfig'], + ['Magento\Framework\App\DeploymentConfig\SessionConfig'], + ['Magento\Framework\App\DeploymentConfig\CacheConfig'], ]; diff --git a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php index 1a31f00953691..ba6b3a0ca69a2 100644 --- a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php +++ b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php @@ -5,7 +5,8 @@ */ namespace Magento\Framework\App\Cache\Frontend; -use Magento\Framework\App\DeploymentConfig\CacheConfig; +use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Setup\Model\ConfigOptionsList; /** * In-memory readonly pool of all cache front-end instances known to the system @@ -18,9 +19,9 @@ class Pool implements \Iterator const DEFAULT_FRONTEND_ID = 'default'; /** - * @var \Magento\Framework\App\DeploymentConfig + * @var Reader */ - private $_deploymentConfig; + private $reader; /** * @var Factory @@ -38,16 +39,13 @@ class Pool implements \Iterator private $_frontendSettings; /** - * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig + * @param Reader $reader * @param Factory $frontendFactory * @param array $frontendSettings Format: array('' => array(), ...) */ - public function __construct( - \Magento\Framework\App\DeploymentConfig $deploymentConfig, - Factory $frontendFactory, - array $frontendSettings = [] - ) { - $this->_deploymentConfig = $deploymentConfig; + public function __construct(Reader $reader, Factory $frontendFactory, array $frontendSettings = []) + { + $this->reader = $reader; $this->_factory = $frontendFactory; $this->_frontendSettings = $frontendSettings + [self::DEFAULT_FRONTEND_ID => []]; } @@ -79,10 +77,9 @@ protected function _getCacheSettings() * Merging is intentionally implemented through array_merge() instead of array_replace_recursive() * to avoid "inheritance" of the default settings that become irrelevant as soon as cache storage type changes */ - $cacheInfo = $this->_deploymentConfig->getSegment(CacheConfig::CONFIG_KEY); + $cacheInfo = $this->reader->getConfigData(ConfigOptionsList::KEY_CACHE); if (null !== $cacheInfo) { - $cacheConfig = new CacheConfig($cacheInfo); - return array_merge($this->_frontendSettings, $cacheConfig->getCacheFrontendSettings()); + return array_merge($this->_frontendSettings, $cacheInfo[ConfigOptionsList::KEY_FRONTEND]); } return $this->_frontendSettings; } diff --git a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php index 89ce24b09a8bc..5e86bd3cdc744 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php @@ -5,7 +5,8 @@ */ namespace Magento\Framework\App\Cache\Type; -use Magento\Framework\App\DeploymentConfig\CacheConfig; +use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Setup\Model\ConfigOptionsList; /** * In-memory readonly pool of cache front-ends with enforced access control, specific to cache types @@ -18,9 +19,9 @@ class FrontendPool private $_objectManager; /** - * @var \Magento\Framework\App\DeploymentConfig + * @var \Magento\Framework\App\DeploymentConfig\Reader */ - private $_deploymentConfig; + private $reader; /** * @var \Magento\Framework\App\Cache\Frontend\Pool @@ -39,18 +40,18 @@ class FrontendPool /** * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig + * @param \Magento\Framework\App\DeploymentConfig\Reader $deploymentConfig * @param \Magento\Framework\App\Cache\Frontend\Pool $frontendPool * @param array $typeFrontendMap Format: array('' => '', ...) */ public function __construct( \Magento\Framework\ObjectManagerInterface $objectManager, - \Magento\Framework\App\DeploymentConfig $deploymentConfig, + \Magento\Framework\App\DeploymentConfig\Reader $reader, \Magento\Framework\App\Cache\Frontend\Pool $frontendPool, array $typeFrontendMap = [] ) { $this->_objectManager = $objectManager; - $this->_deploymentConfig = $deploymentConfig; + $this->reader = $reader; $this->_frontendPool = $frontendPool; $this->_typeFrontendMap = $typeFrontendMap; } @@ -85,10 +86,9 @@ public function get($cacheType) protected function _getCacheFrontendId($cacheType) { $result = null; - $cacheInfo = $this->_deploymentConfig->getSegment(CacheConfig::CONFIG_KEY); + $cacheInfo = $this->reader->getConfigData(ConfigOptionsList::KEY_CACHE); if (null !== $cacheInfo) { - $cacheConfig = new CacheConfig($cacheInfo); - $result = $cacheConfig->getCacheTypeFrontendId($cacheType); + $result = $cacheInfo[ConfigOptionsList::KEY_TYPE][$cacheType][ConfigOptionsList::KEY_FRONTEND]; } if (!$result) { if (isset($this->_typeFrontendMap[$cacheType])) { diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/BackendConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig/BackendConfig.php deleted file mode 100644 index 20b3f461ceff2..0000000000000 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/BackendConfig.php +++ /dev/null @@ -1,45 +0,0 @@ -validate($data); - parent::__construct($data); - } - - /** - * Validate data - * - * @param array $data - * @return void - * @throws \InvalidArgumentException - */ - private function validate(array $data) - { - if (!isset($data[self::KEY_FRONTEND])) { - throw new \InvalidArgumentException('No cache frontend configuration provided.'); - } - if (!is_array($data[self::KEY_FRONTEND])) { - throw new \InvalidArgumentException('Invalid cache frontend configuration provided.'); - } - foreach ($data[self::KEY_FRONTEND] as $settings) { - if (!is_array($settings)) { - throw new \InvalidArgumentException('Invalid cache settings.'); - } - } - } - - /** - * {@inheritdoc} - */ - public function getKey() - { - return self::CONFIG_KEY; - } - - /** - * Retrieve settings for all cache front-ends configured in the system - * - * @return array Format: array('' => array(), ...) - */ - public function getCacheFrontendSettings() - { - return isset($this->data[self::KEY_FRONTEND]) ? $this->data[self::KEY_FRONTEND] : []; - } - - /** - * Retrieve identifier of a cache frontend, configured to be used for a cache type - * - * @param string $cacheType Cache type identifier - * @return string|null - */ - public function getCacheTypeFrontendId($cacheType) - { - return isset($this->data[self::KEY_TYPE][$cacheType][self::KEY_FRONTEND]) ? - $this->data[self::KEY_TYPE][$cacheType][self::KEY_FRONTEND] : null; - } -} diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/DbConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig/DbConfig.php deleted file mode 100644 index fd0b117b6ada2..0000000000000 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/DbConfig.php +++ /dev/null @@ -1,116 +0,0 @@ -data = [ - self::KEY_PREFIX => '', - 'connection' => [ - 'default' => [ - self::KEY_HOST => '', - self::KEY_NAME => '', - self::KEY_USER => '', - self::KEY_PASS => '', - self::KEY_MODEL => 'mysql4', - self::KEY_INIT_STATEMENTS => 'SET NAMES utf8;', - self::KEY_ACTIVE => '1', - ], - ], - ]; - $data = $this->update($data); - $this->checkData($data); - parent::__construct($data); - } - - /** - * Validate data - * - * @param array $data - * @return void - * @throws \InvalidArgumentException - */ - private function checkData(array $data) - { - $prefix = $data[self::KEY_PREFIX]; - if ($prefix != '') { - $prefix = strtolower($prefix); - if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $prefix)) { - throw new \InvalidArgumentException( - 'The table prefix should contain only letters (a-z), numbers (0-9) or underscores (_); ' - . 'the first character should be a letter.' - ); - } - } - foreach ($data['connection'] as $db) { - if (empty($db[self::KEY_NAME])) { - throw new \InvalidArgumentException('The Database Name field cannot be empty.'); - } - if (empty($db[self::KEY_HOST])) { - throw new \InvalidArgumentException('The Database Host field cannot be empty.'); - } - if (empty($db[self::KEY_USER])) { - throw new \InvalidArgumentException('The Database User field cannot be empty.'); - } - } - } - - /** - * {@inheritdoc} - */ - public function getKey() - { - return self::CONFIG_KEY; - } - - /** - * Retrieve connection configuration by connection name - * - * @param string $connectionName - * @return array|null - */ - public function getConnection($connectionName) - { - return isset($this->data['connection'][$connectionName]) ? $this->data['connection'][$connectionName] : null; - } - - /** - * Retrieve list of connections - * - * @return array - */ - public function getConnections() - { - return isset($this->data['connection']) ? $this->data['connection'] : []; - } -} diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/EncryptConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig/EncryptConfig.php index 905f3a07783fd..1e0dadaa02898 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/EncryptConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/EncryptConfig.php @@ -6,18 +6,10 @@ namespace Magento\Framework\App\DeploymentConfig; +use Magento\Setup\Model\ConfigOptionsList; + class EncryptConfig extends AbstractSegment { - /** - * Array Key for encryption key in deployment config file - */ - const KEY_ENCRYPTION_KEY = 'key'; - - /** - * Segment key - */ - const CONFIG_KEY = 'crypt'; - /** * Constructor * @@ -26,7 +18,7 @@ class EncryptConfig extends AbstractSegment */ public function __construct(array $data) { - if (!isset($data[self::KEY_ENCRYPTION_KEY])) { + if (!isset($data[ConfigOptionsList::KEY_ENCRYPTION_KEY])) { throw new \InvalidArgumentException('No encryption key provided'); } parent::__construct($data); @@ -37,6 +29,6 @@ public function __construct(array $data) */ public function getKey() { - return self::CONFIG_KEY; + return ConfigOptionsList::ENCRYPT_CONFIG_KEY; } } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/InstallConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig/InstallConfig.php deleted file mode 100644 index a4e565ced5ed3..0000000000000 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/InstallConfig.php +++ /dev/null @@ -1,42 +0,0 @@ -load(); } + + /** + * Gets a value specified key from config data + * + * @param $key + * @return null + */ + public function getConfigData($key) + { + $config = $this->load(); + if (!isset($config[$key])) { + return null; + } + return $config[$key]; + } } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/ResourceConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig/ResourceConfig.php deleted file mode 100644 index 7e0bf9d0aa74b..0000000000000 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/ResourceConfig.php +++ /dev/null @@ -1,63 +0,0 @@ -data = [ - 'default_setup' => [ - self::KEY_CONNECTION => 'default', - ], - ]; - if (!$this->validate($data)) { - throw new \InvalidArgumentException('Invalid resource configuration.'); - } - parent::__construct($this->update($data)); - } - - /** - * Validate input data - * - * @param array $data - * @return bool - */ - private function validate(array $data = []) - { - foreach ($data as $resource) { - if (!isset($resource[self::KEY_CONNECTION])) { - return false; - } - } - return true; - } - - /** - * {@inheritdoc} - */ - public function getKey() - { - return self::CONFIG_KEY; - } -} diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/SessionConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig/SessionConfig.php deleted file mode 100644 index b80cb007b744b..0000000000000 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/SessionConfig.php +++ /dev/null @@ -1,47 +0,0 @@ - 'files', - ]; - } elseif ($data[self::KEY_SAVE] !== 'files' && $data[self::KEY_SAVE] !== 'db') { - throw new \InvalidArgumentException("Invalid session_save location {$data[self::KEY_SAVE]}"); - } - - parent::__construct($data); - } - - /** - * {@inheritdoc} - */ - public function getKey() - { - return self::CONFIG_KEY; - } -} diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index 518f642c31680..b182f6f608aed 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -7,9 +7,10 @@ */ namespace Magento\Framework\App; -use Magento\Framework\App\DeploymentConfig\DbConfig; +use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\Resource\ConfigInterface as ResourceConfigInterface; use Magento\Framework\Model\Resource\Type\Db\ConnectionFactoryInterface; +use Magento\Setup\Model\ConfigOptionsList; class Resource { @@ -19,8 +20,6 @@ class Resource const AUTO_UPDATE_ALWAYS = 1; - const PARAM_TABLE_PREFIX = 'db/table_prefix'; - const DEFAULT_READ_RESOURCE = 'core_read'; const DEFAULT_WRITE_RESOURCE = 'core_write'; @@ -54,9 +53,9 @@ class Resource protected $_connectionFactory; /** - * @var DeploymentConfig $deploymentConfig + * @var Reader $reader */ - private $deploymentConfig; + private $reader; /** * @var string @@ -66,18 +65,18 @@ class Resource /** * @param ResourceConfigInterface $resourceConfig * @param ConnectionFactoryInterface $adapterFactory - * @param DeploymentConfig $deploymentConfig + * @param Reader $reader * @param string $tablePrefix */ public function __construct( ResourceConfigInterface $resourceConfig, ConnectionFactoryInterface $adapterFactory, - DeploymentConfig $deploymentConfig, + Reader $reader, $tablePrefix = '' ) { $this->_config = $resourceConfig; $this->_connectionFactory = $adapterFactory; - $this->deploymentConfig = $deploymentConfig; + $this->reader = $reader; $this->_tablePrefix = $tablePrefix ?: null; } @@ -105,12 +104,11 @@ public function getConnectionByName($connectionName) return $this->_connections[$connectionName]; } - $dbInfo = $this->deploymentConfig->getSegment(DbConfig::CONFIG_KEY); + $dbInfo = $this->reader->getConfigData(ConfigOptionsList::CONFIG_KEY); if (null === $dbInfo) { return false; } - $dbConfig = new DbConfig($dbInfo); - $connectionConfig = $dbConfig->getConnection($connectionName); + $connectionConfig = $dbInfo['connection'][$connectionName]; if ($connectionConfig) { $connection = $this->_connectionFactory->create($connectionConfig); } @@ -233,7 +231,7 @@ public function getFkName($priTableName, $priColumnName, $refTableName, $refColu private function getTablePrefix() { if (null === $this->_tablePrefix) { - $this->_tablePrefix = (string)$this->deploymentConfig->get(self::PARAM_TABLE_PREFIX); + $this->_tablePrefix = (string)$this->reader->getConfigData(ConfigOptionsList::KEY_PREFIX); } return $this->_tablePrefix; } diff --git a/lib/internal/Magento/Framework/App/Resource/Config.php b/lib/internal/Magento/Framework/App/Resource/Config.php index 381ad3e718605..9b6564e790266 100644 --- a/lib/internal/Magento/Framework/App/Resource/Config.php +++ b/lib/internal/Magento/Framework/App/Resource/Config.php @@ -24,7 +24,7 @@ class Config extends \Magento\Framework\Config\Data\Scoped implements ConfigInte * @param Config\Reader $reader * @param \Magento\Framework\Config\ScopeInterface $configScope * @param \Magento\Framework\Config\CacheInterface $cache - * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig + * @param \Magento\Framework\App\DeploymentConfig\Reader $configReader * @param string $cacheId * @throws \InvalidArgumentException */ @@ -32,11 +32,12 @@ public function __construct( Config\Reader $reader, \Magento\Framework\Config\ScopeInterface $configScope, \Magento\Framework\Config\CacheInterface $cache, - \Magento\Framework\App\DeploymentConfig $deploymentConfig, + \Magento\Framework\App\DeploymentConfig\Reader $configReader, $cacheId = 'resourcesCache' ) { parent::__construct($reader, $configScope, $cache, $cacheId); - foreach ($deploymentConfig->getSegment('resource') as $resourceName => $resourceData) { + + foreach ($configReader->getConfigData('resource') as $resourceName => $resourceData) { if (!isset($resourceData['connection'])) { throw new \InvalidArgumentException('Invalid initial resource configuration'); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php index d0e6740409f34..1bcd576b87e6e 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php @@ -6,6 +6,7 @@ namespace Magento\Framework\App\Test\Unit\Cache\Frontend; use \Magento\Framework\App\Cache\Frontend\Pool; +use Magento\Setup\Model\ConfigOptionsList; class PoolTest extends \PHPUnit_Framework_TestCase { @@ -40,13 +41,13 @@ protected function setUp() $frontendFactory = $this->getMock('Magento\Framework\App\Cache\Frontend\Factory', [], [], '', false); $frontendFactory->expects($this->any())->method('create')->will($this->returnValueMap($frontendFactoryMap)); - $deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $deploymentConfig->expects( + $reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $reader->expects( $this->any() )->method( - 'getSegment' + 'getConfigData' )->with( - \Magento\Framework\App\DeploymentConfig\CacheConfig::CONFIG_KEY + ConfigOptionsList::KEY_CACHE )->will( $this->returnValue(['frontend' => ['resource2' => ['r2d1' => 'value1', 'r2d2' => 'value2']]]) ); @@ -57,7 +58,7 @@ protected function setUp() ]; $this->_model = new \Magento\Framework\App\Cache\Frontend\Pool( - $deploymentConfig, + $reader, $frontendFactory, $frontendSettings ); @@ -68,10 +69,10 @@ protected function setUp() */ public function testConstructorNoInitialization() { - $deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); $frontendFactory = $this->getMock('Magento\Framework\App\Cache\Frontend\Factory', [], [], '', false); $frontendFactory->expects($this->never())->method('create'); - new \Magento\Framework\App\Cache\Frontend\Pool($deploymentConfig, $frontendFactory); + new \Magento\Framework\App\Cache\Frontend\Pool($reader, $frontendFactory); } /** @@ -86,13 +87,13 @@ public function testInitializationParams( array $frontendSettings, array $expectedFactoryArg ) { - $deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $deploymentConfig->expects( + $reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $reader->expects( $this->once() )->method( - 'getSegment' + 'getConfigData' )->with( - \Magento\Framework\App\DeploymentConfig\CacheConfig::CONFIG_KEY + ConfigOptionsList::KEY_CACHE )->will( $this->returnValue($fixtureCacheConfig) ); @@ -100,7 +101,7 @@ public function testInitializationParams( $frontendFactory = $this->getMock('Magento\Framework\App\Cache\Frontend\Factory', [], [], '', false); $frontendFactory->expects($this->at(0))->method('create')->with($expectedFactoryArg); - $model = new \Magento\Framework\App\Cache\Frontend\Pool($deploymentConfig, $frontendFactory, $frontendSettings); + $model = new \Magento\Framework\App\Cache\Frontend\Pool($reader, $frontendFactory, $frontendSettings); $model->current(); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php index 1d8ad48a97925..ad2363b5a5212 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php @@ -6,6 +6,7 @@ namespace Magento\Framework\App\Test\Unit\Cache\Type; use \Magento\Framework\App\Cache\Type\FrontendPool; +use Magento\Setup\Model\ConfigOptionsList; class FrontendPoolTest extends \PHPUnit_Framework_TestCase { @@ -20,9 +21,9 @@ class FrontendPoolTest extends \PHPUnit_Framework_TestCase protected $_objectManager; /** - * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject */ - protected $_deploymentConfig; + protected $reader; /** * @var \Magento\Framework\App\Cache\Frontend\Pool|\PHPUnit_Framework_MockObject_MockObject @@ -32,17 +33,11 @@ class FrontendPoolTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->_objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->_deploymentConfig = $this->getMock( - 'Magento\Framework\App\DeploymentConfig', - [], - [], - '', - false - ); + $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); $this->_cachePool = $this->getMock('Magento\Framework\App\Cache\Frontend\Pool', [], [], '', false); $this->_model = new FrontendPool( $this->_objectManager, - $this->_deploymentConfig, + $this->reader, $this->_cachePool, ['fixture_cache_type' => 'fixture_frontend_id'] ); @@ -57,12 +52,12 @@ protected function setUp() */ public function testGet($fixtureSegment, $inputCacheType, $expectedFrontendId) { - $this->_deploymentConfig->expects( + $this->reader->expects( $this->once() )->method( - 'getSegment' + 'getConfigData' )->with( - \Magento\Framework\App\DeploymentConfig\CacheConfig::CONFIG_KEY + ConfigOptionsList::KEY_CACHE )->will( $this->returnValue($fixtureSegment) ); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/BackendConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/BackendConfigTest.php deleted file mode 100644 index 2cf6618ef428c..0000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/BackendConfigTest.php +++ /dev/null @@ -1,64 +0,0 @@ - 'backend']); - $this->assertNotEmpty($object->getKey()); - } - - public function testGetData() - { - $object = new BackendConfig(['frontName' => 'backend']); - $this->assertSame(['frontName' => 'backend'], $object->getData()); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage No backend frontname provided. - */ - public function testUnsetData() - { - new BackendConfig([]); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage No backend frontname provided. - */ - public function testEmptyData() - { - new BackendConfig(['frontName' => '']); - } - - /** - * @param array $data - * @dataProvider invalidDataDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid backend frontname - */ - public function testInvalidData($data) - { - new BackendConfig($data); - } - - /** - * @return array - */ - public function invalidDataDataProvider() - { - return [ - [['frontName' => '**']], - [['frontName' => 'invalid frontname']], - ]; - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/CacheConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/CacheConfigTest.php deleted file mode 100644 index e8bf5786a93bd..0000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/CacheConfigTest.php +++ /dev/null @@ -1,70 +0,0 @@ - [ - 'default' => [], - ], - ]; - public function testGetKey() - { - $object = new CacheConfig($this->data); - $this->assertNotEmpty($object->getKey()); - } - - public function testGetData() - { - $object = new CacheConfig($this->data); - $this->assertSame($this->data, $object->getData()); - } - - public function testEmptyData() - { - $data = [ - 'default_setup' => [ - ResourceConfig::KEY_CONNECTION => 'default', - ], - ]; - $object = new ResourceConfig([]); - $this->assertSame($data, $object->getData()); - } - - /** - * @param array $data - * @expectedException \InvalidArgumentException - * @dataProvider invalidDataDataProvider - */ - public function testInvalidData($data) - { - new CacheConfig($data); - } - - public function invalidDataDataProvider() - { - return [ - [ - 'frontend' => [ - 'default' => 'not setting array', - ], - ], - [ - 'no_frontend' => [ - 'default' => [], - ] - ], - [ - ['frontend' => 'setting'] - ], - ]; - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/DbConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/DbConfigTest.php deleted file mode 100644 index b4e4f52ae9ff3..0000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/DbConfigTest.php +++ /dev/null @@ -1,128 +0,0 @@ - 'mg2_', - 'connection' => [ - 'default' => [ - DbConfig::KEY_HOST => 'magento.local', - DbConfig::KEY_NAME => 'magento2', - DbConfig::KEY_USER => 'mysql_user', - DbConfig::KEY_PASS => 'mysql_pass', - DbConfig::KEY_MODEL => 'mysql4', - DbConfig::KEY_INIT_STATEMENTS => 'SET NAMES utf8;', - DbConfig::KEY_ACTIVE => '1', - ], - ], - ]; - - public function testGetKey() - { - $object = new DbConfig($this->data); - $this->assertNotEmpty($object->getKey()); - } - - public function testGetData() - { - $object = new DbConfig($this->data); - $this->assertSame($this->data, $object->getData()); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The Database Name field cannot be empty. - */ - public function testEmptyData() - { - new DbConfig([]); - } - - /** - * @param array $data - * @expectedException \InvalidArgumentException - * @dataProvider invalidDataDataProvider - */ - public function testInvalidData($data) - { - new DbConfig($data); - } - - public function invalidDataDataProvider() - { - return [ - [ - [ - DbConfig::KEY_PREFIX => 'mg2_', - 'connection' => [ - 'default' => [ - DbConfig::KEY_HOST => 'magento.local', - DbConfig::KEY_NAME => '', - DbConfig::KEY_USER => 'mysql_user', - DbConfig::KEY_PASS => 'mysql_pass', - DbConfig::KEY_MODEL => 'mysql4', - DbConfig::KEY_INIT_STATEMENTS => 'SET NAMES utf8;', - DbConfig::KEY_ACTIVE => '1', - ], - ], - ], - ], - [ - [ - DbConfig::KEY_PREFIX => 'mg2*', - 'connection' => [ - 'default' => [ - DbConfig::KEY_HOST => 'magento.local', - DbConfig::KEY_NAME => 'magento2', - DbConfig::KEY_USER => 'mysql_user', - DbConfig::KEY_PASS => 'mysql_pass', - DbConfig::KEY_MODEL => 'mysql4', - DbConfig::KEY_INIT_STATEMENTS => 'SET NAMES utf8;', - DbConfig::KEY_ACTIVE => '1', - ], - ], - ] - ], - [ - [ - DbConfig::KEY_PREFIX => '', - 'connection' => [ - 'default' => [ - DbConfig::KEY_HOST => 'magento.local', - DbConfig::KEY_NAME => 'magento2', - DbConfig::KEY_USER => '', - DbConfig::KEY_PASS => 'mysql_pass', - DbConfig::KEY_MODEL => 'mysql4', - DbConfig::KEY_INIT_STATEMENTS => 'SET NAMES utf8;', - DbConfig::KEY_ACTIVE => '1', - ], - ], - ] - ], - [ - [ - DbConfig::KEY_PREFIX => '', - 'connection' => [ - 'default' => [ - DbConfig::KEY_HOST => '', - DbConfig::KEY_NAME => 'magento2', - DbConfig::KEY_USER => 'user', - DbConfig::KEY_PASS => 'mysql_pass', - DbConfig::KEY_MODEL => 'mysql4', - DbConfig::KEY_INIT_STATEMENTS => 'SET NAMES utf8;', - DbConfig::KEY_ACTIVE => '1', - ], - ], - ] - ], - ]; - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/InstallConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/InstallConfigTest.php deleted file mode 100644 index d7eca92e18fdc..0000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/InstallConfigTest.php +++ /dev/null @@ -1,34 +0,0 @@ - date('r')]); - $this->assertNotEmpty($object->getKey()); - } - - public function testGetData() - { - $date = date('r'); - $object = new InstallConfig(['date' => $date]); - $this->assertSame(['date' => $date], $object->getData()); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Install date not provided - */ - public function testEmptyData() - { - new InstallConfig([]); - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ResourceConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ResourceConfigTest.php deleted file mode 100644 index ccba7027db927..0000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ResourceConfigTest.php +++ /dev/null @@ -1,74 +0,0 @@ -assertNotEmpty($object->getKey()); - } - - public function testGetData() - { - $data = [ - 'test' => [ - ResourceConfig::KEY_CONNECTION => 'default', - ], - ]; - $expected = [ - 'default_setup' => [ - ResourceConfig::KEY_CONNECTION => 'default', - ], - 'test' => $data['test'], - ]; - - $object = new ResourceConfig($data); - $this->assertSame($expected, $object->getData()); - } - - public function testEmptyData() - { - $data = [ - 'default_setup' => [ - ResourceConfig::KEY_CONNECTION => 'default', - ], - ]; - $object = new ResourceConfig([]); - $this->assertSame($data, $object->getData()); - } - - /** - * @param array $data - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid resource configuration. - * @dataProvider invalidDataDataProvider - */ - public function testInvalidData($data) - { - new ResourceConfig($data); - } - - public function invalidDataDataProvider() - { - return [ - [ - [ - 'no_connection' => [], - ], - [ - 'other' => [ - 'other' => 'default', - ] - ], - ], - ]; - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/SessionConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/SessionConfigTest.php deleted file mode 100644 index fce5030ae5818..0000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/SessionConfigTest.php +++ /dev/null @@ -1,47 +0,0 @@ -assertNotEmpty($object->getKey()); - } - - /** - * @param array $data - * @param string $expected - * @dataProvider getDataDataProvider - */ - public function testGetData($data, $expected) - { - $object = new SessionConfig([$data]); - $this->assertSame(['save' => $expected], $object->getData()); - } - - public function getDataDataProvider() - { - return [ - [[], 'files'], - [['save' => 'files'], 'files'], - [['save' => 'db'], 'files'], - ]; - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid session_save location - */ - public function testInvalidData() - { - new SessionConfig(['save' => 'invalid']); - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Resource/ConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Resource/ConfigTest.php index deac021b7e541..750d8105e2401 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Resource/ConfigTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Resource/ConfigTest.php @@ -65,9 +65,9 @@ protected function setUp() $this->returnValue(serialize($this->_resourcesConfig)) ); - $deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false); - $deploymentConfigMock->expects($this->once()) - ->method('getSegment') + $readerMock = $this->getMock('\Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $readerMock->expects($this->once()) + ->method('getConfigData') ->with('resource') ->willReturn($this->_initialResources); @@ -75,7 +75,7 @@ protected function setUp() $this->_readerMock, $this->_scopeMock, $this->_cacheMock, - $deploymentConfigMock, + $readerMock, 'cacheId' ); } @@ -95,9 +95,9 @@ public function testGetConnectionName($resourceName, $connectionName) */ public function testExceptionConstructor() { - $deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false); - $deploymentConfigMock->expects($this->once()) - ->method('getSegment') + $readerMock = $this->getMock('\Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $readerMock->expects($this->once()) + ->method('getConfigData') ->with('resource') ->willReturn(['validResource' => ['somekey' => 'validConnectionName']]); @@ -105,7 +105,7 @@ public function testExceptionConstructor() $this->_readerMock, $this->_scopeMock, $this->_cacheMock, - $deploymentConfigMock, + $readerMock, 'cacheId' ); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php index 239ec1e17bb91..fa3f52673e8cd 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php @@ -10,6 +10,8 @@ use \Magento\Framework\App\Resource; +use Magento\Setup\Model\ConfigOptionsList; + class ResourceTest extends \PHPUnit_Framework_TestCase { const RESOURCE_NAME = \Magento\Framework\App\Resource::DEFAULT_READ_RESOURCE; @@ -27,9 +29,9 @@ class ResourceTest extends \PHPUnit_Framework_TestCase protected $_connectionFactory; /** - * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject */ - private $deploymentConfig; + private $reader; /** * @var \Magento\Framework\App\Resource @@ -56,10 +58,10 @@ public function setUp() ->with(self::RESOURCE_NAME) ->will($this->returnValue(self::CONNECTION_NAME)); - $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $this->deploymentConfig->expects($this->any()) - ->method('getSegment') - ->with(\Magento\Framework\App\DeploymentConfig\DbConfig::CONFIG_KEY) + $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $this->reader->expects($this->any()) + ->method('getConfigData') + ->with(ConfigOptionsList::CONFIG_KEY) ->will($this->returnValue( [ 'connection' => [ @@ -86,7 +88,7 @@ public function setUp() $this->resource = new Resource( $this->_config, $this->_connectionFactory, - $this->deploymentConfig, + $this->reader, self::TABLE_PREFIX ); } diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php index f04e60f3e26c6..3b16a2ca448e4 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/ModuleList.php @@ -6,6 +6,7 @@ namespace Magento\Framework\Module; use Magento\Framework\App\DeploymentConfig; +use Magento\Setup\Model\ConfigOptionsList; /** * A list of modules in the Magento application @@ -139,7 +140,7 @@ public function isModuleInfoAvailable() private function loadConfigData() { if (null === $this->configData) { - $this->configData = $this->config->getSegment(ModuleList\DeploymentConfig::CONFIG_KEY); + $this->configData = $this->config->getSegment(ConfigOptionsList::KEY_MODULES); } } } diff --git a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php b/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php index a40748bcce186..c71f5fadc896e 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php @@ -7,17 +7,13 @@ namespace Magento\Framework\Module\ModuleList; use Magento\Framework\App\DeploymentConfig\AbstractSegment; +use Magento\Setup\Model\ConfigOptionsList; /** * Deployment configuration segment for modules */ class DeploymentConfig extends AbstractSegment { - /** - * Segment key - */ - const CONFIG_KEY = 'modules'; - /** * Constructor * @@ -39,6 +35,6 @@ public function __construct(array $data) */ public function getKey() { - return self::CONFIG_KEY; + } } diff --git a/pub/get.php b/pub/get.php index 7e9adfd0e9fd7..68626e0a57e0a 100755 --- a/pub/get.php +++ b/pub/get.php @@ -8,7 +8,6 @@ use Magento\Framework\App\Cache\Frontend\Factory; use Magento\Framework\App\ObjectManagerFactory; -use Magento\Framework\Module\ModuleList\DeploymentConfig; require dirname(__DIR__) . '/app/bootstrap.php'; diff --git a/setup/src/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php index 05e7c69c9f3b0..6355415f0dee4 100644 --- a/setup/src/Magento/Setup/Controller/Install.php +++ b/setup/src/Magento/Setup/Controller/Install.php @@ -6,8 +6,8 @@ namespace Magento\Setup\Controller; -use Magento\Framework\App\DeploymentConfig\EncryptConfig; use Magento\Setup\Model\AdminAccount; +use Magento\Setup\Model\ConfigOptionsList; use Magento\Setup\Model\DeploymentConfigMapper; use Magento\Setup\Model\Installer; use Magento\Setup\Model\Installer\ProgressFactory; @@ -86,7 +86,7 @@ public function startAction() $this->installer->install($data); $json->setVariable( 'key', - $this->installer->getInstallInfo()[EncryptConfig::KEY_ENCRYPTION_KEY] + $this->installer->getInstallInfo()[ConfigOptionsList::KEY_ENCRYPTION_KEY] ); $json->setVariable('success', true); $json->setVariable('messages', $this->installer->getInstallInfo()[Installer::INFO_MESSAGE]); diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index b1f76183a0e52..54b00704fccb9 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -10,11 +10,6 @@ use Magento\Framework\Math\Random; use Magento\Framework\Module\ModuleList\Loader; use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\App\DeploymentConfig\DbConfig; -use Magento\Framework\App\DeploymentConfig\EncryptConfig; -use Magento\Framework\App\DeploymentConfig\InstallConfig; -use Magento\Framework\App\DeploymentConfig\SessionConfig; -use Magento\Framework\App\DeploymentConfig\ResourceConfig; /** * Creates deployment config data based on user input array @@ -27,17 +22,17 @@ class ConfigGenerator * @var array */ public static $paramMap = [ - ConfigOptionsList::INPUT_KEY_DB_HOST => DbConfig::KEY_HOST, - ConfigOptionsList::INPUT_KEY_DB_NAME => DbConfig::KEY_NAME, - ConfigOptionsList::INPUT_KEY_DB_USER => DbConfig::KEY_USER, - ConfigOptionsList::INPUT_KEY_DB_PASS => DbConfig::KEY_PASS, - ConfigOptionsList::INPUT_KEY_DB_PREFIX => DbConfig::KEY_PREFIX, - ConfigOptionsList::INPUT_KEY_DB_MODEL => DbConfig::KEY_MODEL, - ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, - ConfigOptionsList::INPUT_KEY_ACTIVE => DbConfig::KEY_ACTIVE, - ConfigOptionsList::INPUT_KEY_CRYPT_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, - ConfigOptionsList::INPUT_KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, - ConfigOptionsList::INPUT_KEY_RESOURCE => ResourceConfig::CONFIG_KEY, + ConfigOptionsList::INPUT_KEY_DB_HOST => ConfigOptionsList::KEY_HOST, + ConfigOptionsList::INPUT_KEY_DB_NAME => ConfigOptionsList::KEY_NAME, + ConfigOptionsList::INPUT_KEY_DB_USER => ConfigOptionsList::KEY_USER, + ConfigOptionsList::INPUT_KEY_DB_PASS => ConfigOptionsList::KEY_PASS, + ConfigOptionsList::INPUT_KEY_DB_PREFIX => ConfigOptionsList::KEY_PREFIX, + ConfigOptionsList::INPUT_KEY_DB_MODEL => ConfigOptionsList::KEY_MODEL, + ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS => ConfigOptionsList::KEY_INIT_STATEMENTS, + ConfigOptionsList::INPUT_KEY_ACTIVE => ConfigOptionsList::KEY_ACTIVE, + ConfigOptionsList::INPUT_KEY_CRYPT_KEY => ConfigOptionsList::KEY_ENCRYPTION_KEY, + ConfigOptionsList::INPUT_KEY_SESSION_SAVE => ConfigOptionsList::KEY_SAVE, + ConfigOptionsList::INPUT_KEY_RESOURCE => ConfigOptionsList::KEY_RESOURCE, ]; /** diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index 5652bdeccef2c..2052eacd62c0f 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -44,6 +44,63 @@ class ConfigOptionsList implements ConfigOptionsListInterface */ const SESSION_SAVE_FILES = 'files'; const SESSION_SAVE_DB = 'db'; + + /** + * Array Key for session save method + */ + const KEY_SAVE = 'save'; + + /**#@+ + * Array keys for Database configuration + */ + const KEY_HOST = 'host'; + const KEY_NAME = 'dbname'; + const KEY_USER = 'username'; + const KEY_PASS = 'password'; + const KEY_PREFIX = 'table_prefix'; + const KEY_MODEL = 'model'; + const KEY_INIT_STATEMENTS = 'initStatements'; + const KEY_ACTIVE = 'active'; + /** + * Segment key + */ + const CONFIG_KEY = 'db'; + /** + * Array Key for encryption key in deployment config file + */ + const KEY_ENCRYPTION_KEY = 'key'; + /** + * Segment key + */ + const ENCRYPT_CONFIG_KEY = 'crypt'; + /** + * Array Key for install date + */ + const KEY_DATE = 'date'; + /** + * Array Key for connection + */ + const KEY_CONNECTION = 'connection'; + /** + * Segment key + */ + const KEY_RESOURCE = 'resource'; + /** + * Array key for cache frontend + */ + const KEY_FRONTEND = 'frontend'; + /** + * Array key for cache type + */ + const KEY_TYPE = 'type'; + /** + * Segment key + */ + const KEY_CACHE = 'cache'; + /** + * Segment key + */ + const KEY_MODULES = 'modules'; /**#@-*/ /** diff --git a/setup/src/Magento/Setup/Model/DeploymentConfigMapper.php b/setup/src/Magento/Setup/Model/DeploymentConfigMapper.php index 4a32e88067754..3a586c65cc0de 100644 --- a/setup/src/Magento/Setup/Model/DeploymentConfigMapper.php +++ b/setup/src/Magento/Setup/Model/DeploymentConfigMapper.php @@ -6,11 +6,8 @@ namespace Magento\Setup\Model; -use Magento\Framework\App\DeploymentConfig\BackendConfig; -use Magento\Framework\App\DeploymentConfig\DbConfig; -use Magento\Framework\App\DeploymentConfig\EncryptConfig; -use Magento\Framework\App\DeploymentConfig\InstallConfig; -use Magento\Framework\App\DeploymentConfig\SessionConfig; +use Magento\Backend\Setup\ConfigOptionsList as BackendConfig; +use Magento\Setup\Model\ConfigOptionsList as SetupConfig; class DeploymentConfigMapper { @@ -36,16 +33,16 @@ class DeploymentConfigMapper * @var array */ public static $paramMap = [ - self::KEY_DATE => InstallConfig::KEY_DATE, - self::KEY_DB_HOST => DbConfig::KEY_HOST, - self::KEY_DB_NAME => DbConfig::KEY_NAME, - self::KEY_DB_USER => DbConfig::KEY_USER, - self::KEY_DB_PASS => DbConfig::KEY_PASS, - self::KEY_DB_PREFIX => DbConfig::KEY_PREFIX, - self::KEY_DB_MODEL => DbConfig::KEY_MODEL, - self::KEY_DB_INIT_STATEMENTS => DbConfig::KEY_INIT_STATEMENTS, - self::KEY_SESSION_SAVE => SessionConfig::KEY_SAVE, + self::KEY_DATE => SetupConfig::KEY_DATE, + self::KEY_DB_HOST => SetupConfig::KEY_HOST, + self::KEY_DB_NAME => SetupConfig::KEY_NAME, + self::KEY_DB_USER => SetupConfig::KEY_USER, + self::KEY_DB_PASS => SetupConfig::KEY_PASS, + self::KEY_DB_PREFIX => SetupConfig::KEY_PREFIX, + self::KEY_DB_MODEL => SetupConfig::KEY_MODEL, + self::KEY_DB_INIT_STATEMENTS => SetupConfig::KEY_INIT_STATEMENTS, + self::KEY_SESSION_SAVE => SetupConfig::KEY_SAVE, self::KEY_BACKEND_FRONTNAME => BackendConfig::KEY_FRONTNAME, - self::KEY_ENCRYPTION_KEY => EncryptConfig::KEY_ENCRYPTION_KEY, + self::KEY_ENCRYPTION_KEY => SetupConfig::KEY_ENCRYPTION_KEY, ]; } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index da913b7a32417..02a5b9336f209 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -25,6 +25,7 @@ use Magento\Framework\Module\ModuleListInterface; use Magento\Framework\Shell; use Magento\Framework\Shell\CommandRenderer; +use Magento\Setup\Model\ConfigOptionsList; use Magento\Setup\Module\ConnectionFactory; use Magento\Setup\Module\Setup; use Magento\Store\Model\Store; @@ -394,8 +395,8 @@ private function createEncryptConfig($data) } // retrieve old encryption keys if ($this->deploymentConfig->isAvailable()) { - $encryptInfo = $this->deploymentConfig->getSegment(EncryptConfig::CONFIG_KEY); - $oldKeys = $encryptInfo[EncryptConfig::KEY_ENCRYPTION_KEY]; + $encryptInfo = $this->deploymentConfig->getSegment(ModuleLoader::ENCRYPT_CONFIG_KEY); + $oldKeys = $encryptInfo[ModuleLoader::KEY_ENCRYPTION_KEY]; $key = empty($key) ? $oldKeys : $oldKeys . "\n" . $key; } else if (empty($key)) { $key = md5($this->random->getRandomString(10)); @@ -405,7 +406,7 @@ private function createEncryptConfig($data) // find the latest key to display $keys = explode("\n", $key); - $this->installInfo[EncryptConfig::KEY_ENCRYPTION_KEY] = array_pop($keys); + $this->installInfo[ModuleLoader::KEY_ENCRYPTION_KEY] = array_pop($keys); return new EncryptConfig($cryptConfigData); } @@ -560,7 +561,7 @@ public function checkApplicationFilePermissions() public function installDeploymentConfig($data) { $this->checkInstallationFilePermissions(); - $data[InstallConfig::KEY_DATE] = date('r'); + $data[DeploymentConfigMapper::KEY_DATE] = date('r'); $configs = [ $this->createBackendConfig($data), @@ -1166,7 +1167,7 @@ public function cleanupDb() { // stops cleanup if app/etc/config.php does not exist if ($this->deploymentConfig->isAvailable()) { - $dbConfig = new DbConfig($this->deploymentConfig->getSegment(DbConfig::CONFIG_KEY)); + $dbConfig = new DbConfig($this->deploymentConfig->getSegment(ModuleLoader::CONFIG_KEY)); $config = $dbConfig->getConnection(\Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION); if ($config) { try { @@ -1257,17 +1258,17 @@ private function assertDeploymentConfigExists() */ private function assertDbAccessible() { - $segment = $this->deploymentConfig->getSegment(DbConfig::CONFIG_KEY); + $segment = $this->deploymentConfig->getSegment(ModuleLoader::CONFIG_KEY); $dbConfig = new DbConfig($segment); $config = $dbConfig->getConnection(\Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION); $this->checkDatabaseConnection( - $config[DbConfig::KEY_NAME], - $config[DbConfig::KEY_HOST], - $config[DbConfig::KEY_USER], - $config[DbConfig::KEY_PASS] + $config[ModuleLoader::KEY_NAME], + $config[ModuleLoader::KEY_HOST], + $config[ModuleLoader::KEY_USER], + $config[ModuleLoader::KEY_PASS] ); - if (isset($config[DbConfig::KEY_PREFIX])) { - $this->checkDatabaseTablePrefix($config[DbConfig::KEY_PREFIX]); + if (isset($config[ModuleLoader::KEY_PREFIX])) { + $this->checkDatabaseTablePrefix($config[ModuleLoader::KEY_PREFIX]); } } diff --git a/setup/src/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php index 6ed7fbb8d3019..27bc4d150e7cc 100644 --- a/setup/src/Magento/Setup/Model/InstallerFactory.php +++ b/setup/src/Magento/Setup/Model/InstallerFactory.php @@ -79,10 +79,7 @@ public function create(LoggerInterface $log) */ private function getResource() { - $deploymentConfig = new \Magento\Framework\App\DeploymentConfig( - $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig\Reader'), - [] - ); - return $this->resourceFactory->create($deploymentConfig); + $reader = $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig\Reader'); + return $this->resourceFactory->create($reader); } } diff --git a/setup/src/Magento/Setup/Model/ModuleStatus.php b/setup/src/Magento/Setup/Model/ModuleStatus.php index ba169048f2ed9..e435110050bfd 100644 --- a/setup/src/Magento/Setup/Model/ModuleStatus.php +++ b/setup/src/Magento/Setup/Model/ModuleStatus.php @@ -11,6 +11,7 @@ use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Module\ModuleList\DeploymentConfig as ModuleDeployment; use \Magento\Framework\Module\DependencyChecker; +use Magento\Setup\Model\ConfigOptionsList; class ModuleStatus { @@ -145,7 +146,7 @@ public function setIsEnabled($status, $moduleName) */ private function deselectDisabledModules() { - $existingModules = $this->deploymentConfig->getSegment(ModuleDeployment::CONFIG_KEY); + $existingModules = $this->deploymentConfig->getSegment(ConfigOptionsList::KEY_MODULES); if (isset($existingModules)) { foreach ($existingModules as $module => $value) { if (!$value) { diff --git a/setup/src/Magento/Setup/Module/ResourceFactory.php b/setup/src/Magento/Setup/Module/ResourceFactory.php index f16941abe74ed..8abae0bab6bb0 100644 --- a/setup/src/Magento/Setup/Module/ResourceFactory.php +++ b/setup/src/Magento/Setup/Module/ResourceFactory.php @@ -29,16 +29,16 @@ public function __construct(ServiceLocatorInterface $serviceLocator) } /** - * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig + * @param \Magento\Framework\App\DeploymentConfig\Reader $reader * @return Resource */ - public function create(\Magento\Framework\App\DeploymentConfig $deploymentConfig) + public function create(\Magento\Framework\App\DeploymentConfig\Reader $reader) { $connectionFactory = $this->serviceLocator->get('Magento\Setup\Module\ConnectionFactory'); $resource = new Resource( new ResourceConfig(), $connectionFactory, - $deploymentConfig + $reader ); return $resource; } diff --git a/setup/src/Magento/Setup/Test/Unit/Module/ResourceFactoryTest.php b/setup/src/Magento/Setup/Test/Unit/Module/ResourceFactoryTest.php index 6d19606899495..60c8800928f1a 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/ResourceFactoryTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/ResourceFactoryTest.php @@ -31,7 +31,7 @@ protected function setUp() public function testCreate() { $resource = $this->resourceFactory->create( - $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false) + $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false) ); $this->assertInstanceOf('Magento\Framework\App\Resource', $resource); } From f50e300b397023687c929d7efddd0157d7ff3ad2 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 24 Mar 2015 17:22:56 -0500 Subject: [PATCH 132/214] MAGETWO-35136: Delete Segments - deleting EncryptConfig - refactoring cache and module segments --- .../Adminhtml/Cache/MassActionTest.php | 16 +++--- .../Magento/Framework/App/Cache/State.php | 7 ++- .../Type/CacheConfig.php} | 50 +++++++++++++------ .../App/Cache/Type/ConfigSegment.php | 45 ----------------- .../Framework/App/DeploymentConfig.php | 6 +-- .../App/DeploymentConfig/EncryptConfig.php | 34 ------------- .../App/DeploymentConfig/SegmentInterface.php | 27 ---------- .../Framework/App/DeploymentConfig/Writer.php | 35 ------------- .../App/Test/Unit/Cache/StateTest.php | 7 ++- ...figSegmentTest.php => CacheConfigTest.php} | 9 ++-- .../Test/Unit/Cache/Type/FrontendPoolTest.php | 18 +++---- .../DeploymentConfig/EncryptConfigTest.php | 33 ------------ .../Test/Unit/DeploymentConfig/WriterTest.php | 47 ----------------- .../App/Test/Unit/DeploymentConfigTest.php | 14 +++--- .../Magento/Framework/Module/ModuleList.php | 2 +- .../Module/ModuleList/DeploymentConfig.php | 35 ++++++++++--- .../ModuleList/DeploymentConfigFactory.php | 2 +- .../Magento/Framework/Module/Status.php | 16 +----- .../Module/Test/Unit/ModuleListTest.php | 6 +-- .../Framework/Module/Test/Unit/StatusTest.php | 20 +------- .../Magento/Setup/Model/ConfigOptionsList.php | 5 +- setup/src/Magento/Setup/Model/Installer.php | 9 ++-- .../src/Magento/Setup/Model/ModuleStatus.php | 3 +- .../Setup/Test/Unit/Model/InstallerTest.php | 8 ++- .../Test/Unit/Model/ModuleStatusTest.php | 6 +-- 25 files changed, 120 insertions(+), 340 deletions(-) rename lib/internal/Magento/Framework/App/{DeploymentConfig/AbstractSegment.php => Cache/Type/CacheConfig.php} (65%) delete mode 100644 lib/internal/Magento/Framework/App/Cache/Type/ConfigSegment.php delete mode 100644 lib/internal/Magento/Framework/App/DeploymentConfig/EncryptConfig.php delete mode 100644 lib/internal/Magento/Framework/App/DeploymentConfig/SegmentInterface.php rename lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/{ConfigSegmentTest.php => CacheConfigTest.php} (87%) delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/EncryptConfigTest.php diff --git a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php index 559381cbe85df..f24fbed165abc 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php @@ -6,31 +6,31 @@ namespace Magento\Backend\Controller\Adminhtml\Cache; -use Magento\Framework\App\Cache\Type\ConfigSegment; +use Magento\Framework\App\Cache\Type\CacheConfig; use Magento\TestFramework\Helper\Bootstrap; class MassActionTest extends \Magento\Backend\Utility\Controller { /** - * Configuration segment of cache types + * Configuratio of cache types * - * @var ConfigSegment + * @var CacheConfig */ - private static $typesSegment; + private static $typesConfig; public static function setUpBeforeClass() { /** @var \Magento\Framework\App\DeploymentConfig $config */ $config = Bootstrap::getObjectManager()->get('Magento\Framework\App\DeploymentConfig'); - $data = $config->getSegment(ConfigSegment::SEGMENT_KEY); - self::$typesSegment = new ConfigSegment($data); + $data = $config->getConfigData(CacheConfig::CACHE_KEY); + self::$typesConfig = new CacheConfig($data); } protected function tearDown() { /** @var $cacheState \Magento\Framework\App\Cache\StateInterface */ $cacheState = Bootstrap::getObjectManager()->get('Magento\Framework\App\Cache\StateInterface'); - foreach (self::$typesSegment->getData() as $type => $value) { + foreach (self::$typesConfig->getData() as $type => $value) { $cacheState->setEnabled($type, $value); } $cacheState->persist(); @@ -103,7 +103,7 @@ private function setAll($isEnabled) { /** @var $cacheState \Magento\Framework\App\Cache\StateInterface */ $cacheState = Bootstrap::getObjectManager()->get('Magento\Framework\App\Cache\StateInterface'); - foreach (array_keys(self::$typesSegment->getData()) as $type) { + foreach (array_keys(self::$typesConfig->getData()) as $type) { $cacheState->setEnabled($type, $isEnabled); } $cacheState->persist(); diff --git a/lib/internal/Magento/Framework/App/Cache/State.php b/lib/internal/Magento/Framework/App/Cache/State.php index a8ddb511717f8..951999c687764 100644 --- a/lib/internal/Magento/Framework/App/Cache/State.php +++ b/lib/internal/Magento/Framework/App/Cache/State.php @@ -7,7 +7,7 @@ */ namespace Magento\Framework\App\Cache; -use Magento\Framework\App\Cache\Type\ConfigSegment; +use Magento\Framework\App\Cache\Type\CacheConfig; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\DeploymentConfig\Writer; @@ -93,8 +93,7 @@ public function setEnabled($cacheType, $isEnabled) public function persist() { $this->load(); - $segment = new ConfigSegment($this->statuses); - $this->writer->update($segment); + $this->writer->saveConfig($this->statuses); } /** @@ -109,7 +108,7 @@ private function load() if ($this->banAll) { return; } - $this->statuses = $this->config->getSegment(ConfigSegment::SEGMENT_KEY) ?: []; + $this->statuses = $this->config->getConfigData(CacheConfig::CACHE_KEY) ?: []; } } } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/AbstractSegment.php b/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php similarity index 65% rename from lib/internal/Magento/Framework/App/DeploymentConfig/AbstractSegment.php rename to lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php index 64c95e1b26dee..50c41a4e579f6 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/AbstractSegment.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php @@ -4,10 +4,18 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\App\DeploymentConfig; +namespace Magento\Framework\App\Cache\Type; -abstract class AbstractSegment implements SegmentInterface +/** + * Deployment configuration for enabled cache types + */ +class CacheConfig { + /** + * Deployment config key + */ + const CACHE_KEY = 'cache_types'; + /** * Data * @@ -19,12 +27,38 @@ abstract class AbstractSegment implements SegmentInterface * Constructor * * @param array $data + * @throws \InvalidArgumentException */ public function __construct(array $data) { + foreach ($data as $key => $value) { + if (!preg_match('/^[a-z_]+$/i', $key)) { + throw new \InvalidArgumentException("Invalid cache type key: {$key}"); + } + $data[$key] = (int)$value; + } $this->data = $data; } + /** + * Returns current key. + * + */ + public function getKey() + { + return self::CACHE_KEY; + } + + /** + * Return current Cache config. + * + * @return array|mixed + */ + public function getData() + { + return $this->data; + } + /** * Update data * @@ -61,16 +95,4 @@ private function filterArray(array $data) return $data; } - /** - * {@inheritdoc} - */ - abstract public function getKey(); - - /** - * {@inheritdoc} - */ - public function getData() - { - return $this->data; - } } diff --git a/lib/internal/Magento/Framework/App/Cache/Type/ConfigSegment.php b/lib/internal/Magento/Framework/App/Cache/Type/ConfigSegment.php deleted file mode 100644 index 1f23b6d97e18e..0000000000000 --- a/lib/internal/Magento/Framework/App/Cache/Type/ConfigSegment.php +++ /dev/null @@ -1,45 +0,0 @@ - $value) { - if (!preg_match('/^[a-z_]+$/i', $key)) { - throw new \InvalidArgumentException("Invalid cache type key: {$key}"); - } - $data[$key] = (int)$value; - } - parent::__construct($data); - } - - /** - * {@inheritdoc} - */ - public function getKey() - { - return self::SEGMENT_KEY; - } -} diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig.php index abe83cd86e852..f4d7c97adfeff 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig.php @@ -6,7 +6,6 @@ namespace Magento\Framework\App; - /** * Application deployment configuration */ @@ -92,13 +91,10 @@ public function isAvailable() /** * Gets a value specified key from config data * - * The key is conventionally called "segment". There can be arbitrary data within each segment. - * This class is agnostic of contents of segments. - * * @param string $key * @return null|mixed */ - public function getSegment($key) + public function getConfigData($key) { $this->load(); if (!isset($this->data[$key])) { diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/EncryptConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig/EncryptConfig.php deleted file mode 100644 index 1e0dadaa02898..0000000000000 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/EncryptConfig.php +++ /dev/null @@ -1,34 +0,0 @@ -configFilePool = $configFilePool; } - /** - * Creates the deployment configuration file - * - * Will overwrite a file, if it exists. - * - * @param SegmentInterface[] $segments - * @return void - * @throws \InvalidArgumentException - */ - public function create($segments) - { - $data = []; - foreach ($segments as $segment) { - if (!($segment instanceof SegmentInterface)) { - throw new \InvalidArgumentException('An instance of SegmentInterface is expected.'); - } - $data[$segment->getKey()] = $segment->getData(); - } - $this->write($data); - } - - /** - * Update data in the configuration file using specified segment object - * - * @param SegmentInterface $segment - * @return void - */ - public function update(SegmentInterface $segment) - { - $key = $segment->getKey(); - $data = $this->reader->load(); - $data[$key] = $segment->getData(); - $this->write($data); - } - /** * Check if configuration file is writable * diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php index 9ddea6bd0951c..0db48a80516ee 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php @@ -36,9 +36,9 @@ public function testIsEnabled($cacheType, $config, $banAll, $expectedIsEnabled) { $model = new State($this->config, $this->writer, $banAll); if ($banAll) { - $this->config->expects($this->never())->method('getSegment'); + $this->config->expects($this->never())->method('getConfigData'); } else { - $this->config->expects($this->once())->method('getSegment')->willReturn($config); + $this->config->expects($this->once())->method('getConfigData')->willReturn($config); } $this->writer->expects($this->never())->method('update'); $actualIsEnabled = $model->isEnabled($cacheType); @@ -91,8 +91,7 @@ public function testSetEnabled() public function testPersist() { $model = new State($this->config, $this->writer); - $constraint = new \PHPUnit_Framework_Constraint_IsInstanceOf('Magento\Framework\App\Cache\Type\ConfigSegment'); - $this->writer->expects($this->once())->method('update')->with($constraint); + $this->writer->expects($this->once())->method('saveConfig')->with([]); $model->persist(); } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigSegmentTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/CacheConfigTest.php similarity index 87% rename from lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigSegmentTest.php rename to lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/CacheConfigTest.php index 5b9fa2cebf783..da8bfd32372a9 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigSegmentTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/CacheConfigTest.php @@ -6,10 +6,9 @@ namespace Magento\Framework\App\Test\Unit\Cache\Type; -use \Magento\Framework\App\Cache\Type\ConfigSegment; +use Magento\Framework\App\Cache\Type\CacheConfig; - -class ConfigSegmentTest extends \PHPUnit_Framework_TestCase +class CacheConfigTest extends \PHPUnit_Framework_TestCase { /** * @param array $data @@ -18,7 +17,7 @@ class ConfigSegmentTest extends \PHPUnit_Framework_TestCase */ public function testGetData($data, $expected) { - $object = new ConfigSegment($data); + $object = new CacheConfig($data); $this->assertSame($expected, $object->getData()); } @@ -46,7 +45,7 @@ public function getDataDataProvider() */ public function testGetDataInvalidKeys($data) { - new ConfigSegment($data); + new CacheConfig($data); } /** diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php index ad2363b5a5212..207bb052970ec 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php @@ -44,13 +44,13 @@ protected function setUp() } /** - * @param string|null $fixtureSegment + * @param string|null $fixtureconfigData * @param string $inputCacheType * @param string $expectedFrontendId * * @dataProvider getDataProvider */ - public function testGet($fixtureSegment, $inputCacheType, $expectedFrontendId) + public function testGet($fixtureconfigData, $inputCacheType, $expectedFrontendId) { $this->reader->expects( $this->once() @@ -59,7 +59,7 @@ public function testGet($fixtureSegment, $inputCacheType, $expectedFrontendId) )->with( ConfigOptionsList::KEY_CACHE )->will( - $this->returnValue($fixtureSegment) + $this->returnValue($fixtureconfigData) ); $cacheFrontend = $this->getMock('Magento\Framework\Cache\FrontendInterface'); @@ -92,17 +92,17 @@ public function testGet($fixtureSegment, $inputCacheType, $expectedFrontendId) public function getDataProvider() { - $segment1 = [ + $configData1 = [ 'frontend' => [], 'type' => ['fixture_cache_type' => ['frontend' => 'configured_frontend_id']], ]; - $segment2 = ['frontend' => [], 'type' => ['fixture_cache_type' => ['frontend' => null]]]; - $segment3 = ['frontend' => [], 'type' => ['unknown_cache_type' => ['frontend' => null]]]; + $configData2 = ['frontend' => [], 'type' => ['fixture_cache_type' => ['frontend' => null]]]; + $configData3 = ['frontend' => [], 'type' => ['unknown_cache_type' => ['frontend' => null]]]; return [ - 'retrieval from config' => [$segment1, 'fixture_cache_type', 'configured_frontend_id'], - 'retrieval from map' => [$segment2, 'fixture_cache_type', 'fixture_frontend_id'], + 'retrieval from config' => [$configData1, 'fixture_cache_type', 'configured_frontend_id'], + 'retrieval from map' => [$configData2, 'fixture_cache_type', 'fixture_frontend_id'], 'fallback to default id' => [ - $segment3, + $configData3, 'unknown_cache_type', \Magento\Framework\App\Cache\Frontend\Pool::DEFAULT_FRONTEND_ID, ] diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/EncryptConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/EncryptConfigTest.php deleted file mode 100644 index 5142046742a1b..0000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/EncryptConfigTest.php +++ /dev/null @@ -1,33 +0,0 @@ - 'testKey']); - $this->assertNotEmpty($object->getKey()); - } - - public function testGetData() - { - $object = new EncryptConfig(['key' => 'testKey']); - $this->assertSame(['key' => 'testKey'], $object->getData()); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage No encryption key provided - **/ - public function testEmptyData() - { - new EncryptConfig([]); - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php index 018e49b589548..7f2ef3bee17da 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php @@ -7,7 +7,6 @@ namespace Magento\Framework\App\Test\Unit\DeploymentConfig; use \Magento\Framework\App\DeploymentConfig\Writer; -use \Magento\Framework\App\DeploymentConfig\SegmentInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Config\File\ConfigFilePool; @@ -55,38 +54,6 @@ protected function setUp() ->willReturn($this->dirWrite); } - public function testCreate() - { - $segments = [ - $this->createSegment('foo', 'bar'), - $this->createSegment('baz', ['value1', 'value2']), - ]; - $expected = ['foo' => 'bar', 'baz' => ['value1', 'value2']]; - $this->formatter->expects($this->once())->method('format')->with($expected)->willReturn('formatted'); - $this->dirWrite->expects($this->once())->method('writeFile')->with('test.php', 'formatted'); - $this->object->create($segments); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage An instance of SegmentInterface is expected - */ - public function testCreateException() - { - $this->object->create(['some_bogus_data']); - } - - public function testUpdate() - { - $segment = $this->createSegment('key', ['nested_key' => 'value']); - $preExisting = ['foo' => 'bar', 'key' => 'value', 'baz' => 1]; - $this->reader->expects($this->once())->method('load')->willReturn($preExisting); - $expected = ['foo' => 'bar', 'key' => ['nested_key' => 'value'], 'baz' => 1]; - $this->formatter->expects($this->once())->method('format')->with($expected)->willReturn('formatted'); - $this->dirWrite->expects($this->once())->method('writeFile')->with('test.php', 'formatted'); - $this->object->update($segment); - } - public function testSaveConfig() { $configFiles = [ @@ -135,18 +102,4 @@ public function testSaveConfig() $this->object->saveConfig($testSetUpdate); } - /** - * Creates a segment mock - * - * @param string $key - * @param mixed $data - * @return SegmentInterface - */ - private function createSegment($key, $data) - { - $result = $this->getMockForAbstractClass('Magento\Framework\App\DeploymentConfig\SegmentInterface'); - $result->expects($this->atLeastOnce())->method('getKey')->willReturn($key); - $result->expects($this->atLeastOnce())->method('getData')->willReturn($data); - return $result; - } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php index 12da79e2f979d..7a03f30f531b4 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php @@ -14,8 +14,8 @@ class DeploymentConfigTest extends \PHPUnit_Framework_TestCase * @var array */ private static $fixture = [ - 'segment1' => 'scalar_value', - 'segment2' => [ + 'configData1' => 'scalar_value', + 'configData2' => [ 'foo' => 1, 'bar' => ['baz' => 2], ], @@ -25,9 +25,9 @@ class DeploymentConfigTest extends \PHPUnit_Framework_TestCase * @var array */ private static $flattenedFixture = [ - 'segment1' => 'scalar_value', - 'segment2/foo' => 1, - 'segment2/bar/baz' => 2, + 'configData1' => 'scalar_value', + 'configData2/foo' => 1, + 'configData2/bar/baz' => 2, ]; /** @@ -77,8 +77,8 @@ public function testGetters() $this->assertSame(self::$flattenedFixture, $this->_deploymentConfig->get()); // second time to ensure loader will be invoked only once $this->assertSame(self::$flattenedFixture, $this->_deploymentConfig->get()); - $this->assertSame('scalar_value', $this->_deploymentConfig->getSegment('segment1')); - $this->assertSame(self::$fixture['segment2'], $this->_deploymentConfig->getSegment('segment2')); + $this->assertSame('scalar_value', $this->_deploymentConfig->getConfigData('configData1')); + $this->assertSame(self::$fixture['configData2'], $this->_deploymentConfig->getConfigData('configData2')); } public function testIsAvailable() diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php index 3b16a2ca448e4..c511fdb880f5b 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/ModuleList.php @@ -140,7 +140,7 @@ public function isModuleInfoAvailable() private function loadConfigData() { if (null === $this->configData) { - $this->configData = $this->config->getSegment(ConfigOptionsList::KEY_MODULES); + $this->configData = $this->config->getConfigData(ModuleList\DeploymentConfig::KEY_MODULES); } } } diff --git a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php b/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php index c71f5fadc896e..c6e0ac425a66a 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php @@ -6,14 +6,23 @@ namespace Magento\Framework\Module\ModuleList; -use Magento\Framework\App\DeploymentConfig\AbstractSegment; -use Magento\Setup\Model\ConfigOptionsList; - /** - * Deployment configuration segment for modules + * Deployment configuration for modules */ -class DeploymentConfig extends AbstractSegment +class DeploymentConfig { + /** + * Segment key + */ + const KEY_MODULES = 'modules'; + + /** + * Data + * + * @var array + */ + protected $data = []; + /** * Constructor * @@ -31,10 +40,22 @@ public function __construct(array $data) } /** - * {@inheritdoc} + * Returns config data + * + * @return array|mixed */ - public function getKey() + public function getData() { + return $this->data; + } + /** + * Returns key + * + * @return string + */ + public function getKey() + { + return self::KEY_MODULES; } } diff --git a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfigFactory.php b/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfigFactory.php index c7b92525fa6a2..ae8f3cc882761 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfigFactory.php +++ b/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfigFactory.php @@ -7,7 +7,7 @@ namespace Magento\Framework\Module\ModuleList; /** - * Factory for Deployment configuration segment for modules + * Factory for Deployment configuration for modules */ class DeploymentConfigFactory { diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index d71a48fc3c668..e8b410b08383f 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -7,7 +7,6 @@ namespace Magento\Framework\Module; use Magento\Framework\App\DeploymentConfig\Writer; -use Magento\Framework\Module\ModuleList\DeploymentConfigFactory; use Magento\Framework\App\State\Cleanup; /** @@ -59,13 +58,6 @@ class Status */ private $conflictChecker; - /** - * Factory to create module deployment config object - * - * @var DeploymentConfigFactory - */ - private $deploymentConfigFactory; - /** * Constructor * @@ -75,7 +67,6 @@ class Status * @param Cleanup $cleanup * @param ConflictChecker $conflictChecker * @param DependencyChecker $dependencyChecker - * @param DeploymentConfigFactory $deploymentConfigFactory */ public function __construct( ModuleList\Loader $loader, @@ -83,8 +74,7 @@ public function __construct( Writer $writer, Cleanup $cleanup, ConflictChecker $conflictChecker, - DependencyChecker $dependencyChecker, - DeploymentConfigFactory $deploymentConfigFactory + DependencyChecker $dependencyChecker ) { $this->loader = $loader; $this->list = $list; @@ -92,7 +82,6 @@ public function __construct( $this->cleanup = $cleanup; $this->conflictChecker = $conflictChecker; $this->dependencyChecker = $dependencyChecker; - $this->deploymentConfigFactory = $deploymentConfigFactory; } /** @@ -172,8 +161,7 @@ public function setIsEnabled($isEnabled, $modules) $result[$name] = $currentStatus; } } - $segment = $this->deploymentConfigFactory->create($result); - $this->writer->update($segment); + $this->writer->saveConfig($result); $this->cleanup->clearCaches(); $this->cleanup->clearCodeGeneratedFiles(); } diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php index a3bd59560dee9..0f379ea0d1a87 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php @@ -94,7 +94,7 @@ public function testIsModuleInfoAvailable() public function testIsModuleInfoAvailableNoConfig() { - $this->config->expects($this->once())->method('getSegment')->willReturn(null); + $this->config->expects($this->once())->method('getConfigData')->willReturn(null); $this->assertFalse($this->model->isModuleInfoAvailable()); } @@ -107,9 +107,9 @@ public function testIsModuleInfoAvailableNoConfig() private function setLoadConfigExpectation($isExpected = true) { if ($isExpected) { - $this->config->expects($this->once())->method('getSegment')->willReturn(self::$enabledFixture); + $this->config->expects($this->once())->method('getConfigData')->willReturn(self::$enabledFixture); } else { - $this->config->expects($this->never())->method('getSegment'); + $this->config->expects($this->never())->method('getConfigData'); } } diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php index f469783e91b58..9c7ceeb9f939b 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php @@ -40,11 +40,6 @@ class StatusTest extends \PHPUnit_Framework_TestCase */ private $dependencyChecker; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $deploymentConfigFactory; - /** * @var Status */ @@ -58,21 +53,13 @@ protected function setUp() $this->cleanup = $this->getMock('Magento\Framework\App\State\Cleanup', [], [], '', false); $this->conflictChecker = $this->getMock('Magento\Framework\Module\ConflictChecker', [], [], '', false); $this->dependencyChecker = $this->getMock('Magento\Framework\Module\DependencyChecker', [], [], '', false); - $this->deploymentConfigFactory = $this->getMock( - 'Magento\Framework\Module\ModuleList\DeploymentConfigFactory', - [], - [], - '', - false - ); $this->object = new Status( $this->loader, $this->moduleList, $this->writer, $this->cleanup, $this->conflictChecker, - $this->dependencyChecker, - $this->deploymentConfigFactory + $this->dependencyChecker ); } @@ -180,11 +167,8 @@ public function testSetIsEnabled() $this->moduleList->expects($this->at(0))->method('has')->with('Module_Foo')->willReturn(false); $this->moduleList->expects($this->at(1))->method('has')->with('Module_Bar')->willReturn(false); $this->moduleList->expects($this->at(2))->method('has')->with('Module_Baz')->willReturn(false); - $deploymentConfig = $this->getMock('Magento\Framework\Module\ModuleList\DeploymentConfig', [], [], '', false); $expectedModules = ['Module_Foo' => 1, 'Module_Bar' => 1, 'Module_Baz' => 0]; - $this->deploymentConfigFactory->expects($this->once())->method('create')->with($expectedModules) - ->willReturn($deploymentConfig); - $this->writer->expects($this->once())->method('update')->with($deploymentConfig); + $this->writer->expects($this->once())->method('saveConfig')->with($expectedModules); $this->cleanup->expects($this->once())->method('clearCaches'); $this->cleanup->expects($this->once())->method('clearCodeGeneratedFiles'); $this->object->setIsEnabled(true, ['Module_Foo', 'Module_Bar']); diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index 2052eacd62c0f..eef55da878c54 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -97,10 +97,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface * Segment key */ const KEY_CACHE = 'cache'; - /** - * Segment key - */ - const KEY_MODULES = 'modules'; + /**#@-*/ /** diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 02a5b9336f209..02cf40e2a21b4 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -395,7 +395,7 @@ private function createEncryptConfig($data) } // retrieve old encryption keys if ($this->deploymentConfig->isAvailable()) { - $encryptInfo = $this->deploymentConfig->getSegment(ModuleLoader::ENCRYPT_CONFIG_KEY); + $encryptInfo = $this->deploymentConfig->getConfigData(ModuleLoader::ENCRYPT_CONFIG_KEY); $oldKeys = $encryptInfo[ModuleLoader::KEY_ENCRYPTION_KEY]; $key = empty($key) ? $oldKeys : $oldKeys . "\n" . $key; } else if (empty($key)) { @@ -1037,8 +1037,7 @@ public function updateModulesSequence() $result[$module] = 1; } } - $segment = $this->deploymentConfigFactory->create($result); - $this->deploymentConfigWriter->update($segment); + $this->deploymentConfigWriter->saveConfig($result); } /** @@ -1167,7 +1166,7 @@ public function cleanupDb() { // stops cleanup if app/etc/config.php does not exist if ($this->deploymentConfig->isAvailable()) { - $dbConfig = new DbConfig($this->deploymentConfig->getSegment(ModuleLoader::CONFIG_KEY)); + $dbConfig = new DbConfig($this->deploymentConfig->getConfigData(ModuleLoader::CONFIG_KEY)); $config = $dbConfig->getConnection(\Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION); if ($config) { try { @@ -1258,7 +1257,7 @@ private function assertDeploymentConfigExists() */ private function assertDbAccessible() { - $segment = $this->deploymentConfig->getSegment(ModuleLoader::CONFIG_KEY); + $segment = $this->deploymentConfig->getConfigData(ModuleLoader::CONFIG_KEY); $dbConfig = new DbConfig($segment); $config = $dbConfig->getConnection(\Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION); $this->checkDatabaseConnection( diff --git a/setup/src/Magento/Setup/Model/ModuleStatus.php b/setup/src/Magento/Setup/Model/ModuleStatus.php index e435110050bfd..75f24ec42a52c 100644 --- a/setup/src/Magento/Setup/Model/ModuleStatus.php +++ b/setup/src/Magento/Setup/Model/ModuleStatus.php @@ -11,7 +11,6 @@ use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Module\ModuleList\DeploymentConfig as ModuleDeployment; use \Magento\Framework\Module\DependencyChecker; -use Magento\Setup\Model\ConfigOptionsList; class ModuleStatus { @@ -146,7 +145,7 @@ public function setIsEnabled($status, $moduleName) */ private function deselectDisabledModules() { - $existingModules = $this->deploymentConfig->getSegment(ConfigOptionsList::KEY_MODULES); + $existingModules = $this->deploymentConfig->getConfigData(ModuleDeployment::KEY_MODULES); if (isset($existingModules)) { foreach ($existingModules as $module => $value) { if (!$value) { diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 459368efdeeeb..6624e45082014 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -8,9 +8,7 @@ use \Magento\Setup\Model\Installer; use \Magento\Setup\Model\DeploymentConfigMapper; - -use Magento\Framework\App\DeploymentConfig\DbConfig; -use Magento\Framework\App\DeploymentConfig\EncryptConfig; +use Magento\Setup\Model\ConfigOptionsList; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; @@ -224,8 +222,8 @@ public function testInstall() ]; $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true); $this->config->expects($this->any())->method('getSegment')->will($this->returnValueMap([ - [DbConfig::CONFIG_KEY, self::$dbConfig], - [EncryptConfig::CONFIG_KEY, [EncryptConfig::KEY_ENCRYPTION_KEY => 'encryption_key']] + [ConfigOptionsList::CONFIG_KEY, self::$dbConfig], + [ConfigOptionsList::ENCRYPT_CONFIG_KEY, [ConfigOptionsList::KEY_ENCRYPTION_KEY => 'encryption_key']] ])); $allModules = ['Foo_One' => [], 'Bar_Two' => []]; $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ModuleStatusTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ModuleStatusTest.php index ff1b85f95c3db..a4e71aeb602a9 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ModuleStatusTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ModuleStatusTest.php @@ -57,7 +57,7 @@ public function setUp() public function testGetAllModules($expectedAllModules, $expectedConfig, $expectedResult) { $this->moduleLoader->expects($this->once())->method('load')->will($this->returnValue($expectedAllModules)); - $this->deploymentConfig->expects($this->once())->method('getSegment') + $this->deploymentConfig->expects($this->once())->method('getConfigData') ->will($this->returnValue($expectedConfig)); $this->dependencyChecker->expects($this->any())->method('checkDependenciesWhenDisableModules')->willReturn( ['module1' => [], 'module2' => [], 'module3' => [], 'module4' => []] @@ -82,7 +82,7 @@ public function testGetAllModules($expectedAllModules, $expectedConfig, $expecte public function testGetAllModulesWithInputs($expectedAllModules, $expectedConfig, $expectedResult) { $this->moduleLoader->expects($this->once())->method('load')->will($this->returnValue($expectedAllModules)); - $this->deploymentConfig->expects($this->never())->method('getSegment') + $this->deploymentConfig->expects($this->never())->method('getConfigData') ->will($this->returnValue($expectedConfig)); $this->dependencyChecker->expects($this->any())->method('checkDependenciesWhenDisableModules')->willReturn( ['module1' => [], 'module2' => [], 'module3' => [], 'module4' => []] @@ -106,7 +106,7 @@ public function testGetAllModulesWithInputs($expectedAllModules, $expectedConfig public function testSetIsEnabled($expectedAllModules, $expectedConfig, $expectedResult) { $this->moduleLoader->expects($this->once())->method('load')->will($this->returnValue($expectedAllModules)); - $this->deploymentConfig->expects($this->once())->method('getSegment') + $this->deploymentConfig->expects($this->once())->method('getConfigData') ->will($this->returnValue($expectedConfig)); $this->dependencyChecker->expects($this->any())->method('checkDependenciesWhenDisableModules')->willReturn( ['module1' => [], 'module2' => [], 'module3' => [], 'module4' => []] From 253a71a34dcae8d2c04b2e2006ae0085b8734a1e Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 24 Mar 2015 17:59:47 -0500 Subject: [PATCH 133/214] MAGETWO-35137: Add deployment configuration set command - fixed and added tests --- .../Unit/Option/SelectConfigOptionTest.php | 25 ++++++++++++---- .../Test/Unit/Option/TextConfigOptionTest.php | 6 ++-- .../Command/ConfigInstallCommandTest.php | 22 -------------- .../Test/Unit/Model/ConfigGeneratorTest.php | 14 +++------ .../Setup/Test/Unit/Model/ConfigModelTest.php | 30 ++++++++++++++++++- 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/SelectConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/SelectConfigOptionTest.php index a8fd1c3998be5..61a395413b9ab 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/SelectConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/SelectConfigOptionTest.php @@ -16,7 +16,7 @@ class SelectConfigOptionTest extends \PHPUnit_Framework_TestCase */ public function testConstructInvalidFrontendType() { - new SelectConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT, ['a', 'b']); + new SelectConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT, ['a', 'b'], 'path/to/value'); } /** @@ -25,18 +25,28 @@ public function testConstructInvalidFrontendType() */ public function testConstructNoOptions() { - new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, []); + new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, [], 'path/to/value'); } public function testGetFrontendType() { - $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); + $option = new SelectConfigOption( + 'test', + SelectConfigOption::FRONTEND_WIZARD_SELECT, + ['a', 'b'], + 'path/to/value' + ); $this->assertEquals(SelectConfigOption::FRONTEND_WIZARD_SELECT, $option->getFrontendType()); } public function testGetSelectOptions() { - $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); + $option = new SelectConfigOption( + 'test', + SelectConfigOption::FRONTEND_WIZARD_SELECT, + ['a', 'b'], + 'path/to/value' + ); $this->assertEquals(['a', 'b'], $option->getSelectOptions()); } @@ -46,7 +56,12 @@ public function testGetSelectOptions() */ public function testValidateException() { - $option = new SelectConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, ['a', 'b']); + $option = new SelectConfigOption( + 'test', + SelectConfigOption::FRONTEND_WIZARD_SELECT, + ['a', 'b'], + 'path/to/value' + ); $option->validate('c'); } } diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/TextConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/TextConfigOptionTest.php index e5ee1cf748b0c..5a6f6379d6aeb 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/TextConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/TextConfigOptionTest.php @@ -16,12 +16,12 @@ class TextConfigOptionTest extends \PHPUnit_Framework_TestCase */ public function testConstructInvalidFrontendType() { - new TextConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT); + new TextConfigOption('test', SelectConfigOption::FRONTEND_WIZARD_SELECT, 'path/to/value'); } public function testGetFrontendType() { - $option = new TextConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT); + $option = new TextConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT, 'path/to/value'); $this->assertEquals(TextConfigOption::FRONTEND_WIZARD_TEXT, $option->getFrontendType()); } @@ -31,7 +31,7 @@ public function testGetFrontendType() */ public function testValidateException() { - $option = new TextConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT); + $option = new TextConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT, 'path/to/value'); $option->validate(1); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php index c56e5d3d0b5b3..4ca29bb9e2912 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php @@ -111,26 +111,4 @@ public function testInitializeFailedValidation() $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $command->initialize($this->input, $this->output); } - - /** - * @expectedException \Exception - * @expectedExceptionMessage Deployment configuration already exists - */ - public function testDeploymentConfigExists() - { - $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(true); - $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); - $optionsSet = [ - $option - ]; - - $this->configModel - ->expects($this->once()) - ->method('getAvailableOptions') - ->will($this->returnValue($optionsSet)); - - $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); - $command->initialize($this->input, $this->output); - } - } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 1307d5a8536eb..5f41dcd000e9c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -34,7 +34,7 @@ protected function setUp() public function testCreateInstallConfig() { - $returnValue = $this->configGeneratorObject->createInstallConfig(); + $returnValue = $this->configGeneratorObject->createInstallConfig([]); $this->assertInstanceOf('Magento\Framework\Config\Data\ConfigData', $returnValue); $this->assertEquals('install', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); @@ -43,7 +43,7 @@ public function testCreateInstallConfig() public function testCreateCryptConfigWithInput() { $testData = [ConfigOptionsList::INPUT_KEY_CRYPT_KEY => 'some-test_key']; - $returnValue = $this->configGeneratorObject->createCryptConfig($testData); + $returnValue = $this->configGeneratorObject->createCryptConfig($testData, []); $this->assertEquals('crypt', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['key' => 'some-test_key'], $returnValue->getData()); @@ -51,7 +51,7 @@ public function testCreateCryptConfigWithInput() public function testCreateCryptConfigWithoutInput() { - $returnValue = $this->configGeneratorObject->createCryptConfig([]); + $returnValue = $this->configGeneratorObject->createCryptConfig([], []); $this->assertEquals('crypt', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['key' => md5('key')], $returnValue->getData()); @@ -85,7 +85,7 @@ public function testCreateSessionConfigWithoutInput() $returnValue = $this->configGeneratorObject->createSessionConfig([]); $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['save' => ConfigOptionsList::SESSION_SAVE_FILES], $returnValue->getData()); + $this->assertEquals([], $returnValue->getData()); } public function testCreateDefinitionsConfig() @@ -119,12 +119,6 @@ public function testCreateDbConfig() $this->assertSame('testDbName', $dbData['connection']['default']['dbname']); $this->assertArrayHasKey('username', $dbData['connection']['default']); $this->assertSame('testDbUser', $dbData['connection']['default']['username']); - $this->assertArrayHasKey('password', $dbData['connection']['default']); - $this->assertSame('', $dbData['connection']['default']['password']); - $this->assertArrayHasKey('model', $dbData['connection']['default']); - $this->assertSame('mysql4', $dbData['connection']['default']['model']); - $this->assertArrayHasKey('initStatements', $dbData['connection']['default']); - $this->assertSame('SET NAMES utf8;', $dbData['connection']['default']['initStatements']); $this->assertArrayHasKey('active', $dbData['connection']['default']); $this->assertSame('1', $dbData['connection']['default']['active']); } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php index c3fa909427f01..b02a0a2b56de7 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php @@ -26,6 +26,11 @@ class ConfigModelTest extends \PHPUnit_Framework_TestCase */ private $writer; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig\Reader + */ + private $reader; + /** * @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Framework\Config\Data\ConfigData */ @@ -40,10 +45,13 @@ public function setUp() { $this->collector = $this->getMock('Magento\Setup\Model\ConfigOptionsListCollector', [], [], '', false); $this->writer = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); + $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); $this->configOptionsList = $this->getMock('Magento\Backend\Setup\ConfigOptionsList', [], [], '', false); $this->configData = $this->getMock('Magento\Framework\Config\Data\ConfigData', [], [], '', false); - $this->configModel = new ConfigModel($this->collector, $this->writer); + $this->reader->expects($this->once())->method('loadConfig')->will($this->returnValue([])); + + $this->configModel = new ConfigModel($this->collector, $this->writer, $this->reader); } public function testValidate() @@ -127,6 +135,26 @@ public function testProcess() $this->configModel->process([]); } + public function testGetConfigValueByPath() + { + $expectedValue = 'test'; + $path = 'test/path/to/value'; + $config = [ + 'test' => [ + 'path' => [ + 'to' => [ + 'value' => $expectedValue + ] + ] + ] + ]; + + $reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $reader->expects($this->once())->method('loadConfig')->will($this->returnValue($config)); + $configModel = new ConfigModel($this->collector, $this->writer, $reader); + $this->assertEquals($expectedValue, $configModel->getConfigValueByPath($path)); + } + /** * @expectedException \Exception * @expectedExceptionMessage In module : Fake_ModuleConfigOption::createConfig From 3a67068663d668039215af4ef667357bdac758fb Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 25 Mar 2015 09:59:16 -0500 Subject: [PATCH 134/214] MAGETWO-35137: Add deployment configuration set command - added $configPath to FlagConfigOption and MultiSelectConfigOption also changed related tests. --- .../Setup/Option/FlagConfigOption.php | 11 +++++++- .../Setup/Option/MultiSelectConfigOption.php | 3 +++ .../Test/Unit/Option/FlagConfigOptionTest.php | 2 +- .../Option/MultiSelectConfigOptionTest.php | 25 +++++++++++++++---- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php index 9ffd5384eaa0d..837ce825c9a9f 100644 --- a/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php @@ -19,14 +19,23 @@ class FlagConfigOption extends AbstractConfigOption * Constructor * * @param string $name + * @param string $configPath * @param string $description * @param string|array|null $shortCut */ public function __construct( $name, + $configPath, $description = '', $shortCut = null ) { - parent::__construct($name, self::FRONTEND_WIZARD_FLAG, self::VALUE_NONE, $description, null, $shortCut); + parent::__construct( + $name, + self::FRONTEND_WIZARD_FLAG, + self::VALUE_NONE, + $configPath, + $description, + null, + $shortCut); } } diff --git a/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php index 98c0953f16b5f..03feebaca18ff 100644 --- a/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/MultiSelectConfigOption.php @@ -30,6 +30,7 @@ class MultiSelectConfigOption extends AbstractConfigOption * @param string $name * @param string $frontendType * @param array $selectOptions + * @param string $configPath * @param string $description * @param array $defaultValue * @param string|array|null $shortCut @@ -39,6 +40,7 @@ public function __construct( $name, $frontendType, array $selectOptions, + $configPath, $description = '', array $defaultValue = [], $shortCut = null @@ -56,6 +58,7 @@ public function __construct( $name, $frontendType, self::VALUE_REQUIRED | self::VALUE_IS_ARRAY, + $configPath, $description, $defaultValue, $shortCut diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/FlagConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/FlagConfigOptionTest.php index 4f2d549820c22..d466dc14f7447 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/FlagConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/FlagConfigOptionTest.php @@ -11,7 +11,7 @@ class FlagConfigOptionTest extends \PHPUnit_Framework_TestCase { public function testGetFrontendType() { - $option = new FlagConfigOption('test', FlagConfigOption::FRONTEND_WIZARD_FLAG); + $option = new FlagConfigOption('test', FlagConfigOption::FRONTEND_WIZARD_FLAG, 'path/to/value'); $this->assertEquals(FlagConfigOption::FRONTEND_WIZARD_FLAG, $option->getFrontendType()); } } diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php index 74271a06c138a..4e3e6dc0335bc 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/Option/MultiSelectConfigOptionTest.php @@ -16,7 +16,7 @@ class MultiSelectConfigOptionTest extends \PHPUnit_Framework_TestCase */ public function testConstructInvalidFrontendType() { - new MultiSelectConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT, ['a', 'b']); + new MultiSelectConfigOption('test', TextConfigOption::FRONTEND_WIZARD_TEXT, ['a', 'b'], 'path/to/value'); } /** @@ -25,18 +25,28 @@ public function testConstructInvalidFrontendType() */ public function testConstructNoOptions() { - new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, []); + new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, [], 'path/to/value'); } public function testGetFrontendType() { - $option = new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, ['a', 'b']); + $option = new MultiSelectConfigOption( + 'test', + MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, + ['a', 'b'], + 'path/to/value' + ); $this->assertEquals(MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, $option->getFrontendType()); } public function testGetSelectOptions() { - $option = new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, ['a', 'b']); + $option = new MultiSelectConfigOption( + 'test', + MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, + ['a', 'b'], + 'path/to/value' + ); $this->assertEquals(['a', 'b'], $option->getSelectOptions()); } @@ -46,7 +56,12 @@ public function testGetSelectOptions() */ public function testValidateException() { - $option = new MultiSelectConfigOption('test', MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, ['a', 'b']); + $option = new MultiSelectConfigOption( + 'test', + MultiSelectConfigOption::FRONTEND_WIZARD_MULTISELECT, + ['a', 'b'], + 'path/to/value' + ); $option->validate(['c', 'd']); } } From 5231e4b02fbebae784ef1369f9e680ce7a0c95c3 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Wed, 25 Mar 2015 10:07:30 -0500 Subject: [PATCH 135/214] MAGETWO-35135: Integrate config command - Replace old install deployment code with new --- .../Console/Command/ConfigCreateCommand.php | 4 +- .../Magento/Setup/Model/ConfigGenerator.php | 5 +- setup/src/Magento/Setup/Model/ConfigModel.php | 30 +++- setup/src/Magento/Setup/Model/Installer.php | 148 ++---------------- .../Magento/Setup/Model/InstallerFactory.php | 3 +- ...ndTest.php => ConfigCreateCommandTest.php} | 3 +- 6 files changed, 51 insertions(+), 142 deletions(-) rename setup/src/Magento/Setup/Test/Unit/Console/Command/{ConfigInstallCommandTest.php => ConfigCreateCommandTest.php} (98%) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php index a505d35df87e1..00f0649e32340 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php @@ -47,8 +47,8 @@ class ConfigCreateCommand extends Command public function __construct( ConfigModel $configModel, ModuleList $moduleList, - DeploymentConfig $deploymentConfig) - { + DeploymentConfig $deploymentConfig + ) { $this->configModel = $configModel; $this->moduleList = $moduleList; $this->deploymentConfig = $deploymentConfig; diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 5f8f323f271fb..0576253911f18 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -184,8 +184,7 @@ public function createDbConfig(array $data) */ public function createResourceConfig() { - $resourceData[self::$paramMap[ConfigOptionsList::INPUT_KEY_RESOURCE]] = - ['default_setup' => ['connection' => 'default']]; - return new ConfigData(ConfigFilePool::APP_CONFIG, 'resource', $resourceData); + $resourceData = ['default_setup' => ['connection' => 'default']]; + return new ConfigData(ConfigFilePool::APP_CONFIG, ConfigOptionsList::INPUT_KEY_RESOURCE, $resourceData); } } diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 75bf45920bbcb..36f281908b8a9 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -21,18 +21,28 @@ class ConfigModel */ protected $writer; + /** + * File permissions checker + * + * @var FilePermissions + */ + // private $filePermissions; + /** * Constructor * * @param ConfigOptionsListCollector $collector * @param Writer $writer + * param FilePermissions $filePermissions */ public function __construct( ConfigOptionsListCollector $collector, - Writer $writer + Writer $writer //, + // FilePermissions $filePermissions ) { $this->collector = $collector; $this->writer = $writer; + // $this->filePermissions = $filePermissions; } /** @@ -61,8 +71,9 @@ public function getAvailableOptions() */ public function process($inputOptions) { - $fileConfigStorage = []; + $this->checkInstallationFilePermissions(); + $fileConfigStorage = []; $options = $this->collector->collectOptions(); foreach ($options as $moduleName => $option) { @@ -126,4 +137,19 @@ public function validate(array $inputOptions) return $errors; } + + /** + * Check permissions of directories that are expected to be writable for installation + * + * @return void + * @throws \Exception + */ + private function checkInstallationFilePermissions() + { + $results = false; // pdltest $this->filePermissions->getMissingWritableDirectoriesForInstallation(); + if ($results) { + $errorMsg = "Missing writing permissions to the following directories: '" . implode("' '", $results) . "'"; + throw new \Exception($errorMsg); + } + } } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index da913b7a32417..9f3fe10ab0fe3 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -25,9 +25,6 @@ use Magento\Framework\Module\ModuleListInterface; use Magento\Framework\Shell; use Magento\Framework\Shell\CommandRenderer; -use Magento\Setup\Module\ConnectionFactory; -use Magento\Setup\Module\Setup; -use Magento\Store\Model\Store; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\InstallDataInterface; @@ -35,6 +32,10 @@ use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Model\Resource\Db\Context; +use Magento\Setup\Model\ConfigModel as SetupConfigModel; +use Magento\Setup\Module\ConnectionFactory; +use Magento\Setup\Module\Setup; +use Magento\Store\Model\Store; /** * Class Installer contains the logic to install Magento application. @@ -222,6 +223,11 @@ class Installer */ private $context; + /** + * @var SetupConfigModel + */ + private $setupConfigModel; + /** * Constructor * @@ -242,6 +248,7 @@ class Installer * @param SampleData $sampleData * @param ObjectManagerProvider $objectManagerProvider * @param Context $context + * @param SetupConfigModel $setupConfigModel * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -262,7 +269,8 @@ public function __construct( Filesystem $filesystem, SampleData $sampleData, ObjectManagerProvider $objectManagerProvider, - Context $context + Context $context, + SetupConfigModel $setupConfigModel ) { $this->filePermissions = $filePermissions; $this->deploymentConfigWriter = $deploymentConfigWriter; @@ -283,6 +291,7 @@ public function __construct( $this->deploymentConfig = $deploymentConfig; $this->objectManagerProvider = $objectManagerProvider; $this->context = $context; + $this->setupConfigModel = $setupConfigModel; } /** @@ -361,122 +370,6 @@ private function createModulesConfig($request) return $this->deploymentConfigFactory->create($result); } - /** - * Creates backend deployment configuration segment - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - * @throws \InvalidArgumentException - */ - private function createBackendConfig($data) - { - $key = DeploymentConfigMapper::KEY_BACKEND_FRONTNAME; - if (empty($data[$key])) { - throw new \InvalidArgumentException("Missing value for: '{$key}'"); - } - return new BackendConfig([DeploymentConfigMapper::$paramMap[$key] => $data[$key]]); - } - - /** - * Creates encrypt deployment configuration segment - * No new encryption key will be added if there is an existing deployment config file unless user provides one. - * Old encryption keys will persist. - * A new encryption key will be generated if there is no existing deployment config file. - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - */ - private function createEncryptConfig($data) - { - $key = ''; - if (isset($data[DeploymentConfigMapper::KEY_ENCRYPTION_KEY])) { - $key = $data[DeploymentConfigMapper::KEY_ENCRYPTION_KEY]; - } - // retrieve old encryption keys - if ($this->deploymentConfig->isAvailable()) { - $encryptInfo = $this->deploymentConfig->getSegment(EncryptConfig::CONFIG_KEY); - $oldKeys = $encryptInfo[EncryptConfig::KEY_ENCRYPTION_KEY]; - $key = empty($key) ? $oldKeys : $oldKeys . "\n" . $key; - } else if (empty($key)) { - $key = md5($this->random->getRandomString(10)); - } - $cryptConfigData = - [DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_ENCRYPTION_KEY] => $key]; - - // find the latest key to display - $keys = explode("\n", $key); - $this->installInfo[EncryptConfig::KEY_ENCRYPTION_KEY] = array_pop($keys); - return new EncryptConfig($cryptConfigData); - } - - /** - * Creates db deployment configuration segment - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - * @throws \InvalidArgumentException - */ - private function createDbConfig($data) - { - $connection = []; - $required = [ - DeploymentConfigMapper::KEY_DB_HOST, - DeploymentConfigMapper::KEY_DB_NAME, - DeploymentConfigMapper::KEY_DB_USER, - ]; - foreach ($required as $key) { - if (!isset($data[$key])) { - throw new \InvalidArgumentException("Missing value: {$key}"); - } - $connection[DeploymentConfigMapper::$paramMap[$key]] = $data[$key]; - } - $optional = [ - DeploymentConfigMapper::KEY_DB_INIT_STATEMENTS, - DeploymentConfigMapper::KEY_DB_MODEL, - DeploymentConfigMapper::KEY_DB_PASS, - ]; - foreach ($optional as $key) { - $connection[DeploymentConfigMapper::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : null; - } - $prefixKey = DeploymentConfigMapper::KEY_DB_PREFIX; - $config = [ - DeploymentConfigMapper::$paramMap[$prefixKey] => isset($data[$prefixKey]) ? $data[$prefixKey] : null, - 'connection' => ['default' => $connection], - ]; - return new DbConfig($config); - } - - /** - * Creates session deployment configuration segment - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - */ - private function createSessionConfig($data) - { - $sessionConfigData = [ - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_SESSION_SAVE] => - isset($data[DeploymentConfigMapper::KEY_SESSION_SAVE]) ? - $data[DeploymentConfigMapper::KEY_SESSION_SAVE] : null - ]; - return new SessionConfig($sessionConfigData); - } - - /** - * Creates install deployment configuration segment - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - */ - private function createInstallConfig($data) - { - $installConfigData = [ - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DATE] => - $data[DeploymentConfigMapper::KEY_DATE] - ]; - return new InstallConfig($installConfigData); - } - /** * Determines list of modules from request based on list of all modules * @@ -560,18 +453,9 @@ public function checkApplicationFilePermissions() public function installDeploymentConfig($data) { $this->checkInstallationFilePermissions(); - $data[InstallConfig::KEY_DATE] = date('r'); - - $configs = [ - $this->createBackendConfig($data), - $this->createDbConfig($data), - $this->createEncryptConfig($data), - $this->createInstallConfig($data), - $this->createSessionConfig($data), - new ResourceConfig(), - $this->createModulesConfig($data), - ]; - $this->deploymentConfigWriter->create($configs); + /* * @var \Magento\Setup\Model\ConfigModel $configModel */ + // $configModel = $this->objectManagerProvider->get()->get('Magento\Setup\Model\ConfigModel'); + $this->setupConfigModel->process($data->getArrayCopy()); } /** diff --git a/setup/src/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php index 6ed7fbb8d3019..a6ac68e2cc799 100644 --- a/setup/src/Magento/Setup/Model/InstallerFactory.php +++ b/setup/src/Magento/Setup/Model/InstallerFactory.php @@ -68,7 +68,8 @@ public function create(LoggerInterface $log) $this->getResource(), $this->serviceLocator->get('Magento\Framework\Model\Resource\Db\TransactionManager'), $this->serviceLocator->get('Magento\Framework\Model\Resource\Db\ObjectRelationProcessor') - ) + ), + $this->serviceLocator->get('Magento\Setup\Model\ConfigModel') ); } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php similarity index 98% rename from setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php rename to setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php index c56e5d3d0b5b3..e6bf720829800 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigInstallCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php @@ -12,7 +12,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ConfigInstallCommandTest extends \PHPUnit_Framework_TestCase +class ConfigCreateCommandTest extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ConfigModel @@ -132,5 +132,4 @@ public function testDeploymentConfigExists() $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $command->initialize($this->input, $this->output); } - } From 7ca4fa730cc83d0094e18ffa638140ca54b24163 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Wed, 25 Mar 2015 13:32:32 -0500 Subject: [PATCH 136/214] MAGETWO-35135: Integrate config command - Reset object manager after deployment config is created - fix tests --- .../Setup/Model/ConfigOptionsListCollector.php | 5 +++-- setup/src/Magento/Setup/Model/Installer.php | 12 ++++-------- .../Magento/Setup/Model/ObjectManagerProvider.php | 13 +++++++++++++ .../Setup/Test/Unit/Model/ConfigGeneratorTest.php | 2 +- .../Setup/Test/Unit/Model/InstallerFactoryTest.php | 4 ++++ .../Magento/Setup/Test/Unit/Model/InstallerTest.php | 9 ++++++++- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php index 92b35d718b83f..d020099367475 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php @@ -9,6 +9,7 @@ use Magento\Framework\Filesystem; use Magento\Framework\Module\FullModuleList; use Magento\Framework\Module\ModuleList; +use Magento\Framework\Setup\ConfigOptionsListInterface; /** * Collects all ConfigOptionsList class in modules and setup @@ -91,7 +92,7 @@ public function collectOptions() $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptionsList'; if (class_exists($optionsClassName)) { $optionsClass = $this->objectManagerProvider->get()->create($optionsClassName); - if ($optionsClass instanceof \Magento\Framework\Setup\ConfigOptionsListInterface) { + if ($optionsClass instanceof ConfigOptionsListInterface) { $optionsList[$moduleName] = $optionsClass; } } @@ -101,7 +102,7 @@ public function collectOptions() $setupOptionsClassName = 'Magento\Setup\Model\ConfigOptionsList'; if (class_exists($setupOptionsClassName)) { $setupOptionsClass = $this->objectManagerProvider->get()->create($setupOptionsClassName); - if ($setupOptionsClass instanceof \Magento\Framework\Setup\ConfigOptionsListInterface) { + if ($setupOptionsClass instanceof ConfigOptionsListInterface) { $optionsList['setup'] = $setupOptionsClass; } } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 9f3fe10ab0fe3..cb00f010705cd 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -6,12 +6,7 @@ namespace Magento\Setup\Model; -use Magento\Framework\App\DeploymentConfig\BackendConfig; use Magento\Framework\App\DeploymentConfig\DbConfig; -use Magento\Framework\App\DeploymentConfig\EncryptConfig; -use Magento\Framework\App\DeploymentConfig\InstallConfig; -use Magento\Framework\App\DeploymentConfig\ResourceConfig; -use Magento\Framework\App\DeploymentConfig\SessionConfig; use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\Filesystem\DirectoryList; @@ -453,9 +448,10 @@ public function checkApplicationFilePermissions() public function installDeploymentConfig($data) { $this->checkInstallationFilePermissions(); - /* * @var \Magento\Setup\Model\ConfigModel $configModel */ - // $configModel = $this->objectManagerProvider->get()->get('Magento\Setup\Model\ConfigModel'); - $this->setupConfigModel->process($data->getArrayCopy()); + $this->setupConfigModel->process(is_array($data) ? $data : $data->getArrayCopy()); + + // reset object manager now that there is a deployment config + $this->objectManagerProvider->reset(); } /** diff --git a/setup/src/Magento/Setup/Model/ObjectManagerProvider.php b/setup/src/Magento/Setup/Model/ObjectManagerProvider.php index 5976518b30d78..d887f0031fe67 100644 --- a/setup/src/Magento/Setup/Model/ObjectManagerProvider.php +++ b/setup/src/Magento/Setup/Model/ObjectManagerProvider.php @@ -29,6 +29,7 @@ class ObjectManagerProvider * @var \Magento\Framework\ObjectManagerInterface */ private $objectManager; + /** * @var DeploymentConfig */ @@ -45,6 +46,8 @@ public function __construct(ServiceLocatorInterface $serviceLocator, DeploymentC } /** + * Retrieve object manager. + * * @return \Magento\Framework\ObjectManagerInterface * @throws \Magento\Setup\Exception */ @@ -57,4 +60,14 @@ public function get() } return $this->objectManager; } + + /** + * Causes object manager to be reinitialized the next time it is retrieved. + * + * @return void + */ + public function reset() + { + $this->objectManager = null; + } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 1307d5a8536eb..71892545ee3c3 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -134,6 +134,6 @@ public function testCreateResourceConfig() $returnValue = $this->configGeneratorObject->createResourceConfig(); $this->assertEquals('resource', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['resource' => ['default_setup' => ['connection' => 'default']]], $returnValue->getData()); + $this->assertEquals(['default_setup' => ['connection' => 'default']], $returnValue->getData()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php index bde3f74878cf3..df1c839863b27 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php @@ -89,6 +89,10 @@ public function testCreate() 'Magento\Framework\Model\Resource\Db\ObjectRelationProcessor', $this->getMock('Magento\Framework\Model\Resource\Db\ObjectRelationProcessor', [], [], '', false), ], + [ + 'Magento\Setup\Model\ConfigModel', + $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false), + ], ]; $serviceLocatorMock = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); $serviceLocatorMock diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 459368efdeeeb..0ebad4aa18ae6 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -110,6 +110,11 @@ class InstallerTest extends \PHPUnit_Framework_TestCase */ private $objectManager; + /** + * @var \Magento\Setup\Model\ConfigModel|\PHPUnit_Framework_MockObject_MockObject + */ + private $configModel; + /** * Sample DB configuration segment * @@ -171,6 +176,7 @@ protected function setUp() $this->sampleData = $this->getMock('Magento\Setup\Model\SampleData', [], [], '', false); $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); $this->contextMock = $this->getMock('Magento\Framework\Model\Resource\Db\Context', [], [], '', false); + $this->configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); $this->object = $this->createObject(); } @@ -209,7 +215,8 @@ private function createObject($connectionFactory = false, $objectManagerProvider $this->filesystem, $this->sampleData, $objectManagerProvider, - $this->contextMock + $this->contextMock, + $this->configModel ); } From 5f9c6134d084b87b86363023631f97f3df8d4611 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 25 Mar 2015 15:28:03 -0500 Subject: [PATCH 137/214] MAGETWO-35137: Add deployment configuration set command - added use of DeploymentConfig instead of plaine config array. --- .../Backend/Setup/ConfigOptionsList.php | 3 +- .../Framework/App/DeploymentConfig.php | 9 +-- .../Framework/App/DeploymentConfig/Reader.php | 6 -- .../Setup/ConfigOptionsListInterface.php | 5 +- .../Magento/Setup/Model/ConfigGenerator.php | 19 +++--- setup/src/Magento/Setup/Model/ConfigModel.php | 62 +++++-------------- .../Magento/Setup/Model/ConfigOptionsList.php | 8 ++- .../Setup/Test/Unit/Model/ConfigModelTest.php | 20 ------ 8 files changed, 39 insertions(+), 93 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php index 1b5eb4481919e..4caf6ea6f0299 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -9,6 +9,7 @@ use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Setup\ConfigOptionsListInterface; use Magento\Framework\Setup\Option\TextConfigOption; +use Magento\Framework\App\DeploymentConfig; /* * Deployment configuration options needed for Backend module @@ -49,7 +50,7 @@ public function getOptions() /** * {@inheritdoc} */ - public function createConfig(array $options, array $currentConfig = []) + public function createConfig(array $options, DeploymentConfig $deploymentConfig) { $data = []; if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) { diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig.php index f4d7c97adfeff..30052fd3b54bd 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig.php @@ -94,13 +94,14 @@ public function isAvailable() * @param string $key * @return null|mixed */ - public function getConfigData($key) + public function getConfigData($key = null) { $this->load(); - if (!isset($this->data[$key])) { - return null; + if (isset($this->data[$key])) { + $this->data[$key]; } - return $this->data[$key]; + + return $this->data; } /** diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php index 05414c773fc74..570e1c01896eb 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php @@ -80,12 +80,6 @@ public function load($configFile = null) return $result ?: []; } - public function loadConfig() - { - // TODO: add multi config functionality here - return $this->load(); - } - /** * Gets a value specified key from config data * diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php index a84578169b500..59d287cd1c449 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Framework\Setup; +use Magento\Framework\App\DeploymentConfig; /** * Interface for handling options in deployment configuration tool @@ -23,10 +24,10 @@ public function getOptions(); * Data in these objects will be stored in array form in deployment config file. * * @param array $options - * @param array $currentConfig + * @param DeploymentConfig $deploymentConfig * @return \Magento\Framework\Config\Data\ConfigData[] */ - public function createConfig(array $options, array $currentConfig = []); + public function createConfig(array $options, DeploymentConfig $deploymentConfig); /** * Validates user input option values and returns error messages diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 487f7c4076740..22bc44e46cbb6 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -52,14 +52,15 @@ public function __construct(Random $random, Loader $moduleLoader, DeploymentConf /** * Creates install segment config data * - * @param array $currentConfig + * @param DeploymentConfig $deploymentConfig * @return ConfigData + * @internal param array $currentConfig */ - public function createInstallConfig(array $currentConfig) + public function createInstallConfig(DeploymentConfig $deploymentConfig) { $installConfig = []; - if (!isset($currentConfig['install']['date'])) { - $installConfig = [InstallConfig::KEY_DATE => date('r')]; + if (!$deploymentConfig->get('install/date')) { + $installConfig = [ConfigOptionsList::INPUT_KEY_DATE => date('r')]; } return new ConfigData(ConfigFilePool::APP_CONFIG, 'install', $installConfig); } @@ -67,15 +68,13 @@ public function createInstallConfig(array $currentConfig) /** * Creates encryption key config data * @param array $data - * @param array $currentData + * @param DeploymentConfig $deploymentConfig * @return ConfigData + * @internal param array $currentData */ - public function createCryptConfig(array $data, array $currentData) + public function createCryptConfig(array $data, DeploymentConfig $deploymentConfig) { - $currentKey = false; - if (isset($currentData['crypt'][ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { - $currentKey = $currentData['crypt'][ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; - } + $currentKey = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY); $cryptData = []; if (isset($data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index e940dc6d2f2c0..301ae42b02c28 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -6,9 +6,10 @@ namespace Magento\Setup\Model; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\App\DeploymentConfig\Writer; -use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Setup\Model; class ConfigModel { @@ -27,37 +28,31 @@ class ConfigModel * * @var FilePermissions */ - // private $filePermissions; + private $filePermissions; /** - * @var \Magento\Framework\App\DeploymentConfig\Reader + * @var \Magento\Framework\App\DeploymentConfig */ - protected $reader; - - /** - * @var array - */ - protected $currentConfig; + protected $deploymentConfig; /** * Constructor * * @param ConfigOptionsListCollector $collector * @param Writer $writer - * @param Reader $reader - * param FilePermissions $filePermissions + * @param DeploymentConfig $deploymentConfig + * @param FilePermissions $filePermissions */ public function __construct( ConfigOptionsListCollector $collector, Writer $writer, - Reader $reader - // FilePermissions $filePermissions + DeploymentConfig $deploymentConfig, + FilePermissions $filePermissions ) { $this->collector = $collector; $this->writer = $writer; - $this->reader = $reader; - $this->currentConfig = $this->reader->loadConfig(); - // $this->filePermissions = $filePermissions; + $this->filePermissions = $filePermissions; + $this->deploymentConfig = $deploymentConfig; } /** @@ -75,7 +70,7 @@ public function getAvailableOptions() } foreach ($optionCollection as $option) { - $currentValue = $this->getConfigValueByPath($option->getConfigPath()); + $currentValue = $this->deploymentConfig->get($option->getConfigPath()); if ($currentValue !== null) { $option->setDefault(); } @@ -100,7 +95,7 @@ public function process($inputOptions) foreach ($options as $moduleName => $option) { - $configData = $option->createConfig($inputOptions, $this->currentConfig); + $configData = $option->createConfig($inputOptions, $this->deploymentConfig); foreach ($configData as $config) { if (!$config instanceof ConfigData) { @@ -159,34 +154,7 @@ public function validate(array $inputOptions) return $errors; } - - /** - * Gets config value by path - * - * @param string $path - * @return mixed - */ - public function getConfigValueByPath($path) - { - $currentConfig = $this->currentConfig; - $chunks = explode('/', $path); - if (!empty($chunks)) { - - $sizeOfPath = count($chunks); - for ($level = 0; $level < $sizeOfPath; $level++) { - if (isset($currentConfig[$chunks[$level]])) { - if ($level === $sizeOfPath-1) { - return $currentConfig[$chunks[$level]]; - } - - $currentConfig = $currentConfig[$chunks[$level]]; - } - } - } - - return null; - } - + /** * Check permissions of directories that are expected to be writable for installation * @@ -195,7 +163,7 @@ public function getConfigValueByPath($path) */ private function checkInstallationFilePermissions() { - $results = false; // pdltest $this->filePermissions->getMissingWritableDirectoriesForInstallation(); + $results = $this->filePermissions->getMissingWritableDirectoriesForInstallation(); if ($results) { $errorMsg = "Missing writing permissions to the following directories: '" . implode("' '", $results) . "'"; throw new \Exception($errorMsg); diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index eef55da878c54..e9b1ab2e06b3b 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -20,11 +20,13 @@ class ConfigOptionsList implements ConfigOptionsListInterface * Path to the values in the deployment config */ const CONFIG_PATH_INSTALL_DATE = 'install/date'; + const CONFIG_PATH_CRYPT_KEY = 'crypt/key'; /**#@-*/ /**#@+ * Input keys for the options */ + const INPUT_KEY_DATE = 'date'; const INPUT_KEY_CRYPT_KEY = 'key'; const INPUT_KEY_SESSION_SAVE = 'session_save'; const INPUT_KEY_DEFINITION_FORMAT = 'definition_format'; @@ -198,11 +200,11 @@ public function getOptions() /** * {@inheritdoc} */ - public function createConfig(array $data, array $currentConfig = []) + public function createConfig(array $data, DeploymentConfig $deploymentConfig) { $configData = []; - $configData[] = $this->configGenerator->createInstallConfig($currentConfig); - $configData[] = $this->configGenerator->createCryptConfig($data, $currentConfig); + $configData[] = $this->configGenerator->createInstallConfig($deploymentConfig); + $configData[] = $this->configGenerator->createCryptConfig($data, $deploymentConfig); $modulesConfig = $this->configGenerator->createModuleConfig(); if (isset($modulesConfig)) { $configData[] = $modulesConfig; diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php index b02a0a2b56de7..c4e61cdb5ef8c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php @@ -135,26 +135,6 @@ public function testProcess() $this->configModel->process([]); } - public function testGetConfigValueByPath() - { - $expectedValue = 'test'; - $path = 'test/path/to/value'; - $config = [ - 'test' => [ - 'path' => [ - 'to' => [ - 'value' => $expectedValue - ] - ] - ] - ]; - - $reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); - $reader->expects($this->once())->method('loadConfig')->will($this->returnValue($config)); - $configModel = new ConfigModel($this->collector, $this->writer, $reader); - $this->assertEquals($expectedValue, $configModel->getConfigValueByPath($path)); - } - /** * @expectedException \Exception * @expectedExceptionMessage In module : Fake_ModuleConfigOption::createConfig From 6ecde368dd7cd470531043b0a11bdf8215739247 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 25 Mar 2015 15:52:28 -0500 Subject: [PATCH 138/214] MAGETWO-35137: Add deployment configuration set command - fixed ConfigModel and test --- setup/src/Magento/Setup/Model/ConfigModel.php | 1 - .../Setup/Test/Unit/Model/ConfigModelTest.php | 21 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 301ae42b02c28..0a14df5821bf7 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -9,7 +9,6 @@ use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\App\DeploymentConfig\Writer; -use Magento\Setup\Model; class ConfigModel { diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php index c4e61cdb5ef8c..13e290f53e4d2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php @@ -27,15 +27,20 @@ class ConfigModelTest extends \PHPUnit_Framework_TestCase private $writer; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig\Reader + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig */ - private $reader; + private $deploymentConfig; /** * @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Framework\Config\Data\ConfigData */ private $configData; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\FilePermissions + */ + private $filePermissions; + /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Setup\ConfigOptionsList */ @@ -45,13 +50,19 @@ public function setUp() { $this->collector = $this->getMock('Magento\Setup\Model\ConfigOptionsListCollector', [], [], '', false); $this->writer = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); - $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->configOptionsList = $this->getMock('Magento\Backend\Setup\ConfigOptionsList', [], [], '', false); $this->configData = $this->getMock('Magento\Framework\Config\Data\ConfigData', [], [], '', false); + $this->filePermissions = $this->getMock('\Magento\Setup\Model\FilePermissions', [], [], '', false); - $this->reader->expects($this->once())->method('loadConfig')->will($this->returnValue([])); + $this->deploymentConfig->expects($this->any())->method('get'); - $this->configModel = new ConfigModel($this->collector, $this->writer, $this->reader); + $this->configModel = new ConfigModel( + $this->collector, + $this->writer, + $this->deploymentConfig, + $this->filePermissions + ); } public function testValidate() From a51a4ebc529e980d4b91f6f6b8415dd96f86c682 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Wed, 25 Mar 2015 15:53:37 -0500 Subject: [PATCH 139/214] MAGETWO-35135: Integrate config command - fix tests after merge --- setup/src/Magento/Setup/Model/Installer.php | 35 +++++++++++-------- .../Command/ConfigCreateCommandTest.php | 21 ----------- .../Setup/Test/Unit/Model/InstallerTest.php | 18 +++++----- 3 files changed, 29 insertions(+), 45 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index cba85ee14fda8..49a9380747669 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -11,6 +11,7 @@ use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\MaintenanceMode; +use Magento\Framework\App\Resource\Config; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\FilesystemException; use Magento\Framework\Math\Random; @@ -20,9 +21,6 @@ use Magento\Framework\Module\ModuleListInterface; use Magento\Framework\Shell; use Magento\Framework\Shell\CommandRenderer; -use Magento\Setup\Module\ConnectionFactory; -use Magento\Setup\Module\Setup; -use Magento\Store\Model\Store; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\InstallDataInterface; @@ -567,7 +565,14 @@ public function checkApplicationFilePermissions() public function installDeploymentConfig($data) { $this->checkInstallationFilePermissions(); - $this->setupConfigModel->process(is_array($data) ? $data : $data->getArrayCopy()); + $userData = is_array($data) ? $data : $data->getArrayCopy(); + + // TODO: remove this when moving install command to symfony + if (!isset($userData['db_pass'])) { + $userData['db_pass'] = ''; + } + + $this->setupConfigModel->process($userData); // reset object manager now that there is a deployment config $this->objectManagerProvider->reset(); @@ -1164,8 +1169,9 @@ public function cleanupDb() { // stops cleanup if app/etc/config.php does not exist if ($this->deploymentConfig->isAvailable()) { - $dbConfig = new DbConfig($this->deploymentConfig->getConfigData(ModuleLoader::CONFIG_KEY)); - $config = $dbConfig->getConnection(\Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION); + $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_KEY); + $config = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION]; + if ($config) { try { $connection = $this->connectionFactory->create($config); @@ -1255,17 +1261,16 @@ private function assertDeploymentConfigExists() */ private function assertDbAccessible() { - $segment = $this->deploymentConfig->getConfigData(ModuleLoader::CONFIG_KEY); - $dbConfig = new DbConfig($segment); - $config = $dbConfig->getConnection(\Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION); + $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_KEY); + $connectionConfig = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION]; $this->checkDatabaseConnection( - $config[ModuleLoader::KEY_NAME], - $config[ModuleLoader::KEY_HOST], - $config[ModuleLoader::KEY_USER], - $config[ModuleLoader::KEY_PASS] + $connectionConfig[ConfigOptionsList::KEY_NAME], + $connectionConfig[ConfigOptionsList::KEY_HOST], + $connectionConfig[ConfigOptionsList::KEY_USER], + $connectionConfig[ConfigOptionsList::KEY_PASS] ); - if (isset($config[ModuleLoader::KEY_PREFIX])) { - $this->checkDatabaseTablePrefix($config[ModuleLoader::KEY_PREFIX]); + if (isset($config[ConfigOptionsList::KEY_PREFIX])) { + $this->checkDatabaseTablePrefix($config[ConfigOptionsList::KEY_PREFIX]); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php index e6bf720829800..c30c39aa52114 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php @@ -111,25 +111,4 @@ public function testInitializeFailedValidation() $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $command->initialize($this->input, $this->output); } - - /** - * @expectedException \Exception - * @expectedExceptionMessage Deployment configuration already exists - */ - public function testDeploymentConfigExists() - { - $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(true); - $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); - $optionsSet = [ - $option - ]; - - $this->configModel - ->expects($this->once()) - ->method('getAvailableOptions') - ->will($this->returnValue($optionsSet)); - - $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); - $command->initialize($this->input, $this->output); - } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index bca280a85bd11..ec593bc991562 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -119,19 +119,19 @@ class InstallerTest extends \PHPUnit_Framework_TestCase * @var array */ private static $dbConfig = [ - DbConfig::KEY_PREFIX => '', + ConfigOptionsList::KEY_PREFIX => '', 'connection' => [ 'default' => [ - DbConfig::KEY_HOST => '127.0.0.1', - DbConfig::KEY_NAME => 'magento', - DbConfig::KEY_USER => 'magento', - DbConfig::KEY_PASS => '', + ConfigOptionsList::KEY_HOST => '127.0.0.1', + ConfigOptionsList::KEY_NAME => 'magento', + ConfigOptionsList::KEY_USER => 'magento', + ConfigOptionsList::KEY_PASS => '', ], ], ]; /** - * @var Magento\Framework\Model\Resource\Db\Context|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Model\Resource\Db\Context|\PHPUnit_Framework_MockObject_MockObject */ private $contextMock; @@ -353,7 +353,7 @@ public function testUpdateModulesSequence() $newObject = $this->createObject(false, false); $this->configReader->expects($this->once())->method('load') ->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0] ]); - $this->configWriter->expects($this->once())->method('update')->with($this->deploymentConfig); + $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules); $this->logger->expects($this->at(0))->method('log')->with('File system cleanup:'); $this->logger->expects($this->at(1))->method('log') ->with('The directory \'/var\' doesn\'t exist - skipping cleanup'); @@ -405,8 +405,8 @@ public function testCleanupDb() { $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->config->expects($this->once()) - ->method('getSegment') - ->with(DbConfig::CONFIG_KEY) + ->method('getConfigData') + ->with(ConfigOptionsList::CONFIG_KEY) ->willReturn(self::$dbConfig); $this->connection->expects($this->at(0))->method('quoteIdentifier')->with('magento')->willReturn('`magento`'); $this->connection->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); From 2d62f9315c54ff93d2923d503ed7dcd1e3e5f2c0 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 25 Mar 2015 16:09:06 -0500 Subject: [PATCH 140/214] MAGETWO-35137: Add deployment configuration set command - fixed DeploymentConfig::getConfigData --- lib/internal/Magento/Framework/App/DeploymentConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig.php index 30052fd3b54bd..0f6bf7cdb133b 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig.php @@ -98,7 +98,7 @@ public function getConfigData($key = null) { $this->load(); if (isset($this->data[$key])) { - $this->data[$key]; + return $this->data[$key]; } return $this->data; From 34253dfa7fa298a4c74d5fde687d1684a0a0d180 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Wed, 25 Mar 2015 16:38:37 -0500 Subject: [PATCH 141/214] MAGETWO-35138: Add Interactive Confirmation to config update - Implemented the feature. --- .../Setup/Console/Command/ConfigCreateCommand.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php index c1204648af195..856d1b3d6fabd 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php @@ -77,7 +77,19 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $inputOptions = $input->getOptions(); - + $optionCollection = $this->configModel->getAvailableOptions(); + foreach ($optionCollection as $option) { + $currentValue = $this->deploymentConfig->get($option->getConfigPath()); + if (($currentValue !== null) && ($inputOptions[$option->getName()] !== null)) { + $dialog = $this->getHelperSet()->get('dialog'); + if (!$dialog->askConfirmation( + $output, + 'Overwrite the existing configuration for ' . $option->getName() . '?' + )) { + $inputOptions[$option->getName()] = null; + } + } + } $inputOptions = array_filter($inputOptions, function ($value) { return $value !== null; From 4462d9fac92925e534d2cec401b2cd4c48f8a2d1 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 25 Mar 2015 17:43:50 -0500 Subject: [PATCH 142/214] MAGETWO-35137: Add deployment configuration set command - fixed tests --- .../Backend/Test/Unit/Setup/ConfigOptionsListTest.php | 8 +++++++- setup/src/Magento/Setup/Model/ConfigGenerator.php | 10 ++++------ .../Setup/Test/Unit/Model/ConfigOptionsListTest.php | 10 ++++++++-- .../Magento/Setup/Test/Unit/Model/InstallerTest.php | 2 -- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php index d2a7c36e84954..b3b5023ed542f 100644 --- a/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php +++ b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php @@ -15,9 +15,15 @@ class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase */ private $object; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig + */ + private $deploymentConfig; + protected function setUp() { $this->object = new ConfigOptionsList(); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); } public function testGetOptions() @@ -32,7 +38,7 @@ public function testGetOptions() public function testCreateConfig() { $options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; - $actualConfig = $this->object->createConfig($options); + $actualConfig = $this->object->createConfig($options, $this->deploymentConfig); $expectedData = [ ['file' => ConfigFilePool::APP_CONFIG, 'segment' => 'backend', 'data' => ['frontName' => 'admin']] ]; diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 22bc44e46cbb6..aabc0c5ed2256 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -52,14 +52,13 @@ public function __construct(Random $random, Loader $moduleLoader, DeploymentConf /** * Creates install segment config data * - * @param DeploymentConfig $deploymentConfig * @return ConfigData * @internal param array $currentConfig */ - public function createInstallConfig(DeploymentConfig $deploymentConfig) + public function createInstallConfig() { $installConfig = []; - if (!$deploymentConfig->get('install/date')) { + if (!$this->deploymentConfig->get('install/date')) { $installConfig = [ConfigOptionsList::INPUT_KEY_DATE => date('r')]; } return new ConfigData(ConfigFilePool::APP_CONFIG, 'install', $installConfig); @@ -68,13 +67,12 @@ public function createInstallConfig(DeploymentConfig $deploymentConfig) /** * Creates encryption key config data * @param array $data - * @param DeploymentConfig $deploymentConfig * @return ConfigData * @internal param array $currentData */ - public function createCryptConfig(array $data, DeploymentConfig $deploymentConfig) + public function createCryptConfig(array $data) { - $currentKey = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY); + $currentKey = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY); $cryptData = []; if (isset($data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php index 5f0d2bb78e6fb..df6d6205b3942 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php @@ -20,9 +20,15 @@ class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase */ private $generator; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig + */ + private $deploymentConfig; + protected function setUp() { $this->generator = $this->getMock('Magento\Setup\Model\ConfigGenerator', [], [], '', false); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->object = new ConfigOptionsList($this->generator); } @@ -62,7 +68,7 @@ public function testCreateOptions() $this->generator->expects($this->once())->method('createDefinitionsConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); - $configData = $this->object->createConfig([]); + $configData = $this->object->createConfig([], $this->deploymentConfig); $this->assertEquals(7, count($configData)); } @@ -76,7 +82,7 @@ public function testCreateOptionsWithOptionalNull() $this->generator->expects($this->once())->method('createDefinitionsConfig')->willReturn(null); $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); - $configData = $this->object->createConfig([]); + $configData = $this->object->createConfig([], $this->deploymentConfig); $this->assertEquals(5, count($configData)); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index ec593bc991562..c0e510ed42796 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -347,8 +347,6 @@ public function testUpdateModulesSequence() ]; $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true); - $this->deploymentConfigFactory->expects($this->once())->method('create')->with($expectedModules) - ->willReturn($this->deploymentConfig); $newObject = $this->createObject(false, false); $this->configReader->expects($this->once())->method('load') From 3ababd8f554f85c9b51ba93910d7d963b6e93b2c Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Thu, 26 Mar 2015 10:45:02 -0500 Subject: [PATCH 143/214] MAGETWO-35137: Add deployment configuration set command - fixed comment and used constant instead string --- setup/src/Magento/Setup/Model/ConfigGenerator.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index aabc0c5ed2256..14aa5fb75866b 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -53,12 +53,11 @@ public function __construct(Random $random, Loader $moduleLoader, DeploymentConf * Creates install segment config data * * @return ConfigData - * @internal param array $currentConfig */ public function createInstallConfig() { $installConfig = []; - if (!$this->deploymentConfig->get('install/date')) { + if (!$this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)) { $installConfig = [ConfigOptionsList::INPUT_KEY_DATE => date('r')]; } return new ConfigData(ConfigFilePool::APP_CONFIG, 'install', $installConfig); @@ -68,7 +67,6 @@ public function createInstallConfig() * Creates encryption key config data * @param array $data * @return ConfigData - * @internal param array $currentData */ public function createCryptConfig(array $data) { From 6b392cf9f3bdd3a07e48b24e6d77edb99ceaee98 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 26 Mar 2015 10:48:02 -0500 Subject: [PATCH 144/214] MAGETWO-35136: Delete Segments - fixing moduleList for installation --- .../Model/Config/Source/Storage/Media/Database.php | 14 +++++++------- .../Config/Source/Storage/Media/DatabaseTest.php | 13 +++++++------ .../lib/Magento/Mtf/App/State/AbstractState.php | 4 +++- .../Controller/Adminhtml/Cache/MassActionTest.php | 2 +- .../Framework/App/DeploymentConfig/Writer.php | 12 ------------ .../Magento/Framework/Module/ModuleList.php | 2 +- setup/src/Magento/Setup/Model/Installer.php | 6 +++--- 7 files changed, 22 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php b/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php index 66fc5d30cd075..cea0e51674976 100644 --- a/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php +++ b/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php @@ -9,22 +9,22 @@ */ namespace Magento\MediaStorage\Model\Config\Source\Storage\Media; -use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Framework\App\DeploymentConfig; use Magento\Setup\Model\ConfigOptionsList; class Database implements \Magento\Framework\Option\ArrayInterface { /** - * @var Reader + * @var DeploymentConfig */ - protected $reader; + protected $deploymentConfig; /** - * @param Reader $reader + * @param DeploymentConfig $deploymentConfig */ - public function __construct(Reader $reader) + public function __construct(DeploymentConfig $deploymentConfig) { - $this->reader = $reader; + $this->deploymentConfig = $deploymentConfig; } /** @@ -35,7 +35,7 @@ public function __construct(Reader $reader) public function toOptionArray() { $resourceOptions = []; - $resourceConfig = $this->reader->getConfigData(ConfigOptionsList::KEY_RESOURCE); + $resourceConfig = $this->deploymentConfig->get(ConfigOptionsList::KEY_RESOURCE); if (null !== $resourceConfig) { foreach (array_keys($resourceConfig) as $resourceName) { $resourceOptions[] = ['value' => $resourceName, 'label' => $resourceName]; diff --git a/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php b/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php index 3b3226dc6026c..01d16182002ed 100644 --- a/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php +++ b/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php @@ -9,6 +9,7 @@ namespace Magento\MediaStorage\Test\Unit\Model\Config\Source\Storage\Media; use Magento\Setup\Model\ConfigOptionsList; +use Magento\MediaStorage\Model\Config\Source\Storage\Media\Database; /** * Class DatabaseTest @@ -21,17 +22,17 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase protected $mediaDatabase; /** - * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */ - protected $readerMock; + protected $deploymentConfig; protected function setUp() { - $this->readerMock = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); - $this->readerMock->expects( + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $this->deploymentConfig->expects( $this->any() )->method( - 'getConfigData' + 'get' )->with( ConfigOptionsList::KEY_RESOURCE )->will( @@ -42,7 +43,7 @@ protected function setUp() ] ) ); - $this->mediaDatabase = new \Magento\MediaStorage\Model\Config\Source\Storage\Media\Database($this->readerMock); + $this->mediaDatabase = new Database($this->deploymentConfig); } /** diff --git a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php index 06cd15d819529..8463257448c9d 100644 --- a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php +++ b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php @@ -43,7 +43,9 @@ public function clearInstance() ->get('Magento\Framework\Filesystem\DirectoryList'); $reader = new \Magento\Framework\App\DeploymentConfig\Reader($dirList); - $dbConfig = $reader->getConfigData(ConfigOptionsList::CONFIG_KEY); + $deploymentConfig = new \Magento\Framework\App\DeploymentConfig($reader); + $dbConfig = $deploymentConfig->get(ConfigOptionsList::CONFIG_KEY); + $dbInfo = $dbConfig['connection']['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; diff --git a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php index f24fbed165abc..f3df444141a8a 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php @@ -12,7 +12,7 @@ class MassActionTest extends \Magento\Backend\Utility\Controller { /** - * Configuratio of cache types + * Configuration of cache types * * @var CacheConfig */ diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index bb61b598930c1..d07a68632ac8e 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -98,16 +98,4 @@ public function saveConfig(array $data) } } } - - /** - * Persists the data into file - * - * @param array $data - * @return void - */ - private function write($data) - { - $contents = $this->formatter->format($data); - $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($this->reader->getFile(), $contents); - } } diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php index c511fdb880f5b..8ff6b0bf53206 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/ModuleList.php @@ -139,7 +139,7 @@ public function isModuleInfoAvailable() */ private function loadConfigData() { - if (null === $this->configData) { + if (null === $this->configData && ($this->config->isAvailable())) { $this->configData = $this->config->getConfigData(ModuleList\DeploymentConfig::KEY_MODULES); } } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 49a9380747669..c07dbf155ebf4 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -324,7 +324,7 @@ public function install($request) $script[] = ['Post installation file permissions check...', 'checkApplicationFilePermissions', []]; $estimatedModules = $this->createModulesConfig($request); - $total = count($script) + 3 * count(array_filter($estimatedModules->getData())); + $total = count($script) + 3 * count(array_filter($estimatedModules)); $this->progress = new Installer\Progress($total, 0); $this->log->log('Starting Magento installation:'); @@ -346,7 +346,7 @@ public function install($request) * Creates modules deployment configuration segment * * @param \ArrayObject|array $request - * @return DeploymentConfig + * @return array * @throws \LogicException */ private function createModulesConfig($request) @@ -363,7 +363,7 @@ private function createModulesConfig($request) $key = array_search($module, $toEnable); $result[$module] = false !== $key; } - return $this->deploymentConfigFactory->create($result); + return $result; } /** From ab95cd159b7e2ff922f266a105142ff3a4f86971 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 26 Mar 2015 10:53:01 -0500 Subject: [PATCH 145/214] MAGETWO-35497: Remove Old install-configuration Tool - removed the command - removed unused methods - removed options mapper --- .../Test/Legacy/_files/obsolete_classes.php | 1 + ...CreateCommand.php => ConfigSetCommand.php} | 2 +- .../Setup/Controller/ConsoleController.php | 44 ++----- .../src/Magento/Setup/Controller/Install.php | 20 +-- .../Magento/Setup/Model/ConfigGenerator.php | 14 +-- .../Magento/Setup/Model/ConfigOptionsList.php | 8 +- .../Setup/Model/DeploymentConfigMapper.php | 48 -------- setup/src/Magento/Setup/Model/Installer.php | 116 ------------------ ...mmandTest.php => ConfigSetCommandTest.php} | 8 +- .../Unit/Controller/ConsoleControllerTest.php | 7 -- .../Test/Unit/Model/ConfigGeneratorTest.php | 2 +- .../Setup/Test/Unit/Model/InstallerTest.php | 13 +- 12 files changed, 47 insertions(+), 236 deletions(-) rename setup/src/Magento/Setup/Console/Command/{ConfigCreateCommand.php => ConfigSetCommand.php} (98%) delete mode 100644 setup/src/Magento/Setup/Model/DeploymentConfigMapper.php rename setup/src/Magento/Setup/Test/Unit/Console/Command/{ConfigCreateCommandTest.php => ConfigSetCommandTest.php} (92%) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 016f703823479..1cb37c7eb7d5b 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3123,4 +3123,5 @@ ['Magento\Framework\App\DeploymentConfig\ResourceConfig'], ['Magento\Framework\App\DeploymentConfig\SessionConfig'], ['Magento\Framework\App\DeploymentConfig\CacheConfig'], + ['Magento\Setup\Model\DeploymentConfigMapper'], ]; diff --git a/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php similarity index 98% rename from setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php rename to setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 856d1b3d6fabd..b402295095a37 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigCreateCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -13,7 +13,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ConfigCreateCommand extends Command +class ConfigSetCommand extends Command { /** * @var ConfigModel diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 58bf6d31f9166..6dab83a6da3b7 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -7,10 +7,11 @@ namespace Magento\Setup\Controller; use Composer\Package\Version\VersionParser; +use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; use Magento\Framework\App\MaintenanceMode; use Magento\Setup\Model\AdminAccount; +use Magento\Setup\Model\ConfigOptionsList as SetupConfigOptionsList; use Magento\Setup\Model\ConsoleLogger; -use Magento\Setup\Model\DeploymentConfigMapper; use Magento\Setup\Model\Installer; use Magento\Setup\Model\InstallerFactory; use Magento\Setup\Model\Lists; @@ -60,7 +61,6 @@ class ConsoleController extends AbstractActionController private static $actions = [ self::CMD_HELP => 'help', self::CMD_INSTALL => 'install', - self::CMD_INSTALL_CONFIG => 'installDeploymentConfig', self::CMD_INSTALL_SCHEMA => 'installSchema', self::CMD_INSTALL_DATA => 'installData', self::CMD_INSTALL_USER_CONFIG => 'installUserConfig', @@ -80,7 +80,6 @@ class ConsoleController extends AbstractActionController */ private static $helpOptions = [ self::CMD_INSTALL, - self::CMD_INSTALL_CONFIG, self::CMD_INSTALL_SCHEMA, self::CMD_INSTALL_DATA, self::CMD_INSTALL_USER_CONFIG, @@ -182,16 +181,16 @@ public static function getCommandUsage() */ private static function getCliConfig() { - $deployConfig = '--' . DeploymentConfigMapper::KEY_DB_HOST . '=' - . ' --' . DeploymentConfigMapper::KEY_DB_NAME . '=' - . ' --' . DeploymentConfigMapper::KEY_DB_USER . '=' - . ' --' . DeploymentConfigMapper::KEY_BACKEND_FRONTNAME . '=' - . ' [--' . DeploymentConfigMapper::KEY_DB_PASS . '=]' - . ' [--' . DeploymentConfigMapper::KEY_DB_PREFIX . '=]' - . ' [--' . DeploymentConfigMapper::KEY_DB_MODEL . '=]' - . ' [--' . DeploymentConfigMapper::KEY_DB_INIT_STATEMENTS . '=]' - . ' [--' . DeploymentConfigMapper::KEY_SESSION_SAVE . '=]' - . ' [--' . DeploymentConfigMapper::KEY_ENCRYPTION_KEY . '=]' + $deployConfig = '--' . SetupConfigOptionsList::INPUT_KEY_DB_HOST . '=' + . ' --' . SetupConfigOptionsList::INPUT_KEY_DB_NAME . '=' + . ' --' . SetupConfigOptionsList::INPUT_KEY_DB_USER . '=' + . ' --' . BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME . '=' + . ' [--' . SetupConfigOptionsList::INPUT_KEY_DB_PASS . '=]' + . ' [--' . SetupConfigOptionsList::INPUT_KEY_DB_PREFIX . '=]' + . ' [--' . SetupConfigOptionsList::INPUT_KEY_DB_MODEL . '=]' + . ' [--' . SetupConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS . '=]' + . ' [--' . SetupConfigOptionsList::INPUT_KEY_SESSION_SAVE . '=]' + . ' [--' . SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY . '=]' . ' [--' . Installer::ENABLE_MODULES . '=]' . ' [--' . Installer::DISABLE_MODULES . '=]'; $userConfig = '[--' . UserConfig::KEY_BASE_URL . '=]' @@ -239,12 +238,6 @@ private static function getCliConfig() 'usage_short' => self::CMD_UNINSTALL, 'usage_desc' => 'Uninstall Magento application', ], - self::CMD_INSTALL_CONFIG => [ - 'route' => self::CMD_INSTALL_CONFIG . ' ' . $deployConfig, - 'usage' => $deployConfig, - 'usage_short' => self::CMD_INSTALL_CONFIG . ' ', - 'usage_desc' => 'Install deployment configuration', - ], self::CMD_INSTALL_SCHEMA => [ 'route' => self::CMD_INSTALL_SCHEMA, 'usage' => '', @@ -367,19 +360,6 @@ public function installAction() $this->installer->install($request->getParams()); } - /** - * Creates the config.php file - * - * @return void - */ - public function installDeploymentConfigAction() - { - /** @var \Zend\Console\Request $request */ - $request = $this->getRequest(); - $this->installer->checkInstallationFilePermissions(); - $this->installer->installDeploymentConfig($request->getParams()); - } - /** * Installs and updates database schema * diff --git a/setup/src/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php index 6355415f0dee4..45211914e8ea2 100644 --- a/setup/src/Magento/Setup/Controller/Install.php +++ b/setup/src/Magento/Setup/Controller/Install.php @@ -7,8 +7,8 @@ namespace Magento\Setup\Controller; use Magento\Setup\Model\AdminAccount; -use Magento\Setup\Model\ConfigOptionsList; -use Magento\Setup\Model\DeploymentConfigMapper; +use Magento\Setup\Model\ConfigOptionsList as SetupConfigOptionsList; +use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; use Magento\Setup\Model\Installer; use Magento\Setup\Model\Installer\ProgressFactory; use Magento\Setup\Model\InstallerFactory; @@ -86,7 +86,7 @@ public function startAction() $this->installer->install($data); $json->setVariable( 'key', - $this->installer->getInstallInfo()[ConfigOptionsList::KEY_ENCRYPTION_KEY] + $this->installer->getInstallInfo()[SetupConfigOptionsList::KEY_ENCRYPTION_KEY] ); $json->setVariable('success', true); $json->setVariable('messages', $this->installer->getInstallInfo()[Installer::INFO_MESSAGE]); @@ -128,16 +128,16 @@ private function importDeploymentConfigForm() { $source = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); $result = []; - $result[DeploymentConfigMapper::KEY_DB_HOST] = isset($source['db']['host']) ? $source['db']['host'] : ''; - $result[DeploymentConfigMapper::KEY_DB_NAME] = isset($source['db']['name']) ? $source['db']['name'] : ''; - $result[DeploymentConfigMapper::KEY_DB_USER] = isset($source['db']['user']) ? $source['db']['user'] :''; - $result[DeploymentConfigMapper::KEY_DB_PASS] = + $result[SetupConfigOptionsList::INPUT_KEY_DB_HOST] = isset($source['db']['host']) ? $source['db']['host'] : ''; + $result[SetupConfigOptionsList::INPUT_KEY_DB_NAME] = isset($source['db']['name']) ? $source['db']['name'] : ''; + $result[SetupConfigOptionsList::INPUT_KEY_DB_USER] = isset($source['db']['user']) ? $source['db']['user'] :''; + $result[SetupConfigOptionsList::INPUT_KEY_DB_PASS] = isset($source['db']['password']) ? $source['db']['password'] : ''; - $result[DeploymentConfigMapper::KEY_DB_PREFIX] = + $result[SetupConfigOptionsList::INPUT_KEY_DB_PREFIX] = isset($source['db']['tablePrefix']) ? $source['db']['tablePrefix'] : ''; - $result[DeploymentConfigMapper::KEY_BACKEND_FRONTNAME] = isset($source['config']['address']['admin']) + $result[BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME] = isset($source['config']['address']['admin']) ? $source['config']['address']['admin'] : ''; - $result[DeploymentConfigMapper::KEY_ENCRYPTION_KEY] = isset($source['config']['encrypt']['key']) + $result[SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY] = isset($source['config']['encrypt']['key']) ? $source['config']['encrypt']['key'] : ''; $result[Installer::ENABLE_MODULES] = isset($source['store']['selectedModules']) ? implode(',', $source['store']['selectedModules']) : ''; diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 14aa5fb75866b..478970344eaba 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -21,7 +21,7 @@ class ConfigGenerator * * @var array */ - public static $paramMap = [ + private static $paramMap = [ ConfigOptionsList::INPUT_KEY_DB_HOST => ConfigOptionsList::KEY_HOST, ConfigOptionsList::INPUT_KEY_DB_NAME => ConfigOptionsList::KEY_NAME, ConfigOptionsList::INPUT_KEY_DB_USER => ConfigOptionsList::KEY_USER, @@ -30,7 +30,7 @@ class ConfigGenerator ConfigOptionsList::INPUT_KEY_DB_MODEL => ConfigOptionsList::KEY_MODEL, ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS => ConfigOptionsList::KEY_INIT_STATEMENTS, ConfigOptionsList::INPUT_KEY_ACTIVE => ConfigOptionsList::KEY_ACTIVE, - ConfigOptionsList::INPUT_KEY_CRYPT_KEY => ConfigOptionsList::KEY_ENCRYPTION_KEY, + ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => ConfigOptionsList::KEY_ENCRYPTION_KEY, ConfigOptionsList::INPUT_KEY_SESSION_SAVE => ConfigOptionsList::KEY_SAVE, ConfigOptionsList::INPUT_KEY_RESOURCE => ConfigOptionsList::KEY_RESOURCE, ]; @@ -73,17 +73,17 @@ public function createCryptConfig(array $data) $currentKey = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY); $cryptData = []; - if (isset($data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY])) { + if (isset($data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY])) { if ($currentKey) { - $key = $currentKey . "\n" . $data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; + $key = $currentKey . "\n" . $data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]; } else { - $key = $data[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]; + $key = $data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]; } - $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = $key; + $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]] = $key; } else { if (!$currentKey) { - $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]] = + $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]] = md5($this->random->getRandomString(10)); } } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index e9b1ab2e06b3b..7d49ac89e8cd0 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -27,7 +27,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface * Input keys for the options */ const INPUT_KEY_DATE = 'date'; - const INPUT_KEY_CRYPT_KEY = 'key'; + const INPUT_KEY_ENCRYPTION_KEY = 'key'; const INPUT_KEY_SESSION_SAVE = 'session_save'; const INPUT_KEY_DEFINITION_FORMAT = 'definition_format'; const INPUT_KEY_DB_HOST = 'db_host'; @@ -126,7 +126,7 @@ public function getOptions() { return [ new TextConfigOption( - self::INPUT_KEY_CRYPT_KEY, + self::INPUT_KEY_ENCRYPTION_KEY, TextConfigOption::FRONTEND_WIZARD_TEXT, 'crypt/key', 'Encryption key' @@ -226,8 +226,8 @@ public function validate(array $options) { $errors = []; - if (isset($options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) - && !$options[ConfigOptionsList::INPUT_KEY_CRYPT_KEY]) { + if (isset($options[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]) + && !$options[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]) { $errors[] = 'Invalid encryption key.'; } diff --git a/setup/src/Magento/Setup/Model/DeploymentConfigMapper.php b/setup/src/Magento/Setup/Model/DeploymentConfigMapper.php deleted file mode 100644 index 3a586c65cc0de..0000000000000 --- a/setup/src/Magento/Setup/Model/DeploymentConfigMapper.php +++ /dev/null @@ -1,48 +0,0 @@ - SetupConfig::KEY_DATE, - self::KEY_DB_HOST => SetupConfig::KEY_HOST, - self::KEY_DB_NAME => SetupConfig::KEY_NAME, - self::KEY_DB_USER => SetupConfig::KEY_USER, - self::KEY_DB_PASS => SetupConfig::KEY_PASS, - self::KEY_DB_PREFIX => SetupConfig::KEY_PREFIX, - self::KEY_DB_MODEL => SetupConfig::KEY_MODEL, - self::KEY_DB_INIT_STATEMENTS => SetupConfig::KEY_INIT_STATEMENTS, - self::KEY_SESSION_SAVE => SetupConfig::KEY_SAVE, - self::KEY_BACKEND_FRONTNAME => BackendConfig::KEY_FRONTNAME, - self::KEY_ENCRYPTION_KEY => SetupConfig::KEY_ENCRYPTION_KEY, - ]; -} diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index c07dbf155ebf4..87fca094a49ee 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -366,122 +366,6 @@ private function createModulesConfig($request) return $result; } - /** - * Creates backend deployment configuration segment - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - * @throws \InvalidArgumentException - */ - private function createBackendConfig($data) - { - $key = DeploymentConfigMapper::KEY_BACKEND_FRONTNAME; - if (empty($data[$key])) { - throw new \InvalidArgumentException("Missing value for: '{$key}'"); - } - return new BackendConfig([DeploymentConfigMapper::$paramMap[$key] => $data[$key]]); - } - - /** - * Creates encrypt deployment configuration segment - * No new encryption key will be added if there is an existing deployment config file unless user provides one. - * Old encryption keys will persist. - * A new encryption key will be generated if there is no existing deployment config file. - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - */ - private function createEncryptConfig($data) - { - $key = ''; - if (isset($data[DeploymentConfigMapper::KEY_ENCRYPTION_KEY])) { - $key = $data[DeploymentConfigMapper::KEY_ENCRYPTION_KEY]; - } - // retrieve old encryption keys - if ($this->deploymentConfig->isAvailable()) { - $encryptInfo = $this->deploymentConfig->getSegment(EncryptConfig::CONFIG_KEY); - $oldKeys = $encryptInfo[EncryptConfig::KEY_ENCRYPTION_KEY]; - $key = empty($key) ? $oldKeys : $oldKeys . "\n" . $key; - } else if (empty($key)) { - $key = md5($this->random->getRandomString(10)); - } - $cryptConfigData = - [DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_ENCRYPTION_KEY] => $key]; - - // find the latest key to display - $keys = explode("\n", $key); - $this->installInfo[EncryptConfig::KEY_ENCRYPTION_KEY] = array_pop($keys); - return new EncryptConfig($cryptConfigData); - } - - /** - * Creates db deployment configuration segment - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - * @throws \InvalidArgumentException - */ - private function createDbConfig($data) - { - $connection = []; - $required = [ - DeploymentConfigMapper::KEY_DB_HOST, - DeploymentConfigMapper::KEY_DB_NAME, - DeploymentConfigMapper::KEY_DB_USER, - ]; - foreach ($required as $key) { - if (!isset($data[$key])) { - throw new \InvalidArgumentException("Missing value: {$key}"); - } - $connection[DeploymentConfigMapper::$paramMap[$key]] = $data[$key]; - } - $optional = [ - DeploymentConfigMapper::KEY_DB_INIT_STATEMENTS, - DeploymentConfigMapper::KEY_DB_MODEL, - DeploymentConfigMapper::KEY_DB_PASS, - ]; - foreach ($optional as $key) { - $connection[DeploymentConfigMapper::$paramMap[$key]] = isset($data[$key]) ? $data[$key] : null; - } - $prefixKey = DeploymentConfigMapper::KEY_DB_PREFIX; - $config = [ - DeploymentConfigMapper::$paramMap[$prefixKey] => isset($data[$prefixKey]) ? $data[$prefixKey] : null, - 'connection' => ['default' => $connection], - ]; - return new DbConfig($config); - } - - /** - * Creates session deployment configuration segment - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - */ - private function createSessionConfig($data) - { - $sessionConfigData = [ - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_SESSION_SAVE] => - isset($data[DeploymentConfigMapper::KEY_SESSION_SAVE]) ? - $data[DeploymentConfigMapper::KEY_SESSION_SAVE] : null - ]; - return new SessionConfig($sessionConfigData); - } - - /** - * Creates install deployment configuration segment - * - * @param \ArrayObject|array $data - * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - */ - private function createInstallConfig($data) - { - $installConfigData = [ - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DATE] => - $data[DeploymentConfigMapper::KEY_DATE] - ]; - return new InstallConfig($installConfigData); - } - /** * Determines list of modules from request based on list of all modules * diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php similarity index 92% rename from setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php rename to setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index c30c39aa52114..d923445854b90 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigCreateCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -8,11 +8,11 @@ use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Module\ModuleList; -use Magento\Setup\Console\Command\ConfigCreateCommand; +use Magento\Setup\Console\Command\ConfigSetCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ConfigCreateCommandTest extends \PHPUnit_Framework_TestCase +class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ConfigModel @@ -77,7 +77,7 @@ public function testInitialize() ->with('No module configuration is available, so all modules are enabled.'); $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); + $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $command->initialize($this->input, $this->output); } @@ -108,7 +108,7 @@ public function testInitializeFailedValidation() ->will($this->returnValue($optionsSet)); $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $command = new ConfigCreateCommand($this->configModel, $this->moduleList, $this->deploymentConfig); + $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $command->initialize($this->input, $this->output); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php index 9829a32e94d62..372292f499f4e 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php @@ -146,13 +146,6 @@ public function testInstallAction() $this->controller->installAction(); } - public function testInstallDeploymentConfigAction() - { - $this->installer->expects($this->once())->method('checkInstallationFilePermissions'); - $this->installer->expects($this->once())->method('installDeploymentConfig')->with($this->parameters); - $this->controller->installDeploymentConfigAction(); - } - public function testInstallSchemaAction() { $this->installer->expects($this->once())->method('installSchema'); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 572ba86173de3..43314629408cc 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -42,7 +42,7 @@ public function testCreateInstallConfig() public function testCreateCryptConfigWithInput() { - $testData = [ConfigOptionsList::INPUT_KEY_CRYPT_KEY => 'some-test_key']; + $testData = [ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key']; $returnValue = $this->configGeneratorObject->createCryptConfig($testData, []); $this->assertEquals('crypt', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index c0e510ed42796..698cd25ff3538 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -6,8 +6,9 @@ namespace Magento\Setup\Test\Unit\Model; +use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; +use Magento\Setup\Model\ConfigOptionsList as SetupConfigOptionsList; use \Magento\Setup\Model\Installer; -use \Magento\Setup\Model\DeploymentConfigMapper; use Magento\Setup\Model\ConfigOptionsList; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; @@ -221,11 +222,11 @@ private function createObject($connectionFactory = false, $objectManagerProvider public function testInstall() { $request = [ - DeploymentConfigMapper::KEY_DB_HOST => '127.0.0.1', - DeploymentConfigMapper::KEY_DB_NAME => 'magento', - DeploymentConfigMapper::KEY_DB_USER => 'magento', - DeploymentConfigMapper::KEY_ENCRYPTION_KEY => 'encryption_key', - DeploymentConfigMapper::KEY_BACKEND_FRONTNAME => 'backend', + SetupConfigOptionsList::INPUT_KEY_DB_HOST => '127.0.0.1', + SetupConfigOptionsList::INPUT_KEY_DB_NAME => 'magento', + SetupConfigOptionsList::INPUT_KEY_DB_USER => 'magento', + SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', + BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', ]; $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true); $this->config->expects($this->any())->method('getSegment')->will($this->returnValueMap([ From 2ed2fdcc15c22acb7cbc2d0b30fb93aa7ab6f8a1 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Thu, 26 Mar 2015 11:39:59 -0500 Subject: [PATCH 146/214] MAGETWO-35137: Add deployment configuration set command - fixed static test and changes according to CR --- .../Magento/Framework/Setup/ConfigOptionsListInterface.php | 1 + .../Magento/Framework/Setup/Option/FlagConfigOption.php | 3 ++- setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php b/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php index 59d287cd1c449..1a693cc22931c 100644 --- a/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConfigOptionsListInterface.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Framework\Setup; + use Magento\Framework\App\DeploymentConfig; /** diff --git a/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php index 837ce825c9a9f..997e1d69e6869 100644 --- a/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php +++ b/lib/internal/Magento/Framework/Setup/Option/FlagConfigOption.php @@ -36,6 +36,7 @@ public function __construct( $configPath, $description, null, - $shortCut); + $shortCut + ); } } diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index b402295095a37..253b1a2da76a8 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -74,7 +74,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + public function execute(InputInterface $input, OutputInterface $output) { $inputOptions = $input->getOptions(); $optionCollection = $this->configModel->getAvailableOptions(); @@ -90,7 +90,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } } } - $inputOptions = array_filter($inputOptions, + $inputOptions = array_filter( + $inputOptions, function ($value) { return $value !== null; } From 25c9baae035cd70c470755611d1a207f3fdfb5cf Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Thu, 26 Mar 2015 11:56:37 -0500 Subject: [PATCH 147/214] MAGETWO-35137: Add deployment configuration set command - fixes according to CR --- app/code/Magento/Backend/Setup/ConfigOptionsList.php | 1 + lib/internal/Magento/Framework/App/DeploymentConfig.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php index 4caf6ea6f0299..2fcc36977b8d0 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -49,6 +49,7 @@ public function getOptions() /** * {@inheritdoc} + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function createConfig(array $options, DeploymentConfig $deploymentConfig) { diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig.php index 0f6bf7cdb133b..fe8ecaf8c1263 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig.php @@ -97,6 +97,11 @@ public function isAvailable() public function getConfigData($key = null) { $this->load(); + + if ($key !== null && !isset($this->data[$key])) { + return null; + } + if (isset($this->data[$key])) { return $this->data[$key]; } From b0beb7562f2cce578fc3815cd151228d218beba1 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 26 Mar 2015 12:37:30 -0500 Subject: [PATCH 148/214] MAGETWO-35497: Remove Old install-configuration Tool - removed unused code --- .../Backend/Setup/ConfigOptionsList.php | 5 --- .../Magento/Setup/Model/ConfigGenerator.php | 2 +- .../Magento/Setup/Model/ConfigOptionsList.php | 1 - setup/src/Magento/Setup/Model/Installer.php | 38 ------------------- .../Magento/Setup/Model/InstallerFactory.php | 3 -- .../Test/Unit/Model/InstallerFactoryTest.php | 20 ---------- .../Setup/Test/Unit/Model/InstallerTest.php | 3 -- 7 files changed, 1 insertion(+), 71 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php index 2fcc36977b8d0..0e58289f6a50e 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -26,11 +26,6 @@ class ConfigOptionsList implements ConfigOptionsListInterface */ const CONFIG_PATH_BACKEND_FRONTNAME = 'backend/frontName'; - /** - * Key for config - */ - const KEY_FRONTNAME = 'frontend'; - /** * {@inheritdoc} */ diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 478970344eaba..aeadbe77fdbf7 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -58,7 +58,7 @@ public function createInstallConfig() { $installConfig = []; if (!$this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)) { - $installConfig = [ConfigOptionsList::INPUT_KEY_DATE => date('r')]; + $installConfig = [ConfigOptionsList::KEY_DATE => date('r')]; } return new ConfigData(ConfigFilePool::APP_CONFIG, 'install', $installConfig); } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index 7d49ac89e8cd0..2869ce0b25aa5 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -26,7 +26,6 @@ class ConfigOptionsList implements ConfigOptionsListInterface /**#@+ * Input keys for the options */ - const INPUT_KEY_DATE = 'date'; const INPUT_KEY_ENCRYPTION_KEY = 'key'; const INPUT_KEY_SESSION_SAVE = 'session_save'; const INPUT_KEY_DEFINITION_FORMAT = 'definition_format'; diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 87fca094a49ee..00d8d54854039 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -115,13 +115,6 @@ class Installer */ private $moduleList; - /** - * Factory for module deployment config - * - * @var DeploymentConfigFactory - */ - private $deploymentConfigFactory; - /** * Module list loader * @@ -129,13 +122,6 @@ class Installer */ private $moduleLoader; - /** - * List of directories of Magento application - * - * @var DirectoryList - */ - private $directoryList; - /** * Admin account factory * @@ -150,13 +136,6 @@ class Installer */ private $log; - /** - * Random Generator - * - * @var Random - */ - private $random; - /** * DB connection factory * @@ -164,13 +143,6 @@ class Installer */ private $connectionFactory; - /** - * Shell command renderer - * - * @var CommandRenderer - */ - private $shellRenderer; - /** * Progress indicator * @@ -231,13 +203,10 @@ class Installer * @param Writer $deploymentConfigWriter * @param Reader $deploymentConfigReader * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig - * @param DeploymentConfigFactory $deploymentConfigFactory * @param ModuleListInterface $moduleList * @param ModuleLoader $moduleLoader - * @param DirectoryList $directoryList * @param AdminAccountFactory $adminAccountFactory * @param LoggerInterface $log - * @param Random $random * @param ConnectionFactory $connectionFactory * @param MaintenanceMode $maintenanceMode * @param Filesystem $filesystem @@ -253,13 +222,10 @@ public function __construct( Writer $deploymentConfigWriter, Reader $deploymentConfigReader, \Magento\Framework\App\DeploymentConfig $deploymentConfig, - DeploymentConfigFactory $deploymentConfigFactory, ModuleListInterface $moduleList, ModuleLoader $moduleLoader, - DirectoryList $directoryList, AdminAccountFactory $adminAccountFactory, LoggerInterface $log, - Random $random, ConnectionFactory $connectionFactory, MaintenanceMode $maintenanceMode, Filesystem $filesystem, @@ -271,15 +237,11 @@ public function __construct( $this->filePermissions = $filePermissions; $this->deploymentConfigWriter = $deploymentConfigWriter; $this->deploymentConfigReader = $deploymentConfigReader; - $this->deploymentConfigFactory = $deploymentConfigFactory; $this->moduleList = $moduleList; $this->moduleLoader = $moduleLoader; - $this->directoryList = $directoryList; $this->adminAccountFactory = $adminAccountFactory; $this->log = $log; - $this->random = $random; $this->connectionFactory = $connectionFactory; - $this->shellRenderer = new CommandRenderer; $this->maintenanceMode = $maintenanceMode; $this->filesystem = $filesystem; $this->sampleData = $sampleData; diff --git a/setup/src/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php index 1d906db05a943..74af7cd0cbd07 100644 --- a/setup/src/Magento/Setup/Model/InstallerFactory.php +++ b/setup/src/Magento/Setup/Model/InstallerFactory.php @@ -52,13 +52,10 @@ public function create(LoggerInterface $log) $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig\Writer'), $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig\Reader'), $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig'), - $this->serviceLocator->get('Magento\Framework\Module\ModuleList\DeploymentConfigFactory'), $this->serviceLocator->get('Magento\Framework\Module\ModuleList'), $this->serviceLocator->get('Magento\Framework\Module\ModuleList\Loader'), - $this->serviceLocator->get('Magento\Framework\App\Filesystem\DirectoryList'), $this->serviceLocator->get('Magento\Setup\Model\AdminAccountFactory'), $log, - $this->serviceLocator->get('Magento\Framework\Math\Random'), $this->serviceLocator->get('Magento\Setup\Module\ConnectionFactory'), $this->serviceLocator->get('Magento\Framework\App\MaintenanceMode'), $this->serviceLocator->get('Magento\Framework\Filesystem'), diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php index df1c839863b27..b211b970509dd 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php @@ -29,14 +29,6 @@ public function testCreate() 'Magento\Framework\App\DeploymentConfig', $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false), ], - [ - 'Magento\Setup\Module\Setup', - $this->getMock('Magento\Setup\Module\Setup', [], [], '', false), - ], - [ - 'Magento\Framework\Module\ModuleList\DeploymentConfigFactory', - $this->getMock('Magento\Framework\Module\ModuleList\DeploymentConfigFactory', [], [], '', false), - ], [ 'Magento\Framework\Module\ModuleList', $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false), @@ -45,18 +37,10 @@ public function testCreate() 'Magento\Framework\Module\ModuleList\Loader', $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false), ], - [ - 'Magento\Framework\App\Filesystem\DirectoryList', - $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false), - ], [ 'Magento\Setup\Model\AdminAccountFactory', $this->getMock('Magento\Setup\Model\AdminAccountFactory', [], [], '', false), ], - [ - 'Magento\Framework\Math\Random', - $this->getMock('Magento\Framework\Math\Random', [], [], '', false), - ], [ 'Magento\Setup\Module\ConnectionFactory', $this->getMock('Magento\Setup\Module\ConnectionFactory', [], [], '', false), @@ -77,10 +61,6 @@ public function testCreate() 'Magento\Setup\Model\ObjectManagerProvider', $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false), ], - [ - 'Magento\Framework\App\DeploymentConfig\Reader', - $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false), - ], [ 'Magento\Framework\Model\Resource\Db\TransactionManager', $this->getMock('Magento\Framework\Model\Resource\Db\TransactionManager', [], [], '', false), diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 698cd25ff3538..85874c9313219 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -202,13 +202,10 @@ private function createObject($connectionFactory = false, $objectManagerProvider $this->configWriter, $this->configReader, $this->config, - $this->deploymentConfigFactory, $this->moduleList, $this->moduleLoader, - $this->directoryList, $this->adminFactory, $this->logger, - $this->random, $connectionFactory, $this->maintenanceMode, $this->filesystem, From 26010057beb53b97702f6ca3294ba4a120201de7 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Thu, 26 Mar 2015 14:43:12 -0500 Subject: [PATCH 149/214] MAGETWO-35138: Add Interactive Confirmation to config update - Implemented unit test for interactive command line. --- .../Console/Command/ConfigSetCommand.php | 4 +- .../Console/Command/ConfigSetCommandTest.php | 126 ++++++++++-------- 2 files changed, 73 insertions(+), 57 deletions(-) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 253b1a2da76a8..5bedf5f3d7a8d 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -74,7 +74,7 @@ protected function configure() /** * {@inheritdoc} */ - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output) { $inputOptions = $input->getOptions(); $optionCollection = $this->configModel->getAvailableOptions(); @@ -103,7 +103,7 @@ function ($value) { /** * {@inheritdoc} */ - public function initialize(InputInterface $input, OutputInterface $output) + protected function initialize(InputInterface $input, OutputInterface $output) { if (!$this->moduleList->isModuleInfoAvailable()) { $output->writeln( diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index d923445854b90..d9cf37f8b33a1 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -6,11 +6,10 @@ namespace Magento\Setup\Test\Unit\Console\Command; -use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Module\ModuleList; use Magento\Setup\Console\Command\ConfigSetCommand; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\Console\Application; class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase { @@ -19,11 +18,6 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase */ private $configModel; - /** - * @var \PHPUnit_Framework_MockObject_MockObject| ConfigFilePool - */ - private $configFilePool; - /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Module\ModuleList */ @@ -35,80 +29,102 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase private $deploymentConfig; /** - * @var \PHPUnit_Framework_MockObject_MockObject|InputInterface - */ - private $input; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|OutputInterface + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig */ - private $output; + private $option; public function setUp() { $this->configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); - $this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $this->input = $this->getMock('Symfony\Component\Console\Input\InputInterface', [], [], '', false); - $this->output = $this->getMock('Symfony\Component\Console\Output\OutputInterface', [], [], '', false); + $this->deploymentConfig + ->expects($this->once()) + ->method('get') + ->will($this->returnValue('localhost')); + $this->option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); } - public function testInitialize() + public function testExecuteNoInteractive() { - $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); $optionsSet = [ - $option + $this->option ]; - $this->input->expects($this->once())->method('getOptions')->will($this->returnValue([])); - - $this->moduleList->expects($this->once())->method('isModuleInfoAvailable')->will($this->returnValue(false)); - - $this->configModel->expects($this->once()) - ->method('validate') - ->will($this->returnValue([])); $this->configModel - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getAvailableOptions') ->will($this->returnValue($optionsSet)); - $this->output->expects($this->once()) - ->method('writeln') - ->with('No module configuration is available, so all modules are enabled.'); - $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); - $command->initialize($this->input, $this->output); + $commandTester = new CommandTester($command); + $commandTester->execute(['config:set']); + $this->assertSame( + 'No module configuration is available, so all modules are enabled.' . PHP_EOL + . 'You saved the deployment config.' . PHP_EOL, + $commandTester->getDisplay() + ); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Parameters validation is failed - */ - public function testInitializeFailedValidation() + public function testExecuteInteractiveWithYes() { - $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $this->option + ->expects($this->exactly(7)) + ->method('getName') + ->will($this->returnValue('db_host')); $optionsSet = [ - $option + $this->option ]; + $this->configModel + ->expects($this->exactly(2)) + ->method('getAvailableOptions') + ->will($this->returnValue($optionsSet)); - $this->input->expects($this->once())->method('getOptions')->will($this->returnValue([])); - - $this->moduleList->expects($this->once())->method('isModuleInfoAvailable')->will($this->returnValue(true)); - - $this->configModel->expects($this->once()) - ->method('validate') - ->will($this->returnValue(['Error message'])); - - $this->output->expects($this->once())->method('writeln')->with('Error message'); + $this->checkInteraction(true); + } + public function testExecuteInteractiveWithNo() + { + $this->option + ->expects($this->exactly(8)) + ->method('getName') + ->will($this->returnValue('db_host')); + $optionsSet = [ + $this->option + ]; $this->configModel - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getAvailableOptions') ->will($this->returnValue($optionsSet)); - $this->deploymentConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); - $command->initialize($this->input, $this->output); + $this->checkInteraction(false); + } + + /** + * Checks interaction with users on CLI + * + * @param bool $interactionType + * @return void + */ + private function checkInteraction($interactionType) + { + $app = new Application(); + $app->add(new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig)); + $command = $app->find('config:set'); + $dialog = $this->getMock('Symfony\Component\Console\Helper\DialogHelper', [], [], '', false); + $dialog + ->expects($this->once()) + ->method('askConfirmation') + ->will($this->returnValue($interactionType)); + $command->getHelperSet()->set($dialog, 'dialog'); + $commandTester = new CommandTester($command); + $commandTester->execute( + ['command' => $command->getName(), '--db_host' => 'host'], + ['interactive'] + ); + $this->assertSame( + 'No module configuration is available, so all modules are enabled.' . PHP_EOL + . 'You saved the deployment config.' . PHP_EOL, + $commandTester->getDisplay() + ); } } From 23ee28b39e76362e46b0d928ef79ecf2033d6751 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 26 Mar 2015 14:50:39 -0500 Subject: [PATCH 150/214] MAGETWO-35497: Remove Old install-configuration Tool - fixed usage of command --- setup/src/Magento/Setup/Console/CommandList.php | 2 +- setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php index 87b70b9dae3a5..0a4f4ef8f281a 100644 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -40,7 +40,7 @@ public function __construct(ServiceManager $serviceManager) protected function getCommandsClasses() { return [ - 'Magento\Setup\Console\Command\ConfigCreateCommand', + 'Magento\Setup\Console\Command\ConfigSetCommand', ]; } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php index 12c555953e9b4..3e0d5bd666a42 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php @@ -30,7 +30,7 @@ public function testGetCommands() { $this->serviceManager->expects($this->at(0)) ->method('create') - ->with('Magento\Setup\Console\Command\ConfigCreateCommand'); + ->with('Magento\Setup\Console\Command\ConfigSetCommand'); $this->commandList->getCommands(); } } From fc550d677dd39cec1d55cdcd9704a477102dc146 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Thu, 26 Mar 2015 15:39:21 -0500 Subject: [PATCH 151/214] MAGETWO-35135: Integrate config command - Use correct constants for resource segment in deployment config - organize imports in Installer --- setup/src/Magento/Setup/Model/ConfigGenerator.php | 4 ++-- setup/src/Magento/Setup/Model/Installer.php | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index aeadbe77fdbf7..45f4093a6687a 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -186,7 +186,7 @@ public function createDbConfig(array $data) */ public function createResourceConfig() { - $resourceData = ['default_setup' => ['connection' => 'default']]; - return new ConfigData(ConfigFilePool::APP_CONFIG, ConfigOptionsList::INPUT_KEY_RESOURCE, $resourceData); + $resourceData = ['default_setup' => [ConfigOptionsList::KEY_CONNECTION => 'default']]; + return new ConfigData(ConfigFilePool::APP_CONFIG, ConfigOptionsList::KEY_RESOURCE, $resourceData); } } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 00d8d54854039..0463cc1755365 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -6,32 +6,27 @@ namespace Magento\Setup\Model; -use Magento\Framework\App\DeploymentConfig\DbConfig; -use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\MaintenanceMode; use Magento\Framework\App\Resource\Config; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\FilesystemException; -use Magento\Framework\Math\Random; -use Magento\Framework\Module\ModuleList\DeploymentConfig; -use Magento\Framework\Module\ModuleList\DeploymentConfigFactory; +use Magento\Framework\Model\Resource\Db\Context; use Magento\Framework\Module\ModuleList\Loader as ModuleLoader; use Magento\Framework\Module\ModuleListInterface; -use Magento\Framework\Shell; -use Magento\Framework\Shell\CommandRenderer; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Framework\Model\Resource\Db\Context; +use Magento\Framework\Shell; use Magento\Setup\Model\ConfigModel as SetupConfigModel; +use Magento\Store\Model\Store; use Magento\Setup\Module\ConnectionFactory; use Magento\Setup\Module\Setup; -use Magento\Store\Model\Store; /** * Class Installer contains the logic to install Magento application. From 0f6b4e5703391a49729f237bf8720264bf1c93d2 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Thu, 26 Mar 2015 16:46:56 -0500 Subject: [PATCH 152/214] MAGETWO-35135: Integrate config command - put comma between directories in error message - add test for directories not writable --- setup/src/Magento/Setup/Model/ConfigModel.php | 2 +- .../Magento/Setup/Test/Unit/Model/ConfigModelTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 0a14df5821bf7..af0a715caf67b 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -164,7 +164,7 @@ private function checkInstallationFilePermissions() { $results = $this->filePermissions->getMissingWritableDirectoriesForInstallation(); if ($results) { - $errorMsg = "Missing writing permissions to the following directories: '" . implode("' '", $results) . "'"; + $errorMsg = "Missing writing permissions to the following directories: '" . implode("', '", $results) . "'"; throw new \Exception($errorMsg); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php index 13e290f53e4d2..ea2cc52aeb2c1 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php @@ -165,4 +165,15 @@ public function testProcessException() $this->configModel->process([]); } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Missing writing permissions to the following directories: '/a/ro/dir', '/media' + */ + public function testWritePermissionErrors() + { + $this->filePermissions->expects($this->once())->method('getMissingWritableDirectoriesForInstallation') + ->willReturn(['/a/ro/dir', '/media']); + $this->configModel->process([]); + } } From 9843c4032357fbb191797949a62eb23d5e089263 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 26 Mar 2015 17:44:28 -0500 Subject: [PATCH 153/214] MAGETWO-35497: Remove Old install-configuration Tool - fixed phpDoc - fixed test --- .../Magento/Setup/Console/Command/ConfigSetCommand.php | 5 ----- setup/src/Magento/Setup/Model/ConfigModel.php | 8 +++++--- .../Setup/Test/Unit/Controller/ConsoleControllerTest.php | 1 - 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 5bedf5f3d7a8d..b027cdb16c671 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -20,11 +20,6 @@ class ConfigSetCommand extends Command */ protected $configModel; - /** - * @var ConfigFilePool - */ - protected $configFilePool; - /** * Enabled module list * diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index af0a715caf67b..809f4efa9435c 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -9,6 +9,7 @@ use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\Setup\Option\AbstractConfigOption; class ConfigModel { @@ -57,15 +58,16 @@ public function __construct( /** * Gets available config options * - * @return array + * @return AbstractConfigOption[] */ public function getAvailableOptions() { + /** @var AbstractConfigOption[] $optionCollection */ $optionCollection = []; $options = $this->collector->collectOptions(); - foreach ($options as $option) { - $optionCollection = array_merge($optionCollection, $option->getOptions()); + foreach ($options as $optionList) { + $optionCollection = array_merge($optionCollection, $optionList->getOptions()); } foreach ($optionCollection as $option) { diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php index 372292f499f4e..6a5abfd72e66e 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php @@ -652,7 +652,6 @@ public function helpActionDataProvider() ['install',''], ['update', $noParameters], ['uninstall', $noParameters], - ['install-configuration', ''], ['install-schema', $noParameters], ['install-data', $noParameters], ['install-user-configuration', ''], From 667448f69f15aabf3ad8c0a1a022ae7bca765494 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 26 Mar 2015 17:50:44 -0500 Subject: [PATCH 154/214] MAGETWO-35497: Remove Old install-configuration Tool - updated name of the command according to the convention --- setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php | 2 +- .../Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index b027cdb16c671..13741b8f7cf83 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -59,7 +59,7 @@ protected function configure() { $options = $this->configModel->getAvailableOptions(); - $this->setName('config:set') + $this->setName('setup:config:set') ->setDescription('Create deployment configuration') ->setDefinition($options); diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index d9cf37f8b33a1..032d0031e0080 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -57,7 +57,7 @@ public function testExecuteNoInteractive() $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $commandTester = new CommandTester($command); - $commandTester->execute(['config:set']); + $commandTester->execute(['setup:config:set']); $this->assertSame( 'No module configuration is available, so all modules are enabled.' . PHP_EOL . 'You saved the deployment config.' . PHP_EOL, @@ -109,7 +109,7 @@ private function checkInteraction($interactionType) { $app = new Application(); $app->add(new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig)); - $command = $app->find('config:set'); + $command = $app->find('setup:config:set'); $dialog = $this->getMock('Symfony\Component\Console\Helper\DialogHelper', [], [], '', false); $dialog ->expects($this->once()) From df14d7f1e1ffda4d5be319b7e4bec12a630c00a7 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Thu, 26 Mar 2015 18:18:04 -0500 Subject: [PATCH 155/214] MAGETWO-35137: Add deployment configuration set command - added set by path to ConfigModel and related changes. --- .../Backend/Setup/ConfigOptionsList.php | 12 ++- .../Test/Unit/Setup/ConfigOptionsListTest.php | 11 ++- .../Framework/Config/Data/ConfigData.php | 65 +++++++++----- .../Magento/Setup/Model/ConfigGenerator.php | 86 +++++++++---------- setup/src/Magento/Setup/Model/ConfigModel.php | 10 +-- .../Magento/Setup/Model/ConfigOptionsList.php | 6 +- .../Test/Unit/Model/ConfigGeneratorTest.php | 17 ---- .../Test/Unit/Model/ConfigOptionsListTest.php | 4 +- 8 files changed, 104 insertions(+), 107 deletions(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php index 0e58289f6a50e..a6b1ff8915c4f 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -48,15 +48,13 @@ public function getOptions() */ public function createConfig(array $options, DeploymentConfig $deploymentConfig) { - $data = []; + $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) { - $data = ['frontName' => $options[self::INPUT_KEY_BACKEND_FRONTNAME]]; + $configData->set(self::CONFIG_PATH_BACKEND_FRONTNAME, $options[self::INPUT_KEY_BACKEND_FRONTNAME]); } - return [new ConfigData( - ConfigFilePool::APP_CONFIG, - 'backend', - $data - )]; + + return [$configData]; } /** diff --git a/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php index b3b5023ed542f..279d11ddfbff8 100644 --- a/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php +++ b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php @@ -39,15 +39,22 @@ public function testCreateConfig() { $options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin']; $actualConfig = $this->object->createConfig($options, $this->deploymentConfig); + $expectedData = [ - ['file' => ConfigFilePool::APP_CONFIG, 'segment' => 'backend', 'data' => ['frontName' => 'admin']] + [ + 'file' => ConfigFilePool::APP_CONFIG, + 'segment' => 'backend', + 'data' => [ + 'backend' => ['frontName' => 'admin'] + ] + ] ]; + $this->assertInternalType('array', $actualConfig); /** @var \Magento\Framework\Config\Data\ConfigData $config */ foreach ($actualConfig as $i => $config) { $this->assertInstanceOf('\Magento\Framework\Config\Data\ConfigData', $config); $this->assertSame($expectedData[$i]['file'], $config->getFileKey()); - $this->assertSame($expectedData[$i]['segment'], $config->getSegmentKey()); $this->assertSame($expectedData[$i]['data'], $config->getData()); } } diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index cdf323ac267b4..2f4ed5ee9761b 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -18,32 +18,21 @@ class ConfigData */ private $fileKey; - /** - * Segment key - * - * @var string - */ - private $segmentKey; - /** * Data * * @var array */ - private $data; + private $data = []; /** * Constructor * * @param string $fileKey - * @param string $segmentKey - * @param array $data */ - public function __construct($fileKey, $segmentKey, array $data) + public function __construct($fileKey) { $this->fileKey = $fileKey; - $this->segmentKey = $segmentKey; - $this->data = $data; } /** @@ -57,22 +46,56 @@ public function getFileKey() } /** - * Gets Segment Key + * Gets Data * - * @return string + * @return array */ - public function getSegmentKey() + public function getData() { - return $this->segmentKey; + return $this->data; } /** - * Gets Data + * Updates a value in ConfigData configuration by specified path * - * @return array + * @param string $path + * @param mixed $value + * @return void */ - public function getData() + public function set($path, $value) { - return $this->data; + $chunks = $this->expand($path); + $data = []; + $element = &$data; + while ($chunks) { + $key = array_shift($chunks); + if ($chunks) { + $element[$key] = []; + $element = &$element[$key]; + } else { + $element[$key] = $value; + } + } + $this->data = array_replace_recursive($this->data, $data); + } + + /** + * Expands a path into chunks + * + * All chunks must be not empty and there must be at least two. + * + * @param string $path + * @return string[] + * @throws \InvalidArgumentException + */ + private function expand($path) + { + $chunks = array_pad(explode('/', $path), 2, ''); + foreach ($chunks as $chunk) { + if ('' == $chunk) { + throw new \InvalidArgumentException("The path '$path' is invalid"); + } + } + return $chunks; } } diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 45f4093a6687a..9b98a19116711 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -35,6 +35,8 @@ class ConfigGenerator ConfigOptionsList::INPUT_KEY_RESOURCE => ConfigOptionsList::KEY_RESOURCE, ]; + + /** * Constructor * @@ -56,11 +58,12 @@ public function __construct(Random $random, Loader $moduleLoader, DeploymentConf */ public function createInstallConfig() { - $installConfig = []; + $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + if (!$this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)) { - $installConfig = [ConfigOptionsList::KEY_DATE => date('r')]; + $configData->set(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE, date('r')); } - return new ConfigData(ConfigFilePool::APP_CONFIG, 'install', $installConfig); + return $configData; } /** @@ -72,7 +75,7 @@ public function createCryptConfig(array $data) { $currentKey = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY); - $cryptData = []; + $configData = new ConfigData(ConfigFilePool::APP_CONFIG); if (isset($data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY])) { if ($currentKey) { $key = $currentKey . "\n" . $data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]; @@ -80,33 +83,14 @@ public function createCryptConfig(array $data) $key = $data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]; } - $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]] = $key; + $configData->set(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY, $key); } else { if (!$currentKey) { - $cryptData[self::$paramMap[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]] = - md5($this->random->getRandomString(10)); + $configData->set(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY, md5($this->random->getRandomString(10))); } } - return new ConfigData(ConfigFilePool::APP_CONFIG, 'crypt', $cryptData); - } - - /** - * Creates module config data - * - * @return ConfigData - */ - public function createModuleConfig() - { - if (!$this->deploymentConfig->isAvailable()) { - $modulesData = []; - if (isset($this->moduleList)) { - foreach ($this->moduleList as $key) { - $modulesData[$key] = 1; - } - } - return new ConfigData(ConfigFilePool::APP_CONFIG, 'modules', $modulesData); - } + return $configData; } /** @@ -117,13 +101,16 @@ public function createModuleConfig() */ public function createSessionConfig(array $data) { - $sessionData = []; + $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + if (isset($data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { - $sessionData[self::$paramMap[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]] = - $data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE]; + $configData->set( + ConfigOptionsList::CONFIG_PATH_SESSION_SAVE, + $data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE] + ); } - return new ConfigData(ConfigFilePool::APP_CONFIG, 'session', $sessionData); + return $configData; } /** @@ -134,13 +121,16 @@ public function createSessionConfig(array $data) */ public function createDefinitionsConfig(array $data) { + $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + if (!empty($data[ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT])) { - return new ConfigData( - ConfigFilePool::APP_CONFIG, - 'definition', - ['format' => $data[ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT]] + $configData->set( + ConfigOptionsList::CONFIG_PATH_DEFINITION_FORMAT, + $data[ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT] ); } + + return $configData; } /** @@ -151,7 +141,7 @@ public function createDefinitionsConfig(array $data) */ public function createDbConfig(array $data) { - $connection = []; + $configData = new ConfigData(ConfigFilePool::APP_CONFIG); $optional = [ ConfigOptionsList::INPUT_KEY_DB_HOST, @@ -162,21 +152,20 @@ public function createDbConfig(array $data) ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS, ]; + $prefixKey = isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]) + ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] + : ''; + $configData->set('db/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX], $prefixKey); + foreach ($optional as $key) { if (isset($data[$key])) { - $connection[self::$paramMap[$key]] = $data[$key]; + $configData->set('db/connection/default/' . self::$paramMap[$key], $data[$key]); } } - $connection[self::$paramMap[ConfigOptionsList::INPUT_KEY_ACTIVE]] = '1'; - $prefixKey = isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]) - ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] - : ''; - $dbData = [ - self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX] => $prefixKey, - 'connection' => ['default' => $connection] - ]; - return new ConfigData(ConfigFilePool::APP_CONFIG, 'db', $dbData); + $configData->set('db/connection/default/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_ACTIVE], '1'); + + return $configData; } /** @@ -186,7 +175,10 @@ public function createDbConfig(array $data) */ public function createResourceConfig() { - $resourceData = ['default_setup' => [ConfigOptionsList::KEY_CONNECTION => 'default']]; - return new ConfigData(ConfigFilePool::APP_CONFIG, ConfigOptionsList::KEY_RESOURCE, $resourceData); + $configData = new ConfigData(ConfigFilePool::APP_CONFIG); + + $configData->set('resource/default_setup/connection', 'default'); + + return $configData; } } diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 809f4efa9435c..5910446093808 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -107,15 +107,13 @@ public function process($inputOptions) ); } - if (isset($fileConfigStorage[$config->getFileKey()]) - && isset($fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()]) - ) { - $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = array_replace_recursive( - $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()], + if (isset($fileConfigStorage[$config->getFileKey()])) { + $fileConfigStorage[$config->getFileKey()] = array_replace_recursive( + $fileConfigStorage[$config->getFileKey()], $config->getData() ); } else { - $fileConfigStorage[$config->getFileKey()][$config->getSegmentKey()] = $config->getData(); + $fileConfigStorage[$config->getFileKey()] = $config->getData(); } } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index 2869ce0b25aa5..ff4f60b2e8a9c 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -21,6 +21,8 @@ class ConfigOptionsList implements ConfigOptionsListInterface */ const CONFIG_PATH_INSTALL_DATE = 'install/date'; const CONFIG_PATH_CRYPT_KEY = 'crypt/key'; + const CONFIG_PATH_SESSION_SAVE = 'session/save'; + const CONFIG_PATH_DEFINITION_FORMAT = 'definition/format'; /**#@-*/ /**#@+ @@ -204,10 +206,6 @@ public function createConfig(array $data, DeploymentConfig $deploymentConfig) $configData = []; $configData[] = $this->configGenerator->createInstallConfig($deploymentConfig); $configData[] = $this->configGenerator->createCryptConfig($data, $deploymentConfig); - $modulesConfig = $this->configGenerator->createModuleConfig(); - if (isset($modulesConfig)) { - $configData[] = $modulesConfig; - } $configData[] = $this->configGenerator->createSessionConfig($data); $definitionConfig = $this->configGenerator->createDefinitionsConfig($data); if (isset($definitionConfig)) { diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 43314629408cc..9430fa001ec1d 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -36,7 +36,6 @@ public function testCreateInstallConfig() { $returnValue = $this->configGeneratorObject->createInstallConfig([]); $this->assertInstanceOf('Magento\Framework\Config\Data\ConfigData', $returnValue); - $this->assertEquals('install', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); } @@ -44,7 +43,6 @@ public function testCreateCryptConfigWithInput() { $testData = [ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key']; $returnValue = $this->configGeneratorObject->createCryptConfig($testData, []); - $this->assertEquals('crypt', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['key' => 'some-test_key'], $returnValue->getData()); } @@ -52,30 +50,19 @@ public function testCreateCryptConfigWithInput() public function testCreateCryptConfigWithoutInput() { $returnValue = $this->configGeneratorObject->createCryptConfig([], []); - $this->assertEquals('crypt', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['key' => md5('key')], $returnValue->getData()); } - public function testCreateModuleConfig() - { - $returnValue = $this->configGeneratorObject->createModuleConfig(); - $this->assertEquals('modules', $returnValue->getSegmentKey()); - $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['module1' => 1, 'module2' => 1], $returnValue->getData()); - } - public function testCreateSessionConfigWithInput() { $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); - $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['save' => ConfigOptionsList::SESSION_SAVE_FILES], $returnValue->getData()); $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); - $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['save' => ConfigOptionsList::SESSION_SAVE_DB], $returnValue->getData()); } @@ -83,7 +70,6 @@ public function testCreateSessionConfigWithInput() public function testCreateSessionConfigWithoutInput() { $returnValue = $this->configGeneratorObject->createSessionConfig([]); - $this->assertEquals('session', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals([], $returnValue->getData()); } @@ -92,7 +78,6 @@ public function testCreateDefinitionsConfig() { $testData = [ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; $returnValue = $this->configGeneratorObject->createDefinitionsConfig($testData); - $this->assertEquals('definition', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['format' => 'test-format'], $returnValue->getData()); } @@ -106,7 +91,6 @@ public function testCreateDbConfig() ConfigOptionsList::INPUT_KEY_DB_PREFIX => 'testSomePrefix', ]; $returnValue = $this->configGeneratorObject->createDbConfig($testData); - $this->assertEquals('db', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $dbData = $returnValue->getData(); $this->assertArrayHasKey('table_prefix', $dbData); @@ -126,7 +110,6 @@ public function testCreateDbConfig() public function testCreateResourceConfig() { $returnValue = $this->configGeneratorObject->createResourceConfig(); - $this->assertEquals('resource', $returnValue->getSegmentKey()); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['default_setup' => ['connection' => 'default']], $returnValue->getData()); } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php index df6d6205b3942..5e72651aec539 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php @@ -63,13 +63,12 @@ public function testCreateOptions() $configDataMock = $this->getMock('Magento\Framework\Config\Data\ConfigData', [], [], '', false); $this->generator->expects($this->once())->method('createInstallConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createCryptConfig')->willReturn($configDataMock); - $this->generator->expects($this->once())->method('createModuleConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createSessionConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createDefinitionsConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createResourceConfig')->willReturn($configDataMock); $configData = $this->object->createConfig([], $this->deploymentConfig); - $this->assertEquals(7, count($configData)); + $this->assertEquals(6, count($configData)); } public function testCreateOptionsWithOptionalNull() @@ -77,7 +76,6 @@ public function testCreateOptionsWithOptionalNull() $configDataMock = $this->getMock('Magento\Framework\Config\Data\ConfigData', [], [], '', false); $this->generator->expects($this->once())->method('createInstallConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createCryptConfig')->willReturn($configDataMock); - $this->generator->expects($this->once())->method('createModuleConfig')->willReturn(null); $this->generator->expects($this->once())->method('createSessionConfig')->willReturn($configDataMock); $this->generator->expects($this->once())->method('createDefinitionsConfig')->willReturn(null); $this->generator->expects($this->once())->method('createDbConfig')->willReturn($configDataMock); From 6417588b3d81b074acc460e7318dbd3dc9540699 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Thu, 26 Mar 2015 21:50:03 -0500 Subject: [PATCH 156/214] MAGETWO-35137: Add deployment configuration set command - added test for ConfigData - fixed following tests ConfigGeneratorTest, ConfigModelTest --- .../Framework/Config/Data/ConfigData.php | 4 ++ .../Config/Test/Unit/Data/ConfigDataTest.php | 69 +++++++++++++++++++ .../Test/Unit/Model/ConfigGeneratorTest.php | 17 ++--- .../Setup/Test/Unit/Model/ConfigModelTest.php | 6 +- 4 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index 2f4ed5ee9761b..b95274c19e352 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -67,6 +67,7 @@ public function set($path, $value) $chunks = $this->expand($path); $data = []; $element = &$data; + while ($chunks) { $key = array_shift($chunks); if ($chunks) { @@ -76,6 +77,7 @@ public function set($path, $value) $element[$key] = $value; } } + $this->data = array_replace_recursive($this->data, $data); } @@ -91,11 +93,13 @@ public function set($path, $value) private function expand($path) { $chunks = array_pad(explode('/', $path), 2, ''); + foreach ($chunks as $chunk) { if ('' == $chunk) { throw new \InvalidArgumentException("The path '$path' is invalid"); } } + return $chunks; } } diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php new file mode 100644 index 0000000000000..d6255bbc541f8 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php @@ -0,0 +1,69 @@ + [ + 'path' => [ + 'value1' => '1', + 'value2' => '4', + 'value3' => '3', + ] + ] + ]; + $configData = new ConfigData($fileKey); + + $configData->set('test/path/value1', '1'); + $configData->set('test/path/value2', '2'); + $configData->set('test/path/value3', '3'); + $configData->set('test/path/value2', '4'); + + $this->assertEquals($expectedValue, $configData->getData()); + $this->assertEquals($fileKey, $configData->getFileKey()); + } + + /** + * @param string $key + * @param string $expectedException + * @dataProvider exceptionDataProvider + */ + public function testSetWrongKey($key, $expectedException) { + + $configData = new ConfigData('testKey'); + + $this->setExpectedException('InvalidArgumentException', $expectedException); + $configData->set($key, 'value'); + } + + public function exceptionDataProvider() + { + return [ + 'segment element' => [ + 'test', + "The path 'test' is invalid" + ], + 'segment is empty' => [ + '/test/test/test', + "The path '/test/test/test' is invalid" + ], + 'key is empty' => [ + '', + "The path '' is invalid" + ], + 'access by empty value key' => [ + 'test/', + "The path 'test/' is invalid" + ] + ]; + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 9430fa001ec1d..9ae41dbdf4384 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -42,16 +42,16 @@ public function testCreateInstallConfig() public function testCreateCryptConfigWithInput() { $testData = [ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key']; - $returnValue = $this->configGeneratorObject->createCryptConfig($testData, []); + $returnValue = $this->configGeneratorObject->createCryptConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['key' => 'some-test_key'], $returnValue->getData()); + $this->assertEquals(['crypt' => ['key' => 'some-test_key']], $returnValue->getData()); } public function testCreateCryptConfigWithoutInput() { - $returnValue = $this->configGeneratorObject->createCryptConfig([], []); + $returnValue = $this->configGeneratorObject->createCryptConfig([]); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['key' => md5('key')], $returnValue->getData()); + $this->assertEquals(['crypt' => ['key' => md5('key')]], $returnValue->getData()); } public function testCreateSessionConfigWithInput() @@ -59,12 +59,12 @@ public function testCreateSessionConfigWithInput() $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['save' => ConfigOptionsList::SESSION_SAVE_FILES], $returnValue->getData()); + $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_FILES]], $returnValue->getData()); $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['save' => ConfigOptionsList::SESSION_SAVE_DB], $returnValue->getData()); + $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_DB]], $returnValue->getData()); } public function testCreateSessionConfigWithoutInput() @@ -79,7 +79,7 @@ public function testCreateDefinitionsConfig() $testData = [ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; $returnValue = $this->configGeneratorObject->createDefinitionsConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['format' => 'test-format'], $returnValue->getData()); + $this->assertEquals(['definition' => ['format' => 'test-format']], $returnValue->getData()); } public function testCreateDbConfig() @@ -93,6 +93,7 @@ public function testCreateDbConfig() $returnValue = $this->configGeneratorObject->createDbConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $dbData = $returnValue->getData(); + $dbData = $dbData['db']; $this->assertArrayHasKey('table_prefix', $dbData); $this->assertSame('testSomePrefix', $dbData['table_prefix']); $this->assertArrayHasKey('connection', $dbData); @@ -111,6 +112,6 @@ public function testCreateResourceConfig() { $returnValue = $this->configGeneratorObject->createResourceConfig(); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['default_setup' => ['connection' => 'default']], $returnValue->getData()); + $this->assertEquals(['resource' => ['default_setup' => ['connection' => 'default']]], $returnValue->getData()); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php index ea2cc52aeb2c1..78d9cdb7ba882 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php @@ -119,15 +119,13 @@ public function testProcess() $configData1->expects($this->any()) ->method('getData') - ->will($this->returnValue($testSet1[ConfigFilePool::APP_CONFIG]['segment'])); + ->will($this->returnValue($testSet1[ConfigFilePool::APP_CONFIG])); $configData1->expects($this->any())->method('getFileKey')->will($this->returnValue(ConfigFilePool::APP_CONFIG)); - $configData1->expects($this->any())->method('getSegmentKey')->will($this->returnValue('segment')); $configData2->expects($this->any()) ->method('getData') - ->will($this->returnValue($testSet2[ConfigFilePool::APP_CONFIG]['segment'])); + ->will($this->returnValue($testSet2[ConfigFilePool::APP_CONFIG])); $configData2->expects($this->any())->method('getFileKey')->will($this->returnValue(ConfigFilePool::APP_CONFIG)); - $configData2->expects($this->any())->method('getSegmentKey')->will($this->returnValue('segment')); $configOption = $this->configOptionsList; $configOption->expects($this->once()) From bff5b70544ebe8ed69ef9fd72e2f27bf8df6fc89 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 00:04:23 -0500 Subject: [PATCH 157/214] MAGETWO-35137: Add deployment configuration set command - small fixes in ConfigGenerator and test --- .../Magento/Setup/Model/ConfigGenerator.php | 29 +++++++++++++------ .../Magento/Setup/Model/ConfigOptionsList.php | 3 +- .../Test/Unit/Model/ConfigGeneratorTest.php | 9 +----- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 9b98a19116711..f40ba000a8139 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -8,11 +8,11 @@ use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Math\Random; -use Magento\Framework\Module\ModuleList\Loader; use Magento\Framework\App\DeploymentConfig; /** * Creates deployment config data based on user input array + * this class introduced to brake Magento\Setup\Model\ConfigOptionsList::createConfig */ class ConfigGenerator { @@ -29,26 +29,31 @@ class ConfigGenerator ConfigOptionsList::INPUT_KEY_DB_PREFIX => ConfigOptionsList::KEY_PREFIX, ConfigOptionsList::INPUT_KEY_DB_MODEL => ConfigOptionsList::KEY_MODEL, ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS => ConfigOptionsList::KEY_INIT_STATEMENTS, - ConfigOptionsList::INPUT_KEY_ACTIVE => ConfigOptionsList::KEY_ACTIVE, ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => ConfigOptionsList::KEY_ENCRYPTION_KEY, ConfigOptionsList::INPUT_KEY_SESSION_SAVE => ConfigOptionsList::KEY_SAVE, ConfigOptionsList::INPUT_KEY_RESOURCE => ConfigOptionsList::KEY_RESOURCE, ]; + /** + * @var Random + */ + protected $random; + /** + * @var DeploymentConfig + */ + protected $deploymentConfig; /** * Constructor * * @param Random $random - * @param Loader $moduleLoader * @param DeploymentConfig $deploymentConfig */ - public function __construct(Random $random, Loader $moduleLoader, DeploymentConfig $deploymentConfig) + public function __construct(Random $random, DeploymentConfig $deploymentConfig) { $this->random = $random; $this->deploymentConfig = $deploymentConfig; - $this->moduleList = array_keys($moduleLoader->load()); } /** @@ -155,15 +160,21 @@ public function createDbConfig(array $data) $prefixKey = isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]) ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] : ''; - $configData->set('db/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX], $prefixKey); + $configData->set( + ConfigOptionsList::SESSION_SAVE_DB . '/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX], + $prefixKey + ); foreach ($optional as $key) { if (isset($data[$key])) { - $configData->set('db/connection/default/' . self::$paramMap[$key], $data[$key]); + $configData->set( + ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::$paramMap[$key], + $data[$key] + ); } } - $configData->set('db/connection/default/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_ACTIVE], '1'); + $configData->set(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT . ConfigOptionsList::KEY_ACTIVE, '1'); return $configData; } @@ -177,7 +188,7 @@ public function createResourceConfig() { $configData = new ConfigData(ConfigFilePool::APP_CONFIG); - $configData->set('resource/default_setup/connection', 'default'); + $configData->set(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP, 'default'); return $configData; } diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index ff4f60b2e8a9c..0eeaaefafe5fc 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -23,6 +23,8 @@ class ConfigOptionsList implements ConfigOptionsListInterface const CONFIG_PATH_CRYPT_KEY = 'crypt/key'; const CONFIG_PATH_SESSION_SAVE = 'session/save'; const CONFIG_PATH_DEFINITION_FORMAT = 'definition/format'; + const CONFIG_PATH_RESOURCE_DEFAULT_SETUP = 'resource/default_setup/connection'; + const CONFIG_PATH_DB_CONNECTION_DEFAULT = 'db/connection/default/'; /**#@-*/ /**#@+ @@ -38,7 +40,6 @@ class ConfigOptionsList implements ConfigOptionsListInterface const INPUT_KEY_DB_PREFIX = 'db_prefix'; const INPUT_KEY_DB_MODEL = 'db_model'; const INPUT_KEY_DB_INIT_STATEMENTS = 'db_init_statements'; - const INPUT_KEY_ACTIVE = 'active'; const INPUT_KEY_RESOURCE = 'resource'; /**#@-*/ diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php index 9ae41dbdf4384..7821207cb3e2f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php @@ -20,16 +20,9 @@ protected function setUp() { $random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); $random->expects($this->any())->method('getRandomString')->willReturn('key'); - $loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); - $loader->expects($this->any())->method('load')->willReturn( - [ - 'module1' => ['name' => 'module_one', 'version' => '1.0.0'], - 'module2' => ['name' => 'module_two', 'version' => '1.0.0'] - ] - ); $deployConfig= $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $deployConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $this->configGeneratorObject = new ConfigGenerator($random, $loader, $deployConfig); + $this->configGeneratorObject = new ConfigGenerator($random, $deployConfig); } public function testCreateInstallConfig() From be1545f7eefbb541141008c51a056c8e93b1e308 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 10:23:14 -0500 Subject: [PATCH 158/214] MAGETWO-35137: Add deployment configuration set command - moved ConfigOptionsList from setup to Framework to avoid framework dependency on Setup --- .../Magento/AdminNotification/Model/Feed.php | 4 +-- .../Test/Unit/Model/FeedTest.php | 2 +- .../Magento/Backend/Helper/Dashboard/Data.php | 2 +- .../Config/Source/Storage/Media/Database.php | 2 +- .../Source/Storage/Media/DatabaseTest.php | 2 +- .../Magento/Mtf/App/State/AbstractState.php | 2 +- .../Magento/TestFramework/Application.php | 2 +- .../Model/Resource/Db/ProfilerTest.php | 2 +- .../Model/ConfigOptionsListCollectorTest.php | 4 +-- .../Framework/App/Cache/Frontend/Pool.php | 2 +- .../Framework/App/Cache/Type/FrontendPool.php | 2 +- .../Magento/Framework/App/Resource.php | 2 +- .../App/Test/Unit/Cache/Frontend/PoolTest.php | 2 +- .../Test/Unit/Cache/Type/FrontendPoolTest.php | 2 +- .../Framework/App/Test/Unit/ResourceTest.php | 2 +- .../Framework/Config}/ConfigGenerator.php | 4 +-- .../Framework/Config}/ConfigOptionsList.php | 2 +- .../Config/Test/Unit}/ConfigGeneratorTest.php | 28 +++++++++---------- .../Test/Unit}/ConfigOptionsListTest.php | 10 +++---- .../Magento/Framework/Module/ModuleList.php | 2 +- .../Setup/Controller/ConsoleController.php | 2 +- .../src/Magento/Setup/Controller/Install.php | 2 +- .../Model/ConfigOptionsListCollector.php | 2 +- setup/src/Magento/Setup/Model/Installer.php | 1 + .../Setup/Test/Unit/Model/InstallerTest.php | 10 +++---- 25 files changed, 49 insertions(+), 48 deletions(-) rename {setup/src/Magento/Setup/Model => lib/internal/Magento/Framework/Config}/ConfigGenerator.php (97%) rename {setup/src/Magento/Setup/Model => lib/internal/Magento/Framework/Config}/ConfigOptionsList.php (99%) rename {setup/src/Magento/Setup/Test/Unit/Model => lib/internal/Magento/Framework/Config/Test/Unit}/ConfigGeneratorTest.php (76%) rename {setup/src/Magento/Setup/Test/Unit/Model => lib/internal/Magento/Framework/Config/Test/Unit}/ConfigOptionsListTest.php (92%) diff --git a/app/code/Magento/AdminNotification/Model/Feed.php b/app/code/Magento/AdminNotification/Model/Feed.php index a834c3cde3f77..6496e2160a9e8 100644 --- a/app/code/Magento/AdminNotification/Model/Feed.php +++ b/app/code/Magento/AdminNotification/Model/Feed.php @@ -5,7 +5,7 @@ */ namespace Magento\AdminNotification\Model; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * AdminNotification Feed model @@ -137,7 +137,7 @@ public function checkUpdate() $feedXml = $this->getFeedData(); - $installDate = strtotime($this->_deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)); + $installDate = strtotime($this->_deploymentConfig->get(\Magento\Framework\Config\ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)); if ($feedXml && $feedXml->channel && $feedXml->channel->item) { foreach ($feedXml->channel->item as $item) { diff --git a/app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php b/app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php index e2ae7139e30c9..00ebf99bdcf24 100644 --- a/app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php +++ b/app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php @@ -7,7 +7,7 @@ namespace Magento\AdminNotification\Test\Unit\Model; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) diff --git a/app/code/Magento/Backend/Helper/Dashboard/Data.php b/app/code/Magento/Backend/Helper/Dashboard/Data.php index 84233cd1cb00d..601c68c131ebd 100644 --- a/app/code/Magento/Backend/Helper/Dashboard/Data.php +++ b/app/code/Magento/Backend/Helper/Dashboard/Data.php @@ -6,7 +6,7 @@ namespace Magento\Backend\Helper\Dashboard; use Magento\Framework\App\DeploymentConfig; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * Data helper for dashboard diff --git a/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php b/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php index cea0e51674976..b27633f7e99ab 100644 --- a/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php +++ b/app/code/Magento/MediaStorage/Model/Config/Source/Storage/Media/Database.php @@ -10,7 +10,7 @@ namespace Magento\MediaStorage\Model\Config\Source\Storage\Media; use Magento\Framework\App\DeploymentConfig; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; class Database implements \Magento\Framework\Option\ArrayInterface { diff --git a/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php b/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php index 01d16182002ed..f873b430975e6 100644 --- a/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php +++ b/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php @@ -8,7 +8,7 @@ namespace Magento\MediaStorage\Test\Unit\Model\Config\Source\Storage\Media; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; use Magento\MediaStorage\Model\Config\Source\Storage\Media\Database; /** diff --git a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php index 8463257448c9d..90b07c2d341d0 100644 --- a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php +++ b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php @@ -7,7 +7,7 @@ namespace Magento\Mtf\App\State; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * Abstract class AbstractState diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 98b636d630603..aa6f4285c1688 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -10,7 +10,7 @@ use Magento\Framework\Filesystem; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\DeploymentConfig; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * Encapsulates application installation, initialization and uninstall diff --git a/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php b/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php index c93de0e670df0..fa326a6df0a03 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php @@ -7,7 +7,7 @@ */ namespace Magento\Framework\Model\Resource\Db; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; class ProfilerTest extends \PHPUnit_Framework_TestCase { diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php index 85388215606bb..cec4ae25cfa63 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php @@ -41,7 +41,7 @@ public function testCollectOptionsDeploymentConfigAvailable() $result = $object->collectOptions(); $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get('Magento\Setup\Model\ConfigOptionsList'); + ->get('Magento\Framework\Config\ConfigOptionsList'); $backendOptions = new \Magento\Backend\Setup\ConfigOptionsList(); $expected = [ 'setup' => $setupOptions, @@ -70,7 +70,7 @@ public function testCollectOptionsDeploymentConfigUnavailable() $backendOptions = new \Magento\Backend\Setup\ConfigOptionsList(); $expected = [ 'setup' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get('Magento\Setup\Model\ConfigOptionsList'), + ->get('Magento\Framework\Config\ConfigOptionsList'), 'Magento_Backend' => $backendOptions, ]; diff --git a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php index ba6b3a0ca69a2..8ba4061203c79 100644 --- a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php +++ b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php @@ -6,7 +6,7 @@ namespace Magento\Framework\App\Cache\Frontend; use Magento\Framework\App\DeploymentConfig\Reader; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * In-memory readonly pool of all cache front-end instances known to the system diff --git a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php index 5e86bd3cdc744..8790a2a3e1685 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php @@ -6,7 +6,7 @@ namespace Magento\Framework\App\Cache\Type; use Magento\Framework\App\DeploymentConfig\Reader; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * In-memory readonly pool of cache front-ends with enforced access control, specific to cache types diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index b182f6f608aed..5d1d05d28aff5 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -10,7 +10,7 @@ use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\Resource\ConfigInterface as ResourceConfigInterface; use Magento\Framework\Model\Resource\Type\Db\ConnectionFactoryInterface; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; class Resource { diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php index 1bcd576b87e6e..54975ff686672 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php @@ -6,7 +6,7 @@ namespace Magento\Framework\App\Test\Unit\Cache\Frontend; use \Magento\Framework\App\Cache\Frontend\Pool; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; class PoolTest extends \PHPUnit_Framework_TestCase { diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php index 207bb052970ec..236281dfbaa69 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php @@ -6,7 +6,7 @@ namespace Magento\Framework\App\Test\Unit\Cache\Type; use \Magento\Framework\App\Cache\Type\FrontendPool; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; class FrontendPoolTest extends \PHPUnit_Framework_TestCase { diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php index fa3f52673e8cd..970caabd55e81 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php @@ -10,7 +10,7 @@ use \Magento\Framework\App\Resource; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; class ResourceTest extends \PHPUnit_Framework_TestCase { diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php similarity index 97% rename from setup/src/Magento/Setup/Model/ConfigGenerator.php rename to lib/internal/Magento/Framework/Config/ConfigGenerator.php index f40ba000a8139..61ca397cdd340 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup\Model; +namespace Magento\Framework\Config; use Magento\Framework\Config\Data\ConfigData; use Magento\Framework\Config\File\ConfigFilePool; @@ -12,7 +12,7 @@ /** * Creates deployment config data based on user input array - * this class introduced to brake Magento\Setup\Model\ConfigOptionsList::createConfig + * this class introduced to brake Magento\Framework\Config\ConfigOptionsList::createConfig */ class ConfigGenerator { diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php similarity index 99% rename from setup/src/Magento/Setup/Model/ConfigOptionsList.php rename to lib/internal/Magento/Framework/Config/ConfigOptionsList.php index 0eeaaefafe5fc..f6e9e1e7e8257 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup\Model; +namespace Magento\Framework\Config; use Magento\Framework\ObjectManager\DefinitionFactory; use Magento\Framework\Setup\ConfigOptionsListInterface; diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php similarity index 76% rename from setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php rename to lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php index 7821207cb3e2f..14891604ab71c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php @@ -3,16 +3,16 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup\Test\Unit\Model; +namespace Magento\Framework\Config\Test\Unit; use Magento\Framework\Config\File\ConfigFilePool; -use Magento\Setup\Model\ConfigGenerator; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigGenerator; +use Magento\Framework\Config\ConfigOptionsList; class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase { /** - * @var ConfigGenerator + * @var \Magento\Framework\Config\ConfigGenerator */ private $configGeneratorObject; @@ -22,7 +22,7 @@ protected function setUp() $random->expects($this->any())->method('getRandomString')->willReturn('key'); $deployConfig= $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $deployConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $this->configGeneratorObject = new ConfigGenerator($random, $deployConfig); + $this->configGeneratorObject = new \Magento\Framework\Config\ConfigGenerator($random, $deployConfig); } public function testCreateInstallConfig() @@ -34,7 +34,7 @@ public function testCreateInstallConfig() public function testCreateCryptConfigWithInput() { - $testData = [ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key']; + $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key']; $returnValue = $this->configGeneratorObject->createCryptConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['crypt' => ['key' => 'some-test_key']], $returnValue->getData()); @@ -49,15 +49,15 @@ public function testCreateCryptConfigWithoutInput() public function testCreateSessionConfigWithInput() { - $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files']; + $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_FILES]], $returnValue->getData()); + $this->assertEquals(['session' => ['save' => \Magento\Framework\Config\ConfigOptionsList::SESSION_SAVE_FILES]], $returnValue->getData()); - $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db']; + $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_DB]], $returnValue->getData()); + $this->assertEquals(['session' => ['save' => \Magento\Framework\Config\ConfigOptionsList::SESSION_SAVE_DB]], $returnValue->getData()); } public function testCreateSessionConfigWithoutInput() @@ -69,7 +69,7 @@ public function testCreateSessionConfigWithoutInput() public function testCreateDefinitionsConfig() { - $testData = [ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; + $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; $returnValue = $this->configGeneratorObject->createDefinitionsConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['definition' => ['format' => 'test-format']], $returnValue->getData()); @@ -79,9 +79,9 @@ public function testCreateDbConfig() { $testData = [ ConfigOptionsList::INPUT_KEY_DB_HOST => 'testLocalhost', - ConfigOptionsList::INPUT_KEY_DB_NAME => 'testDbName', - ConfigOptionsList::INPUT_KEY_DB_USER => 'testDbUser', - ConfigOptionsList::INPUT_KEY_DB_PREFIX => 'testSomePrefix', + \Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DB_NAME => 'testDbName', + \Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DB_USER => 'testDbUser', + \Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DB_PREFIX => 'testSomePrefix', ]; $returnValue = $this->configGeneratorObject->createDbConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigOptionsListTest.php similarity index 92% rename from setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php rename to lib/internal/Magento/Framework/Config/Test/Unit/ConfigOptionsListTest.php index 5e72651aec539..6471a0b9eb36a 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigOptionsListTest.php @@ -3,10 +3,10 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup\Test\Unit\Model; +namespace Magento\Framework\Config\Test\Unit; -use Magento\Setup\Model\ConfigGenerator; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigGenerator; +use Magento\Framework\Config\ConfigOptionsList; class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase { @@ -16,7 +16,7 @@ class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase private $object; /** - * @var ConfigGenerator|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Config\ConfigGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $generator; @@ -27,7 +27,7 @@ class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->generator = $this->getMock('Magento\Setup\Model\ConfigGenerator', [], [], '', false); + $this->generator = $this->getMock('Magento\Framework\Config\ConfigGenerator', [], [], '', false); $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->object = new ConfigOptionsList($this->generator); } diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php index 8ff6b0bf53206..6feb34bce0fde 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/ModuleList.php @@ -6,7 +6,7 @@ namespace Magento\Framework\Module; use Magento\Framework\App\DeploymentConfig; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * A list of modules in the Magento application diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 6dab83a6da3b7..eb0ca1f1d1e79 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -10,7 +10,7 @@ use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; use Magento\Framework\App\MaintenanceMode; use Magento\Setup\Model\AdminAccount; -use Magento\Setup\Model\ConfigOptionsList as SetupConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList as SetupConfigOptionsList; use Magento\Setup\Model\ConsoleLogger; use Magento\Setup\Model\Installer; use Magento\Setup\Model\InstallerFactory; diff --git a/setup/src/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php index 45211914e8ea2..d32721a39e9f6 100644 --- a/setup/src/Magento/Setup/Controller/Install.php +++ b/setup/src/Magento/Setup/Controller/Install.php @@ -7,7 +7,7 @@ namespace Magento\Setup\Controller; use Magento\Setup\Model\AdminAccount; -use Magento\Setup\Model\ConfigOptionsList as SetupConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList as SetupConfigOptionsList; use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; use Magento\Setup\Model\Installer; use Magento\Setup\Model\Installer\ProgressFactory; diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php index d020099367475..0af2ef972ae95 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php @@ -99,7 +99,7 @@ public function collectOptions() } // check setup - $setupOptionsClassName = 'Magento\Setup\Model\ConfigOptionsList'; + $setupOptionsClassName = 'Magento\Framework\Config\ConfigOptionsList'; if (class_exists($setupOptionsClassName)) { $setupOptionsClass = $this->objectManagerProvider->get()->create($setupOptionsClassName); if ($setupOptionsClass instanceof ConfigOptionsListInterface) { diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 0463cc1755365..75172dbfee20c 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -11,6 +11,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\MaintenanceMode; use Magento\Framework\App\Resource\Config; +use Magento\Framework\Config\ConfigOptionsList; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\FilesystemException; use Magento\Framework\Model\Resource\Db\Context; diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 85874c9313219..47fba55367f92 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -7,9 +7,9 @@ namespace Magento\Setup\Test\Unit\Model; use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; -use Magento\Setup\Model\ConfigOptionsList as SetupConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList as SetupConfigOptionsList; use \Magento\Setup\Model\Installer; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; @@ -120,11 +120,11 @@ class InstallerTest extends \PHPUnit_Framework_TestCase * @var array */ private static $dbConfig = [ - ConfigOptionsList::KEY_PREFIX => '', + \Magento\Framework\Config\ConfigOptionsList::KEY_PREFIX => '', 'connection' => [ 'default' => [ - ConfigOptionsList::KEY_HOST => '127.0.0.1', - ConfigOptionsList::KEY_NAME => 'magento', + \Magento\Framework\Config\ConfigOptionsList::KEY_HOST => '127.0.0.1', + \Magento\Framework\Config\ConfigOptionsList::KEY_NAME => 'magento', ConfigOptionsList::KEY_USER => 'magento', ConfigOptionsList::KEY_PASS => '', ], From 8ce8aacdae73bc3fb6c8214130561f6d13ff12dc Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 10:37:01 -0500 Subject: [PATCH 159/214] MAGETWO-35137: Add deployment configuration set command - fixed indentation and typo. --- lib/internal/Magento/Framework/Config/ConfigGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index 61ca397cdd340..ad267a9c12f9d 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -12,7 +12,7 @@ /** * Creates deployment config data based on user input array - * this class introduced to brake Magento\Framework\Config\ConfigOptionsList::createConfig + * this class introduced to break Magento\Framework\Config\ConfigOptionsList::createConfig */ class ConfigGenerator { @@ -66,7 +66,7 @@ public function createInstallConfig() $configData = new ConfigData(ConfigFilePool::APP_CONFIG); if (!$this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)) { - $configData->set(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE, date('r')); + $configData->set(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE, date('r')); } return $configData; } From 067ef1b91e1e6a9110d248ba277239b8d6efbc2f Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 27 Mar 2015 10:35:02 -0500 Subject: [PATCH 160/214] MAGETWO-35138: Add Interactive Confirmation to config update - Changes based on code review feedback. --- .../Console/Command/ConfigSetCommand.php | 2 +- .../Console/Command/ConfigSetCommandTest.php | 53 +++++++------------ 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 13741b8f7cf83..a99d08d957a43 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation( $output, - 'Overwrite the existing configuration for ' . $option->getName() . '?' + 'Overwrite the existing configuration for ' . $option->getName() . '?[Y|n]' )) { $inputOptions[$option->getName()] = null; } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index 032d0031e0080..6d88b1c6afb55 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -9,7 +9,6 @@ use Magento\Framework\Module\ModuleList; use Magento\Setup\Console\Command\ConfigSetCommand; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Console\Application; class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase { @@ -35,29 +34,25 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase public function setUp() { + $this->option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); $this->configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); + $this->configModel + ->expects($this->exactly(2)) + ->method('getAvailableOptions') + ->will($this->returnValue([$this->option])); $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->deploymentConfig ->expects($this->once()) ->method('get') ->will($this->returnValue('localhost')); - $this->option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); } public function testExecuteNoInteractive() { - $optionsSet = [ - $this->option - ]; - $this->configModel - ->expects($this->exactly(2)) - ->method('getAvailableOptions') - ->will($this->returnValue($optionsSet)); - $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $commandTester = new CommandTester($command); - $commandTester->execute(['setup:config:set']); + $commandTester->execute([]); $this->assertSame( 'No module configuration is available, so all modules are enabled.' . PHP_EOL . 'You saved the deployment config.' . PHP_EOL, @@ -71,14 +66,6 @@ public function testExecuteInteractiveWithYes() ->expects($this->exactly(7)) ->method('getName') ->will($this->returnValue('db_host')); - $optionsSet = [ - $this->option - ]; - $this->configModel - ->expects($this->exactly(2)) - ->method('getAvailableOptions') - ->will($this->returnValue($optionsSet)); - $this->checkInteraction(true); } @@ -88,14 +75,6 @@ public function testExecuteInteractiveWithNo() ->expects($this->exactly(8)) ->method('getName') ->will($this->returnValue('db_host')); - $optionsSet = [ - $this->option - ]; - $this->configModel - ->expects($this->exactly(2)) - ->method('getAvailableOptions') - ->will($this->returnValue($optionsSet)); - $this->checkInteraction(false); } @@ -107,20 +86,24 @@ public function testExecuteInteractiveWithNo() */ private function checkInteraction($interactionType) { - $app = new Application(); - $app->add(new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig)); - $command = $app->find('setup:config:set'); + $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $dialog = $this->getMock('Symfony\Component\Console\Helper\DialogHelper', [], [], '', false); $dialog ->expects($this->once()) ->method('askConfirmation') ->will($this->returnValue($interactionType)); - $command->getHelperSet()->set($dialog, 'dialog'); + + /** @var \Symfony\Component\Console\Helper\HelperSet|\PHPUnit_Framework_MockObject_MockObject $helperSet */ + $helperSet = $this->getMock('Symfony\Component\Console\Helper\HelperSet', [], [], '', false); + $helperSet + ->expects($this->once()) + ->method('get') + ->with('dialog') + ->will($this->returnValue($dialog)); + $command->setHelperSet($helperSet); + $commandTester = new CommandTester($command); - $commandTester->execute( - ['command' => $command->getName(), '--db_host' => 'host'], - ['interactive'] - ); + $commandTester->execute(['--db_host' => 'host']); $this->assertSame( 'No module configuration is available, so all modules are enabled.' . PHP_EOL . 'You saved the deployment config.' . PHP_EOL, From bc45066a9915503fe8a2c2bc7a2f51fa0aaeff1b Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 11:28:08 -0500 Subject: [PATCH 161/214] MAGETWO-35137: Add deployment configuration set command - changes according to CR --- .../Magento/AdminNotification/Model/Feed.php | 2 +- .../Framework/Config/ConfigGenerator.php | 4 ++-- .../Framework/Config/ConfigOptionsList.php | 20 +++++++++---------- .../Config/Test/Unit/ConfigGeneratorTest.php | 18 ++++++++--------- .../Test/Unit/ConfigOptionsListTest.php | 2 +- .../Model/ConfigOptionsListCollector.php | 2 +- .../Setup/Test/Unit/Model/InstallerTest.php | 20 ++++++++++--------- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/app/code/Magento/AdminNotification/Model/Feed.php b/app/code/Magento/AdminNotification/Model/Feed.php index 6496e2160a9e8..99f3b30a2ce45 100644 --- a/app/code/Magento/AdminNotification/Model/Feed.php +++ b/app/code/Magento/AdminNotification/Model/Feed.php @@ -137,7 +137,7 @@ public function checkUpdate() $feedXml = $this->getFeedData(); - $installDate = strtotime($this->_deploymentConfig->get(\Magento\Framework\Config\ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)); + $installDate = strtotime($this->_deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)); if ($feedXml && $feedXml->channel && $feedXml->channel->item) { foreach ($feedXml->channel->item as $item) { diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index ad267a9c12f9d..c2d4fc6290867 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -12,7 +12,7 @@ /** * Creates deployment config data based on user input array - * this class introduced to break Magento\Framework\Config\ConfigOptionsList::createConfig + * this class introduced to break down Magento\Framework\Config\ConfigOptionsList::createConfig */ class ConfigGenerator { @@ -161,7 +161,7 @@ public function createDbConfig(array $data) ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] : ''; $configData->set( - ConfigOptionsList::SESSION_SAVE_DB . '/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX], + ConfigOptionsList::CONFIG_KEY . '/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX], $prefixKey ); diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php index f6e9e1e7e8257..4dc3e92edef3a 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -130,14 +130,14 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_ENCRYPTION_KEY, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'crypt/key', + self::CONFIG_PATH_CRYPT_KEY, 'Encryption key' ), new SelectConfigOption( self::INPUT_KEY_SESSION_SAVE, SelectConfigOption::FRONTEND_WIZARD_SELECT, [self::SESSION_SAVE_FILES, self::SESSION_SAVE_DB], - 'session/save', + self::CONFIG_PATH_SESSION_SAVE, 'Session save location', self::SESSION_SAVE_FILES ), @@ -145,54 +145,54 @@ public function getOptions() self::INPUT_KEY_DEFINITION_FORMAT, SelectConfigOption::FRONTEND_WIZARD_SELECT, DefinitionFactory::getSupportedFormats(), - 'definition/format', + self::CONFIG_PATH_DEFINITION_FORMAT, 'Type of definitions used by Object Manager' ), new TextConfigOption( self::INPUT_KEY_DB_HOST, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'db/connection/default/host', + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::KEY_HOST, 'Database server host', 'localhost' ), new TextConfigOption( self::INPUT_KEY_DB_NAME, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'db/connection/default/dbname', + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_NAME, 'Database name', 'magento2' ), new TextConfigOption( self::INPUT_KEY_DB_USER, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'db/connection/default/username', + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_USER, 'Database server username', 'root' ), new TextConfigOption( self::INPUT_KEY_DB_PASS, TextConfigOption::FRONTEND_WIZARD_PASSWORD, - 'db/connection/default/password', + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_PASS, 'Database server password', '' ), new TextConfigOption( self::INPUT_KEY_DB_PREFIX, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'db/table_prefix', + self::CONFIG_KEY . '/' . self::KEY_PREFIX, 'Database table prefix' ), new TextConfigOption( self::INPUT_KEY_DB_MODEL, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'db/connection/default/model', + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_MODEL, 'Database type', 'mysql4' ), new TextConfigOption( self::INPUT_KEY_DB_INIT_STATEMENTS, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'db/connection/default/initStatements', + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_INIT_STATEMENTS, 'Database initial set of commands', 'SET NAMES utf8;' ), diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php index 14891604ab71c..8479894c4e7ba 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php @@ -22,7 +22,7 @@ protected function setUp() $random->expects($this->any())->method('getRandomString')->willReturn('key'); $deployConfig= $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $deployConfig->expects($this->any())->method('isAvailable')->willReturn(false); - $this->configGeneratorObject = new \Magento\Framework\Config\ConfigGenerator($random, $deployConfig); + $this->configGeneratorObject = new ConfigGenerator($random, $deployConfig); } public function testCreateInstallConfig() @@ -34,7 +34,7 @@ public function testCreateInstallConfig() public function testCreateCryptConfigWithInput() { - $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key']; + $testData = [ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key']; $returnValue = $this->configGeneratorObject->createCryptConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); $this->assertEquals(['crypt' => ['key' => 'some-test_key']], $returnValue->getData()); @@ -49,15 +49,15 @@ public function testCreateCryptConfigWithoutInput() public function testCreateSessionConfigWithInput() { - $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files']; + $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['session' => ['save' => \Magento\Framework\Config\ConfigOptionsList::SESSION_SAVE_FILES]], $returnValue->getData()); + $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_FILES]], $returnValue->getData()); - $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db']; + $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db']; $returnValue = $this->configGeneratorObject->createSessionConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); - $this->assertEquals(['session' => ['save' => \Magento\Framework\Config\ConfigOptionsList::SESSION_SAVE_DB]], $returnValue->getData()); + $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_DB]], $returnValue->getData()); } public function testCreateSessionConfigWithoutInput() @@ -79,9 +79,9 @@ public function testCreateDbConfig() { $testData = [ ConfigOptionsList::INPUT_KEY_DB_HOST => 'testLocalhost', - \Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DB_NAME => 'testDbName', - \Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DB_USER => 'testDbUser', - \Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DB_PREFIX => 'testSomePrefix', + ConfigOptionsList::INPUT_KEY_DB_NAME => 'testDbName', + ConfigOptionsList::INPUT_KEY_DB_USER => 'testDbUser', + ConfigOptionsList::INPUT_KEY_DB_PREFIX => 'testSomePrefix', ]; $returnValue = $this->configGeneratorObject->createDbConfig($testData); $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey()); diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/ConfigOptionsListTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigOptionsListTest.php index 6471a0b9eb36a..cbc4a0cf75ab7 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/ConfigOptionsListTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigOptionsListTest.php @@ -16,7 +16,7 @@ class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase private $object; /** - * @var \Magento\Framework\Config\ConfigGenerator|\PHPUnit_Framework_MockObject_MockObject + * @var ConfigGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $generator; diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php index 0af2ef972ae95..a8b122f6c70f5 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php @@ -98,7 +98,7 @@ public function collectOptions() } } - // check setup + // check Framework $setupOptionsClassName = 'Magento\Framework\Config\ConfigOptionsList'; if (class_exists($setupOptionsClassName)) { $setupOptionsClass = $this->objectManagerProvider->get()->create($setupOptionsClassName); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 47fba55367f92..c63c1adc5f7d7 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -9,7 +9,6 @@ use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; use Magento\Framework\Config\ConfigOptionsList as SetupConfigOptionsList; use \Magento\Setup\Model\Installer; -use Magento\Framework\Config\ConfigOptionsList; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; @@ -120,13 +119,13 @@ class InstallerTest extends \PHPUnit_Framework_TestCase * @var array */ private static $dbConfig = [ - \Magento\Framework\Config\ConfigOptionsList::KEY_PREFIX => '', + SetupConfigOptionsList::KEY_PREFIX => '', 'connection' => [ 'default' => [ - \Magento\Framework\Config\ConfigOptionsList::KEY_HOST => '127.0.0.1', - \Magento\Framework\Config\ConfigOptionsList::KEY_NAME => 'magento', - ConfigOptionsList::KEY_USER => 'magento', - ConfigOptionsList::KEY_PASS => '', + SetupConfigOptionsList::KEY_HOST => '127.0.0.1', + SetupConfigOptionsList::KEY_NAME => 'magento', + SetupConfigOptionsList::KEY_USER => 'magento', + SetupConfigOptionsList::KEY_PASS => '', ], ], ]; @@ -227,8 +226,11 @@ public function testInstall() ]; $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true); $this->config->expects($this->any())->method('getSegment')->will($this->returnValueMap([ - [ConfigOptionsList::CONFIG_KEY, self::$dbConfig], - [ConfigOptionsList::ENCRYPT_CONFIG_KEY, [ConfigOptionsList::KEY_ENCRYPTION_KEY => 'encryption_key']] + [SetupConfigOptionsList::CONFIG_KEY, self::$dbConfig], + [ + SetupConfigOptionsList::ENCRYPT_CONFIG_KEY, + [SetupConfigOptionsList::KEY_ENCRYPTION_KEY => 'encryption_key'] + ] ])); $allModules = ['Foo_One' => [], 'Bar_Two' => []]; $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules); @@ -402,7 +404,7 @@ public function testCleanupDb() $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->config->expects($this->once()) ->method('getConfigData') - ->with(ConfigOptionsList::CONFIG_KEY) + ->with(SetupConfigOptionsList::CONFIG_KEY) ->willReturn(self::$dbConfig); $this->connection->expects($this->at(0))->method('quoteIdentifier')->with('magento')->willReturn('`magento`'); $this->connection->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); From dcb5c58754b2f26065d5b40dea095183bb91cda2 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 11:52:01 -0500 Subject: [PATCH 162/214] MAGETWO-35137: Add deployment configuration set command - removed condition from ConfigData::set() where it is inpossible to set root element --- .../Magento/Framework/Config/Data/ConfigData.php | 6 ++++-- .../Framework/Config/Test/Unit/Data/ConfigDataTest.php | 10 +++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index b95274c19e352..d8b7848ae105b 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -92,11 +92,13 @@ public function set($path, $value) */ private function expand($path) { - $chunks = array_pad(explode('/', $path), 2, ''); + $chunks = explode('/', $path); foreach ($chunks as $chunk) { if ('' == $chunk) { - throw new \InvalidArgumentException("The path '$path' is invalid"); + throw new \InvalidArgumentException( + "The path '$path' is invalid, it should not be empty and started or ended with '/' symbol" + ); } } diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php index d6255bbc541f8..06dac8ffd52e1 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php @@ -48,21 +48,17 @@ public function testSetWrongKey($key, $expectedException) { public function exceptionDataProvider() { return [ - 'segment element' => [ - 'test', - "The path 'test' is invalid" - ], 'segment is empty' => [ '/test/test/test', - "The path '/test/test/test' is invalid" + "The path '/test/test/test' is invalid, it should not be empty and started or ended with '/' symbol" ], 'key is empty' => [ '', - "The path '' is invalid" + "The path '' is invalid, it should not be empty and started or ended with '/' symbol" ], 'access by empty value key' => [ 'test/', - "The path 'test/' is invalid" + "The path 'test/' is invalid, it should not be empty and started or ended with '/' symbol" ] ]; } From bc61c8a8f657a609c0da2b8a956b69a4899ab53b Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 11:55:09 -0500 Subject: [PATCH 163/214] MAGETWO-35137: Add deployment configuration set command - fixed data provider name according to naming convencions --- .../Framework/Config/Test/Unit/Data/ConfigDataTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php index 06dac8ffd52e1..2d09936c80de8 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php @@ -35,7 +35,7 @@ public function testSet() /** * @param string $key * @param string $expectedException - * @dataProvider exceptionDataProvider + * @dataProvider setWrongKeyDataProvider */ public function testSetWrongKey($key, $expectedException) { @@ -45,7 +45,7 @@ public function testSetWrongKey($key, $expectedException) { $configData->set($key, 'value'); } - public function exceptionDataProvider() + public function setWrongKeyDataProvider() { return [ 'segment is empty' => [ From 8e16671a8f0b08fce9619ba04437b6906fa56e2a Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 12:00:03 -0500 Subject: [PATCH 164/214] MAGETWO-35137: Add deployment configuration set command - used constant instead of string value --- app/code/Magento/Backend/Setup/ConfigOptionsList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php index a6b1ff8915c4f..83a953cd2f223 100644 --- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php +++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php @@ -35,7 +35,7 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_BACKEND_FRONTNAME, TextConfigOption::FRONTEND_WIZARD_TEXT, - 'backend/frontName', + self::CONFIG_PATH_BACKEND_FRONTNAME, 'Backend frontname', 'admin' ) From 2e1ea3dad0da16e2e8fd45513d181bc81a7d21a4 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 12:17:46 -0500 Subject: [PATCH 165/214] MAGETWO-35137: Add deployment configuration set command - used path constand for db/table_prefix --- lib/internal/Magento/Framework/Config/ConfigOptionsList.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php index 4dc3e92edef3a..97b762139fcbd 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -25,6 +25,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface const CONFIG_PATH_DEFINITION_FORMAT = 'definition/format'; const CONFIG_PATH_RESOURCE_DEFAULT_SETUP = 'resource/default_setup/connection'; const CONFIG_PATH_DB_CONNECTION_DEFAULT = 'db/connection/default/'; + const CONFIG_PATH_DB_PREFIX = 'db/table_prefix'; /**#@-*/ /**#@+ @@ -179,7 +180,7 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_DB_PREFIX, TextConfigOption::FRONTEND_WIZARD_TEXT, - self::CONFIG_KEY . '/' . self::KEY_PREFIX, + self::CONFIG_PATH_DB_PREFIX, 'Database table prefix' ), new TextConfigOption( From b84456365cc0f1a5bbd50c8c5b820b5ee0471f0f Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 27 Mar 2015 12:20:03 -0500 Subject: [PATCH 166/214] MAGETWO-35138: Add Interactive Confirmation to config update - Changes based on CR feedback. --- .../Console/Command/ConfigSetCommandTest.php | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index 6d88b1c6afb55..bedf686796fdf 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -28,30 +28,34 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase private $deploymentConfig; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Console\Command\ConfigSetCommand */ - private $option; + private $command; public function setUp() { - $this->option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue('db_host')); $this->configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); $this->configModel ->expects($this->exactly(2)) ->method('getAvailableOptions') - ->will($this->returnValue([$this->option])); - $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); - $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $this->deploymentConfig + ->will($this->returnValue([$option])); + $moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $deploymentConfig ->expects($this->once()) ->method('get') ->will($this->returnValue('localhost')); + $this->command = new ConfigSetCommand($this->configModel, $moduleList, $deploymentConfig); } public function testExecuteNoInteractive() { - $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); - $commandTester = new CommandTester($command); + $commandTester = new CommandTester($this->command); $commandTester->execute([]); $this->assertSame( 'No module configuration is available, so all modules are enabled.' . PHP_EOL @@ -62,19 +66,20 @@ public function testExecuteNoInteractive() public function testExecuteInteractiveWithYes() { - $this->option - ->expects($this->exactly(7)) - ->method('getName') - ->will($this->returnValue('db_host')); + $this->configModel + ->expects($this->once()) + ->method('process') + ->with( ['db_host' => 'host']); + $this->checkInteraction(true); } public function testExecuteInteractiveWithNo() { - $this->option - ->expects($this->exactly(8)) - ->method('getName') - ->will($this->returnValue('db_host')); + $this->configModel + ->expects($this->once()) + ->method('process') + ->with([]); $this->checkInteraction(false); } @@ -86,7 +91,6 @@ public function testExecuteInteractiveWithNo() */ private function checkInteraction($interactionType) { - $command = new ConfigSetCommand($this->configModel, $this->moduleList, $this->deploymentConfig); $dialog = $this->getMock('Symfony\Component\Console\Helper\DialogHelper', [], [], '', false); $dialog ->expects($this->once()) @@ -100,9 +104,9 @@ private function checkInteraction($interactionType) ->method('get') ->with('dialog') ->will($this->returnValue($dialog)); - $command->setHelperSet($helperSet); + $this->command->setHelperSet($helperSet); - $commandTester = new CommandTester($command); + $commandTester = new CommandTester($this->command); $commandTester->execute(['--db_host' => 'host']); $this->assertSame( 'No module configuration is available, so all modules are enabled.' . PHP_EOL From c4eaf24df32bcabb55054bcaae6971b79f52ead4 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 26 Mar 2015 14:51:00 -0500 Subject: [PATCH 167/214] MAGETWO-35136: Delete Segments - fixes for CR comments --- .../Magento/TestFramework/Application.php | 3 ++- .../Test/Legacy/_files/obsolete_classes.php | 1 + .../Framework/App/Cache/Frontend/Pool.php | 16 +++++++------- .../Framework/App/Cache/Type/CacheConfig.php | 2 +- .../Framework/App/Cache/Type/FrontendPool.php | 16 +++++++------- .../Framework/App/DeploymentConfig/Reader.php | 4 ++-- .../Magento/Framework/App/Resource.php | 16 +++++++------- .../Magento/Framework/App/Resource/Config.php | 6 ++--- .../App/Test/Unit/Cache/Frontend/PoolTest.php | 22 +++++++++---------- .../Test/Unit/Cache/Type/FrontendPoolTest.php | 20 ++++++++--------- .../Test/Unit/DeploymentConfig/WriterTest.php | 1 - .../Framework/App/Test/Unit/ResourceTest.php | 13 +++++------ 12 files changed, 60 insertions(+), 60 deletions(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index aa6f4285c1688..994e73f145e6f 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -162,7 +162,8 @@ public function getDbInstance() if (null === $this->_db) { if ($this->isInstalled()) { $reader = new \Magento\Framework\App\DeploymentConfig\Reader($this->dirList); - $dbConfig = $reader->getConfigData(ConfigOptionsList::CONFIG_KEY); + $deploymentConfig = new \Magento\Framework\App\DeploymentConfig($reader); + $dbConfig = $deploymentConfig->get(ConfigOptionsList::CONFIG_KEY); $dbInfo = $dbConfig['connection']['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 1cb37c7eb7d5b..0c241018faedf 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3124,4 +3124,5 @@ ['Magento\Framework\App\DeploymentConfig\SessionConfig'], ['Magento\Framework\App\DeploymentConfig\CacheConfig'], ['Magento\Setup\Model\DeploymentConfigMapper'], + ['Magento\Framework\App\DeploymentConfig\EncryptConfig'], ]; diff --git a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php index 8ba4061203c79..36ad8a3858d93 100644 --- a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php +++ b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php @@ -5,8 +5,8 @@ */ namespace Magento\Framework\App\Cache\Frontend; -use Magento\Framework\App\DeploymentConfig\Reader; -use Magento\Framework\Config\ConfigOptionsList; +use Magento\Framework\App\DeploymentConfig; +use Magento\Setup\Model\ConfigOptionsList; /** * In-memory readonly pool of all cache front-end instances known to the system @@ -19,9 +19,9 @@ class Pool implements \Iterator const DEFAULT_FRONTEND_ID = 'default'; /** - * @var Reader + * @var DeploymentConfig */ - private $reader; + private $deploymentConfig; /** * @var Factory @@ -39,13 +39,13 @@ class Pool implements \Iterator private $_frontendSettings; /** - * @param Reader $reader + * @param DeploymentConfig $deploymentConfig * @param Factory $frontendFactory * @param array $frontendSettings Format: array('' => array(), ...) */ - public function __construct(Reader $reader, Factory $frontendFactory, array $frontendSettings = []) + public function __construct(DeploymentConfig $deploymentConfig, Factory $frontendFactory, array $frontendSettings = []) { - $this->reader = $reader; + $this->deploymentConfig = $deploymentConfig; $this->_factory = $frontendFactory; $this->_frontendSettings = $frontendSettings + [self::DEFAULT_FRONTEND_ID => []]; } @@ -77,7 +77,7 @@ protected function _getCacheSettings() * Merging is intentionally implemented through array_merge() instead of array_replace_recursive() * to avoid "inheritance" of the default settings that become irrelevant as soon as cache storage type changes */ - $cacheInfo = $this->reader->getConfigData(ConfigOptionsList::KEY_CACHE); + $cacheInfo = $this->deploymentConfig->get(ConfigOptionsList::KEY_CACHE); if (null !== $cacheInfo) { return array_merge($this->_frontendSettings, $cacheInfo[ConfigOptionsList::KEY_FRONTEND]); } diff --git a/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php b/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php index 50c41a4e579f6..38aec295d9387 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php @@ -43,6 +43,7 @@ public function __construct(array $data) /** * Returns current key. * + * @return string */ public function getKey() { @@ -94,5 +95,4 @@ private function filterArray(array $data) } return $data; } - } diff --git a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php index 8790a2a3e1685..76b9563a4f126 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php @@ -5,8 +5,8 @@ */ namespace Magento\Framework\App\Cache\Type; -use Magento\Framework\App\DeploymentConfig\Reader; -use Magento\Framework\Config\ConfigOptionsList; +use Magento\Framework\App\DeploymentConfig; +use Magento\Setup\Model\ConfigOptionsList; /** * In-memory readonly pool of cache front-ends with enforced access control, specific to cache types @@ -19,9 +19,9 @@ class FrontendPool private $_objectManager; /** - * @var \Magento\Framework\App\DeploymentConfig\Reader + * @var \Magento\Framework\App\DeploymentConfig */ - private $reader; + private $deploymentConfig; /** * @var \Magento\Framework\App\Cache\Frontend\Pool @@ -40,18 +40,18 @@ class FrontendPool /** * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Framework\App\DeploymentConfig\Reader $deploymentConfig + * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig * @param \Magento\Framework\App\Cache\Frontend\Pool $frontendPool * @param array $typeFrontendMap Format: array('' => '', ...) */ public function __construct( \Magento\Framework\ObjectManagerInterface $objectManager, - \Magento\Framework\App\DeploymentConfig\Reader $reader, + \Magento\Framework\App\DeploymentConfig $deploymentConfig, \Magento\Framework\App\Cache\Frontend\Pool $frontendPool, array $typeFrontendMap = [] ) { $this->_objectManager = $objectManager; - $this->reader = $reader; + $this->deploymentConfig = $deploymentConfig; $this->_frontendPool = $frontendPool; $this->_typeFrontendMap = $typeFrontendMap; } @@ -86,7 +86,7 @@ public function get($cacheType) protected function _getCacheFrontendId($cacheType) { $result = null; - $cacheInfo = $this->reader->getConfigData(ConfigOptionsList::KEY_CACHE); + $cacheInfo = $this->deploymentConfig->get(ConfigOptionsList::KEY_CACHE); if (null !== $cacheInfo) { $result = $cacheInfo[ConfigOptionsList::KEY_TYPE][$cacheType][ConfigOptionsList::KEY_FRONTEND]; } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php index 570e1c01896eb..05017e6821608 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php @@ -83,8 +83,8 @@ public function load($configFile = null) /** * Gets a value specified key from config data * - * @param $key - * @return null + * @param string $key + * @return array */ public function getConfigData($key) { diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index 5d1d05d28aff5..7bbd8a4c6ea4a 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -7,7 +7,7 @@ */ namespace Magento\Framework\App; -use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Resource\ConfigInterface as ResourceConfigInterface; use Magento\Framework\Model\Resource\Type\Db\ConnectionFactoryInterface; use Magento\Framework\Config\ConfigOptionsList; @@ -53,9 +53,9 @@ class Resource protected $_connectionFactory; /** - * @var Reader $reader + * @var DeploymentConfig $deploymentConfig */ - private $reader; + private $deploymentConfig; /** * @var string @@ -65,18 +65,18 @@ class Resource /** * @param ResourceConfigInterface $resourceConfig * @param ConnectionFactoryInterface $adapterFactory - * @param Reader $reader + * @param DeploymentConfig $deploymentConfig * @param string $tablePrefix */ public function __construct( ResourceConfigInterface $resourceConfig, ConnectionFactoryInterface $adapterFactory, - Reader $reader, + DeploymentConfig $deploymentConfig, $tablePrefix = '' ) { $this->_config = $resourceConfig; $this->_connectionFactory = $adapterFactory; - $this->reader = $reader; + $this->deploymentConfig = $deploymentConfig; $this->_tablePrefix = $tablePrefix ?: null; } @@ -104,7 +104,7 @@ public function getConnectionByName($connectionName) return $this->_connections[$connectionName]; } - $dbInfo = $this->reader->getConfigData(ConfigOptionsList::CONFIG_KEY); + $dbInfo = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_KEY); if (null === $dbInfo) { return false; } @@ -231,7 +231,7 @@ public function getFkName($priTableName, $priColumnName, $refTableName, $refColu private function getTablePrefix() { if (null === $this->_tablePrefix) { - $this->_tablePrefix = (string)$this->reader->getConfigData(ConfigOptionsList::KEY_PREFIX); + $this->_tablePrefix = (string)$this->deploymentConfig->get(ConfigOptionsList::KEY_PREFIX); } return $this->_tablePrefix; } diff --git a/lib/internal/Magento/Framework/App/Resource/Config.php b/lib/internal/Magento/Framework/App/Resource/Config.php index 9b6564e790266..52afda9fd2a58 100644 --- a/lib/internal/Magento/Framework/App/Resource/Config.php +++ b/lib/internal/Magento/Framework/App/Resource/Config.php @@ -24,7 +24,7 @@ class Config extends \Magento\Framework\Config\Data\Scoped implements ConfigInte * @param Config\Reader $reader * @param \Magento\Framework\Config\ScopeInterface $configScope * @param \Magento\Framework\Config\CacheInterface $cache - * @param \Magento\Framework\App\DeploymentConfig\Reader $configReader + * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig * @param string $cacheId * @throws \InvalidArgumentException */ @@ -32,12 +32,12 @@ public function __construct( Config\Reader $reader, \Magento\Framework\Config\ScopeInterface $configScope, \Magento\Framework\Config\CacheInterface $cache, - \Magento\Framework\App\DeploymentConfig\Reader $configReader, + \Magento\Framework\App\DeploymentConfig $deploymentConfig, $cacheId = 'resourcesCache' ) { parent::__construct($reader, $configScope, $cache, $cacheId); - foreach ($configReader->getConfigData('resource') as $resourceName => $resourceData) { + foreach ($deploymentConfig->get('resource') as $resourceName => $resourceData) { if (!isset($resourceData['connection'])) { throw new \InvalidArgumentException('Invalid initial resource configuration'); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php index 54975ff686672..820540752ed2f 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\App\Test\Unit\Cache\Frontend; -use \Magento\Framework\App\Cache\Frontend\Pool; +use Magento\Framework\App\Cache\Frontend\Pool; use Magento\Framework\Config\ConfigOptionsList; class PoolTest extends \PHPUnit_Framework_TestCase @@ -41,11 +41,11 @@ protected function setUp() $frontendFactory = $this->getMock('Magento\Framework\App\Cache\Frontend\Factory', [], [], '', false); $frontendFactory->expects($this->any())->method('create')->will($this->returnValueMap($frontendFactoryMap)); - $reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); - $reader->expects( + $deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $deploymentConfig->expects( $this->any() )->method( - 'getConfigData' + 'get' )->with( ConfigOptionsList::KEY_CACHE )->will( @@ -58,7 +58,7 @@ protected function setUp() ]; $this->_model = new \Magento\Framework\App\Cache\Frontend\Pool( - $reader, + $deploymentConfig, $frontendFactory, $frontendSettings ); @@ -69,10 +69,10 @@ protected function setUp() */ public function testConstructorNoInitialization() { - $reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $frontendFactory = $this->getMock('Magento\Framework\App\Cache\Frontend\Factory', [], [], '', false); $frontendFactory->expects($this->never())->method('create'); - new \Magento\Framework\App\Cache\Frontend\Pool($reader, $frontendFactory); + new \Magento\Framework\App\Cache\Frontend\Pool($deploymentConfig, $frontendFactory); } /** @@ -87,11 +87,11 @@ public function testInitializationParams( array $frontendSettings, array $expectedFactoryArg ) { - $reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); - $reader->expects( + $deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $deploymentConfig->expects( $this->once() )->method( - 'getConfigData' + 'get' )->with( ConfigOptionsList::KEY_CACHE )->will( @@ -101,7 +101,7 @@ public function testInitializationParams( $frontendFactory = $this->getMock('Magento\Framework\App\Cache\Frontend\Factory', [], [], '', false); $frontendFactory->expects($this->at(0))->method('create')->with($expectedFactoryArg); - $model = new \Magento\Framework\App\Cache\Frontend\Pool($reader, $frontendFactory, $frontendSettings); + $model = new \Magento\Framework\App\Cache\Frontend\Pool($deploymentConfig, $frontendFactory, $frontendSettings); $model->current(); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php index 236281dfbaa69..d29d95617c690 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php @@ -21,9 +21,9 @@ class FrontendPoolTest extends \PHPUnit_Framework_TestCase protected $_objectManager; /** - * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */ - protected $reader; + protected $deploymentConfig; /** * @var \Magento\Framework\App\Cache\Frontend\Pool|\PHPUnit_Framework_MockObject_MockObject @@ -33,33 +33,33 @@ class FrontendPoolTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->_objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface'); - $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->_cachePool = $this->getMock('Magento\Framework\App\Cache\Frontend\Pool', [], [], '', false); $this->_model = new FrontendPool( $this->_objectManager, - $this->reader, + $this->deploymentConfig, $this->_cachePool, ['fixture_cache_type' => 'fixture_frontend_id'] ); } /** - * @param string|null $fixtureconfigData + * @param string|null $fixtureConfigData * @param string $inputCacheType * @param string $expectedFrontendId * * @dataProvider getDataProvider */ - public function testGet($fixtureconfigData, $inputCacheType, $expectedFrontendId) + public function testGet($fixtureConfigData, $inputCacheType, $expectedFrontendId) { - $this->reader->expects( + $this->deploymentConfig->expects( $this->once() )->method( - 'getConfigData' + 'get' )->with( - ConfigOptionsList::KEY_CACHE + ConfigOptionsList::KEY_CACHE )->will( - $this->returnValue($fixtureconfigData) + $this->returnValue($fixtureConfigData) ); $cacheFrontend = $this->getMock('Magento\Framework\Cache\FrontendInterface'); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php index 7f2ef3bee17da..7f7e5558a9b80 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php @@ -101,5 +101,4 @@ public function testSaveConfig() $this->object->saveConfig($testSetUpdate); } - } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php index 970caabd55e81..a5604bf9e0543 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php @@ -9,7 +9,6 @@ namespace Magento\Framework\App\Test\Unit; use \Magento\Framework\App\Resource; - use Magento\Framework\Config\ConfigOptionsList; class ResourceTest extends \PHPUnit_Framework_TestCase @@ -29,9 +28,9 @@ class ResourceTest extends \PHPUnit_Framework_TestCase protected $_connectionFactory; /** - * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $reader; + private $deploymentConfig; /** * @var \Magento\Framework\App\Resource @@ -58,9 +57,9 @@ public function setUp() ->with(self::RESOURCE_NAME) ->will($this->returnValue(self::CONNECTION_NAME)); - $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); - $this->reader->expects($this->any()) - ->method('getConfigData') + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $this->deploymentConfig->expects($this->any()) + ->method('get') ->with(ConfigOptionsList::CONFIG_KEY) ->will($this->returnValue( [ @@ -88,7 +87,7 @@ public function setUp() $this->resource = new Resource( $this->_config, $this->_connectionFactory, - $this->reader, + $this->deploymentConfig, self::TABLE_PREFIX ); } From e8ee8516261cf4bb8b133f1100f487a3048e8aff Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 11:34:36 -0500 Subject: [PATCH 168/214] MAGETWO-35136: Delete Segments - CR comment fixes --- .../Source/Storage/Media/DatabaseTest.php | 6 +- .../Magento/Mtf/App/State/AbstractState.php | 5 +- .../Magento/TestFramework/Application.php | 2 +- .../Model/Resource/Db/ProfilerTest.php | 2 +- .../Framework/App/Cache/Frontend/Pool.php | 7 ++- .../Framework/App/Cache/Type/CacheConfig.php | 36 ----------- .../Framework/App/Cache/Type/FrontendPool.php | 22 ++++++- .../Framework/App/DeploymentConfig.php | 10 +++ .../Framework/App/DeploymentConfig/Reader.php | 15 ----- .../Framework/App/DeploymentConfig/Writer.php | 11 ++++ .../Magento/Framework/App/Resource.php | 6 +- .../Magento/Framework/App/Resource/Config.php | 2 +- .../App/Test/Unit/Cache/Frontend/PoolTest.php | 5 +- .../Test/Unit/Cache/Type/FrontendPoolTest.php | 2 +- .../Test/Unit/DeploymentConfig/WriterTest.php | 18 +++++- .../App/Test/Unit/Resource/ConfigTest.php | 12 ++-- .../Framework/App/Test/Unit/ResourceTest.php | 4 +- .../Test/Unit/Backend/_files/MongoBinData.txt | 0 .../Framework/Config/ConfigGenerator.php | 2 +- .../Framework/Config/ConfigOptionsList.php | 33 +++------- .../Magento/Framework/Module/ModuleList.php | 2 +- .../Module/ModuleList/DeploymentConfig.php | 61 ------------------- .../ModuleList/DeploymentConfigFactory.php | 24 -------- .../Magento/Framework/Module/Status.php | 7 ++- .../DeploymentConfigFactoryTest.php | 26 -------- .../Unit/ModuleList/DeploymentConfigTest.php | 48 --------------- .../Module/Test/Unit/ModuleListTest.php | 7 +++ .../Framework/Module/Test/Unit/StatusTest.php | 4 +- setup/src/Magento/Setup/Model/Installer.php | 43 ++++++------- .../Magento/Setup/Model/InstallerFactory.php | 4 +- .../src/Magento/Setup/Model/ModuleStatus.php | 6 +- .../Magento/Setup/Module/ResourceFactory.php | 6 +- .../Setup/Test/Unit/Model/InstallerTest.php | 46 ++++---------- .../Test/Unit/Module/ResourceFactoryTest.php | 2 +- 34 files changed, 149 insertions(+), 337 deletions(-) mode change 100644 => 100755 lib/internal/Magento/Framework/Cache/Test/Unit/Backend/_files/MongoBinData.txt delete mode 100644 lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php delete mode 100644 lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfigFactory.php delete mode 100644 lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/DeploymentConfigFactoryTest.php delete mode 100644 lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/DeploymentConfigTest.php diff --git a/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php b/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php index f873b430975e6..d23e188d5fc45 100644 --- a/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php +++ b/app/code/Magento/MediaStorage/Test/Unit/Model/Config/Source/Storage/Media/DatabaseTest.php @@ -34,12 +34,12 @@ protected function setUp() )->method( 'get' )->with( - ConfigOptionsList::KEY_RESOURCE + 'resource' )->will( $this->returnValue( [ - 'default_setup' => ['name' => 'default_setup', ConfigOptionsList::KEY_CONNECTION => 'connect1'], - 'custom_resource' => ['name' => 'custom_resource', ConfigOptionsList::KEY_CONNECTION => 'connect2'], + 'default_setup' => ['name' => 'default_setup', 'connection' => 'connect1'], + 'custom_resource' => ['name' => 'custom_resource', 'connection' => 'connect2'], ] ) ); diff --git a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php index 90b07c2d341d0..f62fe6bc415cc 100644 --- a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php +++ b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php @@ -44,9 +44,8 @@ public function clearInstance() $reader = new \Magento\Framework\App\DeploymentConfig\Reader($dirList); $deploymentConfig = new \Magento\Framework\App\DeploymentConfig($reader); - $dbConfig = $deploymentConfig->get(ConfigOptionsList::CONFIG_KEY); - - $dbInfo = $dbConfig['connection']['default']; + $dbConfig = $deploymentConfig->get('resource/db/connection'); + $dbInfo = $dbConfig['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; $password = $dbInfo['password']; diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 994e73f145e6f..079edf64d9749 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -163,7 +163,7 @@ public function getDbInstance() if ($this->isInstalled()) { $reader = new \Magento\Framework\App\DeploymentConfig\Reader($this->dirList); $deploymentConfig = new \Magento\Framework\App\DeploymentConfig($reader); - $dbConfig = $deploymentConfig->get(ConfigOptionsList::CONFIG_KEY); + $dbConfig = $deploymentConfig->get(ConfigOptionsList::CONFIG_DB_KEY); $dbInfo = $dbConfig['connection']['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; diff --git a/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php b/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php index fa326a6df0a03..a7929fd23d60a 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php @@ -46,7 +46,7 @@ protected function _getConnectionRead() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $reader = $objectManager->get('Magento\Framework\App\DeploymentConfig\Reader'); - $dbConfig = $reader->getConfigData(ConfigOptionsList::CONFIG_KEY); + $dbConfig = $reader->getConfigData(ConfigOptionsList::CONFIG_DB_KEY); $connectionConfig = $dbConfig['connection']['default']; $connectionConfig['profiler'] = [ 'class' => 'Magento\Framework\Model\Resource\Db\Profiler', diff --git a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php index 36ad8a3858d93..f42bc1cfb07b8 100644 --- a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php +++ b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php @@ -5,8 +5,9 @@ */ namespace Magento\Framework\App\Cache\Frontend; +use Magento\Framework\App\Cache\Type\FrontendPool; use Magento\Framework\App\DeploymentConfig; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * In-memory readonly pool of all cache front-end instances known to the system @@ -77,9 +78,9 @@ protected function _getCacheSettings() * Merging is intentionally implemented through array_merge() instead of array_replace_recursive() * to avoid "inheritance" of the default settings that become irrelevant as soon as cache storage type changes */ - $cacheInfo = $this->deploymentConfig->get(ConfigOptionsList::KEY_CACHE); + $cacheInfo = $this->deploymentConfig->get(FrontendPool::KEY_CACHE); if (null !== $cacheInfo) { - return array_merge($this->_frontendSettings, $cacheInfo[ConfigOptionsList::KEY_FRONTEND]); + return array_merge($this->_frontendSettings, $cacheInfo[FrontendPool::KEY_FRONTEND_CACHE]); } return $this->_frontendSettings; } diff --git a/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php b/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php index 38aec295d9387..0b72097d78d9b 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php @@ -59,40 +59,4 @@ public function getData() { return $this->data; } - - /** - * Update data - * - * @param string[] $data - * @return array - */ - protected function update(array $data) - { - // get rid of null values - $data = $this->filterArray($data); - if (empty($data)) { - return $this->data; - } - - $new = array_replace_recursive($this->data, $data); - return $new; - } - - /** - * Filter an array recursively - * - * @param array $data - * @return array - */ - private function filterArray(array $data) - { - foreach ($data as $key => $value) { - if (is_array($value)) { - $data[$key] = $this->filterArray($value); - } elseif (!isset($value)) { - unset($data[$key]); - } - } - return $data; - } } diff --git a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php index 76b9563a4f126..0255c688f70c5 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php @@ -5,14 +5,30 @@ */ namespace Magento\Framework\App\Cache\Type; +use Magento\Framework\App\Cache\Frontend\Pool; use Magento\Framework\App\DeploymentConfig; -use Magento\Setup\Model\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList; /** * In-memory readonly pool of cache front-ends with enforced access control, specific to cache types */ class FrontendPool { + /** + * Array key for cache type + */ + const KEY_CACHE_TYPE = 'type'; + + /** + * Array key for cache frontend + */ + const KEY_FRONTEND_CACHE = 'frontend'; + + /** + * Segment key for cache + */ + const KEY_CACHE = 'cache'; + /** * @var \Magento\Framework\ObjectManagerInterface */ @@ -86,9 +102,9 @@ public function get($cacheType) protected function _getCacheFrontendId($cacheType) { $result = null; - $cacheInfo = $this->deploymentConfig->get(ConfigOptionsList::KEY_CACHE); + $cacheInfo = $this->deploymentConfig->get(self::KEY_CACHE); if (null !== $cacheInfo) { - $result = $cacheInfo[ConfigOptionsList::KEY_TYPE][$cacheType][ConfigOptionsList::KEY_FRONTEND]; + $result = $cacheInfo[self::KEY_CACHE_TYPE][$cacheType][self::KEY_FRONTEND_CACHE]; } if (!$result) { if (isset($this->_typeFrontendMap[$cacheType])) { diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig.php index fe8ecaf8c1263..cd909817925c9 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig.php @@ -109,6 +109,16 @@ public function getConfigData($key = null) return $this->data; } + /** + * Resets config data + * + * @return void + */ + public function resetData() + { + $this->data = null; + } + /** * Loads the configuration data * diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php index 05017e6821608..de210b4287105 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php @@ -79,19 +79,4 @@ public function load($configFile = null) $result = @include $file; return $result ?: []; } - - /** - * Gets a value specified key from config data - * - * @param string $key - * @return array - */ - public function getConfigData($key) - { - $config = $this->load(); - if (!isset($config[$key])) { - return null; - } - return $config[$key]; - } } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index d07a68632ac8e..61237d0a3e2e0 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -6,9 +6,11 @@ namespace Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Tools\SampleData\Helper\Deploy; /** * Deployment configuration writer @@ -41,24 +43,32 @@ class Writer */ private $configFilePool; + /** + * @var DeploymentConfig + */ + private $deploymentConfig; + /** * Constructor * * @param Reader $reader * @param Filesystem $filesystem * @param ConfigFilePool $configFilePool + * @param DeploymentConfig $deploymentConfig * @param Writer\FormatterInterface $formatter */ public function __construct( Reader $reader, Filesystem $filesystem, ConfigFilePool $configFilePool, + DeploymentConfig $deploymentConfig, Writer\FormatterInterface $formatter = null ) { $this->reader = $reader; $this->filesystem = $filesystem; $this->formatter = $formatter ?: new Writer\PhpFormatter(); $this->configFilePool = $configFilePool; + $this->deploymentConfig = $deploymentConfig; } /** @@ -97,5 +107,6 @@ public function saveConfig(array $data) $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents); } } + $this->deploymentConfig->resetData(); } } diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index 7bbd8a4c6ea4a..4b60fc797073d 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -104,7 +104,7 @@ public function getConnectionByName($connectionName) return $this->_connections[$connectionName]; } - $dbInfo = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_KEY); + $dbInfo = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_DB_KEY); if (null === $dbInfo) { return false; } @@ -231,7 +231,9 @@ public function getFkName($priTableName, $priColumnName, $refTableName, $refColu private function getTablePrefix() { if (null === $this->_tablePrefix) { - $this->_tablePrefix = (string)$this->deploymentConfig->get(ConfigOptionsList::KEY_PREFIX); + $this->_tablePrefix = (string)$this->deploymentConfig->get( + ConfigOptionsList::CONFIG_DB_KEY .'/' . ConfigOptionsList::KEY_PREFIX + ); } return $this->_tablePrefix; } diff --git a/lib/internal/Magento/Framework/App/Resource/Config.php b/lib/internal/Magento/Framework/App/Resource/Config.php index 52afda9fd2a58..214a97437fb59 100644 --- a/lib/internal/Magento/Framework/App/Resource/Config.php +++ b/lib/internal/Magento/Framework/App/Resource/Config.php @@ -37,7 +37,7 @@ public function __construct( ) { parent::__construct($reader, $configScope, $cache, $cacheId); - foreach ($deploymentConfig->get('resource') as $resourceName => $resourceData) { + foreach ($deploymentConfig->getConfigData('resource') as $resourceName => $resourceData) { if (!isset($resourceData['connection'])) { throw new \InvalidArgumentException('Invalid initial resource configuration'); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php index 820540752ed2f..ea043cf096b04 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php @@ -6,6 +6,7 @@ namespace Magento\Framework\App\Test\Unit\Cache\Frontend; use Magento\Framework\App\Cache\Frontend\Pool; +use Magento\Framework\App\Cache\Type\FrontendPool; use Magento\Framework\Config\ConfigOptionsList; class PoolTest extends \PHPUnit_Framework_TestCase @@ -47,7 +48,7 @@ protected function setUp() )->method( 'get' )->with( - ConfigOptionsList::KEY_CACHE + FrontendPool::KEY_CACHE )->will( $this->returnValue(['frontend' => ['resource2' => ['r2d1' => 'value1', 'r2d2' => 'value2']]]) ); @@ -93,7 +94,7 @@ public function testInitializationParams( )->method( 'get' )->with( - ConfigOptionsList::KEY_CACHE + FrontendPool::KEY_CACHE )->will( $this->returnValue($fixtureCacheConfig) ); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php index d29d95617c690..4eb49a45bbeff 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php @@ -57,7 +57,7 @@ public function testGet($fixtureConfigData, $inputCacheType, $expectedFrontendId )->method( 'get' )->with( - ConfigOptionsList::KEY_CACHE + FrontendPool::KEY_CACHE )->will( $this->returnValue($fixtureConfigData) ); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php index 7f7e5558a9b80..8141a35fe8b0d 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php @@ -6,7 +6,8 @@ namespace Magento\Framework\App\Test\Unit\DeploymentConfig; -use \Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Config\File\ConfigFilePool; @@ -37,6 +38,11 @@ class WriterTest extends \PHPUnit_Framework_TestCase */ private $configFilePool; + /** + * @var DeploymentConfig + */ + private $deploymentConfig; + protected function setUp() { $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); @@ -45,7 +51,14 @@ protected function setUp() 'Magento\Framework\App\DeploymentConfig\Writer\FormatterInterface' ); $this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); - $this->object = new Writer($this->reader, $filesystem, $this->configFilePool, $this->formatter); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $this->object = new Writer( + $this->reader, + $filesystem, + $this->configFilePool, + $this->deploymentConfig, + $this->formatter + ); $this->reader->expects($this->any())->method('getFile')->willReturn('test.php'); $this->dirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $filesystem->expects($this->any()) @@ -89,6 +102,7 @@ public function testSaveConfig() ], ]; + $this->deploymentConfig->expects($this->once())->method('resetData'); $this->configFilePool->expects($this->once())->method('getPaths')->willReturn($configFiles); $this->dirWrite->expects($this->any())->method('isExist')->willReturn(true); $this->reader->expects($this->once())->method('load')->willReturn($testSetExisting[ConfigFilePool::APP_CONFIG]); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Resource/ConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Resource/ConfigTest.php index 750d8105e2401..ea30012039568 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Resource/ConfigTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Resource/ConfigTest.php @@ -65,8 +65,8 @@ protected function setUp() $this->returnValue(serialize($this->_resourcesConfig)) ); - $readerMock = $this->getMock('\Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); - $readerMock->expects($this->once()) + $deploymentConfig = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false); + $deploymentConfig->expects($this->once()) ->method('getConfigData') ->with('resource') ->willReturn($this->_initialResources); @@ -75,7 +75,7 @@ protected function setUp() $this->_readerMock, $this->_scopeMock, $this->_cacheMock, - $readerMock, + $deploymentConfig, 'cacheId' ); } @@ -95,8 +95,8 @@ public function testGetConnectionName($resourceName, $connectionName) */ public function testExceptionConstructor() { - $readerMock = $this->getMock('\Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); - $readerMock->expects($this->once()) + $deploymentConfig = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false); + $deploymentConfig->expects($this->once()) ->method('getConfigData') ->with('resource') ->willReturn(['validResource' => ['somekey' => 'validConnectionName']]); @@ -105,7 +105,7 @@ public function testExceptionConstructor() $this->_readerMock, $this->_scopeMock, $this->_cacheMock, - $readerMock, + $deploymentConfig, 'cacheId' ); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php index a5604bf9e0543..565838ce9a600 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php @@ -59,8 +59,8 @@ public function setUp() $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->deploymentConfig->expects($this->any()) - ->method('get') - ->with(ConfigOptionsList::CONFIG_KEY) + ->method('getConfigData') + ->with(ConfigOptionsList::CONFIG_DB_KEY) ->will($this->returnValue( [ 'connection' => [ diff --git a/lib/internal/Magento/Framework/Cache/Test/Unit/Backend/_files/MongoBinData.txt b/lib/internal/Magento/Framework/Cache/Test/Unit/Backend/_files/MongoBinData.txt old mode 100644 new mode 100755 diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index c2d4fc6290867..0083629019f2c 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -161,7 +161,7 @@ public function createDbConfig(array $data) ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] : ''; $configData->set( - ConfigOptionsList::CONFIG_KEY . '/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX], + ConfigOptionsList::CONFIG_DB_KEY . '/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX], $prefixKey ); diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php index 97b762139fcbd..9493f2438add5 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -66,44 +66,27 @@ class ConfigOptionsList implements ConfigOptionsListInterface const KEY_MODEL = 'model'; const KEY_INIT_STATEMENTS = 'initStatements'; const KEY_ACTIVE = 'active'; + /**#@-*/ + /** * Segment key */ - const CONFIG_KEY = 'db'; + const CONFIG_DB_KEY = 'db'; + /** * Array Key for encryption key in deployment config file */ const KEY_ENCRYPTION_KEY = 'key'; - /** - * Segment key - */ - const ENCRYPT_CONFIG_KEY = 'crypt'; - /** - * Array Key for install date - */ - const KEY_DATE = 'date'; - /** - * Array Key for connection - */ - const KEY_CONNECTION = 'connection'; + /** * Segment key */ const KEY_RESOURCE = 'resource'; + /** - * Array key for cache frontend - */ - const KEY_FRONTEND = 'frontend'; - /** - * Array key for cache type - */ - const KEY_TYPE = 'type'; - /** - * Segment key + * Segment key for modules */ - const KEY_CACHE = 'cache'; - - /**#@-*/ + const KEY_MODULES = 'modules'; /** * Generate config data for individual segments diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php index 6feb34bce0fde..aa5cf2dc92096 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/ModuleList.php @@ -140,7 +140,7 @@ public function isModuleInfoAvailable() private function loadConfigData() { if (null === $this->configData && ($this->config->isAvailable())) { - $this->configData = $this->config->getConfigData(ModuleList\DeploymentConfig::KEY_MODULES); + $this->configData = $this->config->getConfigData(ConfigOptionsList::KEY_MODULES); } } } diff --git a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php b/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php deleted file mode 100644 index c6e0ac425a66a..0000000000000 --- a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfig.php +++ /dev/null @@ -1,61 +0,0 @@ - $value) { - if (!preg_match('/^[A-Z][A-Za-z\d]+_[A-Z][A-Za-z\d]+$/', $key)) { - throw new \InvalidArgumentException("Incorrect module name: '{$key}'"); - } - $this->data[$key] = (int)$value; - } - } - - /** - * Returns config data - * - * @return array|mixed - */ - public function getData() - { - return $this->data; - } - - /** - * Returns key - * - * @return string - */ - public function getKey() - { - return self::KEY_MODULES; - } -} diff --git a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfigFactory.php b/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfigFactory.php deleted file mode 100644 index ae8f3cc882761..0000000000000 --- a/lib/internal/Magento/Framework/Module/ModuleList/DeploymentConfigFactory.php +++ /dev/null @@ -1,24 +0,0 @@ -getAllModules($modules) as $name) { $currentStatus = $this->list->has($name); if (in_array($name, $modules)) { - $result[$name] = $isEnabled; + $result[$name] = (int)$isEnabled; } else { - $result[$name] = $currentStatus; + $result[$name] = (int)$currentStatus; } } - $this->writer->saveConfig($result); + $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]]); $this->cleanup->clearCaches(); $this->cleanup->clearCodeGeneratedFiles(); } diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/DeploymentConfigFactoryTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/DeploymentConfigFactoryTest.php deleted file mode 100644 index fc07edc800666..0000000000000 --- a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/DeploymentConfigFactoryTest.php +++ /dev/null @@ -1,26 +0,0 @@ -object = new DeploymentConfigFactory(); - $this->assertInstanceOf( - 'Magento\Framework\Module\ModuleList\DeploymentConfig', - $this->object->create(['Module_One' => 0, 'Module_Two' =>1]) - ); - } -} diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/DeploymentConfigTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/DeploymentConfigTest.php deleted file mode 100644 index 6997c26a60961..0000000000000 --- a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/DeploymentConfigTest.php +++ /dev/null @@ -1,48 +0,0 @@ -assertNotEmpty($object->getKey()); - } - - public function testGetData() - { - $object = new DeploymentConfig([]); - $this->assertSame([], $object->getData()); - $object = new DeploymentConfig(['Module_One' => '1', 'Module_Two' => false]); - $this->assertSame(['Module_One' => 1, 'Module_Two' => 0], $object->getData()); - } - - /** - * @param array $data - * @dataProvider invalidDataDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Incorrect module name: - */ - public function testInvalidData($data) - { - new DeploymentConfig($data); - } - - /** - * @return array - */ - public function invalidDataDataProvider() - { - return [ - [['1', '2']], - [['invalid_module' => 1]], - ]; - } -} diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php index 0f379ea0d1a87..92870f4790c50 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/ModuleListTest.php @@ -47,6 +47,7 @@ protected function setUp() public function testGetAll() { + $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->setLoadAllExpectation(); $this->setLoadConfigExpectation(); $expected = ['foo' => self::$allFixture['foo']]; @@ -57,6 +58,7 @@ public function testGetAll() public function testGetAllNoData() { $this->loader->expects($this->exactly(2))->method('load')->willReturn([]); + $this->config->expects($this->never())->method('isAvailable'); $this->setLoadConfigExpectation(false); $this->assertEquals([], $this->model->getAll()); $this->assertEquals([], $this->model->getAll()); @@ -64,6 +66,7 @@ public function testGetAllNoData() public function testGetOne() { + $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->setLoadAllExpectation(); $this->setLoadConfigExpectation(); $this->assertSame(['key' => 'value'], $this->model->getOne('foo')); @@ -72,6 +75,7 @@ public function testGetOne() public function testGetNames() { + $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->setLoadAllExpectation(false); $this->setLoadConfigExpectation(); $this->assertSame(['foo'], $this->model->getNames()); @@ -80,6 +84,7 @@ public function testGetNames() public function testHas() { + $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->setLoadAllExpectation(false); $this->setLoadConfigExpectation(); $this->assertTrue($this->model->has('foo')); @@ -88,12 +93,14 @@ public function testHas() public function testIsModuleInfoAvailable() { + $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->setLoadConfigExpectation(true); $this->assertTrue($this->model->isModuleInfoAvailable()); } public function testIsModuleInfoAvailableNoConfig() { + $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->config->expects($this->once())->method('getConfigData')->willReturn(null); $this->assertFalse($this->model->isModuleInfoAvailable()); } diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php index 9c7ceeb9f939b..697677f6b1044 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php @@ -7,6 +7,7 @@ namespace Magento\Framework\Module\Test\Unit; use \Magento\Framework\Module\Status; +use Magento\Framework\Config\File\ConfigFilePool; class StatusTest extends \PHPUnit_Framework_TestCase { @@ -168,7 +169,8 @@ public function testSetIsEnabled() $this->moduleList->expects($this->at(1))->method('has')->with('Module_Bar')->willReturn(false); $this->moduleList->expects($this->at(2))->method('has')->with('Module_Baz')->willReturn(false); $expectedModules = ['Module_Foo' => 1, 'Module_Bar' => 1, 'Module_Baz' => 0]; - $this->writer->expects($this->once())->method('saveConfig')->with($expectedModules); + $this->writer->expects($this->once())->method('saveConfig') + ->with([ConfigFilePool::APP_CONFIG => ['modules' => $expectedModules]]); $this->cleanup->expects($this->once())->method('clearCaches'); $this->cleanup->expects($this->once())->method('clearCodeGeneratedFiles'); $this->object->setIsEnabled(true, ['Module_Foo', 'Module_Bar']); diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 75172dbfee20c..0e072d43d86e3 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -6,8 +6,8 @@ namespace Magento\Setup\Model; -use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\MaintenanceMode; use Magento\Framework\App\Resource\Config; @@ -17,17 +17,18 @@ use Magento\Framework\Model\Resource\Db\Context; use Magento\Framework\Module\ModuleList\Loader as ModuleLoader; use Magento\Framework\Module\ModuleListInterface; +use Magento\Framework\Shell; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Framework\Shell; use Magento\Setup\Model\ConfigModel as SetupConfigModel; use Magento\Store\Model\Store; use Magento\Setup\Module\ConnectionFactory; use Magento\Setup\Module\Setup; +use Magento\Framework\Config\File\ConfigFilePool; /** * Class Installer contains the logic to install Magento application. @@ -310,17 +311,24 @@ public function install($request) private function createModulesConfig($request) { $all = array_keys($this->moduleLoader->load()); - $enable = $this->readListOfModules($all, $request, self::ENABLE_MODULES) ?: $all; - $disable = $this->readListOfModules($all, $request, self::DISABLE_MODULES); - $toEnable = array_diff($enable, $disable); - if (empty($toEnable)) { - throw new \LogicException('Unable to determine list of enabled modules.'); + $currentModules = []; + if ($this->deploymentConfig->isAvailable()) { + $deploymentConfig = $this->deploymentConfigReader->load(); + $currentModules = isset($deploymentConfig['modules']) ? $deploymentConfig['modules'] : [] ; } + $enable = $this->readListOfModules($all, $request, self::ENABLE_MODULES); + $disable = $this->readListOfModules($all, $request, self::DISABLE_MODULES); $result = []; foreach ($all as $module) { - $key = array_search($module, $toEnable); - $result[$module] = false !== $key; + if ((isset($currentModules[$module]) && !$currentModules[$module])) { + $result[$module] = 0; + } else { + $result[$module] = 1; + } + $result[$module] = in_array($module, $disable) ? 0 : $result[$module]; + $result[$module] = in_array($module, $enable) ? 1 : $result[$module]; } + $this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]]); return $result; } @@ -871,18 +879,7 @@ public function updateModulesSequence() $this->deleteDirContents(DirectoryList::GENERATION); $this->deleteDirContents(DirectoryList::CACHE); $this->log->log('Updating modules:'); - $allModules = array_keys($this->moduleLoader->load()); - $deploymentConfig = $this->deploymentConfigReader->load(); - $currentModules = isset($deploymentConfig['modules']) ? $deploymentConfig['modules'] : [] ; - $result = []; - foreach ($allModules as $module) { - if (isset($currentModules[$module]) && !$currentModules[$module]) { - $result[$module] = 0; - } else { - $result[$module] = 1; - } - } - $this->deploymentConfigWriter->saveConfig($result); + $this->createModulesConfig([]); } /** @@ -1011,7 +1008,7 @@ public function cleanupDb() { // stops cleanup if app/etc/config.php does not exist if ($this->deploymentConfig->isAvailable()) { - $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_KEY); + $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_DB_KEY); $config = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION]; if ($config) { @@ -1103,7 +1100,7 @@ private function assertDeploymentConfigExists() */ private function assertDbAccessible() { - $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_KEY); + $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_DB_KEY); $connectionConfig = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION]; $this->checkDatabaseConnection( $connectionConfig[ConfigOptionsList::KEY_NAME], diff --git a/setup/src/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php index 74af7cd0cbd07..3f12a06c8ffd7 100644 --- a/setup/src/Magento/Setup/Model/InstallerFactory.php +++ b/setup/src/Magento/Setup/Model/InstallerFactory.php @@ -77,7 +77,7 @@ public function create(LoggerInterface $log) */ private function getResource() { - $reader = $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig\Reader'); - return $this->resourceFactory->create($reader); + $deploymentConfig = $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig'); + return $this->resourceFactory->create($deploymentConfig); } } diff --git a/setup/src/Magento/Setup/Model/ModuleStatus.php b/setup/src/Magento/Setup/Model/ModuleStatus.php index 75f24ec42a52c..761be2e112519 100644 --- a/setup/src/Magento/Setup/Model/ModuleStatus.php +++ b/setup/src/Magento/Setup/Model/ModuleStatus.php @@ -9,8 +9,8 @@ use Magento\Framework\Module\ModuleList\Loader as ModuleLoader; use Magento\Framework\App\DeploymentConfig; -use Magento\Framework\Module\ModuleList\DeploymentConfig as ModuleDeployment; -use \Magento\Framework\Module\DependencyChecker; +use Magento\Framework\Module\DependencyChecker; +use Magento\Framework\Config\ConfigOptionsList;; class ModuleStatus { @@ -145,7 +145,7 @@ public function setIsEnabled($status, $moduleName) */ private function deselectDisabledModules() { - $existingModules = $this->deploymentConfig->getConfigData(ModuleDeployment::KEY_MODULES); + $existingModules = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_MODULES); if (isset($existingModules)) { foreach ($existingModules as $module => $value) { if (!$value) { diff --git a/setup/src/Magento/Setup/Module/ResourceFactory.php b/setup/src/Magento/Setup/Module/ResourceFactory.php index 8abae0bab6bb0..f16941abe74ed 100644 --- a/setup/src/Magento/Setup/Module/ResourceFactory.php +++ b/setup/src/Magento/Setup/Module/ResourceFactory.php @@ -29,16 +29,16 @@ public function __construct(ServiceLocatorInterface $serviceLocator) } /** - * @param \Magento\Framework\App\DeploymentConfig\Reader $reader + * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig * @return Resource */ - public function create(\Magento\Framework\App\DeploymentConfig\Reader $reader) + public function create(\Magento\Framework\App\DeploymentConfig $deploymentConfig) { $connectionFactory = $this->serviceLocator->get('Magento\Setup\Module\ConnectionFactory'); $resource = new Resource( new ResourceConfig(), $connectionFactory, - $reader + $deploymentConfig ); return $resource; } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index c63c1adc5f7d7..bd0061510d6b5 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -9,8 +9,10 @@ use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; use Magento\Framework\Config\ConfigOptionsList as SetupConfigOptionsList; use \Magento\Setup\Model\Installer; +use Magento\Framework\Config\ConfigOptionsList; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; +use Magento\Framework\Config\File\ConfigFilePool; /** * @SuppressWarnings(PHPMD.TooManyFields) @@ -53,16 +55,6 @@ class InstallerTest extends \PHPUnit_Framework_TestCase */ private $moduleLoader; - /** - * @var \Magento\Framework\Module\ModuleList\DeploymentConfigFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $deploymentConfigFactory; - - /** - * @var \Magento\Framework\Module\ModuleList\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject - */ - private $deploymentConfig; - /** * @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject */ @@ -150,20 +142,6 @@ protected function setUp() ['Foo_One', 'Bar_Two'] ); $this->moduleLoader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); - $this->deploymentConfigFactory = $this->getMock( - 'Magento\Framework\Module\ModuleList\DeploymentConfigFactory', - [], - [], - '', - false - ); - $this->deploymentConfig = $this->getMock( - 'Magento\Framework\Module\ModuleList\DeploymentConfig', - [], - [], - '', - false - ); $this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); $this->adminFactory = $this->getMock('Magento\Setup\Model\AdminAccountFactory', [], [], '', false); $this->logger = $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface'); @@ -226,18 +204,14 @@ public function testInstall() ]; $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true); $this->config->expects($this->any())->method('getSegment')->will($this->returnValueMap([ - [SetupConfigOptionsList::CONFIG_KEY, self::$dbConfig], + [SetupConfigOptionsList::CONFIG_DB_KEY, self::$dbConfig], [ - SetupConfigOptionsList::ENCRYPT_CONFIG_KEY, + 'crypt', [SetupConfigOptionsList::KEY_ENCRYPTION_KEY => 'encryption_key'] ] ])); $allModules = ['Foo_One' => [], 'Bar_Two' => []]; $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules); - $modules = ['Foo_One' => 1, 'Bar_Two' => 1 ]; - $this->deploymentConfig->expects($this->any())->method('getData')->willReturn($modules); - $this->deploymentConfigFactory->expects($this->any())->method('create')->with($modules) - ->willReturn($this->deploymentConfig); $setup = $this->getMock('Magento\Setup\Module\Setup', [], [], '', false); $table = $this->getMock('Magento\Framework\DB\Ddl\Table', [], [], '', false); $connection = $this->getMockForAbstractClass('Magento\Framework\DB\Adapter\AdapterInterface'); @@ -341,9 +315,13 @@ public function testUpdateModulesSequence() $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules); $expectedModules = [ - 'Bar_Two' => 0, - 'Foo_One' => 1, - 'New_Module' => 1 + ConfigFilePool::APP_CONFIG => [ + 'modules' => [ + 'Bar_Two' => 0, + 'Foo_One' => 1, + 'New_Module' => 1 + ] + ] ]; $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true); @@ -404,7 +382,7 @@ public function testCleanupDb() $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->config->expects($this->once()) ->method('getConfigData') - ->with(SetupConfigOptionsList::CONFIG_KEY) + ->with(SetupConfigOptionsList::CONFIG_DB_KEY) ->willReturn(self::$dbConfig); $this->connection->expects($this->at(0))->method('quoteIdentifier')->with('magento')->willReturn('`magento`'); $this->connection->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); diff --git a/setup/src/Magento/Setup/Test/Unit/Module/ResourceFactoryTest.php b/setup/src/Magento/Setup/Test/Unit/Module/ResourceFactoryTest.php index 60c8800928f1a..6d19606899495 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/ResourceFactoryTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/ResourceFactoryTest.php @@ -31,7 +31,7 @@ protected function setUp() public function testCreate() { $resource = $this->resourceFactory->create( - $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false) + $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false) ); $this->assertInstanceOf('Magento\Framework\App\Resource', $resource); } From 0d24d85b739e4c8bdcb87e44e7c0334066cac932 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 12:41:46 -0500 Subject: [PATCH 169/214] MAGETWO-35137: Add deployment configuration set command - changed exception message (provided by techwriter) --- lib/internal/Magento/Framework/Config/Data/ConfigData.php | 2 +- .../Framework/Config/Test/Unit/Data/ConfigDataTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Data/ConfigData.php b/lib/internal/Magento/Framework/Config/Data/ConfigData.php index d8b7848ae105b..45f7ca6a91c85 100644 --- a/lib/internal/Magento/Framework/Config/Data/ConfigData.php +++ b/lib/internal/Magento/Framework/Config/Data/ConfigData.php @@ -97,7 +97,7 @@ private function expand($path) foreach ($chunks as $chunk) { if ('' == $chunk) { throw new \InvalidArgumentException( - "The path '$path' is invalid, it should not be empty and started or ended with '/' symbol" + "Path '$path' is invalid. It cannot be empty nor start or end with '/'" ); } } diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php index 2d09936c80de8..818bb8650aebd 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php @@ -50,15 +50,15 @@ public function setWrongKeyDataProvider() return [ 'segment is empty' => [ '/test/test/test', - "The path '/test/test/test' is invalid, it should not be empty and started or ended with '/' symbol" + "Path '/test/test/test' is invalid. It cannot be empty nor start or end with '/'" ], 'key is empty' => [ '', - "The path '' is invalid, it should not be empty and started or ended with '/' symbol" + "Path '' is invalid. It cannot be empty nor start or end with '/'" ], 'access by empty value key' => [ 'test/', - "The path 'test/' is invalid, it should not be empty and started or ended with '/' symbol" + "Path 'test/' is invalid. It cannot be empty nor start or end with '/'" ] ]; } From d4c75dafbda6f16d539e9cb8bae753aea986bfde Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 13:07:08 -0500 Subject: [PATCH 170/214] MAGETWO-35137: Add deployment configuration set command - fix according CR --- .../Config/Test/Unit/Data/ConfigDataTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php index 818bb8650aebd..c6cfc4999161a 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php @@ -15,18 +15,18 @@ public function testSet() $expectedValue = [ 'test' => [ 'path' => [ - 'value1' => '1', - 'value2' => '4', - 'value3' => '3', + 'value1' => 'val1', + 'value2' => 'val4', + 'value3' => 'val3', ] ] ]; $configData = new ConfigData($fileKey); - $configData->set('test/path/value1', '1'); - $configData->set('test/path/value2', '2'); - $configData->set('test/path/value3', '3'); - $configData->set('test/path/value2', '4'); + $configData->set('test/path/value1', 'val1'); + $configData->set('test/path/value2', 'val2'); + $configData->set('test/path/value3', 'val3'); + $configData->set('test/path/value2', 'val4'); $this->assertEquals($expectedValue, $configData->getData()); $this->assertEquals($fileKey, $configData->getFileKey()); From 28f82ed77e213462f2b50b07478256553861342c Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 13:02:22 -0500 Subject: [PATCH 171/214] MAGETWO-35136: Delete Segments - CR fixes. --- lib/internal/Magento/Framework/App/Resource.php | 4 ++-- .../Framework/App/Test/Unit/Cache/Frontend/PoolTest.php | 2 +- .../Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index 4b60fc797073d..2880fd4121935 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -231,8 +231,8 @@ public function getFkName($priTableName, $priColumnName, $refTableName, $refColu private function getTablePrefix() { if (null === $this->_tablePrefix) { - $this->_tablePrefix = (string)$this->deploymentConfig->get( - ConfigOptionsList::CONFIG_DB_KEY .'/' . ConfigOptionsList::KEY_PREFIX + $this->_tablePrefix = (string)$this->deploymentConfig->getConfigData( + ConfigOptionsList::CONFIG_PATH_DB_PREFIX ); } return $this->_tablePrefix; diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php index ea043cf096b04..e4fcbc3f21eff 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php @@ -94,7 +94,7 @@ public function testInitializationParams( )->method( 'get' )->with( - FrontendPool::KEY_CACHE + FrontendPool::KEY_CACHE )->will( $this->returnValue($fixtureCacheConfig) ); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php index 4eb49a45bbeff..814508dfd9e95 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php @@ -57,7 +57,7 @@ public function testGet($fixtureConfigData, $inputCacheType, $expectedFrontendId )->method( 'get' )->with( - FrontendPool::KEY_CACHE + FrontendPool::KEY_CACHE )->will( $this->returnValue($fixtureConfigData) ); From eb0784429385ca747e0efa988399de33c5976e2e Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 13:12:50 -0500 Subject: [PATCH 172/214] MAGETWO-35136: Delete Segments - CR fixes --- .../Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php index e4fcbc3f21eff..b1fe82c0a167d 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php @@ -48,7 +48,7 @@ protected function setUp() )->method( 'get' )->with( - FrontendPool::KEY_CACHE + FrontendPool::KEY_CACHE )->will( $this->returnValue(['frontend' => ['resource2' => ['r2d1' => 'value1', 'r2d2' => 'value2']]]) ); From 212c7aa6f0cf3a31c3457675af23a520a219bba8 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Fri, 27 Mar 2015 13:15:31 -0500 Subject: [PATCH 173/214] MAGETWO-35497: Remove Old install-configuration Tool - fixed naming of option list variables and method --- .../Setup/Model/ConfigOptionsListCollectorTest.php | 5 +++-- setup/src/Magento/Setup/Model/ConfigModel.php | 8 ++++---- .../Magento/Setup/Model/ConfigOptionsListCollector.php | 2 +- .../src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php index cec4ae25cfa63..03f4b69c16097 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php @@ -38,7 +38,7 @@ public function testCollectOptionsDeploymentConfigAvailable() 'fullModuleList' => $fullModuleListMock, ] ); - $result = $object->collectOptions(); + $result = $object->collectOptionLists(); $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('Magento\Framework\Config\ConfigOptionsList'); @@ -58,6 +58,7 @@ public function testCollectOptionsDeploymentConfigUnavailable() $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); $moduleListMock->expects($this->once())->method('isModuleInfoAvailable')->willReturn(false); $moduleListMock->expects($this->never())->method('getNames'); + /** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */ $object = $objectManager->create( 'Magento\Setup\Model\ConfigOptionsListCollector', [ @@ -65,7 +66,7 @@ public function testCollectOptionsDeploymentConfigUnavailable() 'moduleList' => $moduleListMock, ] ); - $result = $object->collectOptions(); + $result = $object->collectOptionLists(); $backendOptions = new \Magento\Backend\Setup\ConfigOptionsList(); $expected = [ diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index 5910446093808..c47fa27315b82 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -64,9 +64,9 @@ public function getAvailableOptions() { /** @var AbstractConfigOption[] $optionCollection */ $optionCollection = []; - $options = $this->collector->collectOptions(); + $optionLists = $this->collector->collectOptionLists(); - foreach ($options as $optionList) { + foreach ($optionLists as $optionList) { $optionCollection = array_merge($optionCollection, $optionList->getOptions()); } @@ -92,7 +92,7 @@ public function process($inputOptions) $this->checkInstallationFilePermissions(); $fileConfigStorage = []; - $options = $this->collector->collectOptions(); + $options = $this->collector->collectOptionLists(); foreach ($options as $moduleName => $option) { @@ -145,7 +145,7 @@ public function validate(array $inputOptions) } // validate ConfigOptionsList - $options = $this->collector->collectOptions(); + $options = $this->collector->collectOptionLists(); foreach ($options as $option) { $errors = array_merge($errors, $option->validate($inputOptions)); diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php index a8b122f6c70f5..314c05a24e0aa 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php @@ -82,7 +82,7 @@ public function __construct( * * @return \Magento\Framework\Setup\ConfigOptionsListInterface[] */ - public function collectOptions() + public function collectOptionLists() { $optionsList = []; diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php index 78d9cdb7ba882..d8ffe7968ca16 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php @@ -80,7 +80,7 @@ public function testValidate() $this->collector ->expects($this->exactly(2)) - ->method('collectOptions') + ->method('collectOptionLists') ->will($this->returnValue([$configOption])); $this->configModel->validate(['Fake' => null]); @@ -136,7 +136,7 @@ public function testProcess() 'Fake_Module' => $configOption ]; $this->collector->expects($this->once()) - ->method('collectOptions') + ->method('collectOptionLists') ->will($this->returnValue($configOptionsList)); $this->writer->expects($this->once())->method('saveConfig')->with($testSetExpected); @@ -159,7 +159,7 @@ public function testProcessException() 'Fake_Module' => $configOption ]; - $this->collector->expects($this->once())->method('collectOptions')->will($this->returnValue($wrongData)); + $this->collector->expects($this->once())->method('collectOptionLists')->will($this->returnValue($wrongData)); $this->configModel->process([]); } From 9cfaeff2acb0619675eec3917a4729e0bb4ea636 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 13:27:09 -0500 Subject: [PATCH 174/214] MAGETWO-35136: Delete Segments - build fixes --- lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php | 7 +++++-- .../Framework/Config/Test/Unit/Data/ConfigDataTest.php | 3 ++- setup/src/Magento/Setup/Model/ModuleStatus.php | 2 +- .../Test/Unit/Console/Command/ConfigSetCommandTest.php | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php index f42bc1cfb07b8..a92c995ff7909 100644 --- a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php +++ b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php @@ -44,8 +44,11 @@ class Pool implements \Iterator * @param Factory $frontendFactory * @param array $frontendSettings Format: array('' => array(), ...) */ - public function __construct(DeploymentConfig $deploymentConfig, Factory $frontendFactory, array $frontendSettings = []) - { + public function __construct( + DeploymentConfig $deploymentConfig, + Factory $frontendFactory, + array $frontendSettings = [] + ) { $this->deploymentConfig = $deploymentConfig; $this->_factory = $frontendFactory; $this->_frontendSettings = $frontendSettings + [self::DEFAULT_FRONTEND_ID => []]; diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php index c6cfc4999161a..a82f2152a9737 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ConfigDataTest.php @@ -37,7 +37,8 @@ public function testSet() * @param string $expectedException * @dataProvider setWrongKeyDataProvider */ - public function testSetWrongKey($key, $expectedException) { + public function testSetWrongKey($key, $expectedException) + { $configData = new ConfigData('testKey'); diff --git a/setup/src/Magento/Setup/Model/ModuleStatus.php b/setup/src/Magento/Setup/Model/ModuleStatus.php index 761be2e112519..d49206b274a48 100644 --- a/setup/src/Magento/Setup/Model/ModuleStatus.php +++ b/setup/src/Magento/Setup/Model/ModuleStatus.php @@ -10,7 +10,7 @@ use Magento\Framework\Module\ModuleList\Loader as ModuleLoader; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Module\DependencyChecker; -use Magento\Framework\Config\ConfigOptionsList;; +use Magento\Framework\Config\ConfigOptionsList; class ModuleStatus { diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index bedf686796fdf..1c80e5872e77d 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -69,8 +69,8 @@ public function testExecuteInteractiveWithYes() $this->configModel ->expects($this->once()) ->method('process') - ->with( ['db_host' => 'host']); - + ->with( ['db_host' => 'host'] + ); $this->checkInteraction(true); } From 786466cbcd99bc6d55334a0115a9731ea4792959 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 27 Mar 2015 14:43:45 -0500 Subject: [PATCH 175/214] MAGETWO-35138: Add Interactive Confirmation to config update - Removed unused variables. --- .../Test/Unit/Console/Command/ConfigSetCommandTest.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index 1c80e5872e77d..fe3087786df2f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -17,16 +17,6 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase */ private $configModel; - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Module\ModuleList - */ - private $moduleList; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig - */ - private $deploymentConfig; - /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Console\Command\ConfigSetCommand */ From 5b60aad98cd013c99f5275244e41546001bf83fe Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Fri, 27 Mar 2015 14:50:52 -0500 Subject: [PATCH 176/214] MAGETWO-35137: Add deployment configuration set command - used better constant --- lib/internal/Magento/Framework/Config/ConfigGenerator.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index 0083629019f2c..f2bee823e7fbc 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -160,10 +160,7 @@ public function createDbConfig(array $data) $prefixKey = isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]) ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] : ''; - $configData->set( - ConfigOptionsList::CONFIG_DB_KEY . '/' . self::$paramMap[ConfigOptionsList::INPUT_KEY_DB_PREFIX], - $prefixKey - ); + $configData->set(ConfigOptionsList::CONFIG_PATH_DB_PREFIX, $prefixKey); foreach ($optional as $key) { if (isset($data[$key])) { From 0c4ee5834611758b6334d12c07a8e80fb94e2f0a Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 27 Mar 2015 15:24:14 -0500 Subject: [PATCH 177/214] MAGETWO-35138: Add Interactive Confirmation to config update - Fixed code style. --- .../Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index fe3087786df2f..0a94fa1317f9d 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -59,8 +59,7 @@ public function testExecuteInteractiveWithYes() $this->configModel ->expects($this->once()) ->method('process') - ->with( ['db_host' => 'host'] - ); + ->with(['db_host' => 'host']); $this->checkInteraction(true); } From ece9d3d63c527f98a430be4eb573879d6c24ba53 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 27 Mar 2015 15:30:32 -0500 Subject: [PATCH 178/214] MAGETWO-35138: Add Interactive Confirmation to config update - Changes based on CR. --- .../Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index 0a94fa1317f9d..ca31f0ec51063 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -45,6 +45,10 @@ public function setUp() public function testExecuteNoInteractive() { + $this->configModel + ->expects($this->once()) + ->method('process') + ->with([]); $commandTester = new CommandTester($this->command); $commandTester->execute([]); $this->assertSame( From e66ce113b174aed20cbcdcc450b2bbdf5b1b9368 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 14:09:46 -0500 Subject: [PATCH 179/214] MAGETWO-35136: Delete Segments - build errors and CR fixes --- setup/src/Magento/Setup/Model/Installer.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 0e072d43d86e3..c73a718cd556b 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -325,8 +325,12 @@ private function createModulesConfig($request) } else { $result[$module] = 1; } - $result[$module] = in_array($module, $disable) ? 0 : $result[$module]; - $result[$module] = in_array($module, $enable) ? 1 : $result[$module]; + if (in_array($module, $disable)) { + $result[$module] = 0; + } + if (in_array($module, $enable)) { + $result[$module] = 1; + } } $this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]]); return $result; From 2676f5fb064cca3e0272817f57710634822586a4 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 15:58:20 -0500 Subject: [PATCH 180/214] MAGETWO-35136: Delete Segments - CR comments --- .../lib/Magento/Mtf/App/State/AbstractState.php | 3 +-- .../framework/Magento/TestFramework/Application.php | 5 ++--- .../Magento/Framework/Model/Resource/Db/ProfilerTest.php | 4 ++-- .../Magento/Framework/App/Cache/Frontend/Pool.php | 2 +- .../Magento/Framework/App/Cache/Type/FrontendPool.php | 2 +- .../Magento/Framework/App/DeploymentConfig/Writer.php | 1 - lib/internal/Magento/Framework/App/Resource.php | 2 +- lib/internal/Magento/Framework/App/Resource/Config.php | 6 +++--- .../Framework/App/Test/Unit/Cache/Frontend/PoolTest.php | 4 ++-- .../App/Test/Unit/Cache/Type/FrontendPoolTest.php | 2 +- .../Magento/Framework/App/Test/Unit/ResourceTest.php | 2 +- .../Magento/Framework/Config/ConfigOptionsList.php | 9 +++++---- setup/src/Magento/Setup/Model/Installer.php | 4 ++-- .../src/Magento/Setup/Test/Unit/Model/InstallerTest.php | 4 ++-- 14 files changed, 24 insertions(+), 26 deletions(-) diff --git a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php index f62fe6bc415cc..b3e19b2157989 100644 --- a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php +++ b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php @@ -44,8 +44,7 @@ public function clearInstance() $reader = new \Magento\Framework\App\DeploymentConfig\Reader($dirList); $deploymentConfig = new \Magento\Framework\App\DeploymentConfig($reader); - $dbConfig = $deploymentConfig->get('resource/db/connection'); - $dbInfo = $dbConfig['default']; + $dbInfo = $deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT); $host = $dbInfo['host']; $user = $dbInfo['username']; $password = $dbInfo['password']; diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 079edf64d9749..91b81f9c4b5d7 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -162,9 +162,8 @@ public function getDbInstance() if (null === $this->_db) { if ($this->isInstalled()) { $reader = new \Magento\Framework\App\DeploymentConfig\Reader($this->dirList); - $deploymentConfig = new \Magento\Framework\App\DeploymentConfig($reader); - $dbConfig = $deploymentConfig->get(ConfigOptionsList::CONFIG_DB_KEY); - $dbInfo = $dbConfig['connection']['default']; + $deploymentConfig = new DeploymentConfig($reader); + $dbInfo = $deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT); $host = $dbInfo['host']; $user = $dbInfo['username']; $password = $dbInfo['password']; diff --git a/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php b/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php index a7929fd23d60a..066cd1a237817 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Model/Resource/Db/ProfilerTest.php @@ -45,8 +45,8 @@ protected function setUp() protected function _getConnectionRead() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $reader = $objectManager->get('Magento\Framework\App\DeploymentConfig\Reader'); - $dbConfig = $reader->getConfigData(ConfigOptionsList::CONFIG_DB_KEY); + $reader = $objectManager->get('Magento\Framework\App\DeploymentConfig'); + $dbConfig = $reader->getConfigData(ConfigOptionsList::KEY_DB); $connectionConfig = $dbConfig['connection']['default']; $connectionConfig['profiler'] = [ 'class' => 'Magento\Framework\Model\Resource\Db\Profiler', diff --git a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php index a92c995ff7909..0a21d0ac00ac7 100644 --- a/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php +++ b/lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php @@ -81,7 +81,7 @@ protected function _getCacheSettings() * Merging is intentionally implemented through array_merge() instead of array_replace_recursive() * to avoid "inheritance" of the default settings that become irrelevant as soon as cache storage type changes */ - $cacheInfo = $this->deploymentConfig->get(FrontendPool::KEY_CACHE); + $cacheInfo = $this->deploymentConfig->getConfigData(FrontendPool::KEY_CACHE); if (null !== $cacheInfo) { return array_merge($this->_frontendSettings, $cacheInfo[FrontendPool::KEY_FRONTEND_CACHE]); } diff --git a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php index 0255c688f70c5..88716e052b961 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php @@ -102,7 +102,7 @@ public function get($cacheType) protected function _getCacheFrontendId($cacheType) { $result = null; - $cacheInfo = $this->deploymentConfig->get(self::KEY_CACHE); + $cacheInfo = $this->deploymentConfig->getConfigData(self::KEY_CACHE); if (null !== $cacheInfo) { $result = $cacheInfo[self::KEY_CACHE_TYPE][$cacheType][self::KEY_FRONTEND_CACHE]; } diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index 61237d0a3e2e0..0455c08214100 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -10,7 +10,6 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Framework\Config\File\ConfigFilePool; -use Magento\Tools\SampleData\Helper\Deploy; /** * Deployment configuration writer diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index 2880fd4121935..e17434c60327a 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -104,7 +104,7 @@ public function getConnectionByName($connectionName) return $this->_connections[$connectionName]; } - $dbInfo = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_DB_KEY); + $dbInfo = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB); if (null === $dbInfo) { return false; } diff --git a/lib/internal/Magento/Framework/App/Resource/Config.php b/lib/internal/Magento/Framework/App/Resource/Config.php index 214a97437fb59..d6f57e82fd5f4 100644 --- a/lib/internal/Magento/Framework/App/Resource/Config.php +++ b/lib/internal/Magento/Framework/App/Resource/Config.php @@ -7,12 +7,12 @@ */ namespace Magento\Framework\App\Resource; +use Magento\Framework\Config\ConfigOptionsList; + class Config extends \Magento\Framework\Config\Data\Scoped implements ConfigInterface { const DEFAULT_SETUP_CONNECTION = 'default'; - const PARAM_INITIAL_RESOURCES = 'resource'; - /** * List of connection names per resource * @@ -37,7 +37,7 @@ public function __construct( ) { parent::__construct($reader, $configScope, $cache, $cacheId); - foreach ($deploymentConfig->getConfigData('resource') as $resourceName => $resourceData) { + foreach ($deploymentConfig->getConfigData(ConfigOptionsList::KEY_RESOURCE) as $resourceName => $resourceData) { if (!isset($resourceData['connection'])) { throw new \InvalidArgumentException('Invalid initial resource configuration'); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php index b1fe82c0a167d..6418ba19f9dd7 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php @@ -46,7 +46,7 @@ protected function setUp() $deploymentConfig->expects( $this->any() )->method( - 'get' + 'getConfigData' )->with( FrontendPool::KEY_CACHE )->will( @@ -92,7 +92,7 @@ public function testInitializationParams( $deploymentConfig->expects( $this->once() )->method( - 'get' + 'getConfigData' )->with( FrontendPool::KEY_CACHE )->will( diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php index 814508dfd9e95..9b0adbe03e123 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/FrontendPoolTest.php @@ -55,7 +55,7 @@ public function testGet($fixtureConfigData, $inputCacheType, $expectedFrontendId $this->deploymentConfig->expects( $this->once() )->method( - 'get' + 'getConfigData' )->with( FrontendPool::KEY_CACHE )->will( diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php index 565838ce9a600..5a1cfec68056a 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ResourceTest.php @@ -60,7 +60,7 @@ public function setUp() $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->deploymentConfig->expects($this->any()) ->method('getConfigData') - ->with(ConfigOptionsList::CONFIG_DB_KEY) + ->with(ConfigOptionsList::KEY_DB) ->will($this->returnValue( [ 'connection' => [ diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php index 9493f2438add5..d800872395e77 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -49,6 +49,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface */ const SESSION_SAVE_FILES = 'files'; const SESSION_SAVE_DB = 'db'; + /**#@-*/ /** * Array Key for session save method @@ -69,9 +70,9 @@ class ConfigOptionsList implements ConfigOptionsListInterface /**#@-*/ /** - * Segment key + * Db config key */ - const CONFIG_DB_KEY = 'db'; + const KEY_DB = 'db'; /** * Array Key for encryption key in deployment config file @@ -79,12 +80,12 @@ class ConfigOptionsList implements ConfigOptionsListInterface const KEY_ENCRYPTION_KEY = 'key'; /** - * Segment key + * Resource config key */ const KEY_RESOURCE = 'resource'; /** - * Segment key for modules + * Key for modules */ const KEY_MODULES = 'modules'; diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index c73a718cd556b..53d9cb3e12d75 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -1012,7 +1012,7 @@ public function cleanupDb() { // stops cleanup if app/etc/config.php does not exist if ($this->deploymentConfig->isAvailable()) { - $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_DB_KEY); + $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB); $config = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION]; if ($config) { @@ -1104,7 +1104,7 @@ private function assertDeploymentConfigExists() */ private function assertDbAccessible() { - $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_DB_KEY); + $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB); $connectionConfig = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION]; $this->checkDatabaseConnection( $connectionConfig[ConfigOptionsList::KEY_NAME], diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index bd0061510d6b5..2423d8c903342 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -204,7 +204,7 @@ public function testInstall() ]; $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true); $this->config->expects($this->any())->method('getSegment')->will($this->returnValueMap([ - [SetupConfigOptionsList::CONFIG_DB_KEY, self::$dbConfig], + [SetupConfigOptionsList::KEY_DB, self::$dbConfig], [ 'crypt', [SetupConfigOptionsList::KEY_ENCRYPTION_KEY => 'encryption_key'] @@ -382,7 +382,7 @@ public function testCleanupDb() $this->config->expects($this->once())->method('isAvailable')->willReturn(true); $this->config->expects($this->once()) ->method('getConfigData') - ->with(SetupConfigOptionsList::CONFIG_DB_KEY) + ->with(SetupConfigOptionsList::KEY_DB) ->willReturn(self::$dbConfig); $this->connection->expects($this->at(0))->method('quoteIdentifier')->with('magento')->willReturn('`magento`'); $this->connection->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); From 9b1c0297dd4a0abac496de41a82bec358ac6b4bc Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 16:11:40 -0500 Subject: [PATCH 181/214] MAGETWO-35136: Delete Segments - CR comments --- lib/internal/Magento/Framework/App/Cache/State.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Cache/State.php b/lib/internal/Magento/Framework/App/Cache/State.php index 951999c687764..129055756f053 100644 --- a/lib/internal/Magento/Framework/App/Cache/State.php +++ b/lib/internal/Magento/Framework/App/Cache/State.php @@ -93,7 +93,7 @@ public function setEnabled($cacheType, $isEnabled) public function persist() { $this->load(); - $this->writer->saveConfig($this->statuses); + $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => [$this->statuses]]); } /** From 621d4b5408131a1c78673d9042743a5e4699a5f7 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 16:20:30 -0500 Subject: [PATCH 182/214] MAGETWO-35136: Delete Segments - CR comments --- lib/internal/Magento/Framework/App/Cache/State.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/Magento/Framework/App/Cache/State.php b/lib/internal/Magento/Framework/App/Cache/State.php index 129055756f053..e20547f588ed9 100644 --- a/lib/internal/Magento/Framework/App/Cache/State.php +++ b/lib/internal/Magento/Framework/App/Cache/State.php @@ -10,6 +10,7 @@ use Magento\Framework\App\Cache\Type\CacheConfig; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\Config\File\ConfigFilePool; class State implements StateInterface { From fc1795816427d40b4aeb19fd5a3fb07596aca921 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 16:45:54 -0500 Subject: [PATCH 183/214] MAGETWO-35136: Delete Segments - CR fixes --- .../Adminhtml/Cache/MassActionTest.php | 9 ++- .../Magento/Framework/App/Cache/State.php | 8 ++- .../Framework/App/Cache/Type/CacheConfig.php | 62 ------------------- .../Test/Unit/Cache/Type/CacheConfigTest.php | 62 ------------------- 4 files changed, 10 insertions(+), 131 deletions(-) delete mode 100644 lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/CacheConfigTest.php diff --git a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php index f3df444141a8a..654f9c217ef97 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php @@ -6,7 +6,7 @@ namespace Magento\Backend\Controller\Adminhtml\Cache; -use Magento\Framework\App\Cache\Type\CacheConfig; +use Magento\Framework\App\Cache\State; use Magento\TestFramework\Helper\Bootstrap; class MassActionTest extends \Magento\Backend\Utility\Controller @@ -14,7 +14,7 @@ class MassActionTest extends \Magento\Backend\Utility\Controller /** * Configuration of cache types * - * @var CacheConfig + * @var array */ private static $typesConfig; @@ -22,15 +22,14 @@ public static function setUpBeforeClass() { /** @var \Magento\Framework\App\DeploymentConfig $config */ $config = Bootstrap::getObjectManager()->get('Magento\Framework\App\DeploymentConfig'); - $data = $config->getConfigData(CacheConfig::CACHE_KEY); - self::$typesConfig = new CacheConfig($data); + self::$typesConfig = $config->getConfigData(State::CACHE_KEY); } protected function tearDown() { /** @var $cacheState \Magento\Framework\App\Cache\StateInterface */ $cacheState = Bootstrap::getObjectManager()->get('Magento\Framework\App\Cache\StateInterface'); - foreach (self::$typesConfig->getData() as $type => $value) { + foreach (self::$typesConfig as $type => $value) { $cacheState->setEnabled($type, $value); } $cacheState->persist(); diff --git a/lib/internal/Magento/Framework/App/Cache/State.php b/lib/internal/Magento/Framework/App/Cache/State.php index e20547f588ed9..6dad45c1f2bdc 100644 --- a/lib/internal/Magento/Framework/App/Cache/State.php +++ b/lib/internal/Magento/Framework/App/Cache/State.php @@ -7,7 +7,6 @@ */ namespace Magento\Framework\App\Cache; -use Magento\Framework\App\Cache\Type\CacheConfig; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\Config\File\ConfigFilePool; @@ -19,6 +18,11 @@ class State implements StateInterface */ const PARAM_BAN_CACHE = 'global_ban_use_cache'; + /** + * Deployment config key + */ + const CACHE_KEY = 'cache_types'; + /** * Deployment configuration * @@ -109,7 +113,7 @@ private function load() if ($this->banAll) { return; } - $this->statuses = $this->config->getConfigData(CacheConfig::CACHE_KEY) ?: []; + $this->statuses = $this->config->getConfigData(self::CACHE_KEY) ?: []; } } } diff --git a/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php b/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php deleted file mode 100644 index 0b72097d78d9b..0000000000000 --- a/lib/internal/Magento/Framework/App/Cache/Type/CacheConfig.php +++ /dev/null @@ -1,62 +0,0 @@ - $value) { - if (!preg_match('/^[a-z_]+$/i', $key)) { - throw new \InvalidArgumentException("Invalid cache type key: {$key}"); - } - $data[$key] = (int)$value; - } - $this->data = $data; - } - - /** - * Returns current key. - * - * @return string - */ - public function getKey() - { - return self::CACHE_KEY; - } - - /** - * Return current Cache config. - * - * @return array|mixed - */ - public function getData() - { - return $this->data; - } -} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/CacheConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/CacheConfigTest.php deleted file mode 100644 index da8bfd32372a9..0000000000000 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/CacheConfigTest.php +++ /dev/null @@ -1,62 +0,0 @@ -assertSame($expected, $object->getData()); - } - - /** - * @return array - */ - public function getDataDataProvider() - { - return [ - [[], []], - [['FoO' => '1'], ['FoO' => 1]], - [['foo' => false, 'bar' => true], ['foo' => 0, 'bar' => 1]], - [['foo' => 'bar', 'baz' => '0'], ['foo' => 0, 'baz' => 0]], - [['foo' => []], ['foo' => 0]], - [['foo' => [0]], ['foo' => 1]], - [['foo' => [1, 2]], ['foo' => 1]], - ]; - } - - /** - * @param array $data - * @dataProvider getDataInvalidKeysDataProvider - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid cache type key: - */ - public function testGetDataInvalidKeys($data) - { - new CacheConfig($data); - } - - /** - * @return array - */ - public function getDataInvalidKeysDataProvider() - { - return [ - [[1]], - [['0' => 1]], - [['in/valid' => 1]], - ]; - } -} From af7ae577f29a5fa0fec6627cb71351a276c891e1 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 27 Mar 2015 16:58:46 -0500 Subject: [PATCH 184/214] MAGETWO-35138: Add Interactive Confirmation to config update - Changes based on CR feedback. --- .../Console/Command/ConfigSetCommandTest.php | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index ca31f0ec51063..35ac57649b8c7 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -17,11 +17,18 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase */ private $configModel; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig + */ + private $deploymentConfig; + /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Console\Command\ConfigSetCommand */ private $command; + + public function setUp() { $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); @@ -35,22 +42,22 @@ public function setUp() ->method('getAvailableOptions') ->will($this->returnValue([$option])); $moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); - $deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); - $deploymentConfig - ->expects($this->once()) - ->method('get') - ->will($this->returnValue('localhost')); - $this->command = new ConfigSetCommand($this->configModel, $moduleList, $deploymentConfig); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $this->command = new ConfigSetCommand($this->configModel, $moduleList, $this->deploymentConfig); } public function testExecuteNoInteractive() { + $this->deploymentConfig + ->expects($this->once()) + ->method('get') + ->will($this->returnValue(null)); $this->configModel ->expects($this->once()) ->method('process') - ->with([]); + ->with(['db_host' => 'host']); $commandTester = new CommandTester($this->command); - $commandTester->execute([]); + $commandTester->execute(['--db_host' => 'host']); $this->assertSame( 'No module configuration is available, so all modules are enabled.' . PHP_EOL . 'You saved the deployment config.' . PHP_EOL, @@ -60,6 +67,10 @@ public function testExecuteNoInteractive() public function testExecuteInteractiveWithYes() { + $this->deploymentConfig + ->expects($this->once()) + ->method('get') + ->will($this->returnValue('localhost')); $this->configModel ->expects($this->once()) ->method('process') @@ -69,6 +80,10 @@ public function testExecuteInteractiveWithYes() public function testExecuteInteractiveWithNo() { + $this->deploymentConfig + ->expects($this->once()) + ->method('get') + ->will($this->returnValue('localhost')); $this->configModel ->expects($this->once()) ->method('process') From 95984cfdff2fe4072dbbb41060562bcaa888e7cd Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 17:10:57 -0500 Subject: [PATCH 185/214] MAGETWO-35135: Integrate config command - reading config for encrypt key --- setup/src/Magento/Setup/Model/Installer.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 53d9cb3e12d75..281e0c888bb08 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -428,6 +428,12 @@ public function installDeploymentConfig($data) $this->setupConfigModel->process($userData); + if ($this->deploymentConfig->isAvailable()) { + $deploymentConfigData = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY); + if (isset($deploymentConfigData)) { + $this->installInfo[ConfigOptionsList::KEY_ENCRYPTION_KEY] = $deploymentConfigData; + } + } // reset object manager now that there is a deployment config $this->objectManagerProvider->reset(); } From 284f3b320d3ce1e629d39048a48a081275642c1e Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 27 Mar 2015 17:14:25 -0500 Subject: [PATCH 186/214] MAGETWO-35136: Delete Segments - updating composer.lock --- composer.lock | 134 +++++++++++++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 56 deletions(-) diff --git a/composer.lock b/composer.lock index f35cfe3ae7e52..0be074072d112 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "463c446e1ab4ab0b3d6ea316c8991227", + "hash": "c42991e56fb8b32295f12ca803bdc6b7", "packages": [ { "name": "composer/composer", @@ -471,17 +471,17 @@ }, { "name": "symfony/console", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/Console", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "e44154bfe3e41e8267d7a3794cd9da9a51cfac34" + "reference": "53f86497ccd01677e22435cfb7262599450a90d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/e44154bfe3e41e8267d7a3794cd9da9a51cfac34", - "reference": "e44154bfe3e41e8267d7a3794cd9da9a51cfac34", + "url": "https://api.github.com/repos/symfony/Console/zipball/53f86497ccd01677e22435cfb7262599450a90d1", + "reference": "53f86497ccd01677e22435cfb7262599450a90d1", "shasum": "" }, "require": { @@ -490,6 +490,7 @@ "require-dev": { "psr/log": "~1.0", "symfony/event-dispatcher": "~2.1", + "symfony/phpunit-bridge": "~2.7", "symfony/process": "~2.1" }, "suggest": { @@ -524,26 +525,29 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2015-01-25 04:39:26" + "time": "2015-03-13 17:37:22" }, { "name": "symfony/finder", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", "url": "https://github.com/symfony/Finder.git", - "reference": "16513333bca64186c01609961a2bb1b95b5e1355" + "reference": "bebc7479c566fa4f14b9bcef9e32e719eabec74e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/16513333bca64186c01609961a2bb1b95b5e1355", - "reference": "16513333bca64186c01609961a2bb1b95b5e1355", + "url": "https://api.github.com/repos/symfony/Finder/zipball/bebc7479c566fa4f14b9bcef9e32e719eabec74e", + "reference": "bebc7479c566fa4f14b9bcef9e32e719eabec74e", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { @@ -571,26 +575,29 @@ ], "description": "Symfony Finder Component", "homepage": "http://symfony.com", - "time": "2015-01-03 08:01:59" + "time": "2015-03-12 10:28:44" }, { "name": "symfony/process", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/Process", "source": { "type": "git", "url": "https://github.com/symfony/Process.git", - "reference": "ecfc23e89d9967999fa5f60a1e9af7384396e9ae" + "reference": "4d717f34f3d1d6ab30fbe79f7132960a27f4a0dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/ecfc23e89d9967999fa5f60a1e9af7384396e9ae", - "reference": "ecfc23e89d9967999fa5f60a1e9af7384396e9ae", + "url": "https://api.github.com/repos/symfony/Process/zipball/4d717f34f3d1d6ab30fbe79f7132960a27f4a0dc", + "reference": "4d717f34f3d1d6ab30fbe79f7132960a27f4a0dc", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { @@ -618,7 +625,7 @@ ], "description": "Symfony Process Component", "homepage": "http://symfony.com", - "time": "2015-01-25 04:39:26" + "time": "2015-03-12 10:28:44" }, { "name": "tubalmartin/cssmin", @@ -2000,16 +2007,16 @@ }, { "name": "fabpot/php-cs-fixer", - "version": "v1.5.1", + "version": "v1.6", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "85777ebc6a1dac48c904acf9412b29b58b5dd592" + "reference": "81a46f8a0f92f1ba64587b384a275d0766cf2c70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/85777ebc6a1dac48c904acf9412b29b58b5dd592", - "reference": "85777ebc6a1dac48c904acf9412b29b58b5dd592", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/81a46f8a0f92f1ba64587b384a275d0766cf2c70", + "reference": "81a46f8a0f92f1ba64587b384a275d0766cf2c70", "shasum": "" }, "require": { @@ -2049,7 +2056,7 @@ } ], "description": "A script to automatically fix Symfony Coding Standard", - "time": "2015-03-13 19:33:24" + "time": "2015-03-26 21:09:59" }, { "name": "league/climate", @@ -2203,16 +2210,16 @@ }, { "name": "phpmd/phpmd", - "version": "2.2.1", + "version": "2.2.2", "source": { "type": "git", "url": "https://github.com/phpmd/phpmd.git", - "reference": "58c4b00f924d301e8c5281f40cfa9a66f3df9eee" + "reference": "7dc4a6b5c07b119ab5da7960b56303fa6855eb84" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpmd/phpmd/zipball/58c4b00f924d301e8c5281f40cfa9a66f3df9eee", - "reference": "58c4b00f924d301e8c5281f40cfa9a66f3df9eee", + "url": "https://api.github.com/repos/phpmd/phpmd/zipball/7dc4a6b5c07b119ab5da7960b56303fa6855eb84", + "reference": "7dc4a6b5c07b119ab5da7960b56303fa6855eb84", "shasum": "" }, "require": { @@ -2261,7 +2268,7 @@ "phpmd", "pmd" ], - "time": "2015-03-02 10:26:50" + "time": "2015-03-26 07:47:05" }, { "name": "phpunit/php-code-coverage", @@ -3086,23 +3093,26 @@ }, { "name": "symfony/config", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/Config", "source": { "type": "git", "url": "https://github.com/symfony/Config.git", - "reference": "a9f781ba1221067d1f07c8cec0bc50f81b8d7408" + "reference": "7a47189c7667ca69bcaafd19ef8a8941db449a2c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/a9f781ba1221067d1f07c8cec0bc50f81b8d7408", - "reference": "a9f781ba1221067d1f07c8cec0bc50f81b8d7408", + "url": "https://api.github.com/repos/symfony/Config/zipball/7a47189c7667ca69bcaafd19ef8a8941db449a2c", + "reference": "7a47189c7667ca69bcaafd19ef8a8941db449a2c", "shasum": "" }, "require": { "php": ">=5.3.3", "symfony/filesystem": "~2.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { @@ -3130,21 +3140,21 @@ ], "description": "Symfony Config Component", "homepage": "http://symfony.com", - "time": "2015-01-21 20:57:55" + "time": "2015-03-12 10:28:44" }, { "name": "symfony/dependency-injection", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/DependencyInjection", "source": { "type": "git", "url": "https://github.com/symfony/DependencyInjection.git", - "reference": "42bbb43fab66292a1865dc9616c299904c3d4d14" + "reference": "a49245b2beebe332924561c30772b16e1d32f13a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/42bbb43fab66292a1865dc9616c299904c3d4d14", - "reference": "42bbb43fab66292a1865dc9616c299904c3d4d14", + "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/a49245b2beebe332924561c30772b16e1d32f13a", + "reference": "a49245b2beebe332924561c30772b16e1d32f13a", "shasum": "" }, "require": { @@ -3156,6 +3166,7 @@ "require-dev": { "symfony/config": "~2.2", "symfony/expression-language": "~2.6", + "symfony/phpunit-bridge": "~2.7", "symfony/yaml": "~2.1" }, "suggest": { @@ -3190,21 +3201,21 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "http://symfony.com", - "time": "2015-01-25 04:39:26" + "time": "2015-03-17 12:44:40" }, { "name": "symfony/event-dispatcher", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/EventDispatcher", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "f75989f3ab2743a82fe0b03ded2598a2b1546813" + "reference": "70f7c8478739ad21e3deef0d977b38c77f1fb284" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/f75989f3ab2743a82fe0b03ded2598a2b1546813", - "reference": "f75989f3ab2743a82fe0b03ded2598a2b1546813", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/70f7c8478739ad21e3deef0d977b38c77f1fb284", + "reference": "70f7c8478739ad21e3deef0d977b38c77f1fb284", "shasum": "" }, "require": { @@ -3215,6 +3226,7 @@ "symfony/config": "~2.0,>=2.0.5", "symfony/dependency-injection": "~2.6", "symfony/expression-language": "~2.6", + "symfony/phpunit-bridge": "~2.7", "symfony/stopwatch": "~2.3" }, "suggest": { @@ -3248,26 +3260,29 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "http://symfony.com", - "time": "2015-02-01 16:10:57" + "time": "2015-03-13 17:37:22" }, { "name": "symfony/filesystem", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/Filesystem", "source": { "type": "git", "url": "https://github.com/symfony/Filesystem.git", - "reference": "a1f566d1f92e142fa1593f4555d6d89e3044a9b7" + "reference": "fdc5f151bc2db066b51870d5bea3773d915ced0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/a1f566d1f92e142fa1593f4555d6d89e3044a9b7", - "reference": "a1f566d1f92e142fa1593f4555d6d89e3044a9b7", + "url": "https://api.github.com/repos/symfony/Filesystem/zipball/fdc5f151bc2db066b51870d5bea3773d915ced0b", + "reference": "fdc5f151bc2db066b51870d5bea3773d915ced0b", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { @@ -3295,26 +3310,29 @@ ], "description": "Symfony Filesystem Component", "homepage": "http://symfony.com", - "time": "2015-01-03 21:13:09" + "time": "2015-03-12 10:28:44" }, { "name": "symfony/stopwatch", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/Stopwatch", "source": { "type": "git", "url": "https://github.com/symfony/Stopwatch.git", - "reference": "e8da5286132ba75ce4b4275fbf0f4cd369bfd71c" + "reference": "ba4e774f71e2ce3e3f65cabac4031b9029972af5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/e8da5286132ba75ce4b4275fbf0f4cd369bfd71c", - "reference": "e8da5286132ba75ce4b4275fbf0f4cd369bfd71c", + "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/ba4e774f71e2ce3e3f65cabac4031b9029972af5", + "reference": "ba4e774f71e2ce3e3f65cabac4031b9029972af5", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { @@ -3342,26 +3360,29 @@ ], "description": "Symfony Stopwatch Component", "homepage": "http://symfony.com", - "time": "2015-01-03 08:01:59" + "time": "2015-02-24 11:52:21" }, { "name": "symfony/yaml", - "version": "v2.6.4", + "version": "v2.6.5", "target-dir": "Symfony/Component/Yaml", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "60ed7751671113cf1ee7d7778e691642c2e9acd8" + "reference": "0cd8e72071e46e15fc072270ae39ea1b66b10a9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/60ed7751671113cf1ee7d7778e691642c2e9acd8", - "reference": "60ed7751671113cf1ee7d7778e691642c2e9acd8", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/0cd8e72071e46e15fc072270ae39ea1b66b10a9d", + "reference": "0cd8e72071e46e15fc072270ae39ea1b66b10a9d", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { @@ -3389,7 +3410,7 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2015-01-25 04:39:26" + "time": "2015-03-12 10:28:44" } ], "aliases": [], @@ -3399,6 +3420,7 @@ "phpmd/phpmd": 0 }, "prefer-stable": false, + "prefer-lowest": false, "platform": { "php": "~5.5.0|~5.6.0" }, From a3600354f08421091178d2a3d40439133b68efdf Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Fri, 27 Mar 2015 17:45:11 -0500 Subject: [PATCH 187/214] MAGETWO-35135: Integrate config command - fixed installation of default encrypt key from Web Wizard --- setup/src/Magento/Setup/Controller/Install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php index d32721a39e9f6..0618df92d08c8 100644 --- a/setup/src/Magento/Setup/Controller/Install.php +++ b/setup/src/Magento/Setup/Controller/Install.php @@ -138,7 +138,7 @@ private function importDeploymentConfigForm() $result[BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME] = isset($source['config']['address']['admin']) ? $source['config']['address']['admin'] : ''; $result[SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY] = isset($source['config']['encrypt']['key']) - ? $source['config']['encrypt']['key'] : ''; + ? $source['config']['encrypt']['key'] : null; $result[Installer::ENABLE_MODULES] = isset($source['store']['selectedModules']) ? implode(',', $source['store']['selectedModules']) : ''; $result[Installer::DISABLE_MODULES] = isset($source['store']['allModules']) From 44bde0bd1b08d31ca55611632eab8f82600bed49 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Sat, 28 Mar 2015 06:57:23 -0500 Subject: [PATCH 188/214] MAGETWO-35136: Delete Segments - fixing unit tests --- .../Magento/Framework/App/Test/Unit/Cache/StateTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php index 0db48a80516ee..57a7e27830a70 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php @@ -6,6 +6,7 @@ namespace Magento\Framework\App\Test\Unit\Cache; use \Magento\Framework\App\Cache\State; +use Magento\Framework\Config\File\ConfigFilePool; class StateTest extends \PHPUnit_Framework_TestCase { @@ -91,7 +92,9 @@ public function testSetEnabled() public function testPersist() { $model = new State($this->config, $this->writer); - $this->writer->expects($this->once())->method('saveConfig')->with([]); + $this->config->expects($this->once())->method('getConfigData')->willReturn(['cache_type' => true]); + $configValue = [ConfigFilePool::APP_CONFIG => [0 => ['cache_type' => true]]]; + $this->writer->expects($this->once())->method('saveConfig')->with($configValue); $model->persist(); } } From 6b887e8ffd13d7a258b5b4fa962ef8b639089fbd Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Sun, 29 Mar 2015 10:52:50 -0500 Subject: [PATCH 189/214] MAGETWO-35135: Integrate config command - fixed default values for installation --- setup/src/Magento/Setup/Model/Installer.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 281e0c888bb08..501731fe1e657 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -422,8 +422,17 @@ public function installDeploymentConfig($data) $userData = is_array($data) ? $data : $data->getArrayCopy(); // TODO: remove this when moving install command to symfony - if (!isset($userData['db_pass'])) { - $userData['db_pass'] = ''; + if (!isset($userData[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { + $userData[ConfigOptionsList::INPUT_KEY_SESSION_SAVE] = ConfigOptionsList::SESSION_SAVE_FILES; + } + if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_PASS])) { + $userData[ConfigOptionsList::INPUT_KEY_DB_PASS] = ''; + } + if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_MODEL])) { + $userData[ConfigOptionsList::INPUT_KEY_DB_MODEL] = 'mysql4'; + } + if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS])) { + $userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS] = 'SET NAMES utf8;'; } $this->setupConfigModel->process($userData); From af45e23a33de5d391d17398485dc9f471bbd30b9 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Sun, 29 Mar 2015 11:43:39 -0500 Subject: [PATCH 190/214] MAGETWO-35135: Integrate config command - fixed table prefix --- lib/internal/Magento/Framework/App/Resource.php | 2 +- setup/src/Magento/Setup/Model/Installer.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index e17434c60327a..b38629a460a4f 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -231,7 +231,7 @@ public function getFkName($priTableName, $priColumnName, $refTableName, $refColu private function getTablePrefix() { if (null === $this->_tablePrefix) { - $this->_tablePrefix = (string)$this->deploymentConfig->getConfigData( + $this->_tablePrefix = (string)$this->deploymentConfig->get( ConfigOptionsList::CONFIG_PATH_DB_PREFIX ); } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 501731fe1e657..55608f7f4bd99 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -1127,8 +1127,8 @@ private function assertDbAccessible() $connectionConfig[ConfigOptionsList::KEY_USER], $connectionConfig[ConfigOptionsList::KEY_PASS] ); - if (isset($config[ConfigOptionsList::KEY_PREFIX])) { - $this->checkDatabaseTablePrefix($config[ConfigOptionsList::KEY_PREFIX]); + if (isset($connectionConfig[ConfigOptionsList::KEY_PREFIX])) { + $this->checkDatabaseTablePrefix($connectionConfig[ConfigOptionsList::KEY_PREFIX]); } } From 10d6acdc96ba9f1346fd9dcf6e13a601b0d747f0 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 30 Mar 2015 10:24:40 -0500 Subject: [PATCH 191/214] MAGETWO-35136: Delete Segments - CR fix --- lib/internal/Magento/Framework/App/Cache/State.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Cache/State.php b/lib/internal/Magento/Framework/App/Cache/State.php index 6dad45c1f2bdc..4522f1bbbc1e3 100644 --- a/lib/internal/Magento/Framework/App/Cache/State.php +++ b/lib/internal/Magento/Framework/App/Cache/State.php @@ -98,7 +98,7 @@ public function setEnabled($cacheType, $isEnabled) public function persist() { $this->load(); - $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => [$this->statuses]]); + $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => ['cache_type' => $this->statuses]]); } /** From 1b0631e3eb86dd6d22fe61a48f26476cec3e3171 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 30 Mar 2015 10:31:15 -0500 Subject: [PATCH 192/214] MAGETWO-35136: Delete Segments - fixing to use constant --- lib/internal/Magento/Framework/App/Cache/State.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Cache/State.php b/lib/internal/Magento/Framework/App/Cache/State.php index 4522f1bbbc1e3..d7de86d9ba359 100644 --- a/lib/internal/Magento/Framework/App/Cache/State.php +++ b/lib/internal/Magento/Framework/App/Cache/State.php @@ -98,7 +98,7 @@ public function setEnabled($cacheType, $isEnabled) public function persist() { $this->load(); - $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => ['cache_type' => $this->statuses]]); + $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => [self::CACHE_KEY => $this->statuses]]); } /** From 5d92eba20c2130af2ccb4107ebc24607f6e44496 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 30 Mar 2015 10:27:47 -0500 Subject: [PATCH 193/214] MAGETWO-35137: Add deployment configuration set command - fixed bug used wrong keys for DB connection --- .../Magento/Framework/Config/ConfigOptionsList.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php index d800872395e77..5217d50feb9e6 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -143,21 +143,21 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_DB_NAME, TextConfigOption::FRONTEND_WIZARD_TEXT, - self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_NAME, + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::KEY_NAME, 'Database name', 'magento2' ), new TextConfigOption( self::INPUT_KEY_DB_USER, TextConfigOption::FRONTEND_WIZARD_TEXT, - self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_USER, + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::KEY_USER, 'Database server username', 'root' ), new TextConfigOption( self::INPUT_KEY_DB_PASS, TextConfigOption::FRONTEND_WIZARD_PASSWORD, - self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_PASS, + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::KEY_PASS, 'Database server password', '' ), @@ -170,14 +170,14 @@ public function getOptions() new TextConfigOption( self::INPUT_KEY_DB_MODEL, TextConfigOption::FRONTEND_WIZARD_TEXT, - self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_MODEL, + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::KEY_MODEL, 'Database type', 'mysql4' ), new TextConfigOption( self::INPUT_KEY_DB_INIT_STATEMENTS, TextConfigOption::FRONTEND_WIZARD_TEXT, - self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::INPUT_KEY_DB_INIT_STATEMENTS, + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::KEY_INIT_STATEMENTS, 'Database initial set of commands', 'SET NAMES utf8;' ), From 403135552207427a5de6abb98ab6792630a9b827 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 30 Mar 2015 10:32:20 -0500 Subject: [PATCH 194/214] MAGETWO-35136: Delete Segments - updating comment --- lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php index 88716e052b961..cf96a267e6a7f 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/FrontendPool.php @@ -25,7 +25,7 @@ class FrontendPool const KEY_FRONTEND_CACHE = 'frontend'; /** - * Segment key for cache + * Config key for cache */ const KEY_CACHE = 'cache'; From ef445a082e27d73e7c7dd4d8e5605a2b60acef62 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 30 Mar 2015 10:50:24 -0500 Subject: [PATCH 195/214] MAGETWO-35136: Delete Segments - fixing unit test --- .../Magento/Framework/App/Test/Unit/Cache/StateTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php index 57a7e27830a70..c5767244b54ee 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php @@ -92,8 +92,8 @@ public function testSetEnabled() public function testPersist() { $model = new State($this->config, $this->writer); - $this->config->expects($this->once())->method('getConfigData')->willReturn(['cache_type' => true]); - $configValue = [ConfigFilePool::APP_CONFIG => [0 => ['cache_type' => true]]]; + $this->config->expects($this->once())->method('getConfigData')->willReturn(['test_cache_type' => true]); + $configValue = [ConfigFilePool::APP_CONFIG => ['cache_types' => ['test_cache_type' => true]]]; $this->writer->expects($this->once())->method('saveConfig')->with($configValue); $model->persist(); } From c08ade3dba0ed8e6b87e833419b7f4eb4a0a4538 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 30 Mar 2015 11:36:42 -0500 Subject: [PATCH 196/214] MAGETWO-35135: Integrate config command - fixing phpmd error --- setup/src/Magento/Setup/Model/Installer.php | 36 ++++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 55608f7f4bd99..0699efd48634d 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -422,18 +422,7 @@ public function installDeploymentConfig($data) $userData = is_array($data) ? $data : $data->getArrayCopy(); // TODO: remove this when moving install command to symfony - if (!isset($userData[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { - $userData[ConfigOptionsList::INPUT_KEY_SESSION_SAVE] = ConfigOptionsList::SESSION_SAVE_FILES; - } - if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_PASS])) { - $userData[ConfigOptionsList::INPUT_KEY_DB_PASS] = ''; - } - if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_MODEL])) { - $userData[ConfigOptionsList::INPUT_KEY_DB_MODEL] = 'mysql4'; - } - if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS])) { - $userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS] = 'SET NAMES utf8;'; - } + $userData = $this->setDefaultValues($userData); $this->setupConfigModel->process($userData); @@ -447,6 +436,29 @@ public function installDeploymentConfig($data) $this->objectManagerProvider->reset(); } + + /** + * Sets defaults if user input is missing + * + * @param array $userData + * @return array + */ + private function setDefaultValues(array $userData) + { + if (!isset($userData[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { + $userData[ConfigOptionsList::INPUT_KEY_SESSION_SAVE] = ConfigOptionsList::SESSION_SAVE_FILES; + } + if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_PASS])) { + $userData[ConfigOptionsList::INPUT_KEY_DB_PASS] = ''; + } + if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_MODEL])) { + $userData[ConfigOptionsList::INPUT_KEY_DB_MODEL] = 'mysql4'; + } + if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS])) { + $userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS] = 'SET NAMES utf8;'; + } + return $userData; + } /** * Set up setup_module table to register modules' versions, skip this process if it already exists * From b20380e7c4520049d8c807e1b6f7532ae35507b8 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 30 Mar 2015 12:33:20 -0500 Subject: [PATCH 197/214] MAGETWO-35137: Add deployment configuration set command - added message that informs is data saved to config or not, also informs if default values are used. - changed confgiOptionsCollector so all options collects even for disabled modules. --- .../Model/ConfigOptionsListCollectorTest.php | 32 +---------------- .../Console/Command/ConfigSetCommand.php | 35 +++++++++++++++---- .../Model/ConfigOptionsListCollector.php | 16 +-------- .../Console/Command/ConfigSetCommandTest.php | 11 +++--- 4 files changed, 37 insertions(+), 57 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php index 03f4b69c16097..3a0d5451068d9 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php @@ -21,12 +21,9 @@ public function setUp() ->willReturn(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()); } - public function testCollectOptionsDeploymentConfigAvailable() + public function testCollectOptionLists() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); - $moduleListMock->expects($this->once())->method('isModuleInfoAvailable')->willReturn(true); - $moduleListMock->expects($this->once())->method('getNames')->willReturn(['Magento_Backend']); $fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); $fullModuleListMock->expects($this->never())->method('getNames'); /** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */ @@ -34,7 +31,6 @@ public function testCollectOptionsDeploymentConfigAvailable() 'Magento\Setup\Model\ConfigOptionsListCollector', [ 'objectManagerProvider' => $this->objectManagerProvider, - 'moduleList' => $moduleListMock, 'fullModuleList' => $fullModuleListMock, ] ); @@ -51,30 +47,4 @@ public function testCollectOptionsDeploymentConfigAvailable() $this->assertEquals($expected, $result); } - - public function testCollectOptionsDeploymentConfigUnavailable() - { - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); - $moduleListMock->expects($this->once())->method('isModuleInfoAvailable')->willReturn(false); - $moduleListMock->expects($this->never())->method('getNames'); - /** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */ - $object = $objectManager->create( - 'Magento\Setup\Model\ConfigOptionsListCollector', - [ - 'objectManagerProvider' => $this->objectManagerProvider, - 'moduleList' => $moduleListMock, - ] - ); - $result = $object->collectOptionLists(); - - $backendOptions = new \Magento\Backend\Setup\ConfigOptionsList(); - $expected = [ - 'setup' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get('Magento\Framework\Config\ConfigOptionsList'), - 'Magento_Backend' => $backendOptions, - ]; - - $this->assertEquals($expected, $result); - } } diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index a99d08d957a43..3670f3ea08fc9 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -73,6 +73,9 @@ protected function execute(InputInterface $input, OutputInterface $output) { $inputOptions = $input->getOptions(); $optionCollection = $this->configModel->getAvailableOptions(); + $optionsToChange = []; + $optionsWithDefaultValues = []; + foreach ($optionCollection as $option) { $currentValue = $this->deploymentConfig->get($option->getConfigPath()); if (($currentValue !== null) && ($inputOptions[$option->getName()] !== null)) { @@ -82,17 +85,41 @@ protected function execute(InputInterface $input, OutputInterface $output) 'Overwrite the existing configuration for ' . $option->getName() . '?[Y|n]' )) { $inputOptions[$option->getName()] = null; + } else { + $optionsToChange[$option->getName()] = $inputOptions[$option->getName()]; + } + } else { + if ($inputOptions[$option->getName()] !== null) { + $optionsToChange[$option->getName()] = $inputOptions[$option->getName()]; } } + if ($option->getDefault() === $inputOptions[$option->getName()] + && $inputOptions[$option->getName()] !== null + ) { + $optionsWithDefaultValues[] = $option->getName(); + } } + $inputOptions = array_filter( $inputOptions, function ($value) { return $value !== null; } ); + $this->configModel->process($inputOptions); - $output->writeln('You saved the deployment config.'); + if (count($optionsWithDefaultValues) > 0) { + $defaultValuesMessage = implode(', ', $optionsWithDefaultValues); + $output->writeln( + 'You saved default value(s) for the next option(s): ' . $defaultValuesMessage . '.' + ); + } else { + if (count($optionsToChange) > 0) { + $output->writeln('You saved the deployment config.'); + } else { + $output->writeln('You did not save the deployment config.'); + } + } } /** @@ -100,12 +127,6 @@ function ($value) { */ protected function initialize(InputInterface $input, OutputInterface $output) { - if (!$this->moduleList->isModuleInfoAvailable()) { - $output->writeln( - 'No module configuration is available, so all modules are enabled.' - ); - } - $inputOptions = $input->getOptions(); $errors = $this->configModel->validate($inputOptions); diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php index 314c05a24e0aa..df708cbeec3bb 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php @@ -8,7 +8,6 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; use Magento\Framework\Module\FullModuleList; -use Magento\Framework\Module\ModuleList; use Magento\Framework\Setup\ConfigOptionsListInterface; /** @@ -37,13 +36,6 @@ class ConfigOptionsListCollector */ private $fullModuleList; - /** - * Enabled module list - * - * @var ModuleList - */ - private $moduleList; - /** * Object manager provider * @@ -57,28 +49,23 @@ class ConfigOptionsListCollector * @param DirectoryList $directoryList * @param Filesystem $filesystem * @param FullModuleList $fullModuleList - * @param ModuleList $moduleList * @param ObjectManagerProvider $objectManagerProvider */ public function __construct( DirectoryList $directoryList, Filesystem $filesystem, FullModuleList $fullModuleList, - ModuleList $moduleList, ObjectManagerProvider $objectManagerProvider ) { $this->directoryList = $directoryList; $this->filesystem = $filesystem; $this->fullModuleList = $fullModuleList; - $this->moduleList = $moduleList; $this->objectManagerProvider = $objectManagerProvider; } /** * Auto discover ConfigOptionsList class and collect them. * These classes should reside in /Setup directories. - * If deployment config is not available, all modules will be searched. Otherwise, only enabled modules - * will be searched. * * @return \Magento\Framework\Setup\ConfigOptionsListInterface[] */ @@ -86,9 +73,8 @@ public function collectOptionLists() { $optionsList = []; - $moduleList = $this->moduleList->isModuleInfoAvailable() ? $this->moduleList : $this->fullModuleList; // go through modules - foreach ($moduleList->getNames() as $moduleName) { + foreach ($this->fullModuleList->getNames() as $moduleName) { $optionsClassName = str_replace('_', '\\', $moduleName) . '\Setup\ConfigOptionsList'; if (class_exists($optionsClassName)) { $optionsClass = $this->objectManagerProvider->get()->create($optionsClassName); diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index 35ac57649b8c7..9dce15246489c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -59,8 +59,7 @@ public function testExecuteNoInteractive() $commandTester = new CommandTester($this->command); $commandTester->execute(['--db_host' => 'host']); $this->assertSame( - 'No module configuration is available, so all modules are enabled.' . PHP_EOL - . 'You saved the deployment config.' . PHP_EOL, + 'You saved the deployment config.' . PHP_EOL, $commandTester->getDisplay() ); } @@ -116,9 +115,13 @@ private function checkInteraction($interactionType) $commandTester = new CommandTester($this->command); $commandTester->execute(['--db_host' => 'host']); + if ($interactionType) { + $message = 'You saved the deployment config.' . PHP_EOL; + } else { + $message = 'You did not save the deployment config.'.PHP_EOL; + } $this->assertSame( - 'No module configuration is available, so all modules are enabled.' . PHP_EOL - . 'You saved the deployment config.' . PHP_EOL, + $message, $commandTester->getDisplay() ); } From 02613538d53daeedadbda6450451d5215415323e Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 30 Mar 2015 14:25:02 -0500 Subject: [PATCH 198/214] MAGETWO-35136: Delete Segments - modifying test application config values --- .../integration/framework/Magento/TestFramework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 91b81f9c4b5d7..78d4c9e013a42 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -162,7 +162,7 @@ public function getDbInstance() if (null === $this->_db) { if ($this->isInstalled()) { $reader = new \Magento\Framework\App\DeploymentConfig\Reader($this->dirList); - $deploymentConfig = new DeploymentConfig($reader); + $deploymentConfig = new DeploymentConfig($reader, []); $dbInfo = $deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT); $host = $dbInfo['host']; $user = $dbInfo['username']; From 67199665e7c759f418ee773a2f23f15ecaa431b3 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 30 Mar 2015 15:25:42 -0500 Subject: [PATCH 199/214] MAGETWO-35137: Add deployment configuration set command - added $override parameter to Writer::saveConfig, false by default - changed messages (approved) - fixed naming in ConfigOptionsListCollector according to CR - fixed Cyclomatic Complexity in ConfigSetCommand::execute --- .../Model/ConfigOptionsListCollectorTest.php | 6 +- .../Framework/App/DeploymentConfig/Writer.php | 9 ++- .../Test/Unit/DeploymentConfig/WriterTest.php | 56 ++++++++++++++++++- .../Console/Command/ConfigSetCommand.php | 20 +++---- setup/src/Magento/Setup/Model/ConfigModel.php | 6 +- .../Model/ConfigOptionsListCollector.php | 2 +- .../Console/Command/ConfigSetCommandTest.php | 6 +- .../Setup/Test/Unit/Model/ConfigModelTest.php | 6 +- 8 files changed, 84 insertions(+), 27 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php index 3a0d5451068d9..dc573c79eadec 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php @@ -21,11 +21,11 @@ public function setUp() ->willReturn(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()); } - public function testCollectOptionLists() + public function testCollectOptionsLists() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); - $fullModuleListMock->expects($this->never())->method('getNames'); + $fullModuleListMock->expects($this->once())->method('getNames'); /** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */ $object = $objectManager->create( 'Magento\Setup\Model\ConfigOptionsListCollector', @@ -34,7 +34,7 @@ public function testCollectOptionLists() 'fullModuleList' => $fullModuleListMock, ] ); - $result = $object->collectOptionLists(); + $result = $object->collectOptionsLists(); $setupOptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('Magento\Framework\Config\ConfigOptionsList'); diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php index 0455c08214100..644af48555deb 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php @@ -88,9 +88,10 @@ public function checkIfWritable() * Saves config * * @param array $data + * @param bool $override * @return void */ - public function saveConfig(array $data) + public function saveConfig(array $data, $override = false) { $paths = $this->configFilePool->getPaths(); @@ -99,7 +100,11 @@ public function saveConfig(array $data) if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) { $currentData = $this->reader->load($paths[$fileKey]); - $config = array_replace_recursive($currentData, $config); + if ($override) { + $config = array_merge($currentData, $config); + } else { + $config = array_replace_recursive($currentData, $config); + } } $contents = $this->formatter->format($config); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php index 8141a35fe8b0d..e1ab784199fa3 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php @@ -79,7 +79,8 @@ public function testSaveConfig() 'foo' => 'bar', 'key' => 'value', 'baz' => [ - 'test' => 'value' + 'test' => 'value', + 'test1' => 'value1' ] ], ]; @@ -97,7 +98,8 @@ public function testSaveConfig() 'foo' => 'bar', 'key' => 'value', 'baz' => [ - 'test' => 'value2' + 'test' => 'value2', + 'test1' => 'value1' ] ], ]; @@ -115,4 +117,54 @@ public function testSaveConfig() $this->object->saveConfig($testSetUpdate); } + + public function testSaveConfigOverride() + { + $configFiles = [ + ConfigFilePool::APP_CONFIG => 'test_conf.php', + 'test_key' => 'test2_conf.php' + ]; + + $testSetExisting = [ + ConfigFilePool::APP_CONFIG => [ + 'foo' => 'bar', + 'key' => 'value', + 'baz' => [ + 'test' => 'value', + 'test1' => 'value1' + ] + ], + ]; + + $testSetUpdate = [ + ConfigFilePool::APP_CONFIG => [ + 'baz' => [ + 'test' => 'value2' + ] + ], + ]; + + $testSetExpected = [ + ConfigFilePool::APP_CONFIG => [ + 'foo' => 'bar', + 'key' => 'value', + 'baz' => [ + 'test' => 'value2', + ] + ], + ]; + + $this->deploymentConfig->expects($this->once())->method('resetData'); + $this->configFilePool->expects($this->once())->method('getPaths')->willReturn($configFiles); + $this->dirWrite->expects($this->any())->method('isExist')->willReturn(true); + $this->reader->expects($this->once())->method('load')->willReturn($testSetExisting[ConfigFilePool::APP_CONFIG]); + $this->formatter + ->expects($this->once()) + ->method('format') + ->with($testSetExpected[ConfigFilePool::APP_CONFIG]) + ->willReturn([]); + $this->dirWrite->expects($this->once())->method('writeFile')->with('test_conf.php', []); + + $this->object->saveConfig($testSetUpdate, true); + } } diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 3670f3ea08fc9..cbe61e2c37d2c 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -73,10 +73,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { $inputOptions = $input->getOptions(); $optionCollection = $this->configModel->getAvailableOptions(); - $optionsToChange = []; + $commandOptions = []; $optionsWithDefaultValues = []; foreach ($optionCollection as $option) { + $commandOptions[$option->getName()] = false; + $currentValue = $this->deploymentConfig->get($option->getConfigPath()); if (($currentValue !== null) && ($inputOptions[$option->getName()] !== null)) { $dialog = $this->getHelperSet()->get('dialog'); @@ -85,14 +87,9 @@ protected function execute(InputInterface $input, OutputInterface $output) 'Overwrite the existing configuration for ' . $option->getName() . '?[Y|n]' )) { $inputOptions[$option->getName()] = null; - } else { - $optionsToChange[$option->getName()] = $inputOptions[$option->getName()]; - } - } else { - if ($inputOptions[$option->getName()] !== null) { - $optionsToChange[$option->getName()] = $inputOptions[$option->getName()]; } } + if ($option->getDefault() === $inputOptions[$option->getName()] && $inputOptions[$option->getName()] !== null ) { @@ -107,17 +104,20 @@ function ($value) { } ); + $optionsToChange = array_diff($inputOptions, $commandOptions); + $this->configModel->process($inputOptions); + if (count($optionsWithDefaultValues) > 0) { $defaultValuesMessage = implode(', ', $optionsWithDefaultValues); $output->writeln( - 'You saved default value(s) for the next option(s): ' . $defaultValuesMessage . '.' + 'We saved default values for these options: ' . $defaultValuesMessage . '.' ); } else { if (count($optionsToChange) > 0) { - $output->writeln('You saved the deployment config.'); + $output->writeln('You saved the new configuration.'); } else { - $output->writeln('You did not save the deployment config.'); + $output->writeln('You made no changes to the configuration.'); } } } diff --git a/setup/src/Magento/Setup/Model/ConfigModel.php b/setup/src/Magento/Setup/Model/ConfigModel.php index c47fa27315b82..056ab89681c33 100644 --- a/setup/src/Magento/Setup/Model/ConfigModel.php +++ b/setup/src/Magento/Setup/Model/ConfigModel.php @@ -64,7 +64,7 @@ public function getAvailableOptions() { /** @var AbstractConfigOption[] $optionCollection */ $optionCollection = []; - $optionLists = $this->collector->collectOptionLists(); + $optionLists = $this->collector->collectOptionsLists(); foreach ($optionLists as $optionList) { $optionCollection = array_merge($optionCollection, $optionList->getOptions()); @@ -92,7 +92,7 @@ public function process($inputOptions) $this->checkInstallationFilePermissions(); $fileConfigStorage = []; - $options = $this->collector->collectOptionLists(); + $options = $this->collector->collectOptionsLists(); foreach ($options as $moduleName => $option) { @@ -145,7 +145,7 @@ public function validate(array $inputOptions) } // validate ConfigOptionsList - $options = $this->collector->collectOptionLists(); + $options = $this->collector->collectOptionsLists(); foreach ($options as $option) { $errors = array_merge($errors, $option->validate($inputOptions)); diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php index df708cbeec3bb..1c07a2394f51f 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsListCollector.php @@ -69,7 +69,7 @@ public function __construct( * * @return \Magento\Framework\Setup\ConfigOptionsListInterface[] */ - public function collectOptionLists() + public function collectOptionsLists() { $optionsList = []; diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index 9dce15246489c..857ea54b8f518 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -59,7 +59,7 @@ public function testExecuteNoInteractive() $commandTester = new CommandTester($this->command); $commandTester->execute(['--db_host' => 'host']); $this->assertSame( - 'You saved the deployment config.' . PHP_EOL, + 'You saved the new configuration.' . PHP_EOL, $commandTester->getDisplay() ); } @@ -116,9 +116,9 @@ private function checkInteraction($interactionType) $commandTester = new CommandTester($this->command); $commandTester->execute(['--db_host' => 'host']); if ($interactionType) { - $message = 'You saved the deployment config.' . PHP_EOL; + $message = 'You saved the new configuration.' . PHP_EOL; } else { - $message = 'You did not save the deployment config.'.PHP_EOL; + $message = 'You made no changes to the configuration.'.PHP_EOL; } $this->assertSame( $message, diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php index d8ffe7968ca16..00a756da206f5 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigModelTest.php @@ -80,7 +80,7 @@ public function testValidate() $this->collector ->expects($this->exactly(2)) - ->method('collectOptionLists') + ->method('collectOptionsLists') ->will($this->returnValue([$configOption])); $this->configModel->validate(['Fake' => null]); @@ -136,7 +136,7 @@ public function testProcess() 'Fake_Module' => $configOption ]; $this->collector->expects($this->once()) - ->method('collectOptionLists') + ->method('collectOptionsLists') ->will($this->returnValue($configOptionsList)); $this->writer->expects($this->once())->method('saveConfig')->with($testSetExpected); @@ -159,7 +159,7 @@ public function testProcessException() 'Fake_Module' => $configOption ]; - $this->collector->expects($this->once())->method('collectOptionLists')->will($this->returnValue($wrongData)); + $this->collector->expects($this->once())->method('collectOptionsLists')->will($this->returnValue($wrongData)); $this->configModel->process([]); } From 782bee942e31b377fb6618793e7fcc3470c82e72 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 30 Mar 2015 15:40:24 -0500 Subject: [PATCH 200/214] MAGETWO-35136: Delete Segments - modifying modules with override function --- app/code/Magento/Catalog/etc/module.xml | 1 + setup/src/Magento/Setup/Model/Installer.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/etc/module.xml b/app/code/Magento/Catalog/etc/module.xml index ccb21b6aadb8e..e76d0365aba5a 100644 --- a/app/code/Magento/Catalog/etc/module.xml +++ b/app/code/Magento/Catalog/etc/module.xml @@ -8,6 +8,7 @@ + diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 0699efd48634d..7c84845bc00b1 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -332,7 +332,7 @@ private function createModulesConfig($request) $result[$module] = 1; } } - $this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]]); + $this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]], true); return $result; } From 43911bb5446e1a9bd37e7db5cec587dc9c68be2d Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Mon, 30 Mar 2015 16:34:13 -0500 Subject: [PATCH 201/214] MAGETWO-35137: Add deployment configuration set command - fixed test --- .../Magento/Setup/Model/ConfigOptionsListCollectorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php index dc573c79eadec..2563503251e03 100644 --- a/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ConfigOptionsListCollectorTest.php @@ -25,7 +25,8 @@ public function testCollectOptionsLists() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); - $fullModuleListMock->expects($this->once())->method('getNames'); + $fullModuleListMock->expects($this->once())->method('getNames')->willReturn(['Magento_Backend']); + /** @var \Magento\Setup\Model\ConfigOptionsListCollector $object */ $object = $objectManager->create( 'Magento\Setup\Model\ConfigOptionsListCollector', From 52c9b75514407a345934d2536701a08bc392783d Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 31 Mar 2015 06:17:41 -0500 Subject: [PATCH 202/214] MAGETWO-35136: Delete Segments - reverting changes made for testing --- app/code/Magento/Catalog/etc/module.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Catalog/etc/module.xml b/app/code/Magento/Catalog/etc/module.xml index e76d0365aba5a..ccb21b6aadb8e 100644 --- a/app/code/Magento/Catalog/etc/module.xml +++ b/app/code/Magento/Catalog/etc/module.xml @@ -8,7 +8,6 @@ - From 73158ef7833c7d900bed096223d27d4fc380b8ed Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 31 Mar 2015 09:28:16 -0500 Subject: [PATCH 203/214] MAGETWO-35136: Delete Segments - updating to use correct key from config. --- .../lib/Magento/Mtf/App/State/AbstractState.php | 9 ++++++--- .../framework/Magento/TestFramework/Application.php | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php index b3e19b2157989..39d384533ef6d 100644 --- a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php +++ b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php @@ -8,6 +8,8 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Config\ConfigOptionsList; +use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Framework\App\DeploymentConfig; /** * Abstract class AbstractState @@ -42,9 +44,10 @@ public function clearInstance() $dirList = \Magento\Mtf\ObjectManagerFactory::getObjectManager() ->get('Magento\Framework\Filesystem\DirectoryList'); - $reader = new \Magento\Framework\App\DeploymentConfig\Reader($dirList); - $deploymentConfig = new \Magento\Framework\App\DeploymentConfig($reader); - $dbInfo = $deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT); + $reader = new Reader($dirList); + $deploymentConfig = new DeploymentConfig($reader); + $dbConfig = $deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB); + $dbInfo = $dbConfig['connection']['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; $password = $dbInfo['password']; diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 78d4c9e013a42..4e543c44c6be0 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -11,6 +11,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\ConfigOptionsList; +use Magento\Framework\App\DeploymentConfig\Reader; /** * Encapsulates application installation, initialization and uninstall @@ -161,9 +162,10 @@ public function getDbInstance() { if (null === $this->_db) { if ($this->isInstalled()) { - $reader = new \Magento\Framework\App\DeploymentConfig\Reader($this->dirList); + $reader = new Reader($this->dirList); $deploymentConfig = new DeploymentConfig($reader, []); - $dbInfo = $deploymentConfig->getConfigData(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT); + $dbConfig = $deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB); + $dbInfo = $dbConfig['connection']['default']; $host = $dbInfo['host']; $user = $dbInfo['username']; $password = $dbInfo['password']; From 487b35df68c7dc01286dd9ac49a114c55d3c716a Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 31 Mar 2015 10:44:13 -0500 Subject: [PATCH 204/214] MAGETWO-35136: Delete Segments - fix for enable/disable modules --- lib/internal/Magento/Framework/Module/Status.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index e2d73ce314ef8..0c93b19feec29 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -162,7 +162,7 @@ public function setIsEnabled($isEnabled, $modules) $result[$name] = (int)$currentStatus; } } - $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]]); + $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]], true); $this->cleanup->clearCaches(); $this->cleanup->clearCodeGeneratedFiles(); } From 95cb7904f17f54a977b44b2ce68c55c33c0d04f8 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 31 Mar 2015 11:30:44 -0500 Subject: [PATCH 205/214] MAGETWO-35009: Add update command and delete old segment classes - modified DeploymentConfig::flattenParams so we will be able to access to any key in config --- .../Framework/App/DeploymentConfig.php | 33 ++++++++++--------- .../App/Test/Unit/DeploymentConfigTest.php | 5 +++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig.php index cd909817925c9..e260a09a27e29 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig.php @@ -141,28 +141,31 @@ private function load() * Convert associative array of arbitrary depth to a flat associative array with concatenated key path as keys * * @param array $params + * @param string $path * @return array * @throws \Exception */ - private function flattenParams(array $params) + private function flattenParams(array $params, $path = null) { - $result = []; - foreach ($params as $key => $value) { - if (is_array($value)) { - $subParams = $this->flattenParams($value); - foreach ($subParams as $subKey => $subValue) { - if (isset($result[$key . '/' . $subKey])) { - throw new \Exception("Key collision {$subKey} is already defined."); - } - $result[$key . '/' . $subKey] = $subValue; + $cache = []; + + if (is_array($params)) { + foreach ($params as $key => $param) { + if ($path) { + $newPath = $path . '/' . $key; + } else { + $newPath = $key; } - } else { - if (isset($result[$key])) { - throw new \Exception("Key collision {$subKey} is already defined."); + if (isset($cache[$newPath])) { + throw new \Exception("Key collision {$newPath} is already defined."); + } + $cache[$newPath] = $param; + if (is_array($param)) { + $cache = array_merge($cache, $this->flattenParams($param, $newPath)); } - $result[$key] = $value; } } - return $result; + + return $cache; } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php index 7a03f30f531b4..913844757a6d0 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfigTest.php @@ -26,7 +26,12 @@ class DeploymentConfigTest extends \PHPUnit_Framework_TestCase */ private static $flattenedFixture = [ 'configData1' => 'scalar_value', + 'configData2' => [ + 'foo' => 1, + 'bar' => ['baz' => 2], + ], 'configData2/foo' => 1, + 'configData2/bar' => ['baz' => 2], 'configData2/bar/baz' => 2, ]; From cd706534821c8929d77574108d14b83e2666941e Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 31 Mar 2015 12:27:44 -0500 Subject: [PATCH 206/214] MAGETWO-35678: db_prefix sets to empty value if it not set in command line as option - fixed --- lib/internal/Magento/Framework/Config/ConfigGenerator.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index f2bee823e7fbc..c83ed50a1d677 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -157,10 +157,9 @@ public function createDbConfig(array $data) ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS, ]; - $prefixKey = isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]) - ? $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX] - : ''; - $configData->set(ConfigOptionsList::CONFIG_PATH_DB_PREFIX, $prefixKey); + if (isset($data[ConfigOptionsList::INPUT_KEY_DB_PREFIX])) { + $configData->set(ConfigOptionsList::CONFIG_PATH_DB_PREFIX, $data[ConfigOptionsList::INPUT_KEY_DB_PREFIX]); + } foreach ($optional as $key) { if (isset($data[$key])) { From 359dda501d5a2888cbcd8a57de6b72badd9bc693 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 31 Mar 2015 12:45:59 -0500 Subject: [PATCH 207/214] MAGETWO-35678: db_prefix sets to empty value if it not set in command line as option - fixed command name --- setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index cbe61e2c37d2c..2adf13033faf9 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -60,7 +60,7 @@ protected function configure() $options = $this->configModel->getAvailableOptions(); $this->setName('setup:config:set') - ->setDescription('Create deployment configuration') + ->setDescription('Sets deployment configuration') ->setDefinition($options); $this->ignoreValidationErrors(); From 6eda3feffb127dcc0644975b534e6fd7222b018d Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 31 Mar 2015 17:27:29 -0500 Subject: [PATCH 208/214] MAGETWO-35009: Add update command and delete old segment classes - changes according to CR --- .../Framework/App/DeploymentConfig.php | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig.php b/lib/internal/Magento/Framework/App/DeploymentConfig.php index e260a09a27e29..ef1710741d222 100644 --- a/lib/internal/Magento/Framework/App/DeploymentConfig.php +++ b/lib/internal/Magento/Framework/App/DeploymentConfig.php @@ -139,6 +139,7 @@ private function load() /** * Convert associative array of arbitrary depth to a flat associative array with concatenated key path as keys + * each level of array is accessible by path key * * @param array $params * @param string $path @@ -149,20 +150,18 @@ private function flattenParams(array $params, $path = null) { $cache = []; - if (is_array($params)) { - foreach ($params as $key => $param) { - if ($path) { - $newPath = $path . '/' . $key; - } else { - $newPath = $key; - } - if (isset($cache[$newPath])) { - throw new \Exception("Key collision {$newPath} is already defined."); - } - $cache[$newPath] = $param; - if (is_array($param)) { - $cache = array_merge($cache, $this->flattenParams($param, $newPath)); - } + foreach ($params as $key => $param) { + if ($path) { + $newPath = $path . '/' . $key; + } else { + $newPath = $key; + } + if (isset($cache[$newPath])) { + throw new \Exception("Key collision {$newPath} is already defined."); + } + $cache[$newPath] = $param; + if (is_array($param)) { + $cache = array_merge($cache, $this->flattenParams($param, $newPath)); } } From 94939e818cc9734ab2d5c3aff77ed4829d761026 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Tue, 31 Mar 2015 17:50:54 -0500 Subject: [PATCH 209/214] MAGETWO-35137: Add deployment configuration set command - fixed command status message --- setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 2adf13033faf9..0a95ba642a39c 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -104,7 +104,7 @@ function ($value) { } ); - $optionsToChange = array_diff($inputOptions, $commandOptions); + $optionsToChange = array_intersect(array_keys($inputOptions), array_keys($commandOptions)); $this->configModel->process($inputOptions); From 9e6bb64b8a6956d7373fc9c0b79f46049009f01a Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 1 Apr 2015 09:56:36 -0500 Subject: [PATCH 210/214] MAGETWO-35136: Delete Segments - fix for failing integration test --- .../Backend/Controller/Adminhtml/Cache/MassActionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php index 654f9c217ef97..5c04e9f144011 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Controller/Adminhtml/Cache/MassActionTest.php @@ -102,7 +102,7 @@ private function setAll($isEnabled) { /** @var $cacheState \Magento\Framework\App\Cache\StateInterface */ $cacheState = Bootstrap::getObjectManager()->get('Magento\Framework\App\Cache\StateInterface'); - foreach (array_keys(self::$typesConfig->getData()) as $type) { + foreach (array_keys(self::$typesConfig) as $type) { $cacheState->setEnabled($type, $isEnabled); } $cacheState->persist(); From 4e397a9b3ab4e14d7850a9774da762c1e2cc6b52 Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 1 Apr 2015 10:12:50 -0500 Subject: [PATCH 211/214] MAGETWO-35748: Default Values are Set Every Time for Some Config Settings - fixed --- .../Magento/Framework/Config/ConfigGenerator.php | 11 +++++++++-- .../Magento/Framework/Config/ConfigOptionsList.php | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index c83ed50a1d677..01f83c571e2ec 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -170,7 +170,12 @@ public function createDbConfig(array $data) } } - $configData->set(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT . ConfigOptionsList::KEY_ACTIVE, '1'); + if ($this->deploymentConfig->get( + ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT . ConfigOptionsList::KEY_ACTIVE + ) === null + ) { + $configData->set(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT . ConfigOptionsList::KEY_ACTIVE, '1'); + } return $configData; } @@ -184,7 +189,9 @@ public function createResourceConfig() { $configData = new ConfigData(ConfigFilePool::APP_CONFIG); - $configData->set(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP, 'default'); + if (!$this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP)) { + $configData->set(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP, 'default'); + } return $configData; } diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php index 5217d50feb9e6..817835ed0d0fd 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -165,7 +165,8 @@ public function getOptions() self::INPUT_KEY_DB_PREFIX, TextConfigOption::FRONTEND_WIZARD_TEXT, self::CONFIG_PATH_DB_PREFIX, - 'Database table prefix' + 'Database table prefix', + '' ), new TextConfigOption( self::INPUT_KEY_DB_MODEL, From d536cc55cb4c5181cccd45fb11749a18e06c14cf Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 1 Apr 2015 10:32:52 -0500 Subject: [PATCH 212/214] MAGETWO-35748: Default Values are Set Every Time for Some Config Settings - fixed test --- .../Magento/Framework/Config/ConfigGenerator.php | 15 ++++++++------- setup/src/Magento/Setup/Model/Installer.php | 7 +++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index 01f83c571e2ec..7f69331b59b8a 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -65,7 +65,7 @@ public function createInstallConfig() { $configData = new ConfigData(ConfigFilePool::APP_CONFIG); - if (!$this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)) { + if ($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE) === null) { $configData->set(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE, date('r')); } return $configData; @@ -82,7 +82,7 @@ public function createCryptConfig(array $data) $configData = new ConfigData(ConfigFilePool::APP_CONFIG); if (isset($data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY])) { - if ($currentKey) { + if ($currentKey !== null) { $key = $currentKey . "\n" . $data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]; } else { $key = $data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY]; @@ -170,10 +170,11 @@ public function createDbConfig(array $data) } } - if ($this->deploymentConfig->get( - ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT . ConfigOptionsList::KEY_ACTIVE - ) === null - ) { + $currentStatus = $this->deploymentConfig->get( + ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT . ConfigOptionsList::KEY_ACTIVE + ); + + if ($currentStatus === null) { $configData->set(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT . ConfigOptionsList::KEY_ACTIVE, '1'); } @@ -189,7 +190,7 @@ public function createResourceConfig() { $configData = new ConfigData(ConfigFilePool::APP_CONFIG); - if (!$this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP)) { + if ($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP) === null) { $configData->set(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP, 'default'); } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 7c84845bc00b1..1c6641e44bb4d 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -435,8 +435,7 @@ public function installDeploymentConfig($data) // reset object manager now that there is a deployment config $this->objectManagerProvider->reset(); } - - + /** * Sets defaults if user input is missing * @@ -457,8 +456,12 @@ private function setDefaultValues(array $userData) if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS])) { $userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS] = 'SET NAMES utf8;'; } + if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_PREFIX])) { + $userData[ConfigOptionsList::INPUT_KEY_DB_PREFIX] = ''; + } return $userData; } + /** * Set up setup_module table to register modules' versions, skip this process if it already exists * From 87c2a6008dcb7337601f40eedb0bc3202d01531c Mon Sep 17 00:00:00 2001 From: Ivan Gavryshko Date: Wed, 1 Apr 2015 10:49:26 -0500 Subject: [PATCH 213/214] MAGETWO-35748: Default Values are Set Every Time for Some Config Settings - fixed --- lib/internal/Magento/Framework/Config/ConfigGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index 7f69331b59b8a..8930487dd35c7 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -90,7 +90,7 @@ public function createCryptConfig(array $data) $configData->set(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY, $key); } else { - if (!$currentKey) { + if ($currentKey === null) { $configData->set(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY, md5($this->random->getRandomString(10))); } } From 45c21429d8c42c504965789b2879f66e68a9ce3a Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 8 Apr 2015 09:14:38 -0500 Subject: [PATCH 214/214] MAGETWO-35388: Contribution of Sprint 26 Part II - updating composer.lock --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 46fb23e53e603..f3d82a6787d16 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "511a3e2167683bd8b75f3cb361ded487", + "hash": "26bb9ecdfde557897bf591d44716668c", "packages": [ { "name": "composer/composer", @@ -2467,16 +2467,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.4.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74" + "reference": "eab81d02569310739373308137284e0158424330" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db32c18eba00b121c145575fcbcd4d4d24e6db74", - "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/eab81d02569310739373308137284e0158424330", + "reference": "eab81d02569310739373308137284e0158424330", "shasum": "" }, "require": { @@ -2512,7 +2512,7 @@ "keywords": [ "tokenizer" ], - "time": "2015-01-17 09:51:32" + "time": "2015-04-08 04:46:07" }, { "name": "phpunit/phpunit",