From 27692d970f7a5646df697858ce65115c21c1c9c0 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 29 Dec 2014 15:35:27 -0600 Subject: [PATCH 01/89] MAGETWO-32085: Setup Controllers Unit Test Coverage - adding unit tests for the first time --- .../Setup/Controller/AddDatabaseTest.php | 18 ++++++ .../Controller/CreateAdminAccountTest.php | 17 ++++++ .../Controller/CustomizeYourStoreTest.php | 61 +++++++++++++++++++ .../Magento/Setup/Controller/IndexTest.php | 18 ++++++ .../Magento/Setup/Controller/LicenseTest.php | 44 +++++++++++++ .../Setup/Controller/NavigationTest.php | 44 +++++++++++++ .../Setup/Controller/ReadinessCheckTest.php | 34 +++++++++++ .../Magento/Setup/Controller/SuccessTest.php | 18 ++++++ .../Setup/Controller/WebConfigurationTest.php | 20 ++++++ 9 files changed, 274 insertions(+) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/AddDatabaseTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/CreateAdminAccountTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/IndexTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/NavigationTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/ReadinessCheckTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/SuccessTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/AddDatabaseTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/AddDatabaseTest.php new file mode 100644 index 0000000000000..78db6435df5ac --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/AddDatabaseTest.php @@ -0,0 +1,18 @@ +indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertTrue($viewModel->terminate()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/CreateAdminAccountTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/CreateAdminAccountTest.php new file mode 100644 index 0000000000000..d0cc3faaa906c --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/CreateAdminAccountTest.php @@ -0,0 +1,17 @@ +indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertTrue($viewModel->terminate()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php new file mode 100644 index 0000000000000..5291853b1fd0a --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php @@ -0,0 +1,61 @@ +getMock('\Magento\Setup\Model\SampleData', [], [], '', false); + $lists = $this->getMock('\Magento\Setup\Model\Lists', [], [], '', false); + $controller = new CustomizeYourStore($lists, $sampleData); + + $sampleData->expects($this->once())->method('isDeployed')->with()->will( + $this->returnValue($isSampleDataEnabled)); + + $lists->expects($this->once())->method('getTimezoneList')->with()->will($this->returnValue($timezone)); + $lists->expects($this->once())->method('getCurrencyList')->with()->will($this->returnValue($currency)); + $lists->expects($this->once())->method('getLocaleList')->with()->will($this->returnValue($language)); + + $viewModel = $controller->indexAction(); + + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertTrue($viewModel->terminate()); + + $variables = $viewModel->getVariables(); + $this->assertSame($timezone, $variables['timezone']); + $this->assertSame($currency, $variables['currency']); + $this->assertSame($language, $variables['language']); + $this->assertEquals($isSampleDataEnabled, $variables['isSampledataEnabled']); + } + + public function indexActionDataProvider() + { + $timezones = ['America/New_York'=>'EST', 'America/Chicago' => 'CST']; + $currency = ['USD'=>'US Dollar', 'EUR' => 'Euro']; + $language = ['en_US'=>'English (USA)', 'en_UK' => 'English (UK)']; + + return [ + 'with_all_data' => [$timezones, $currency, $language, true], + 'no_currency_data' => [$timezones, null, $language, true], + 'no_timezone_data' => [null, $currency, $language, true], + 'no_language_data' => [$timezones, $currency, null, true], + 'empty_currency_data' => [$timezones, [], $language, true], + 'empty_timezone_data' => [[], $currency, $language, true], + 'empty_language_data' => [$timezones, $currency, [], true], + 'no_sample_data' => [$timezones, $currency, $language, false], + ]; + } +} + diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/IndexTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/IndexTest.php new file mode 100644 index 0000000000000..0671ac8acbb8d --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/IndexTest.php @@ -0,0 +1,18 @@ +indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertFalse($viewModel->terminate()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php new file mode 100644 index 0000000000000..b7aaf7ad54b8a --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php @@ -0,0 +1,44 @@ +licenseModel = $this->getMock('\Magento\Setup\Model\License', [], [], '', false); + $this->controller = new License($this->licenseModel); + } + + public function testIndexActionWithLicense() + { + $this->licenseModel->expects($this->once())->method('getContents')->with()->will( + $this->returnValue('some license string')); + $viewModel = $this->controller->indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertArrayHasKey('license', $viewModel->getVariables()); + } + + public function testIndexActionNoLicense() + { + $this->licenseModel->expects($this->once())->method('getContents')->with()->will($this->returnValue(false)); + $viewModel = $this->controller->indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertArrayHasKey('message', $viewModel->getVariables()); + $this->assertEquals('error/404', $viewModel->getTemplate()); + + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/NavigationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/NavigationTest.php new file mode 100644 index 0000000000000..7fc3631f929b2 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/NavigationTest.php @@ -0,0 +1,44 @@ +navigationModel = $this->getMock('\Magento\Setup\Model\Navigation', [], [], '', false); + $this->controller = new Navigation($this->navigationModel); + } + + public function testIndexAction() + { + $this->navigationModel->expects($this->once())->method('getData')->will($this->returnValue('some data')); + $viewModel = $this->controller->indexAction(); + $this->assertInstanceOf('\Zend\View\Model\JsonModel', $viewModel); + $this->assertArrayHasKey('nav', $viewModel->getVariables()); + } + + public function testMenuAction() + { + $viewModel = $this->controller->menuAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $variables = $viewModel->getVariables(); + $this->assertArrayHasKey('menu', $variables); + $this->assertArrayHasKey('main', $variables); + $this->assertTrue($viewModel->terminate()); + $this->assertSame('/magento/setup/navigation/menu.phtml', $viewModel->getTemplate()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ReadinessCheckTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ReadinessCheckTest.php new file mode 100644 index 0000000000000..bd72191cb4053 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ReadinessCheckTest.php @@ -0,0 +1,34 @@ +controller = new ReadinessCheck(); + } + + public function testIndexAction() + { + $viewModel = $this->controller->indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertTrue($viewModel->terminate()); + } + + public function testProgressAction() + { + $viewModel = $this->controller->progressAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertTrue($viewModel->terminate()); + $this->assertSame('/magento/setup/readiness-check/progress.phtml', $viewModel->getTemplate()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/SuccessTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/SuccessTest.php new file mode 100644 index 0000000000000..ccea49999cb8f --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/SuccessTest.php @@ -0,0 +1,18 @@ +indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertTrue($viewModel->terminate()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php new file mode 100644 index 0000000000000..142bb5b26bbc5 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php @@ -0,0 +1,20 @@ +indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertTrue($viewModel->terminate()); + $this->assertArrayHasKey('autoBaseUrl', $viewModel->getVariables()); + } +} From bec501d0157e62298c3d04d7f8deae5f315897cd Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 30 Dec 2014 16:07:38 -0600 Subject: [PATCH 02/89] MAGETWO-32087: Setup "Install" Controller Unit Test Coverage - adding InstallTest for first time --- .../Magento/Setup/Controller/InstallTest.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php new file mode 100644 index 0000000000000..1d5e893311367 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php @@ -0,0 +1,107 @@ +webLogger = $this->getMock('\Magento\Setup\Model\WebLogger', [], [], '', false); + $installerFactory = $this->getMock('\Magento\Setup\Model\InstallerFactory', [], [], '', false); + $this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false); + $this->progressFactory = $this->getMock('\Magento\Setup\Model\Installer\ProgressFactory', [], [], '', false); + $installerFactory->expects($this->once())->method('create')->with($this->webLogger)->will( + $this->returnValue($this->installer)); + $this->controller = new Install($this->webLogger, $installerFactory, $this->progressFactory); + } + + public function testIndexAction() + { + $viewModel = $this->controller->indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertTrue($viewModel->terminate()); + } + + public function testStartAction() + { + $this->webLogger->expects($this->once())->method('clear'); + $this->installer->expects($this->once())->method('install'); + $this->installer->expects($this->exactly(2))->method('getInstallInfo'); + $jsonModel = $this->controller->startAction(); + $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); + $variables = $jsonModel->getVariables(); + $this->assertArrayHasKey('key', $variables); + $this->assertArrayHasKey('success', $variables); + $this->assertArrayHasKey('messages', $variables); + $this->assertTrue($variables['success']); + } + + public function testStartActionWithError() + { + $this->webLogger->expects($this->once())->method('clear'); + $this->webLogger->expects($this->once())->method('logError'); + $this->installer->method('install')->will($this->throwException(new \LogicException)); + $jsonModel = $this->controller->startAction(); + $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); + $variables = $jsonModel->getVariables(); + $this->assertArrayHasKey('success', $variables); + $this->assertFalse($variables['success']); + } + + public function testProgressAction() + { + $someNumber = 42; + $consoleMessages = ['key1' => 'log message 1', 'key2' => 'log message 2']; + $progress = $this->getMock('\Magento\Setup\Model\Installer\Progress', [], [], '', false); + $this->progressFactory->expects($this->once())->method('createFromLog')->with($this->webLogger)->will( + $this->returnValue($progress)); + $progress->expects($this->once())->method('getRatio')->will($this->returnValue($someNumber)); + $this->webLogger->expects($this->once())->method('get')->will($this->returnValue($consoleMessages)); + $jsonModel = $this->controller->progressAction(); + $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); + $variables = $jsonModel->getVariables(); + $this->assertArrayHasKey('progress', $variables); + $this->assertArrayHasKey('success', $variables); + $this->assertArrayHasKey('console', $variables); + $this->assertSame($consoleMessages, $variables['console']); + $this->assertTrue($variables['success']); + $this->assertSame(sprintf('%d', $someNumber * 100), $variables['progress']); + } + + public function testProgressActionWithError() + { + $e = 'Some exception message'; + $this->progressFactory->expects($this->once())->method('createFromLog') + ->will($this->throwException(new \LogicException($e))); + $jsonModel = $this->controller->progressAction(); + $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); + $variables = $jsonModel->getVariables(); + $this->assertArrayHasKey('success', $variables); + $this->assertArrayHasKey('console', $variables); + $this->assertFalse($variables['success']); + $this->assertStringStartsWith('exception \'LogicException\' with message \'' . $e, $variables['console'][0]); + } +} From 5efc1480bda702df9194ddab89d6f5fd9d05994f Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Wed, 31 Dec 2014 16:02:40 -0600 Subject: [PATCH 03/89] MAGETWO-32090: Setup "Mvc" Models Unit Test Coverage - Add setup directory to code coverage filter --- dev/tests/unit/phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/unit/phpunit.xml.dist b/dev/tests/unit/phpunit.xml.dist index ae89eb40b09a4..53c925cebb62e 100644 --- a/dev/tests/unit/phpunit.xml.dist +++ b/dev/tests/unit/phpunit.xml.dist @@ -19,6 +19,7 @@ ../../../app/code/Magento ../../../lib/internal/Magento + ../../../setup/module/Magento ../../../app/code/Magento/*/sql ../../../app/code/Magento/*/data From 64f0fe30e55755bc8e33f6f4a91cbe49cd40250a Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 2 Jan 2015 10:42:22 -0600 Subject: [PATCH 04/89] MAGETWO-32321: Cleanup setup directory structure - removing /src/ folder within setup --- composer.json | 2 +- composer.lock | 23 ++++++++++--------- .../Magento/Test/Integrity/ClassesTest.php | 1 + .../{src => }/Controller/AddDatabase.php | 0 .../Controller/ConsoleController.php | 0 .../Controller/CreateAdminAccount.php | 0 .../Controller/CustomizeYourStore.php | 0 .../{src => }/Controller/DatabaseCheck.php | 0 .../{src => }/Controller/Environment.php | 0 .../Setup/{src => }/Controller/Index.php | 0 .../Setup/{src => }/Controller/Install.php | 0 .../Setup/{src => }/Controller/Landing.php | 0 .../Setup/{src => }/Controller/License.php | 0 .../Setup/{src => }/Controller/Navigation.php | 0 .../{src => }/Controller/ReadinessCheck.php | 0 .../Controller/ResponseTypeInterface.php | 0 .../Setup/{src => }/Controller/Success.php | 0 .../{src => }/Controller/WebConfiguration.php | 0 .../Magento/Setup/{src => }/Exception.php | 0 .../Setup/{src => }/Model/AdminAccount.php | 0 .../{src => }/Model/AdminAccountFactory.php | 0 .../Setup/{src => }/Model/ConsoleLogger.php | 0 .../Model/DeploymentConfigMapper.php | 0 .../Setup/{src => }/Model/FilePermissions.php | 0 .../Setup/{src => }/Model/Installer.php | 0 .../{src => }/Model/Installer/Progress.php | 0 .../Model/Installer/ProgressFactory.php | 0 .../{src => }/Model/InstallerFactory.php | 0 .../Magento/Setup/{src => }/Model/License.php | 0 .../Magento/Setup/{src => }/Model/Lists.php | 0 .../Setup/{src => }/Model/LoggerInterface.php | 0 .../Setup/{src => }/Model/Navigation.php | 0 .../Setup/{src => }/Model/PhpInformation.php | 0 .../Setup/{src => }/Model/SampleData.php | 0 .../Model/UserConfigurationDataMapper.php | 0 .../Setup/{src => }/Model/WebLogger.php | 0 .../{src => }/Module/ConnectionFactory.php | 0 .../{src => }/Module/ResourceFactory.php | 0 .../Magento/Setup/{src => }/Module/Setup.php | 0 .../{src => }/Module/Setup/FileResolver.php | 0 .../{src => }/Module/Setup/ResourceConfig.php | 0 .../Setup/{src => }/Module/SetupFactory.php | 0 .../Setup/{src => }/Module/SetupModule.php | 0 .../Mvc/Bootstrap/InitParamListener.php | 0 .../{src => }/Mvc/Console/RouteListener.php | 0 .../{src => }/Mvc/Console/RouteMatcher.php | 0 .../Mvc/Console/VerboseValidator.php | 0 .../Mvc/View/Http/InjectTemplateListener.php | 0 48 files changed, 14 insertions(+), 12 deletions(-) rename setup/module/Magento/Setup/{src => }/Controller/AddDatabase.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/ConsoleController.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/CreateAdminAccount.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/CustomizeYourStore.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/DatabaseCheck.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/Environment.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/Index.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/Install.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/Landing.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/License.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/Navigation.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/ReadinessCheck.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/ResponseTypeInterface.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/Success.php (100%) rename setup/module/Magento/Setup/{src => }/Controller/WebConfiguration.php (100%) rename setup/module/Magento/Setup/{src => }/Exception.php (100%) rename setup/module/Magento/Setup/{src => }/Model/AdminAccount.php (100%) rename setup/module/Magento/Setup/{src => }/Model/AdminAccountFactory.php (100%) rename setup/module/Magento/Setup/{src => }/Model/ConsoleLogger.php (100%) rename setup/module/Magento/Setup/{src => }/Model/DeploymentConfigMapper.php (100%) rename setup/module/Magento/Setup/{src => }/Model/FilePermissions.php (100%) rename setup/module/Magento/Setup/{src => }/Model/Installer.php (100%) rename setup/module/Magento/Setup/{src => }/Model/Installer/Progress.php (100%) rename setup/module/Magento/Setup/{src => }/Model/Installer/ProgressFactory.php (100%) rename setup/module/Magento/Setup/{src => }/Model/InstallerFactory.php (100%) rename setup/module/Magento/Setup/{src => }/Model/License.php (100%) rename setup/module/Magento/Setup/{src => }/Model/Lists.php (100%) rename setup/module/Magento/Setup/{src => }/Model/LoggerInterface.php (100%) rename setup/module/Magento/Setup/{src => }/Model/Navigation.php (100%) rename setup/module/Magento/Setup/{src => }/Model/PhpInformation.php (100%) rename setup/module/Magento/Setup/{src => }/Model/SampleData.php (100%) rename setup/module/Magento/Setup/{src => }/Model/UserConfigurationDataMapper.php (100%) rename setup/module/Magento/Setup/{src => }/Model/WebLogger.php (100%) rename setup/module/Magento/Setup/{src => }/Module/ConnectionFactory.php (100%) rename setup/module/Magento/Setup/{src => }/Module/ResourceFactory.php (100%) rename setup/module/Magento/Setup/{src => }/Module/Setup.php (100%) rename setup/module/Magento/Setup/{src => }/Module/Setup/FileResolver.php (100%) rename setup/module/Magento/Setup/{src => }/Module/Setup/ResourceConfig.php (100%) rename setup/module/Magento/Setup/{src => }/Module/SetupFactory.php (100%) rename setup/module/Magento/Setup/{src => }/Module/SetupModule.php (100%) rename setup/module/Magento/Setup/{src => }/Mvc/Bootstrap/InitParamListener.php (100%) rename setup/module/Magento/Setup/{src => }/Mvc/Console/RouteListener.php (100%) rename setup/module/Magento/Setup/{src => }/Mvc/Console/RouteMatcher.php (100%) rename setup/module/Magento/Setup/{src => }/Mvc/Console/VerboseValidator.php (100%) rename setup/module/Magento/Setup/{src => }/Mvc/View/Http/InjectTemplateListener.php (100%) diff --git a/composer.json b/composer.json index b30cc8775b2c0..7f1d102c2ea7c 100644 --- a/composer.json +++ b/composer.json @@ -199,7 +199,7 @@ "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/", "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/", "Magento\\ToolkitFramework\\": "dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/", - "Magento\\Setup\\": "setup/module/Magento/Setup/src/" + "Magento\\Setup\\": "setup/module/Magento/Setup/" } } } diff --git a/composer.lock b/composer.lock index d2fc6da7fe7b8..2cffb1893c7e6 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": "d3a510fb8a6b17c084148509d02478d4", + "hash": "59f62dbbb32452fb2ec978b488a7591d", "packages": [ { "name": "composer/composer", @@ -2001,16 +2001,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "2.0.13", + "version": "2.0.14", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "0e7d2eec5554f869fa7a4ec2d21e4b37af943ea5" + "reference": "ca158276c1200cc27f5409a5e338486bc0b4fc94" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0e7d2eec5554f869fa7a4ec2d21e4b37af943ea5", - "reference": "0e7d2eec5554f869fa7a4ec2d21e4b37af943ea5", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ca158276c1200cc27f5409a5e338486bc0b4fc94", + "reference": "ca158276c1200cc27f5409a5e338486bc0b4fc94", "shasum": "" }, "require": { @@ -2062,7 +2062,7 @@ "testing", "xunit" ], - "time": "2014-12-03 06:41:44" + "time": "2014-12-26 13:28:33" }, { "name": "phpunit/php-file-iterator", @@ -2608,16 +2608,16 @@ }, { "name": "sebastian/version", - "version": "1.0.3", + "version": "1.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43" + "reference": "a77d9123f8e809db3fbdea15038c27a95da4058b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", - "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/a77d9123f8e809db3fbdea15038c27a95da4058b", + "reference": "a77d9123f8e809db3fbdea15038c27a95da4058b", "shasum": "" }, "type": "library", @@ -2639,7 +2639,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2014-03-07 15:35:33" + "time": "2014-12-15 14:25:24" }, { "name": "sjparkinson/static-review", @@ -3034,6 +3034,7 @@ "phpmd/phpmd": 0 }, "prefer-stable": false, + "prefer-lowest": false, "platform": { "php": "~5.4.11|~5.5.0" }, diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php index 241f86ff5c6bb..928624a703040 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php @@ -480,6 +480,7 @@ protected function removeSpecialCases($badClasses, $file, $contents, $namespaceP '/dev/tests/static/testsuite/', '/dev/tests/unit/framework/', '/dev/tests/unit/testsuite/', + '/setup/module/', ]; // Full list of directories where there may be namespace classes foreach ($directories as $directory) { diff --git a/setup/module/Magento/Setup/src/Controller/AddDatabase.php b/setup/module/Magento/Setup/Controller/AddDatabase.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/AddDatabase.php rename to setup/module/Magento/Setup/Controller/AddDatabase.php diff --git a/setup/module/Magento/Setup/src/Controller/ConsoleController.php b/setup/module/Magento/Setup/Controller/ConsoleController.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/ConsoleController.php rename to setup/module/Magento/Setup/Controller/ConsoleController.php diff --git a/setup/module/Magento/Setup/src/Controller/CreateAdminAccount.php b/setup/module/Magento/Setup/Controller/CreateAdminAccount.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/CreateAdminAccount.php rename to setup/module/Magento/Setup/Controller/CreateAdminAccount.php diff --git a/setup/module/Magento/Setup/src/Controller/CustomizeYourStore.php b/setup/module/Magento/Setup/Controller/CustomizeYourStore.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/CustomizeYourStore.php rename to setup/module/Magento/Setup/Controller/CustomizeYourStore.php diff --git a/setup/module/Magento/Setup/src/Controller/DatabaseCheck.php b/setup/module/Magento/Setup/Controller/DatabaseCheck.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/DatabaseCheck.php rename to setup/module/Magento/Setup/Controller/DatabaseCheck.php diff --git a/setup/module/Magento/Setup/src/Controller/Environment.php b/setup/module/Magento/Setup/Controller/Environment.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/Environment.php rename to setup/module/Magento/Setup/Controller/Environment.php diff --git a/setup/module/Magento/Setup/src/Controller/Index.php b/setup/module/Magento/Setup/Controller/Index.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/Index.php rename to setup/module/Magento/Setup/Controller/Index.php diff --git a/setup/module/Magento/Setup/src/Controller/Install.php b/setup/module/Magento/Setup/Controller/Install.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/Install.php rename to setup/module/Magento/Setup/Controller/Install.php diff --git a/setup/module/Magento/Setup/src/Controller/Landing.php b/setup/module/Magento/Setup/Controller/Landing.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/Landing.php rename to setup/module/Magento/Setup/Controller/Landing.php diff --git a/setup/module/Magento/Setup/src/Controller/License.php b/setup/module/Magento/Setup/Controller/License.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/License.php rename to setup/module/Magento/Setup/Controller/License.php diff --git a/setup/module/Magento/Setup/src/Controller/Navigation.php b/setup/module/Magento/Setup/Controller/Navigation.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/Navigation.php rename to setup/module/Magento/Setup/Controller/Navigation.php diff --git a/setup/module/Magento/Setup/src/Controller/ReadinessCheck.php b/setup/module/Magento/Setup/Controller/ReadinessCheck.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/ReadinessCheck.php rename to setup/module/Magento/Setup/Controller/ReadinessCheck.php diff --git a/setup/module/Magento/Setup/src/Controller/ResponseTypeInterface.php b/setup/module/Magento/Setup/Controller/ResponseTypeInterface.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/ResponseTypeInterface.php rename to setup/module/Magento/Setup/Controller/ResponseTypeInterface.php diff --git a/setup/module/Magento/Setup/src/Controller/Success.php b/setup/module/Magento/Setup/Controller/Success.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/Success.php rename to setup/module/Magento/Setup/Controller/Success.php diff --git a/setup/module/Magento/Setup/src/Controller/WebConfiguration.php b/setup/module/Magento/Setup/Controller/WebConfiguration.php similarity index 100% rename from setup/module/Magento/Setup/src/Controller/WebConfiguration.php rename to setup/module/Magento/Setup/Controller/WebConfiguration.php diff --git a/setup/module/Magento/Setup/src/Exception.php b/setup/module/Magento/Setup/Exception.php similarity index 100% rename from setup/module/Magento/Setup/src/Exception.php rename to setup/module/Magento/Setup/Exception.php diff --git a/setup/module/Magento/Setup/src/Model/AdminAccount.php b/setup/module/Magento/Setup/Model/AdminAccount.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/AdminAccount.php rename to setup/module/Magento/Setup/Model/AdminAccount.php diff --git a/setup/module/Magento/Setup/src/Model/AdminAccountFactory.php b/setup/module/Magento/Setup/Model/AdminAccountFactory.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/AdminAccountFactory.php rename to setup/module/Magento/Setup/Model/AdminAccountFactory.php diff --git a/setup/module/Magento/Setup/src/Model/ConsoleLogger.php b/setup/module/Magento/Setup/Model/ConsoleLogger.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/ConsoleLogger.php rename to setup/module/Magento/Setup/Model/ConsoleLogger.php diff --git a/setup/module/Magento/Setup/src/Model/DeploymentConfigMapper.php b/setup/module/Magento/Setup/Model/DeploymentConfigMapper.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/DeploymentConfigMapper.php rename to setup/module/Magento/Setup/Model/DeploymentConfigMapper.php diff --git a/setup/module/Magento/Setup/src/Model/FilePermissions.php b/setup/module/Magento/Setup/Model/FilePermissions.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/FilePermissions.php rename to setup/module/Magento/Setup/Model/FilePermissions.php diff --git a/setup/module/Magento/Setup/src/Model/Installer.php b/setup/module/Magento/Setup/Model/Installer.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/Installer.php rename to setup/module/Magento/Setup/Model/Installer.php diff --git a/setup/module/Magento/Setup/src/Model/Installer/Progress.php b/setup/module/Magento/Setup/Model/Installer/Progress.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/Installer/Progress.php rename to setup/module/Magento/Setup/Model/Installer/Progress.php diff --git a/setup/module/Magento/Setup/src/Model/Installer/ProgressFactory.php b/setup/module/Magento/Setup/Model/Installer/ProgressFactory.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/Installer/ProgressFactory.php rename to setup/module/Magento/Setup/Model/Installer/ProgressFactory.php diff --git a/setup/module/Magento/Setup/src/Model/InstallerFactory.php b/setup/module/Magento/Setup/Model/InstallerFactory.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/InstallerFactory.php rename to setup/module/Magento/Setup/Model/InstallerFactory.php diff --git a/setup/module/Magento/Setup/src/Model/License.php b/setup/module/Magento/Setup/Model/License.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/License.php rename to setup/module/Magento/Setup/Model/License.php diff --git a/setup/module/Magento/Setup/src/Model/Lists.php b/setup/module/Magento/Setup/Model/Lists.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/Lists.php rename to setup/module/Magento/Setup/Model/Lists.php diff --git a/setup/module/Magento/Setup/src/Model/LoggerInterface.php b/setup/module/Magento/Setup/Model/LoggerInterface.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/LoggerInterface.php rename to setup/module/Magento/Setup/Model/LoggerInterface.php diff --git a/setup/module/Magento/Setup/src/Model/Navigation.php b/setup/module/Magento/Setup/Model/Navigation.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/Navigation.php rename to setup/module/Magento/Setup/Model/Navigation.php diff --git a/setup/module/Magento/Setup/src/Model/PhpInformation.php b/setup/module/Magento/Setup/Model/PhpInformation.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/PhpInformation.php rename to setup/module/Magento/Setup/Model/PhpInformation.php diff --git a/setup/module/Magento/Setup/src/Model/SampleData.php b/setup/module/Magento/Setup/Model/SampleData.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/SampleData.php rename to setup/module/Magento/Setup/Model/SampleData.php diff --git a/setup/module/Magento/Setup/src/Model/UserConfigurationDataMapper.php b/setup/module/Magento/Setup/Model/UserConfigurationDataMapper.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/UserConfigurationDataMapper.php rename to setup/module/Magento/Setup/Model/UserConfigurationDataMapper.php diff --git a/setup/module/Magento/Setup/src/Model/WebLogger.php b/setup/module/Magento/Setup/Model/WebLogger.php similarity index 100% rename from setup/module/Magento/Setup/src/Model/WebLogger.php rename to setup/module/Magento/Setup/Model/WebLogger.php diff --git a/setup/module/Magento/Setup/src/Module/ConnectionFactory.php b/setup/module/Magento/Setup/Module/ConnectionFactory.php similarity index 100% rename from setup/module/Magento/Setup/src/Module/ConnectionFactory.php rename to setup/module/Magento/Setup/Module/ConnectionFactory.php diff --git a/setup/module/Magento/Setup/src/Module/ResourceFactory.php b/setup/module/Magento/Setup/Module/ResourceFactory.php similarity index 100% rename from setup/module/Magento/Setup/src/Module/ResourceFactory.php rename to setup/module/Magento/Setup/Module/ResourceFactory.php diff --git a/setup/module/Magento/Setup/src/Module/Setup.php b/setup/module/Magento/Setup/Module/Setup.php similarity index 100% rename from setup/module/Magento/Setup/src/Module/Setup.php rename to setup/module/Magento/Setup/Module/Setup.php diff --git a/setup/module/Magento/Setup/src/Module/Setup/FileResolver.php b/setup/module/Magento/Setup/Module/Setup/FileResolver.php similarity index 100% rename from setup/module/Magento/Setup/src/Module/Setup/FileResolver.php rename to setup/module/Magento/Setup/Module/Setup/FileResolver.php diff --git a/setup/module/Magento/Setup/src/Module/Setup/ResourceConfig.php b/setup/module/Magento/Setup/Module/Setup/ResourceConfig.php similarity index 100% rename from setup/module/Magento/Setup/src/Module/Setup/ResourceConfig.php rename to setup/module/Magento/Setup/Module/Setup/ResourceConfig.php diff --git a/setup/module/Magento/Setup/src/Module/SetupFactory.php b/setup/module/Magento/Setup/Module/SetupFactory.php similarity index 100% rename from setup/module/Magento/Setup/src/Module/SetupFactory.php rename to setup/module/Magento/Setup/Module/SetupFactory.php diff --git a/setup/module/Magento/Setup/src/Module/SetupModule.php b/setup/module/Magento/Setup/Module/SetupModule.php similarity index 100% rename from setup/module/Magento/Setup/src/Module/SetupModule.php rename to setup/module/Magento/Setup/Module/SetupModule.php diff --git a/setup/module/Magento/Setup/src/Mvc/Bootstrap/InitParamListener.php b/setup/module/Magento/Setup/Mvc/Bootstrap/InitParamListener.php similarity index 100% rename from setup/module/Magento/Setup/src/Mvc/Bootstrap/InitParamListener.php rename to setup/module/Magento/Setup/Mvc/Bootstrap/InitParamListener.php diff --git a/setup/module/Magento/Setup/src/Mvc/Console/RouteListener.php b/setup/module/Magento/Setup/Mvc/Console/RouteListener.php similarity index 100% rename from setup/module/Magento/Setup/src/Mvc/Console/RouteListener.php rename to setup/module/Magento/Setup/Mvc/Console/RouteListener.php diff --git a/setup/module/Magento/Setup/src/Mvc/Console/RouteMatcher.php b/setup/module/Magento/Setup/Mvc/Console/RouteMatcher.php similarity index 100% rename from setup/module/Magento/Setup/src/Mvc/Console/RouteMatcher.php rename to setup/module/Magento/Setup/Mvc/Console/RouteMatcher.php diff --git a/setup/module/Magento/Setup/src/Mvc/Console/VerboseValidator.php b/setup/module/Magento/Setup/Mvc/Console/VerboseValidator.php similarity index 100% rename from setup/module/Magento/Setup/src/Mvc/Console/VerboseValidator.php rename to setup/module/Magento/Setup/Mvc/Console/VerboseValidator.php diff --git a/setup/module/Magento/Setup/src/Mvc/View/Http/InjectTemplateListener.php b/setup/module/Magento/Setup/Mvc/View/Http/InjectTemplateListener.php similarity index 100% rename from setup/module/Magento/Setup/src/Mvc/View/Http/InjectTemplateListener.php rename to setup/module/Magento/Setup/Mvc/View/Http/InjectTemplateListener.php From a62f044f627afc709b53561adc6a377fdd945b0d Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 2 Jan 2015 11:20:09 -0600 Subject: [PATCH 05/89] MAGETWO-32321: Cleanup setup directory structure - removing phpunit.xml.dist --- setup/module/Magento/Setup/phpunit.xml.dist | 34 --------------------- 1 file changed, 34 deletions(-) delete mode 100644 setup/module/Magento/Setup/phpunit.xml.dist diff --git a/setup/module/Magento/Setup/phpunit.xml.dist b/setup/module/Magento/Setup/phpunit.xml.dist deleted file mode 100644 index e1a46ac09aa5f..0000000000000 --- a/setup/module/Magento/Setup/phpunit.xml.dist +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - ./tests/ - - - - - - ./ - - ./tests - - - - From 736d66f78cc63b7aea56ad103a83465903fcd4b7 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 2 Jan 2015 11:36:44 -0600 Subject: [PATCH 06/89] MAGETWO-32321:Cleanup setup directory structure - more cleanup of setup dir. - removed gitignore - moved setup/module to setup/src and config and view to setup --- composer.json | 2 +- composer.lock | 2 +- .../testsuite/Magento/Test/Integrity/ClassesTest.php | 2 +- setup/config/application.config.php | 3 +-- setup/{module/Magento/Setup => }/config/di.config.php | 0 .../Magento/Setup => }/config/languages.config.php | 0 .../Magento/Setup => }/config/module.config.php | 0 .../Magento/Setup => }/config/router.config.php | 0 .../Magento/Setup => }/config/states.config.php | 0 setup/module/Magento/Setup/.gitignore | 2 -- .../Magento/Setup/Controller/AddDatabase.php | 0 .../Magento/Setup/Controller/ConsoleController.php | 0 .../Magento/Setup/Controller/CreateAdminAccount.php | 0 .../Magento/Setup/Controller/CustomizeYourStore.php | 0 .../Magento/Setup/Controller/DatabaseCheck.php | 0 .../Magento/Setup/Controller/Environment.php | 0 .../{module => src}/Magento/Setup/Controller/Index.php | 0 .../Magento/Setup/Controller/Install.php | 0 .../Magento/Setup/Controller/Landing.php | 0 .../Magento/Setup/Controller/License.php | 0 .../Magento/Setup/Controller/Navigation.php | 0 .../Magento/Setup/Controller/ReadinessCheck.php | 0 .../Magento/Setup/Controller/ResponseTypeInterface.php | 0 .../Magento/Setup/Controller/Success.php | 0 .../Magento/Setup/Controller/WebConfiguration.php | 0 setup/{module => src}/Magento/Setup/Exception.php | 0 .../Magento/Setup/Model/AdminAccount.php | 0 .../Magento/Setup/Model/AdminAccountFactory.php | 0 .../Magento/Setup/Model/ConsoleLogger.php | 0 .../Magento/Setup/Model/DeploymentConfigMapper.php | 0 .../Magento/Setup/Model/FilePermissions.php | 0 .../{module => src}/Magento/Setup/Model/Installer.php | 0 .../Magento/Setup/Model/Installer/Progress.php | 0 .../Magento/Setup/Model/Installer/ProgressFactory.php | 0 .../Magento/Setup/Model/InstallerFactory.php | 0 setup/{module => src}/Magento/Setup/Model/License.php | 0 setup/{module => src}/Magento/Setup/Model/Lists.php | 0 .../Magento/Setup/Model/LoggerInterface.php | 0 .../{module => src}/Magento/Setup/Model/Navigation.php | 0 .../Magento/Setup/Model/PhpInformation.php | 0 .../{module => src}/Magento/Setup/Model/SampleData.php | 0 .../Setup/Model/UserConfigurationDataMapper.php | 0 .../{module => src}/Magento/Setup/Model/WebLogger.php | 0 setup/{module => src}/Magento/Setup/Module.php | 10 +++++----- .../Magento/Setup/Module/ConnectionFactory.php | 0 .../Magento/Setup/Module/ResourceFactory.php | 0 setup/{module => src}/Magento/Setup/Module/Setup.php | 0 .../Magento/Setup/Module/Setup/FileResolver.php | 0 .../Magento/Setup/Module/Setup/ResourceConfig.php | 0 .../Magento/Setup/Module/SetupFactory.php | 0 .../Magento/Setup/Module/SetupModule.php | 0 .../Magento/Setup/Mvc/Bootstrap/InitParamListener.php | 0 .../Magento/Setup/Mvc/Console/RouteListener.php | 0 .../Magento/Setup/Mvc/Console/RouteMatcher.php | 0 .../Magento/Setup/Mvc/Console/VerboseValidator.php | 0 .../Setup/Mvc/View/Http/InjectTemplateListener.php | 0 setup/{module/Magento/Setup => }/view/error/404.phtml | 0 .../{module/Magento/Setup => }/view/error/index.phtml | 0 .../Magento/Setup => }/view/layout/layout.phtml | 0 .../Setup => }/view/magento/setup/add-database.phtml | 0 .../view/magento/setup/create-admin-account.phtml | 0 .../view/magento/setup/customize-your-store.phtml | 0 .../Magento/Setup => }/view/magento/setup/index.phtml | 0 .../Setup => }/view/magento/setup/install.phtml | 0 .../Setup => }/view/magento/setup/landing.phtml | 0 .../Setup => }/view/magento/setup/license.phtml | 0 .../view/magento/setup/navigation/menu.phtml | 0 .../view/magento/setup/readiness-check.phtml | 0 .../view/magento/setup/readiness-check/progress.phtml | 0 .../Setup => }/view/magento/setup/success.phtml | 0 .../view/magento/setup/web-configuration.phtml | 0 71 files changed, 9 insertions(+), 12 deletions(-) rename setup/{module/Magento/Setup => }/config/di.config.php (100%) rename setup/{module/Magento/Setup => }/config/languages.config.php (100%) rename setup/{module/Magento/Setup => }/config/module.config.php (100%) rename setup/{module/Magento/Setup => }/config/router.config.php (100%) rename setup/{module/Magento/Setup => }/config/states.config.php (100%) delete mode 100644 setup/module/Magento/Setup/.gitignore rename setup/{module => src}/Magento/Setup/Controller/AddDatabase.php (100%) rename setup/{module => src}/Magento/Setup/Controller/ConsoleController.php (100%) rename setup/{module => src}/Magento/Setup/Controller/CreateAdminAccount.php (100%) rename setup/{module => src}/Magento/Setup/Controller/CustomizeYourStore.php (100%) rename setup/{module => src}/Magento/Setup/Controller/DatabaseCheck.php (100%) rename setup/{module => src}/Magento/Setup/Controller/Environment.php (100%) rename setup/{module => src}/Magento/Setup/Controller/Index.php (100%) rename setup/{module => src}/Magento/Setup/Controller/Install.php (100%) rename setup/{module => src}/Magento/Setup/Controller/Landing.php (100%) rename setup/{module => src}/Magento/Setup/Controller/License.php (100%) rename setup/{module => src}/Magento/Setup/Controller/Navigation.php (100%) rename setup/{module => src}/Magento/Setup/Controller/ReadinessCheck.php (100%) rename setup/{module => src}/Magento/Setup/Controller/ResponseTypeInterface.php (100%) rename setup/{module => src}/Magento/Setup/Controller/Success.php (100%) rename setup/{module => src}/Magento/Setup/Controller/WebConfiguration.php (100%) rename setup/{module => src}/Magento/Setup/Exception.php (100%) rename setup/{module => src}/Magento/Setup/Model/AdminAccount.php (100%) rename setup/{module => src}/Magento/Setup/Model/AdminAccountFactory.php (100%) rename setup/{module => src}/Magento/Setup/Model/ConsoleLogger.php (100%) rename setup/{module => src}/Magento/Setup/Model/DeploymentConfigMapper.php (100%) rename setup/{module => src}/Magento/Setup/Model/FilePermissions.php (100%) rename setup/{module => src}/Magento/Setup/Model/Installer.php (100%) rename setup/{module => src}/Magento/Setup/Model/Installer/Progress.php (100%) rename setup/{module => src}/Magento/Setup/Model/Installer/ProgressFactory.php (100%) rename setup/{module => src}/Magento/Setup/Model/InstallerFactory.php (100%) rename setup/{module => src}/Magento/Setup/Model/License.php (100%) rename setup/{module => src}/Magento/Setup/Model/Lists.php (100%) rename setup/{module => src}/Magento/Setup/Model/LoggerInterface.php (100%) rename setup/{module => src}/Magento/Setup/Model/Navigation.php (100%) rename setup/{module => src}/Magento/Setup/Model/PhpInformation.php (100%) rename setup/{module => src}/Magento/Setup/Model/SampleData.php (100%) rename setup/{module => src}/Magento/Setup/Model/UserConfigurationDataMapper.php (100%) rename setup/{module => src}/Magento/Setup/Model/WebLogger.php (100%) rename setup/{module => src}/Magento/Setup/Module.php (86%) rename setup/{module => src}/Magento/Setup/Module/ConnectionFactory.php (100%) rename setup/{module => src}/Magento/Setup/Module/ResourceFactory.php (100%) rename setup/{module => src}/Magento/Setup/Module/Setup.php (100%) rename setup/{module => src}/Magento/Setup/Module/Setup/FileResolver.php (100%) rename setup/{module => src}/Magento/Setup/Module/Setup/ResourceConfig.php (100%) rename setup/{module => src}/Magento/Setup/Module/SetupFactory.php (100%) rename setup/{module => src}/Magento/Setup/Module/SetupModule.php (100%) rename setup/{module => src}/Magento/Setup/Mvc/Bootstrap/InitParamListener.php (100%) rename setup/{module => src}/Magento/Setup/Mvc/Console/RouteListener.php (100%) rename setup/{module => src}/Magento/Setup/Mvc/Console/RouteMatcher.php (100%) rename setup/{module => src}/Magento/Setup/Mvc/Console/VerboseValidator.php (100%) rename setup/{module => src}/Magento/Setup/Mvc/View/Http/InjectTemplateListener.php (100%) rename setup/{module/Magento/Setup => }/view/error/404.phtml (100%) rename setup/{module/Magento/Setup => }/view/error/index.phtml (100%) rename setup/{module/Magento/Setup => }/view/layout/layout.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/add-database.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/create-admin-account.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/customize-your-store.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/index.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/install.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/landing.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/license.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/navigation/menu.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/readiness-check.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/readiness-check/progress.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/success.phtml (100%) rename setup/{module/Magento/Setup => }/view/magento/setup/web-configuration.phtml (100%) diff --git a/composer.json b/composer.json index 7f1d102c2ea7c..741b74f019efb 100644 --- a/composer.json +++ b/composer.json @@ -199,7 +199,7 @@ "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/", "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/", "Magento\\ToolkitFramework\\": "dev/tools/performance-toolkit/framework/Magento/ToolkitFramework/", - "Magento\\Setup\\": "setup/module/Magento/Setup/" + "Magento\\Setup\\": "setup/src/Magento/Setup/" } } } diff --git a/composer.lock b/composer.lock index 2cffb1893c7e6..4d1b6d3985c6c 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": "59f62dbbb32452fb2ec978b488a7591d", + "hash": "608b2d952440f602fcfef93ee0ac3a09", "packages": [ { "name": "composer/composer", diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php index 928624a703040..83dd18c3fdc0b 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php @@ -480,7 +480,7 @@ protected function removeSpecialCases($badClasses, $file, $contents, $namespaceP '/dev/tests/static/testsuite/', '/dev/tests/unit/framework/', '/dev/tests/unit/testsuite/', - '/setup/module/', + '/setup/src/', ]; // Full list of directories where there may be namespace classes foreach ($directories as $directory) { diff --git a/setup/config/application.config.php b/setup/config/application.config.php index 79246293eb104..23f3f6f38e092 100644 --- a/setup/config/application.config.php +++ b/setup/config/application.config.php @@ -11,8 +11,7 @@ ], 'module_listener_options' => [ 'module_paths' => [ - __DIR__ . '/../module', - __DIR__ . '/../vendor', + __DIR__ . '/../src', ], 'config_glob_paths' => [ __DIR__ . '/autoload/{,*.}{global,local}.php', diff --git a/setup/module/Magento/Setup/config/di.config.php b/setup/config/di.config.php similarity index 100% rename from setup/module/Magento/Setup/config/di.config.php rename to setup/config/di.config.php diff --git a/setup/module/Magento/Setup/config/languages.config.php b/setup/config/languages.config.php similarity index 100% rename from setup/module/Magento/Setup/config/languages.config.php rename to setup/config/languages.config.php diff --git a/setup/module/Magento/Setup/config/module.config.php b/setup/config/module.config.php similarity index 100% rename from setup/module/Magento/Setup/config/module.config.php rename to setup/config/module.config.php diff --git a/setup/module/Magento/Setup/config/router.config.php b/setup/config/router.config.php similarity index 100% rename from setup/module/Magento/Setup/config/router.config.php rename to setup/config/router.config.php diff --git a/setup/module/Magento/Setup/config/states.config.php b/setup/config/states.config.php similarity index 100% rename from setup/module/Magento/Setup/config/states.config.php rename to setup/config/states.config.php diff --git a/setup/module/Magento/Setup/.gitignore b/setup/module/Magento/Setup/.gitignore deleted file mode 100644 index c7f4956653dae..0000000000000 --- a/setup/module/Magento/Setup/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -vendor/ -phpunit.xml diff --git a/setup/module/Magento/Setup/Controller/AddDatabase.php b/setup/src/Magento/Setup/Controller/AddDatabase.php similarity index 100% rename from setup/module/Magento/Setup/Controller/AddDatabase.php rename to setup/src/Magento/Setup/Controller/AddDatabase.php diff --git a/setup/module/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php similarity index 100% rename from setup/module/Magento/Setup/Controller/ConsoleController.php rename to setup/src/Magento/Setup/Controller/ConsoleController.php diff --git a/setup/module/Magento/Setup/Controller/CreateAdminAccount.php b/setup/src/Magento/Setup/Controller/CreateAdminAccount.php similarity index 100% rename from setup/module/Magento/Setup/Controller/CreateAdminAccount.php rename to setup/src/Magento/Setup/Controller/CreateAdminAccount.php diff --git a/setup/module/Magento/Setup/Controller/CustomizeYourStore.php b/setup/src/Magento/Setup/Controller/CustomizeYourStore.php similarity index 100% rename from setup/module/Magento/Setup/Controller/CustomizeYourStore.php rename to setup/src/Magento/Setup/Controller/CustomizeYourStore.php diff --git a/setup/module/Magento/Setup/Controller/DatabaseCheck.php b/setup/src/Magento/Setup/Controller/DatabaseCheck.php similarity index 100% rename from setup/module/Magento/Setup/Controller/DatabaseCheck.php rename to setup/src/Magento/Setup/Controller/DatabaseCheck.php diff --git a/setup/module/Magento/Setup/Controller/Environment.php b/setup/src/Magento/Setup/Controller/Environment.php similarity index 100% rename from setup/module/Magento/Setup/Controller/Environment.php rename to setup/src/Magento/Setup/Controller/Environment.php diff --git a/setup/module/Magento/Setup/Controller/Index.php b/setup/src/Magento/Setup/Controller/Index.php similarity index 100% rename from setup/module/Magento/Setup/Controller/Index.php rename to setup/src/Magento/Setup/Controller/Index.php diff --git a/setup/module/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php similarity index 100% rename from setup/module/Magento/Setup/Controller/Install.php rename to setup/src/Magento/Setup/Controller/Install.php diff --git a/setup/module/Magento/Setup/Controller/Landing.php b/setup/src/Magento/Setup/Controller/Landing.php similarity index 100% rename from setup/module/Magento/Setup/Controller/Landing.php rename to setup/src/Magento/Setup/Controller/Landing.php diff --git a/setup/module/Magento/Setup/Controller/License.php b/setup/src/Magento/Setup/Controller/License.php similarity index 100% rename from setup/module/Magento/Setup/Controller/License.php rename to setup/src/Magento/Setup/Controller/License.php diff --git a/setup/module/Magento/Setup/Controller/Navigation.php b/setup/src/Magento/Setup/Controller/Navigation.php similarity index 100% rename from setup/module/Magento/Setup/Controller/Navigation.php rename to setup/src/Magento/Setup/Controller/Navigation.php diff --git a/setup/module/Magento/Setup/Controller/ReadinessCheck.php b/setup/src/Magento/Setup/Controller/ReadinessCheck.php similarity index 100% rename from setup/module/Magento/Setup/Controller/ReadinessCheck.php rename to setup/src/Magento/Setup/Controller/ReadinessCheck.php diff --git a/setup/module/Magento/Setup/Controller/ResponseTypeInterface.php b/setup/src/Magento/Setup/Controller/ResponseTypeInterface.php similarity index 100% rename from setup/module/Magento/Setup/Controller/ResponseTypeInterface.php rename to setup/src/Magento/Setup/Controller/ResponseTypeInterface.php diff --git a/setup/module/Magento/Setup/Controller/Success.php b/setup/src/Magento/Setup/Controller/Success.php similarity index 100% rename from setup/module/Magento/Setup/Controller/Success.php rename to setup/src/Magento/Setup/Controller/Success.php diff --git a/setup/module/Magento/Setup/Controller/WebConfiguration.php b/setup/src/Magento/Setup/Controller/WebConfiguration.php similarity index 100% rename from setup/module/Magento/Setup/Controller/WebConfiguration.php rename to setup/src/Magento/Setup/Controller/WebConfiguration.php diff --git a/setup/module/Magento/Setup/Exception.php b/setup/src/Magento/Setup/Exception.php similarity index 100% rename from setup/module/Magento/Setup/Exception.php rename to setup/src/Magento/Setup/Exception.php diff --git a/setup/module/Magento/Setup/Model/AdminAccount.php b/setup/src/Magento/Setup/Model/AdminAccount.php similarity index 100% rename from setup/module/Magento/Setup/Model/AdminAccount.php rename to setup/src/Magento/Setup/Model/AdminAccount.php diff --git a/setup/module/Magento/Setup/Model/AdminAccountFactory.php b/setup/src/Magento/Setup/Model/AdminAccountFactory.php similarity index 100% rename from setup/module/Magento/Setup/Model/AdminAccountFactory.php rename to setup/src/Magento/Setup/Model/AdminAccountFactory.php diff --git a/setup/module/Magento/Setup/Model/ConsoleLogger.php b/setup/src/Magento/Setup/Model/ConsoleLogger.php similarity index 100% rename from setup/module/Magento/Setup/Model/ConsoleLogger.php rename to setup/src/Magento/Setup/Model/ConsoleLogger.php diff --git a/setup/module/Magento/Setup/Model/DeploymentConfigMapper.php b/setup/src/Magento/Setup/Model/DeploymentConfigMapper.php similarity index 100% rename from setup/module/Magento/Setup/Model/DeploymentConfigMapper.php rename to setup/src/Magento/Setup/Model/DeploymentConfigMapper.php diff --git a/setup/module/Magento/Setup/Model/FilePermissions.php b/setup/src/Magento/Setup/Model/FilePermissions.php similarity index 100% rename from setup/module/Magento/Setup/Model/FilePermissions.php rename to setup/src/Magento/Setup/Model/FilePermissions.php diff --git a/setup/module/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php similarity index 100% rename from setup/module/Magento/Setup/Model/Installer.php rename to setup/src/Magento/Setup/Model/Installer.php diff --git a/setup/module/Magento/Setup/Model/Installer/Progress.php b/setup/src/Magento/Setup/Model/Installer/Progress.php similarity index 100% rename from setup/module/Magento/Setup/Model/Installer/Progress.php rename to setup/src/Magento/Setup/Model/Installer/Progress.php diff --git a/setup/module/Magento/Setup/Model/Installer/ProgressFactory.php b/setup/src/Magento/Setup/Model/Installer/ProgressFactory.php similarity index 100% rename from setup/module/Magento/Setup/Model/Installer/ProgressFactory.php rename to setup/src/Magento/Setup/Model/Installer/ProgressFactory.php diff --git a/setup/module/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php similarity index 100% rename from setup/module/Magento/Setup/Model/InstallerFactory.php rename to setup/src/Magento/Setup/Model/InstallerFactory.php diff --git a/setup/module/Magento/Setup/Model/License.php b/setup/src/Magento/Setup/Model/License.php similarity index 100% rename from setup/module/Magento/Setup/Model/License.php rename to setup/src/Magento/Setup/Model/License.php diff --git a/setup/module/Magento/Setup/Model/Lists.php b/setup/src/Magento/Setup/Model/Lists.php similarity index 100% rename from setup/module/Magento/Setup/Model/Lists.php rename to setup/src/Magento/Setup/Model/Lists.php diff --git a/setup/module/Magento/Setup/Model/LoggerInterface.php b/setup/src/Magento/Setup/Model/LoggerInterface.php similarity index 100% rename from setup/module/Magento/Setup/Model/LoggerInterface.php rename to setup/src/Magento/Setup/Model/LoggerInterface.php diff --git a/setup/module/Magento/Setup/Model/Navigation.php b/setup/src/Magento/Setup/Model/Navigation.php similarity index 100% rename from setup/module/Magento/Setup/Model/Navigation.php rename to setup/src/Magento/Setup/Model/Navigation.php diff --git a/setup/module/Magento/Setup/Model/PhpInformation.php b/setup/src/Magento/Setup/Model/PhpInformation.php similarity index 100% rename from setup/module/Magento/Setup/Model/PhpInformation.php rename to setup/src/Magento/Setup/Model/PhpInformation.php diff --git a/setup/module/Magento/Setup/Model/SampleData.php b/setup/src/Magento/Setup/Model/SampleData.php similarity index 100% rename from setup/module/Magento/Setup/Model/SampleData.php rename to setup/src/Magento/Setup/Model/SampleData.php diff --git a/setup/module/Magento/Setup/Model/UserConfigurationDataMapper.php b/setup/src/Magento/Setup/Model/UserConfigurationDataMapper.php similarity index 100% rename from setup/module/Magento/Setup/Model/UserConfigurationDataMapper.php rename to setup/src/Magento/Setup/Model/UserConfigurationDataMapper.php diff --git a/setup/module/Magento/Setup/Model/WebLogger.php b/setup/src/Magento/Setup/Model/WebLogger.php similarity index 100% rename from setup/module/Magento/Setup/Model/WebLogger.php rename to setup/src/Magento/Setup/Model/WebLogger.php diff --git a/setup/module/Magento/Setup/Module.php b/setup/src/Magento/Setup/Module.php similarity index 86% rename from setup/module/Magento/Setup/Module.php rename to setup/src/Magento/Setup/Module.php index 46c60e3dcaa89..f19755f187d62 100644 --- a/setup/module/Magento/Setup/Module.php +++ b/setup/src/Magento/Setup/Module.php @@ -59,11 +59,11 @@ public function onBootstrap(EventInterface $e) public function getConfig() { $result = array_merge( - include __DIR__ . '/config/module.config.php', - include __DIR__ . '/config/router.config.php', - include __DIR__ . '/config/di.config.php', - include __DIR__ . '/config/states.config.php', - include __DIR__ . '/config/languages.config.php' + include __DIR__ . '/../../../config/module.config.php', + include __DIR__ . '/../../../config/router.config.php', + include __DIR__ . '/../../../config/di.config.php', + include __DIR__ . '/../../../config/states.config.php', + include __DIR__ . '/../../../config/languages.config.php' ); $result = InitParamListener::attachToConsoleRoutes($result); return $result; diff --git a/setup/module/Magento/Setup/Module/ConnectionFactory.php b/setup/src/Magento/Setup/Module/ConnectionFactory.php similarity index 100% rename from setup/module/Magento/Setup/Module/ConnectionFactory.php rename to setup/src/Magento/Setup/Module/ConnectionFactory.php diff --git a/setup/module/Magento/Setup/Module/ResourceFactory.php b/setup/src/Magento/Setup/Module/ResourceFactory.php similarity index 100% rename from setup/module/Magento/Setup/Module/ResourceFactory.php rename to setup/src/Magento/Setup/Module/ResourceFactory.php diff --git a/setup/module/Magento/Setup/Module/Setup.php b/setup/src/Magento/Setup/Module/Setup.php similarity index 100% rename from setup/module/Magento/Setup/Module/Setup.php rename to setup/src/Magento/Setup/Module/Setup.php diff --git a/setup/module/Magento/Setup/Module/Setup/FileResolver.php b/setup/src/Magento/Setup/Module/Setup/FileResolver.php similarity index 100% rename from setup/module/Magento/Setup/Module/Setup/FileResolver.php rename to setup/src/Magento/Setup/Module/Setup/FileResolver.php diff --git a/setup/module/Magento/Setup/Module/Setup/ResourceConfig.php b/setup/src/Magento/Setup/Module/Setup/ResourceConfig.php similarity index 100% rename from setup/module/Magento/Setup/Module/Setup/ResourceConfig.php rename to setup/src/Magento/Setup/Module/Setup/ResourceConfig.php diff --git a/setup/module/Magento/Setup/Module/SetupFactory.php b/setup/src/Magento/Setup/Module/SetupFactory.php similarity index 100% rename from setup/module/Magento/Setup/Module/SetupFactory.php rename to setup/src/Magento/Setup/Module/SetupFactory.php diff --git a/setup/module/Magento/Setup/Module/SetupModule.php b/setup/src/Magento/Setup/Module/SetupModule.php similarity index 100% rename from setup/module/Magento/Setup/Module/SetupModule.php rename to setup/src/Magento/Setup/Module/SetupModule.php diff --git a/setup/module/Magento/Setup/Mvc/Bootstrap/InitParamListener.php b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php similarity index 100% rename from setup/module/Magento/Setup/Mvc/Bootstrap/InitParamListener.php rename to setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php diff --git a/setup/module/Magento/Setup/Mvc/Console/RouteListener.php b/setup/src/Magento/Setup/Mvc/Console/RouteListener.php similarity index 100% rename from setup/module/Magento/Setup/Mvc/Console/RouteListener.php rename to setup/src/Magento/Setup/Mvc/Console/RouteListener.php diff --git a/setup/module/Magento/Setup/Mvc/Console/RouteMatcher.php b/setup/src/Magento/Setup/Mvc/Console/RouteMatcher.php similarity index 100% rename from setup/module/Magento/Setup/Mvc/Console/RouteMatcher.php rename to setup/src/Magento/Setup/Mvc/Console/RouteMatcher.php diff --git a/setup/module/Magento/Setup/Mvc/Console/VerboseValidator.php b/setup/src/Magento/Setup/Mvc/Console/VerboseValidator.php similarity index 100% rename from setup/module/Magento/Setup/Mvc/Console/VerboseValidator.php rename to setup/src/Magento/Setup/Mvc/Console/VerboseValidator.php diff --git a/setup/module/Magento/Setup/Mvc/View/Http/InjectTemplateListener.php b/setup/src/Magento/Setup/Mvc/View/Http/InjectTemplateListener.php similarity index 100% rename from setup/module/Magento/Setup/Mvc/View/Http/InjectTemplateListener.php rename to setup/src/Magento/Setup/Mvc/View/Http/InjectTemplateListener.php diff --git a/setup/module/Magento/Setup/view/error/404.phtml b/setup/view/error/404.phtml similarity index 100% rename from setup/module/Magento/Setup/view/error/404.phtml rename to setup/view/error/404.phtml diff --git a/setup/module/Magento/Setup/view/error/index.phtml b/setup/view/error/index.phtml similarity index 100% rename from setup/module/Magento/Setup/view/error/index.phtml rename to setup/view/error/index.phtml diff --git a/setup/module/Magento/Setup/view/layout/layout.phtml b/setup/view/layout/layout.phtml similarity index 100% rename from setup/module/Magento/Setup/view/layout/layout.phtml rename to setup/view/layout/layout.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/add-database.phtml b/setup/view/magento/setup/add-database.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/add-database.phtml rename to setup/view/magento/setup/add-database.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/create-admin-account.phtml b/setup/view/magento/setup/create-admin-account.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/create-admin-account.phtml rename to setup/view/magento/setup/create-admin-account.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/customize-your-store.phtml b/setup/view/magento/setup/customize-your-store.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/customize-your-store.phtml rename to setup/view/magento/setup/customize-your-store.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/index.phtml b/setup/view/magento/setup/index.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/index.phtml rename to setup/view/magento/setup/index.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/install.phtml b/setup/view/magento/setup/install.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/install.phtml rename to setup/view/magento/setup/install.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/landing.phtml b/setup/view/magento/setup/landing.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/landing.phtml rename to setup/view/magento/setup/landing.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/license.phtml b/setup/view/magento/setup/license.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/license.phtml rename to setup/view/magento/setup/license.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/navigation/menu.phtml b/setup/view/magento/setup/navigation/menu.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/navigation/menu.phtml rename to setup/view/magento/setup/navigation/menu.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/readiness-check.phtml b/setup/view/magento/setup/readiness-check.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/readiness-check.phtml rename to setup/view/magento/setup/readiness-check.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/readiness-check/progress.phtml b/setup/view/magento/setup/readiness-check/progress.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/readiness-check/progress.phtml rename to setup/view/magento/setup/readiness-check/progress.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/success.phtml b/setup/view/magento/setup/success.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/success.phtml rename to setup/view/magento/setup/success.phtml diff --git a/setup/module/Magento/Setup/view/magento/setup/web-configuration.phtml b/setup/view/magento/setup/web-configuration.phtml similarity index 100% rename from setup/module/Magento/Setup/view/magento/setup/web-configuration.phtml rename to setup/view/magento/setup/web-configuration.phtml From 6505e2ce5d62a3d551a1b1503f8d31ad06d08895 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 5 Jan 2015 12:56:03 -0600 Subject: [PATCH 07/89] MAGETWO-32087: Setup "Install" Controller Unit Test Coverage - based on CR comments, added test for dispatch to cover conditional statements --- .../Magento/Setup/Controller/InstallTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php index 1d5e893311367..77776dde0a089 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php @@ -104,4 +104,24 @@ public function testProgressActionWithError() $this->assertFalse($variables['success']); $this->assertStringStartsWith('exception \'LogicException\' with message \'' . $e, $variables['console'][0]); } + + public function testDispatch() + { + $request = $this->getMock('\Zend\Http\PhpEnvironment\Request', [], [], '', false); + $response = $this->getMock('\Zend\Http\PhpEnvironment\Response', [], [], '', false); + $routeMatch = $this->getMock('\Zend\Mvc\Router\RouteMatch', [], [], '', false); + + $mvcEvent = $this->getMock('\Zend\Mvc\MvcEvent', [], [], '', false); + $mvcEvent->expects($this->once())->method('setRequest')->with($request)->will($this->returnValue($mvcEvent)); + $mvcEvent->expects($this->once())->method('setResponse')->with($response)->will($this->returnValue($mvcEvent)); + $mvcEvent->expects($this->once())->method('setTarget')->with($this->controller) + ->will($this->returnValue($mvcEvent)); + $mvcEvent->expects($this->any())->method('getRouteMatch')->will($this->returnValue($routeMatch)); + + $contentArray = '{"config": { "address": { "base_url": "http://123.45.678.12"}}}'; + $request->expects($this->any())->method('getContent')->will($this->returnValue($contentArray)); + $this->controller->setEvent($mvcEvent); + $this->controller->dispatch($request, $response); + $this->controller->startAction(); + } } From ccb32a93536521344fea0a2dee86ef977736929d Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Tue, 13 Jan 2015 17:43:29 -0600 Subject: [PATCH 08/89] MAGETWO-32644: Remove PHP 5.4 support from composer.json - Updated composer.json files, composer.lock and .travis.yml files. --- .travis.yml | 5 ----- app/code/Magento/AdminNotification/composer.json | 2 +- app/code/Magento/Authorization/composer.json | 2 +- app/code/Magento/Backend/composer.json | 2 +- app/code/Magento/Backup/composer.json | 2 +- app/code/Magento/Bundle/composer.json | 2 +- app/code/Magento/Captcha/composer.json | 2 +- app/code/Magento/Catalog/composer.json | 2 +- app/code/Magento/CatalogImportExport/composer.json | 2 +- app/code/Magento/CatalogInventory/composer.json | 2 +- app/code/Magento/CatalogRule/composer.json | 2 +- app/code/Magento/CatalogSearch/composer.json | 2 +- app/code/Magento/CatalogUrlRewrite/composer.json | 2 +- app/code/Magento/CatalogWidget/composer.json | 2 +- app/code/Magento/Centinel/composer.json | 2 +- app/code/Magento/Checkout/composer.json | 2 +- app/code/Magento/CheckoutAgreements/composer.json | 2 +- app/code/Magento/Cms/composer.json | 2 +- app/code/Magento/CmsUrlRewrite/composer.json | 2 +- app/code/Magento/ConfigurableImportExport/composer.json | 2 +- app/code/Magento/ConfigurableProduct/composer.json | 2 +- app/code/Magento/Contact/composer.json | 2 +- app/code/Magento/Core/composer.json | 2 +- app/code/Magento/Cron/composer.json | 2 +- app/code/Magento/CurrencySymbol/composer.json | 2 +- app/code/Magento/Customer/composer.json | 2 +- app/code/Magento/CustomerImportExport/composer.json | 2 +- app/code/Magento/DesignEditor/composer.json | 2 +- app/code/Magento/Dhl/composer.json | 2 +- app/code/Magento/Directory/composer.json | 2 +- app/code/Magento/Downloadable/composer.json | 2 +- app/code/Magento/Eav/composer.json | 2 +- app/code/Magento/Email/composer.json | 2 +- app/code/Magento/Fedex/composer.json | 2 +- app/code/Magento/GiftMessage/composer.json | 2 +- app/code/Magento/GoogleAdwords/composer.json | 2 +- app/code/Magento/GoogleAnalytics/composer.json | 2 +- app/code/Magento/GoogleOptimizer/composer.json | 2 +- app/code/Magento/GoogleShopping/composer.json | 2 +- app/code/Magento/GroupedImportExport/composer.json | 2 +- app/code/Magento/GroupedProduct/composer.json | 2 +- app/code/Magento/ImportExport/composer.json | 2 +- app/code/Magento/Indexer/composer.json | 2 +- app/code/Magento/Integration/composer.json | 2 +- app/code/Magento/LayeredNavigation/composer.json | 2 +- app/code/Magento/Log/composer.json | 2 +- app/code/Magento/Msrp/composer.json | 2 +- app/code/Magento/Multishipping/composer.json | 2 +- app/code/Magento/Newsletter/composer.json | 2 +- app/code/Magento/OfflinePayments/composer.json | 2 +- app/code/Magento/OfflineShipping/composer.json | 2 +- app/code/Magento/PageCache/composer.json | 2 +- app/code/Magento/Payment/composer.json | 2 +- app/code/Magento/Persistent/composer.json | 2 +- app/code/Magento/ProductAlert/composer.json | 2 +- app/code/Magento/Reports/composer.json | 2 +- app/code/Magento/RequireJs/composer.json | 2 +- app/code/Magento/Review/composer.json | 2 +- app/code/Magento/Rss/composer.json | 2 +- app/code/Magento/Rule/composer.json | 2 +- app/code/Magento/Sales/composer.json | 2 +- app/code/Magento/SalesRule/composer.json | 2 +- app/code/Magento/Search/composer.json | 2 +- app/code/Magento/Sendfriend/composer.json | 2 +- app/code/Magento/Shipping/composer.json | 2 +- app/code/Magento/Sitemap/composer.json | 2 +- app/code/Magento/Store/composer.json | 2 +- app/code/Magento/Tax/composer.json | 2 +- app/code/Magento/TaxImportExport/composer.json | 2 +- app/code/Magento/Theme/composer.json | 2 +- app/code/Magento/Translation/composer.json | 2 +- app/code/Magento/Ui/composer.json | 2 +- app/code/Magento/Ups/composer.json | 2 +- app/code/Magento/UrlRewrite/composer.json | 2 +- app/code/Magento/User/composer.json | 2 +- app/code/Magento/Usps/composer.json | 2 +- app/code/Magento/Webapi/composer.json | 2 +- app/code/Magento/Weee/composer.json | 2 +- app/code/Magento/Widget/composer.json | 2 +- app/code/Magento/Wishlist/composer.json | 2 +- app/design/adminhtml/Magento/backend/composer.json | 2 +- app/design/frontend/Magento/blank/composer.json | 2 +- app/design/frontend/Magento/luma/composer.json | 2 +- composer.json | 2 +- composer.lock | 5 ++--- .../Magento/Test/Tools/Dependency/_files/composer1.json | 2 +- .../Magento/Test/Tools/Dependency/_files/composer2.json | 2 +- .../Magento/Test/Tools/Dependency/_files/composer3.json | 2 +- .../Magento/Test/Tools/Dependency/_files/composer4.json | 2 +- .../Magento/Test/Tools/Dependency/_files/composer5.json | 2 +- .../_files/design/adminhtml/magento_basic/composer.json | 2 +- .../Core/Model/_files/frontend/magento_iphone/composer.json | 2 +- lib/internal/Magento/Framework/composer.json | 2 +- 93 files changed, 93 insertions(+), 99 deletions(-) diff --git a/.travis.yml b/.travis.yml index 75d26bdfa7d10..c7a952740ba6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: php php: - - 5.4 - 5.5 - 5.6 env: @@ -11,10 +10,6 @@ env: - TEST_SUITE=static_annotation matrix: exclude: - - php: 5.4 - env: TEST_SUITE=static_phpcs - - php: 5.4 - env: TEST_SUITE=static_annotation - php: 5.6 env: TEST_SUITE=static_phpcs - php: 5.6 diff --git a/app/code/Magento/AdminNotification/composer.json b/app/code/Magento/AdminNotification/composer.json index 772dd77e5093f..b22145e0b5a63 100644 --- a/app/code/Magento/AdminNotification/composer.json +++ b/app/code/Magento/AdminNotification/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-admin-notification", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Authorization/composer.json b/app/code/Magento/Authorization/composer.json index 46060369cb7e6..01788199dbdc1 100644 --- a/app/code/Magento/Authorization/composer.json +++ b/app/code/Magento/Authorization/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-authorization", "description": "Authorization module provides access to Magento ACL functionality.", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-backend": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", "magento/magento-composer-installer": "*" diff --git a/app/code/Magento/Backend/composer.json b/app/code/Magento/Backend/composer.json index b1d54364d381f..b99f78aa9e676 100644 --- a/app/code/Magento/Backend/composer.json +++ b/app/code/Magento/Backend/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-backend", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-directory": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Backup/composer.json b/app/code/Magento/Backup/composer.json index 87a0225e86690..8e7e76038469f 100644 --- a/app/code/Magento/Backup/composer.json +++ b/app/code/Magento/Backup/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-backup", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Bundle/composer.json b/app/code/Magento/Bundle/composer.json index 8580562292cb8..d4bda450af8a7 100644 --- a/app/code/Magento/Bundle/composer.json +++ b/app/code/Magento/Bundle/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-bundle", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-tax": "0.42.0-beta3", diff --git a/app/code/Magento/Captcha/composer.json b/app/code/Magento/Captcha/composer.json index 5cd84ce402336..0e1ef77a70cc6 100644 --- a/app/code/Magento/Captcha/composer.json +++ b/app/code/Magento/Captcha/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-captcha", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", "magento/module-checkout": "0.42.0-beta3", diff --git a/app/code/Magento/Catalog/composer.json b/app/code/Magento/Catalog/composer.json index 360e14b27de53..cfe287ad21930 100644 --- a/app/code/Magento/Catalog/composer.json +++ b/app/code/Magento/Catalog/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-catalog", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-eav": "0.42.0-beta3", "magento/module-cms": "0.42.0-beta3", diff --git a/app/code/Magento/CatalogImportExport/composer.json b/app/code/Magento/CatalogImportExport/composer.json index b494e210bef94..c57d6027fbd0a 100644 --- a/app/code/Magento/CatalogImportExport/composer.json +++ b/app/code/Magento/CatalogImportExport/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-catalog-import-export", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-core": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-eav": "0.42.0-beta3", diff --git a/app/code/Magento/CatalogInventory/composer.json b/app/code/Magento/CatalogInventory/composer.json index c226936f18f7b..76bce13966150 100644 --- a/app/code/Magento/CatalogInventory/composer.json +++ b/app/code/Magento/CatalogInventory/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-catalog-inventory", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/CatalogRule/composer.json b/app/code/Magento/CatalogRule/composer.json index 77813109ca80a..142a3ea8e62f7 100644 --- a/app/code/Magento/CatalogRule/composer.json +++ b/app/code/Magento/CatalogRule/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-catalog-rule", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-rule": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", diff --git a/app/code/Magento/CatalogSearch/composer.json b/app/code/Magento/CatalogSearch/composer.json index 1820067884907..4ca3fc0892255 100644 --- a/app/code/Magento/CatalogSearch/composer.json +++ b/app/code/Magento/CatalogSearch/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-catalog-search", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-search": "0.42.0-beta3", diff --git a/app/code/Magento/CatalogUrlRewrite/composer.json b/app/code/Magento/CatalogUrlRewrite/composer.json index 51e3cb2ed671e..4e8ac2d26cc44 100644 --- a/app/code/Magento/CatalogUrlRewrite/composer.json +++ b/app/code/Magento/CatalogUrlRewrite/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-catalog-url-rewrite", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-backend": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-catalog-import-export": "0.42.0-beta3", diff --git a/app/code/Magento/CatalogWidget/composer.json b/app/code/Magento/CatalogWidget/composer.json index 0c728e7ef139c..a36bd8339f20a 100644 --- a/app/code/Magento/CatalogWidget/composer.json +++ b/app/code/Magento/CatalogWidget/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-catalog-widget", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-catalog": "0.42.0-beta3", "magento/module-widget": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Centinel/composer.json b/app/code/Magento/Centinel/composer.json index 23ce3a4a76fa1..3c74909cc467f 100644 --- a/app/code/Magento/Centinel/composer.json +++ b/app/code/Magento/Centinel/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-centinel", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-checkout": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Checkout/composer.json b/app/code/Magento/Checkout/composer.json index 5571403235562..298f7cf2baacc 100644 --- a/app/code/Magento/Checkout/composer.json +++ b/app/code/Magento/Checkout/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-checkout", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-sales": "0.42.0-beta3", "magento/module-authorization": "0.42.0-beta3", diff --git a/app/code/Magento/CheckoutAgreements/composer.json b/app/code/Magento/CheckoutAgreements/composer.json index 0e41b386f1a71..ff4a77a57ce3c 100644 --- a/app/code/Magento/CheckoutAgreements/composer.json +++ b/app/code/Magento/CheckoutAgreements/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-checkout-agreements", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-checkout": "0.42.0-beta3", "magento/module-store": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Cms/composer.json b/app/code/Magento/Cms/composer.json index 1bab1473f233a..5f46d711b101b 100644 --- a/app/code/Magento/Cms/composer.json +++ b/app/code/Magento/Cms/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-cms", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-theme": "0.42.0-beta3", diff --git a/app/code/Magento/CmsUrlRewrite/composer.json b/app/code/Magento/CmsUrlRewrite/composer.json index 8566a9d1e0b73..edd57582beb1e 100644 --- a/app/code/Magento/CmsUrlRewrite/composer.json +++ b/app/code/Magento/CmsUrlRewrite/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-cms-url-rewrite", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-cms": "0.42.0-beta3", "magento/module-store": "0.42.0-beta3", "magento/module-url-rewrite": "0.42.0-beta3", diff --git a/app/code/Magento/ConfigurableImportExport/composer.json b/app/code/Magento/ConfigurableImportExport/composer.json index 350b1f9762dae..6c0222c838ef1 100644 --- a/app/code/Magento/ConfigurableImportExport/composer.json +++ b/app/code/Magento/ConfigurableImportExport/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-configurable-import-export", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-catalog": "0.42.0-beta3", "magento/module-catalog-import-export": "0.42.0-beta3", "magento/module-eav": "0.42.0-beta3", diff --git a/app/code/Magento/ConfigurableProduct/composer.json b/app/code/Magento/ConfigurableProduct/composer.json index 40614acdc7e88..20b12496bac79 100644 --- a/app/code/Magento/ConfigurableProduct/composer.json +++ b/app/code/Magento/ConfigurableProduct/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-configurable-product", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-catalog-inventory": "0.42.0-beta3", diff --git a/app/code/Magento/Contact/composer.json b/app/code/Magento/Contact/composer.json index e746193309c4f..8c56e31585819 100644 --- a/app/code/Magento/Contact/composer.json +++ b/app/code/Magento/Contact/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-contact", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Core/composer.json b/app/code/Magento/Core/composer.json index 3d356da4d534d..ee99f353b0695 100644 --- a/app/code/Magento/Core/composer.json +++ b/app/code/Magento/Core/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-core", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/module-cron": "0.42.0-beta3", diff --git a/app/code/Magento/Cron/composer.json b/app/code/Magento/Cron/composer.json index 5d0310756d4a3..a25237146a626 100644 --- a/app/code/Magento/Cron/composer.json +++ b/app/code/Magento/Cron/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-cron", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", diff --git a/app/code/Magento/CurrencySymbol/composer.json b/app/code/Magento/CurrencySymbol/composer.json index fe027d918ba32..37e5bff2c0b97 100644 --- a/app/code/Magento/CurrencySymbol/composer.json +++ b/app/code/Magento/CurrencySymbol/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-currency-symbol", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-page-cache": "0.42.0-beta3", "magento/module-directory": "0.42.0-beta3", diff --git a/app/code/Magento/Customer/composer.json b/app/code/Magento/Customer/composer.json index 6a8f9941fef46..b4b334e8000e7 100644 --- a/app/code/Magento/Customer/composer.json +++ b/app/code/Magento/Customer/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-customer", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-eav": "0.42.0-beta3", "magento/module-directory": "0.42.0-beta3", diff --git a/app/code/Magento/CustomerImportExport/composer.json b/app/code/Magento/CustomerImportExport/composer.json index 286d4febae3a2..9c745912f8694 100644 --- a/app/code/Magento/CustomerImportExport/composer.json +++ b/app/code/Magento/CustomerImportExport/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-customer-import-export", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-backend": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/DesignEditor/composer.json b/app/code/Magento/DesignEditor/composer.json index 356553a6cc3b6..5d372c1ef2c14 100644 --- a/app/code/Magento/DesignEditor/composer.json +++ b/app/code/Magento/DesignEditor/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-design-editor", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-theme": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Dhl/composer.json b/app/code/Magento/Dhl/composer.json index c9d78cbed3b5a..253abf889c04c 100644 --- a/app/code/Magento/Dhl/composer.json +++ b/app/code/Magento/Dhl/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-dhl", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-shipping": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Directory/composer.json b/app/code/Magento/Directory/composer.json index 58c7f5ad1dda2..17d45a5dd608d 100644 --- a/app/code/Magento/Directory/composer.json +++ b/app/code/Magento/Directory/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-directory", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Downloadable/composer.json b/app/code/Magento/Downloadable/composer.json index c8c0562e88873..4381305a2e2e3 100644 --- a/app/code/Magento/Downloadable/composer.json +++ b/app/code/Magento/Downloadable/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-downloadable", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Eav/composer.json b/app/code/Magento/Eav/composer.json index c60d271e7cf02..46b9c44ab105e 100644 --- a/app/code/Magento/Eav/composer.json +++ b/app/code/Magento/Eav/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-eav", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Email/composer.json b/app/code/Magento/Email/composer.json index 9afda3f5b33af..be700629a053c 100644 --- a/app/code/Magento/Email/composer.json +++ b/app/code/Magento/Email/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-email", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-cms": "0.42.0-beta3", diff --git a/app/code/Magento/Fedex/composer.json b/app/code/Magento/Fedex/composer.json index c4bb50094eda0..f2c09114a701a 100644 --- a/app/code/Magento/Fedex/composer.json +++ b/app/code/Magento/Fedex/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-fedex", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-shipping": "0.42.0-beta3", "magento/module-directory": "0.42.0-beta3", diff --git a/app/code/Magento/GiftMessage/composer.json b/app/code/Magento/GiftMessage/composer.json index 2f330a2b6f519..e8ee8bfda9281 100644 --- a/app/code/Magento/GiftMessage/composer.json +++ b/app/code/Magento/GiftMessage/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-gift-message", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-checkout": "0.42.0-beta3", diff --git a/app/code/Magento/GoogleAdwords/composer.json b/app/code/Magento/GoogleAdwords/composer.json index 0e10e7361b8b5..e50ea38055c51 100644 --- a/app/code/Magento/GoogleAdwords/composer.json +++ b/app/code/Magento/GoogleAdwords/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-google-adwords", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-sales": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", diff --git a/app/code/Magento/GoogleAnalytics/composer.json b/app/code/Magento/GoogleAnalytics/composer.json index ad2a5c677de09..d4558ea182fd8 100644 --- a/app/code/Magento/GoogleAnalytics/composer.json +++ b/app/code/Magento/GoogleAnalytics/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-google-analytics", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-sales": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", diff --git a/app/code/Magento/GoogleOptimizer/composer.json b/app/code/Magento/GoogleOptimizer/composer.json index 6f3640d73b6b3..df374bcac24b1 100644 --- a/app/code/Magento/GoogleOptimizer/composer.json +++ b/app/code/Magento/GoogleOptimizer/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-google-optimizer", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-google-analytics": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", diff --git a/app/code/Magento/GoogleShopping/composer.json b/app/code/Magento/GoogleShopping/composer.json index 38e35843f414a..d9f112035c899 100644 --- a/app/code/Magento/GoogleShopping/composer.json +++ b/app/code/Magento/GoogleShopping/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-google-shopping", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/GroupedImportExport/composer.json b/app/code/Magento/GroupedImportExport/composer.json index f53791499fbd2..e53fdd3d56e97 100644 --- a/app/code/Magento/GroupedImportExport/composer.json +++ b/app/code/Magento/GroupedImportExport/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-grouped-import-export", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-catalog": "0.42.0-beta3", "magento/module-import-export": "0.42.0-beta3", "magento/module-catalog-import-export": "0.42.0-beta3", diff --git a/app/code/Magento/GroupedProduct/composer.json b/app/code/Magento/GroupedProduct/composer.json index d276a035dacf7..73db96a189eb3 100644 --- a/app/code/Magento/GroupedProduct/composer.json +++ b/app/code/Magento/GroupedProduct/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-grouped-product", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-catalog-inventory": "0.42.0-beta3", diff --git a/app/code/Magento/ImportExport/composer.json b/app/code/Magento/ImportExport/composer.json index 89e4b1aab9805..ff1e2df6aae8e 100644 --- a/app/code/Magento/ImportExport/composer.json +++ b/app/code/Magento/ImportExport/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-import-export", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Indexer/composer.json b/app/code/Magento/Indexer/composer.json index 98cc0400270d6..ffc904c8ef590 100644 --- a/app/code/Magento/Indexer/composer.json +++ b/app/code/Magento/Indexer/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-indexer", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-backend": "0.42.0-beta3", "magento/module-page-cache": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", diff --git a/app/code/Magento/Integration/composer.json b/app/code/Magento/Integration/composer.json index 39da0e6194a83..199ec919e0909 100644 --- a/app/code/Magento/Integration/composer.json +++ b/app/code/Magento/Integration/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-integration", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/LayeredNavigation/composer.json b/app/code/Magento/LayeredNavigation/composer.json index a4cf2dc2cef49..17bde426da467 100644 --- a/app/code/Magento/LayeredNavigation/composer.json +++ b/app/code/Magento/LayeredNavigation/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-layered-navigation", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-catalog": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", diff --git a/app/code/Magento/Log/composer.json b/app/code/Magento/Log/composer.json index 4bf9ba061b87f..9e17ddc64417f 100644 --- a/app/code/Magento/Log/composer.json +++ b/app/code/Magento/Log/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-log", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/Msrp/composer.json b/app/code/Magento/Msrp/composer.json index 3d83446f5e40c..b782411e671c9 100644 --- a/app/code/Magento/Msrp/composer.json +++ b/app/code/Magento/Msrp/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-msrp", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-bundle": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Multishipping/composer.json b/app/code/Magento/Multishipping/composer.json index 756598d1fa2a9..ceafee707952d 100644 --- a/app/code/Magento/Multishipping/composer.json +++ b/app/code/Magento/Multishipping/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-multishipping", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-checkout": "0.42.0-beta3", diff --git a/app/code/Magento/Newsletter/composer.json b/app/code/Magento/Newsletter/composer.json index 4c9e57f393230..56569bdfc1a88 100644 --- a/app/code/Magento/Newsletter/composer.json +++ b/app/code/Magento/Newsletter/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-newsletter", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/OfflinePayments/composer.json b/app/code/Magento/OfflinePayments/composer.json index ebd7adb688e87..3a6a864bd710c 100644 --- a/app/code/Magento/OfflinePayments/composer.json +++ b/app/code/Magento/OfflinePayments/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-offline-payments", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-payment": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", "magento/magento-composer-installer": "*" diff --git a/app/code/Magento/OfflineShipping/composer.json b/app/code/Magento/OfflineShipping/composer.json index f233c74afbce1..634756b1cc07a 100644 --- a/app/code/Magento/OfflineShipping/composer.json +++ b/app/code/Magento/OfflineShipping/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-offline-shipping", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/module-shipping": "0.42.0-beta3", diff --git a/app/code/Magento/PageCache/composer.json b/app/code/Magento/PageCache/composer.json index ea05fb95664ae..2bfd0fe9fe72f 100644 --- a/app/code/Magento/PageCache/composer.json +++ b/app/code/Magento/PageCache/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-page-cache", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", diff --git a/app/code/Magento/Payment/composer.json b/app/code/Magento/Payment/composer.json index 1f55fcdc3a829..15f2d423a0afb 100644 --- a/app/code/Magento/Payment/composer.json +++ b/app/code/Magento/Payment/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-payment", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-sales": "0.42.0-beta3", diff --git a/app/code/Magento/Persistent/composer.json b/app/code/Magento/Persistent/composer.json index 022dc88e2fc3d..19eb7cabe97a3 100644 --- a/app/code/Magento/Persistent/composer.json +++ b/app/code/Magento/Persistent/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-persistent", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-checkout": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/ProductAlert/composer.json b/app/code/Magento/ProductAlert/composer.json index b001db5d77d92..ee9d2891a7d4c 100644 --- a/app/code/Magento/ProductAlert/composer.json +++ b/app/code/Magento/ProductAlert/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-product-alert", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/Reports/composer.json b/app/code/Magento/Reports/composer.json index 817eb609ddfed..7c344be89de24 100644 --- a/app/code/Magento/Reports/composer.json +++ b/app/code/Magento/Reports/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-reports", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-eav": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/RequireJs/composer.json b/app/code/Magento/RequireJs/composer.json index 4c029c1c34159..5e94ec295feb4 100644 --- a/app/code/Magento/RequireJs/composer.json +++ b/app/code/Magento/RequireJs/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-require-js", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/framework": "0.42.0-beta3", "magento/magento-composer-installer": "*" }, diff --git a/app/code/Magento/Review/composer.json b/app/code/Magento/Review/composer.json index ec6e7e8629c79..0f104a3ff1a16 100644 --- a/app/code/Magento/Review/composer.json +++ b/app/code/Magento/Review/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-review", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Rss/composer.json b/app/code/Magento/Rss/composer.json index 74952b18d3133..870f2791e3a79 100644 --- a/app/code/Magento/Rss/composer.json +++ b/app/code/Magento/Rss/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-rss", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", diff --git a/app/code/Magento/Rule/composer.json b/app/code/Magento/Rule/composer.json index 023d077408adc..0928a0c7b5a0d 100644 --- a/app/code/Magento/Rule/composer.json +++ b/app/code/Magento/Rule/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-rule", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-eav": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", diff --git a/app/code/Magento/Sales/composer.json b/app/code/Magento/Sales/composer.json index dd52c6dec79cb..510a25f035ccc 100644 --- a/app/code/Magento/Sales/composer.json +++ b/app/code/Magento/Sales/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-sales", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/SalesRule/composer.json b/app/code/Magento/SalesRule/composer.json index 0bc6963fbfe82..c0d70fa87621e 100644 --- a/app/code/Magento/SalesRule/composer.json +++ b/app/code/Magento/SalesRule/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-sales-rule", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-rule": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", diff --git a/app/code/Magento/Search/composer.json b/app/code/Magento/Search/composer.json index 3b6df7b57463c..2cd325db781bd 100644 --- a/app/code/Magento/Search/composer.json +++ b/app/code/Magento/Search/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-search", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/framework": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/module-store": "0.42.0-beta3", diff --git a/app/code/Magento/Sendfriend/composer.json b/app/code/Magento/Sendfriend/composer.json index 79e1041b4822d..24b9c6a47f244 100644 --- a/app/code/Magento/Sendfriend/composer.json +++ b/app/code/Magento/Sendfriend/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-sendfriend", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Shipping/composer.json b/app/code/Magento/Shipping/composer.json index 08a1e9d7969cd..972267ae582ea 100644 --- a/app/code/Magento/Shipping/composer.json +++ b/app/code/Magento/Shipping/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-shipping", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", diff --git a/app/code/Magento/Sitemap/composer.json b/app/code/Magento/Sitemap/composer.json index b22d1586a32d6..78bdead7bc3a1 100644 --- a/app/code/Magento/Sitemap/composer.json +++ b/app/code/Magento/Sitemap/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-sitemap", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Store/composer.json b/app/code/Magento/Store/composer.json index e089091493ed4..72e67304450b9 100644 --- a/app/code/Magento/Store/composer.json +++ b/app/code/Magento/Store/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-store", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-core": "0.42.0-beta3", "magento/module-directory": "0.42.0-beta3", "magento/module-ui": "0.42.0-beta3", diff --git a/app/code/Magento/Tax/composer.json b/app/code/Magento/Tax/composer.json index 5c54feeea3e74..3808cee9866a8 100644 --- a/app/code/Magento/Tax/composer.json +++ b/app/code/Magento/Tax/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-tax", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/TaxImportExport/composer.json b/app/code/Magento/TaxImportExport/composer.json index d49ee464fd3e6..5e17f251c9397 100644 --- a/app/code/Magento/TaxImportExport/composer.json +++ b/app/code/Magento/TaxImportExport/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-tax-import-export", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-tax": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/module-directory": "0.42.0-beta3", diff --git a/app/code/Magento/Theme/composer.json b/app/code/Magento/Theme/composer.json index 9b67f6efa161a..c0e1b4857a2d5 100644 --- a/app/code/Magento/Theme/composer.json +++ b/app/code/Magento/Theme/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-theme", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", diff --git a/app/code/Magento/Translation/composer.json b/app/code/Magento/Translation/composer.json index 259dadd131c12..e190091b93cb4 100644 --- a/app/code/Magento/Translation/composer.json +++ b/app/code/Magento/Translation/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-translation", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-core": "0.42.0-beta3", "magento/module-store": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/Ui/composer.json b/app/code/Magento/Ui/composer.json index efe3403132d45..237180d4ffd82 100644 --- a/app/code/Magento/Ui/composer.json +++ b/app/code/Magento/Ui/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-ui", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-backend": "0.42.0-beta3", "magento/module-store": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", diff --git a/app/code/Magento/Ups/composer.json b/app/code/Magento/Ups/composer.json index 42d5f994aeb4d..78c98d66410e1 100644 --- a/app/code/Magento/Ups/composer.json +++ b/app/code/Magento/Ups/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-ups", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", diff --git a/app/code/Magento/UrlRewrite/composer.json b/app/code/Magento/UrlRewrite/composer.json index a108f1b23a17f..870dc60a8a9bd 100644 --- a/app/code/Magento/UrlRewrite/composer.json +++ b/app/code/Magento/UrlRewrite/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-url-rewrite", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-catalog": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", "magento/module-store": "0.42.0-beta3", diff --git a/app/code/Magento/User/composer.json b/app/code/Magento/User/composer.json index 4bfac9339fc56..ac58549781b3b 100644 --- a/app/code/Magento/User/composer.json +++ b/app/code/Magento/User/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-user", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-authorization": "0.42.0-beta3", "magento/module-backend": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Usps/composer.json b/app/code/Magento/Usps/composer.json index b7c72cec3da72..9e55af22e498b 100644 --- a/app/code/Magento/Usps/composer.json +++ b/app/code/Magento/Usps/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-usps", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-shipping": "0.42.0-beta3", "magento/module-directory": "0.42.0-beta3", diff --git a/app/code/Magento/Webapi/composer.json b/app/code/Magento/Webapi/composer.json index 755ecba204525..aee490391122d 100644 --- a/app/code/Magento/Webapi/composer.json +++ b/app/code/Magento/Webapi/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-webapi", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-authorization": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Weee/composer.json b/app/code/Magento/Weee/composer.json index fb0b9a6779c99..748633d843248 100644 --- a/app/code/Magento/Weee/composer.json +++ b/app/code/Magento/Weee/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-weee", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", "magento/module-tax": "0.42.0-beta3", diff --git a/app/code/Magento/Widget/composer.json b/app/code/Magento/Widget/composer.json index 3a4c1b875c684..749449f2b88f1 100644 --- a/app/code/Magento/Widget/composer.json +++ b/app/code/Magento/Widget/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-widget", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-cms": "0.42.0-beta3", "magento/module-core": "0.42.0-beta3", diff --git a/app/code/Magento/Wishlist/composer.json b/app/code/Magento/Wishlist/composer.json index d6dc5b534083e..5854cbddd5e95 100644 --- a/app/code/Magento/Wishlist/composer.json +++ b/app/code/Magento/Wishlist/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-wishlist", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta3", "magento/module-customer": "0.42.0-beta3", "magento/module-catalog": "0.42.0-beta3", diff --git a/app/design/adminhtml/Magento/backend/composer.json b/app/design/adminhtml/Magento/backend/composer.json index 95c694e034fba..1bde1b8d4e3c7 100644 --- a/app/design/adminhtml/Magento/backend/composer.json +++ b/app/design/adminhtml/Magento/backend/composer.json @@ -2,7 +2,7 @@ "name": "magento/theme-adminhtml-backend", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/framework": "0.42.0-beta3", "magento/magento-composer-installer": "*" }, diff --git a/app/design/frontend/Magento/blank/composer.json b/app/design/frontend/Magento/blank/composer.json index f6da390cca977..0439a4f73d735 100644 --- a/app/design/frontend/Magento/blank/composer.json +++ b/app/design/frontend/Magento/blank/composer.json @@ -2,7 +2,7 @@ "name": "magento/theme-frontend-blank", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/framework": "0.42.0-beta3", "magento/magento-composer-installer": "*" }, diff --git a/app/design/frontend/Magento/luma/composer.json b/app/design/frontend/Magento/luma/composer.json index 3c8c3377313a6..fe1fee555b8f8 100644 --- a/app/design/frontend/Magento/luma/composer.json +++ b/app/design/frontend/Magento/luma/composer.json @@ -2,7 +2,7 @@ "name": "magento/theme-frontend-luma", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/theme-frontend-blank": "0.42.0-beta3", "magento/framework": "0.42.0-beta3", "magento/magento-composer-installer": "*" diff --git a/composer.json b/composer.json index f7f2c094298ce..a038653280d03 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "AFL-3.0" ], "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "zendframework/zend-stdlib": "2.3.1", "zendframework/zend-code": "2.3.1", "zendframework/zend-server": "2.3.1", diff --git a/composer.lock b/composer.lock index f91dcc508eef9..c33ea50ff62be 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": "0ea0b1b2f6f0a7fb58a4780375a1a440", + "hash": "8326b1f17629f5fc46c9b4c089b929d5", "packages": [ { "name": "composer/composer", @@ -3143,9 +3143,8 @@ "phpmd/phpmd": 0 }, "prefer-stable": false, - "prefer-lowest": false, "platform": { - "php": "~5.4.11|~5.5.0|~5.6.0" + "php": "~5.5.0|~5.6.0" }, "platform-dev": { "lib-libxml": "*", diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer1.json b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer1.json index 4fe637e35fcd3..aa86499218364 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer1.json +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer1.json @@ -2,7 +2,7 @@ "name": "magento/module-module1", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-core": "0.1.0-alpha103", "magento/module-module2": "0.1.0-alpha103" }, diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer2.json b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer2.json index a7b58c71e34c7..ee1f92ce06fdb 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer2.json +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer2.json @@ -2,7 +2,7 @@ "name": "magento/module-module2", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-core": "0.1.0-alpha103", "magento/module-module3": "0.1.0-alpha103" }, diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer3.json b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer3.json index 4619c88460d9b..436ee0afe3eb6 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer3.json +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer3.json @@ -2,7 +2,7 @@ "name": "magento/module-module1", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0" + "php": "~5.5.0|~5.6.0" }, "type": "magento2-module", "version": "0.1.0-alpha103" diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer4.json b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer4.json index 441ed7e5af1aa..7d6f115660881 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer4.json +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer4.json @@ -2,7 +2,7 @@ "name": "magento/module-module1", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-core": "0.1.0-alpha103", "magento/module-module2": "0.1.0-alpha103" }, diff --git a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer5.json b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer5.json index a630787a56681..39685bcd99494 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer5.json +++ b/dev/tests/integration/testsuite/Magento/Test/Tools/Dependency/_files/composer5.json @@ -2,7 +2,7 @@ "name": "magento/module-module2", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/module-core": "0.1.0-alpha103", "magento/module-module1": "0.1.0-alpha103" }, diff --git a/dev/tests/integration/testsuite/Magento/Widget/_files/design/adminhtml/magento_basic/composer.json b/dev/tests/integration/testsuite/Magento/Widget/_files/design/adminhtml/magento_basic/composer.json index 4a5c0d27cd304..95b463debf370 100644 --- a/dev/tests/integration/testsuite/Magento/Widget/_files/design/adminhtml/magento_basic/composer.json +++ b/dev/tests/integration/testsuite/Magento/Widget/_files/design/adminhtml/magento_basic/composer.json @@ -2,7 +2,7 @@ "name": "magento/admin-Magento_Catalog", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/framework": "0.1.0-alpha103", "magento/magento-composer-installer": "*" }, diff --git a/dev/tests/unit/testsuite/Magento/Core/Model/_files/frontend/magento_iphone/composer.json b/dev/tests/unit/testsuite/Magento/Core/Model/_files/frontend/magento_iphone/composer.json index 1d60a88e8431e..4ffc59911f55c 100644 --- a/dev/tests/unit/testsuite/Magento/Core/Model/_files/frontend/magento_iphone/composer.json +++ b/dev/tests/unit/testsuite/Magento/Core/Model/_files/frontend/magento_iphone/composer.json @@ -2,7 +2,7 @@ "name": "magento/frontend-magento_iphone", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "magento/framework": "0.1.0-alpha103", "magento/magento-composer-installer": "*" }, diff --git a/lib/internal/Magento/Framework/composer.json b/lib/internal/Magento/Framework/composer.json index d8dde599d2fa1..aedf1e5b3ecc7 100644 --- a/lib/internal/Magento/Framework/composer.json +++ b/lib/internal/Magento/Framework/composer.json @@ -8,7 +8,7 @@ "AFL-3.0" ], "require": { - "php": "~5.4.11|~5.5.0|~5.6.0", + "php": "~5.5.0|~5.6.0", "ext-spl": "*", "ext-dom": "*", "ext-simplexml": "*", From 4c32642174a558feb4c3f60376d396bc9dda7062 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Tue, 13 Jan 2015 17:59:34 -0600 Subject: [PATCH 09/89] MAGETWO-32644: Remove PHP 5.4 support from composer.json - Correction on composer.lock --- composer.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index c33ea50ff62be..9b2a89389d920 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": "8326b1f17629f5fc46c9b4c089b929d5", + "hash": "ed3c90a8f01be302aa9696b86f5c35c9", "packages": [ { "name": "composer/composer", @@ -3143,6 +3143,7 @@ "phpmd/phpmd": 0 }, "prefer-stable": false, + "prefer-lowest": false, "platform": { "php": "~5.5.0|~5.6.0" }, From e44e0f07d19f5201e04049131ff5713dd1293da0 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Wed, 14 Jan 2015 10:07:06 -0600 Subject: [PATCH 10/89] MAGETWO-32644: Remove PHP 5.4 support from composer.json - Updated the bootstrap. --- app/bootstrap.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/bootstrap.php b/app/bootstrap.php index 183edeceabf33..b62375c317bf2 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -12,14 +12,14 @@ umask(0); /* PHP version validation */ -if (version_compare(phpversion(), '5.4.11', '<') === true) { +if (version_compare(phpversion(), '5.5.0', '<') === true) { if (PHP_SAPI == 'cli') { - echo 'Magento supports PHP 5.4.11 or later. ' . + echo 'Magento supports PHP 5.5.0 or later. ' . 'Please read http://devdocs.magento.com/guides/v1.0/install-gde/system-requirements.html'; } else { echo << -

Magento supports PHP 5.4.11 or later. Please read +

Magento supports PHP 5.5.0 or later. Please read Magento System Requirements. From adb1ec78e684bfbac3b128b3206fcf465cbb428e Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Thu, 15 Jan 2015 10:41:01 -0600 Subject: [PATCH 11/89] MAGETWO-32644: Remove PHP 5.4 support from composer.json - Updated functional test composer.json --- dev/tests/functional/composer.json | 2 +- dev/tests/functional/composer.json.dist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/functional/composer.json b/dev/tests/functional/composer.json index e2e3d4ad289ce..8518b924ec28d 100644 --- a/dev/tests/functional/composer.json +++ b/dev/tests/functional/composer.json @@ -1,7 +1,7 @@ { "require": { "magento/mtf": "1.0.0-rc11", - "php": ">=5.4.0", + "php": "~5.5.0|~5.6.0", "phpunit/phpunit": "4.1.0", "phpunit/phpunit-selenium": ">=1.2", "netwing/selenium-server-standalone": ">=2.35" diff --git a/dev/tests/functional/composer.json.dist b/dev/tests/functional/composer.json.dist index 2ea37c5b4a7aa..8746bb02f61e4 100644 --- a/dev/tests/functional/composer.json.dist +++ b/dev/tests/functional/composer.json.dist @@ -1,7 +1,7 @@ { "require": { "magento/mtf": "dev-develop", - "php": ">=5.4.0", + "php": "~5.5.0|~5.6.0", "phpunit/phpunit": "4.1.0", "phpunit/phpunit-selenium": ">=1.2", "netwing/selenium-server-standalone": ">=2.35" From 2f9719c2d04d786f89f1ec2ad39ab4444aa3f1b4 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Tue, 20 Jan 2015 13:50:18 -0600 Subject: [PATCH 12/89] MAGETWO-32644: Remove PHP 5.4 support from composer.json - Correction on a merge conflict solution. --- app/code/Magento/Quote/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/composer.json b/app/code/Magento/Quote/composer.json index 0d64fd35ee6ad..ce8b1803af2ca 100644 --- a/app/code/Magento/Quote/composer.json +++ b/app/code/Magento/Quote/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-quote", "description": "N/A", "require": { - "php": "~5.4.11|~5.5.0", + "php": "~5.5.0|~5.6.0", "magento/module-store": "0.42.0-beta4", "magento/module-catalog": "0.42.0-beta4", "magento/module-customer": "0.42.0-beta4", From 02876916dbb373683a69f7476aae34e62730dec2 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Tue, 20 Jan 2015 15:42:07 -0600 Subject: [PATCH 13/89] MAGETWO-32644: Remove PHP 5.4 support from composer.json - Correction on composer.lock file. --- composer.lock | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/composer.lock b/composer.lock index 678fcb9aeac15..086ab60ce6017 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": "6a743030a52d1c427e92cdf1ece3bf23", + "hash": "c563991108d21cd8fce208e77a1e6522", "packages": [ { "name": "composer/composer", @@ -1821,16 +1821,16 @@ }, { "name": "fabpot/php-cs-fixer", - "version": "v1.3", + "version": "v1.4", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "653cefbf33241185b58f7323157f1829552e370d" + "reference": "72a8c34210c0fbd8caa007fccea87a59f6f0a4d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/653cefbf33241185b58f7323157f1829552e370d", - "reference": "653cefbf33241185b58f7323157f1829552e370d", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/72a8c34210c0fbd8caa007fccea87a59f6f0a4d3", + "reference": "72a8c34210c0fbd8caa007fccea87a59f6f0a4d3", "shasum": "" }, "require": { @@ -1843,15 +1843,13 @@ "symfony/process": "~2.3", "symfony/stopwatch": "~2.5" }, + "require-dev": { + "satooshi/php-coveralls": "0.7.*@dev" + }, "bin": [ "php-cs-fixer" ], "type": "application", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, "autoload": { "psr-4": { "Symfony\\CS\\": "Symfony/CS/" @@ -1872,20 +1870,20 @@ } ], "description": "A script to automatically fix Symfony Coding Standard", - "time": "2014-12-12 06:09:01" + "time": "2015-01-12 21:28:53" }, { "name": "league/climate", - "version": "2.6.0", + "version": "2.6.1", "source": { "type": "git", "url": "https://github.com/thephpleague/climate.git", - "reference": "776b6c3b32837832a9f6d94f134b55cb7910ece6" + "reference": "28851c909017424f61cc6a62089316313c645d1c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/climate/zipball/776b6c3b32837832a9f6d94f134b55cb7910ece6", - "reference": "776b6c3b32837832a9f6d94f134b55cb7910ece6", + "url": "https://api.github.com/repos/thephpleague/climate/zipball/28851c909017424f61cc6a62089316313c645d1c", + "reference": "28851c909017424f61cc6a62089316313c645d1c", "shasum": "" }, "require": { @@ -1921,7 +1919,7 @@ "php", "terminal" ], - "time": "2015-01-08 02:28:23" + "time": "2015-01-18 14:31:58" }, { "name": "lusitanian/oauth", @@ -2261,16 +2259,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "f8d5d08c56de5cfd592b3340424a81733259a876" + "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876", - "reference": "f8d5d08c56de5cfd592b3340424a81733259a876", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db32c18eba00b121c145575fcbcd4d4d24e6db74", + "reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74", "shasum": "" }, "require": { @@ -2283,7 +2281,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -2306,7 +2304,7 @@ "keywords": [ "tokenizer" ], - "time": "2014-08-31 06:12:13" + "time": "2015-01-17 09:51:32" }, { "name": "phpunit/phpunit", From 1e2d3ee11c4745ecbde6dba4619af819a15be73d Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 21 Jan 2015 12:31:15 -0600 Subject: [PATCH 14/89] MAGETWO-31772: DI Compiler Doesn't Take Into Account dev/tools/Magento Folder - added entire dev/tools/Magento folder to compiler. --- dev/tools/Magento/Tools/Di/compiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tools/Magento/Tools/Di/compiler.php b/dev/tools/Magento/Tools/Di/compiler.php index 7bc5ed4baf456..8fc49eb16366f 100644 --- a/dev/tools/Magento/Tools/Di/compiler.php +++ b/dev/tools/Magento/Tools/Di/compiler.php @@ -47,7 +47,7 @@ $compilationDirs = [ $rootDir . '/app/code', $rootDir . '/lib/internal/Magento', - $rootDir . '/dev/tools/Magento/Tools/View' + $rootDir . '/dev/tools/Magento/Tools' ]; /** @var Writer\WriterInterface $logWriter Writer model for success messages */ From 58f6208814088b21573a55cb605d2f7d59f3708e Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 22 Jan 2015 11:41:18 -0600 Subject: [PATCH 15/89] MAGETWO-30831: "File Permission Help" link doesn't work - Added link to Magento Docs --- .../Setup/view/magento/setup/readiness-check/progress.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/module/Magento/Setup/view/magento/setup/readiness-check/progress.phtml b/setup/module/Magento/Setup/view/magento/setup/readiness-check/progress.phtml index b6cf1917d111f..6e50390a23b88 100644 --- a/setup/module/Magento/Setup/view/magento/setup/readiness-check/progress.phtml +++ b/setup/module/Magento/Setup/view/magento/setup/readiness-check/progress.phtml @@ -154,7 +154,7 @@

File Permission Check @@ -166,7 +166,7 @@ Less detail

-

The best way to resolve this is to allow write permissions for the following Magento directories. The exact fix depends on your server, your host, and other system variables.
Our File Permission Help can get you started.

+

The best way to resolve this is to allow write permissions for the following Magento directories. The exact fix depends on your server, your host, and other system variables.
Our File Permission Help can get you started.

If you need more help, please call your hosting provider.

    From 60cf1b24e882acbb2adb8f92f7300339fd1c094d Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 31 Dec 2014 13:42:03 -0600 Subject: [PATCH 16/89] MAGETWO-32086: Setup "Console" Controller Unit Test Coverage - adding ConsoleControllerTest for first time --- composer.lock | 10 +- .../Controller/ConsoleControllerTest.php | 298 ++++++++++++++++++ .../Setup/Controller/ConsoleController.php | 7 +- 3 files changed, 308 insertions(+), 7 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php diff --git a/composer.lock b/composer.lock index 4d1b6d3985c6c..ad7d727f7520f 100644 --- a/composer.lock +++ b/composer.lock @@ -290,16 +290,16 @@ }, { "name": "seld/jsonlint", - "version": "1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "a7bc2ec9520ad15382292591b617c43bdb1fec35" + "reference": "863ae85c6d3ef60ca49cb12bd051c4a0648c40c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/a7bc2ec9520ad15382292591b617c43bdb1fec35", - "reference": "a7bc2ec9520ad15382292591b617c43bdb1fec35", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/863ae85c6d3ef60ca49cb12bd051c4a0648c40c4", + "reference": "863ae85c6d3ef60ca49cb12bd051c4a0648c40c4", "shasum": "" }, "require": { @@ -332,7 +332,7 @@ "parser", "validator" ], - "time": "2014-09-05 15:36:20" + "time": "2015-01-04 21:18:15" }, { "name": "symfony/console", diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php new file mode 100644 index 0000000000000..453581a1763b0 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -0,0 +1,298 @@ +consoleLogger = $this->getMock('\Magento\Setup\Model\ConsoleLogger', [], [], '', false); + $installerFactory = $this->getMock('\Magento\Setup\Model\InstallerFactory', [], [], '', false); + $this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false); + $installerFactory->expects($this->once())->method('create')->with($this->consoleLogger)->willReturn( + $this->installer + ); + $this->options = $this->getMock('\Magento\Setup\Model\Lists', [], [], '', false); + $this->maintenanceMode = $this->getMock('\Magento\Framework\App\MaintenanceMode', [], [], '', false); + + $this->request = $this->getMock('\Zend\Console\Request', [], [], '', false); + $response = $this->getMock('\Zend\Console\Response', [], [], '', false); + $routeMatch = $this->getMock('\Zend\Mvc\Router\RouteMatch', [], [], '', false); + + $this->parameters= $this->getMock('\Zend\Stdlib\Parameters', [], [], '', false); + $this->request->expects($this->any())->method('getParams')->willReturn($this->parameters); + + $this->mvcEvent = $this->getMock('\Zend\Mvc\MvcEvent', [], [], '', false); + $this->mvcEvent->expects($this->once())->method('setRequest')->with($this->request)->willReturn( + $this->mvcEvent + ); + $this->mvcEvent->expects($this->once())->method('getRequest')->willReturn($this->request); + $this->mvcEvent->expects($this->once())->method('setResponse')->with($response)->willReturn($this->mvcEvent); + $routeMatch->expects($this->any())->method('getParam')->willReturn('install'); + $this->mvcEvent->expects($this->any())->method('getRouteMatch')->willReturn($routeMatch); + + $this->controller = new ConsoleController( + $this->consoleLogger, $this->options, $installerFactory, $this->maintenanceMode + ); + $this->controller->setEvent($this->mvcEvent); + $this->controller->dispatch($this->request, $response); + } + + public function testSetEventManager() + { + $controllerMock = $this->controller; + $closureMock = function () use ($controllerMock){ + }; + $eventManager = $this->getMock('\Zend\EventManager\EventManagerInterface'); + $eventManager->expects($this->any())->method('attach')->will($this->returnCallback($closureMock)); + $returnValue = $this->controller->setEventManager($eventManager); + $this->assertEquals($returnValue, $this->controller); + } + + /** + * @expectedException RuntimeException + * @expectedExceptionMessage Some Message + */ + public function testSetEventManagerWithError() + { + $e = 'Some Message'; + $eventManager = $this->getMock('\Zend\EventManager\EventManagerInterface'); + $eventManager->expects($this->once())->method('attach')->willThrowException(new \RuntimeException($e)); + $returnValue = $this->controller->setEventManager($eventManager); + $this->assertEquals($returnValue, $this->controller); + } + + public function testOnDispatch() + { + $this->controller->onDispatch($this->mvcEvent); + } + + /** + * @expectedException \Zend\Mvc\Exception\DomainException + * @expectedExceptionMessage Missing route matches; unsure how to retrieve action + */ + public function testOnDispatchWithException () + { + $e = new \Zend\Mvc\Exception\DomainException('Missing route matches; unsure how to retrieve action'); + $event = $this->getMock('\Zend\Mvc\MvcEvent'); + $this->controller->onDispatch($event); + $this->consoleLogger->expects($this->once())->method('log')->with($e->getMessage()); + } + + public function testInstallAction() + { + $this->installer->expects($this->once())->method('install')->with($this->parameters); + $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'); + $this->controller->installSchemaAction(); + } + + public function testInstallDataAction() + { + $this->installer->expects($this->once())->method('installDataFixtures'); + $this->controller->installDataAction(); + } + + public function testUpdateAction() + { + $this->installer->expects($this->once())->method('installSchema'); + $this->installer->expects($this->once())->method('installDataFixtures'); + $this->controller->updateAction(); + } + + public function testInstallUserConfigAction() + { + $this->installer->expects($this->once())->method('installUserConfig')->with($this->parameters); + $this->controller->installUserConfigAction(); + } + + public function testInstallAdminUserAction() + { + $this->installer->expects($this->once())->method('installAdminUser')->with($this->parameters); + $this->controller->installAdminUserAction(); + } + + public function testUninstallAction() + { + $this->installer->expects($this->once())->method('uninstall'); + $this->controller->uninstallAction(); + } + + /** + * @param int $maintenanceMode + * @param array $addresses + * @param int $setCount + * @param int $logCount + * + * @dataProvider maintenanceActionDataProvider + */ + public function testMaintenanceAction($maintenanceMode, $addresses, $setCount, $logCount) + { + $mapGetParam = [ + ['set', null, $maintenanceMode], + ['addresses', null, $addresses], + ]; + $this->request->expects($this->exactly(2))->method('getParam')->will($this->returnValueMap($mapGetParam)); + $this->maintenanceMode->expects($this->exactly($setCount))->method('set'); + $expected = $addresses !== null ? 1 : 0; + $this->maintenanceMode->expects($this->exactly($expected))->method('setAddresses'); + $this->maintenanceMode->expects($this->once())->method('isOn')->willReturn($maintenanceMode); + $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($addresses); + $this->consoleLogger->expects($this->exactly($logCount))->method('log'); + $this->controller->maintenanceAction(); + } + + public function maintenanceActionDataProvider() + { + return [ + [1, ['address1', 'address2'], 1, 3], + [0, [], 1, 2], + [null, ['address1'], 0, 2], + [1, null, 1, 2], + [0, null, 1, 2], + ]; + } + + /** + * @param string $type + * @param string $method + * @param array $value + * + * @dataProvider helpActionForLanguageCurrencyTimezoneDataProvider + */ + public function testHelpActionForLanguageCurrencyTimezone($type, $method, $value) + { + $this->request->expects($this->once())->method('getParam')->willReturn($type); + $this->options->expects($this->once())->method($method)->willReturn($value); + $this->controller->helpAction(); + } + + /** + * @return array + */ + public function helpActionForLanguageCurrencyTimezoneDataProvider() + { + return [ + [UserConfig::KEY_LANGUAGE, 'getLocaleList', [ + 'en_GB' => 'English (United Kingdom)', + 'en_US' => 'English (United States)' + ] + ], + [UserConfig::KEY_CURRENCY, 'getCurrencyList', [ + 'USD' => 'US Dollar (USD)', + 'EUR' => 'Euro (EUR)' + ] + ], + [UserConfig::KEY_TIMEZONE, 'getTimezoneList', [ + 'America/Chicago' => 'Central Standard Time (America/Chicago)', + 'America/Mexico_City' => 'Central Standard Time (Mexico) (America/Mexico_City)' + ] + ], + ]; + } + + public function testHelpActionNoType() + { + $beginHelpString = "\n==-------------------==\n" + . " Magento Setup CLI \n" + . "==-------------------==\n"; + $this->request->expects($this->once())->method('getParam')->willReturn(false); + $returnValue = $this->controller->helpAction(); + $this->assertStringStartsWith($beginHelpString, $returnValue); + } + + /** + * @param string $option + * @param string $noParameters + * + * @dataProvider helpActionDataProvider + */ + public function testHelpAction($option, $noParameters) + { + $this->request->expects($this->once())->method('getParam')->willReturn($option); + $usage = $this->controller->getCommandUsage(); + $expectedValue = explode(' ', (strlen($usage[$option])>0 ? $usage[$option] : $noParameters)); + $returnValue = explode( + ' ', trim(str_replace([PHP_EOL, 'Available parameters:'], '', $this->controller->helpAction())) + ); + $expectedValue = asort($expectedValue); + $returnValue = asort($returnValue); + $this->assertEquals($expectedValue, $returnValue); + } + + /** + * @return array + */ + public function helpActionDataProvider() + { + $noParameters = 'This command has no parameters.'; + return [ + ['install',''], + ['update', $noParameters], + ['uninstall', $noParameters], + ['install-configuration', ''], + ['install-schema', $noParameters], + ['install-data', $noParameters], + ['install-user-configuration', ''], + ['install-admin-user', ''], + ['maintenance', ''], + ['help', ''], + ]; + } +} diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 2d74333e4c20e..39c787b9a0fe2 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -422,8 +422,11 @@ public function maintenanceAction() } $this->log->log('Status: maintenance mode is ' . ($this->maintenanceMode->isOn() ? 'active' : 'not active')); - $addresses = implode(', ', $this->maintenanceMode->getAddressInfo()); - $this->log->log('List of exempt IP-addresses: ' . ($addresses ? $addresses : 'none')); + $addressInfo = $this->maintenanceMode->getAddressInfo(); + if(isset($addressInfo) && !empty($addressInfo)) { + $addresses = implode(', ', $addressInfo); + $this->log->log('List of exempt IP-addresses: ' . ($addresses ? $addresses : 'none')); + } } /** From 73b4d245c5d7f537e8e2843c4dfc73a79c8b8076 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 7 Jan 2015 12:05:35 -0600 Subject: [PATCH 17/89] MAGETWO-32085: Setup Controllers Unit Test Coverage - adding DatabaseCheckTest for first time - Changes based on CR recommendations --- .../Controller/ConsoleControllerTest.php | 3 + .../Controller/CustomizeYourStoreTest.php | 54 +++++++++--------- .../Setup/Controller/DatabaseCheckTest.php | 55 +++++++++++++++++++ .../Magento/Setup/Controller/LicenseTest.php | 8 +-- .../Setup/Controller/WebConfigurationTest.php | 17 ++++++ 5 files changed, 107 insertions(+), 30 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Controller/DatabaseCheckTest.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 453581a1763b0..fa2b4c959c291 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -198,6 +198,9 @@ public function testMaintenanceAction($maintenanceMode, $addresses, $setCount, $ $this->controller->maintenanceAction(); } + /** + * @return array + */ public function maintenanceActionDataProvider() { return [ diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php index 5291853b1fd0a..922c0a514be6d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php @@ -8,25 +8,22 @@ class CustomizeYourStoreTest extends \PHPUnit_Framework_TestCase { /** - * @param array $timezone - * @param array $currency - * @param array $language - * @param bool $isSampleDataEnabled + * @param array $expected * * @dataProvider indexActionDataProvider */ - public function testIndexAction($timezone, $currency, $language, $isSampleDataEnabled) + public function testIndexAction($expected) { $sampleData = $this->getMock('\Magento\Setup\Model\SampleData', [], [], '', false); $lists = $this->getMock('\Magento\Setup\Model\Lists', [], [], '', false); $controller = new CustomizeYourStore($lists, $sampleData); - $sampleData->expects($this->once())->method('isDeployed')->with()->will( - $this->returnValue($isSampleDataEnabled)); + $sampleData->expects($this->once())->method('isDeployed')->will( + $this->returnValue($expected['isSampledataEnabled'])); - $lists->expects($this->once())->method('getTimezoneList')->with()->will($this->returnValue($timezone)); - $lists->expects($this->once())->method('getCurrencyList')->with()->will($this->returnValue($currency)); - $lists->expects($this->once())->method('getLocaleList')->with()->will($this->returnValue($language)); + $lists->expects($this->once())->method('getTimezoneList')->will($this->returnValue($expected['timezone'])); + $lists->expects($this->once())->method('getCurrencyList')->will($this->returnValue($expected['currency'])); + $lists->expects($this->once())->method('getLocaleList')->will($this->returnValue($expected['language'])); $viewModel = $controller->indexAction(); @@ -34,28 +31,33 @@ public function testIndexAction($timezone, $currency, $language, $isSampleDataEn $this->assertTrue($viewModel->terminate()); $variables = $viewModel->getVariables(); - $this->assertSame($timezone, $variables['timezone']); - $this->assertSame($currency, $variables['currency']); - $this->assertSame($language, $variables['language']); - $this->assertEquals($isSampleDataEnabled, $variables['isSampledataEnabled']); + $this->assertArrayHasKey('timezone', $variables); + $this->assertArrayHasKey('currency', $variables); + $this->assertArrayHasKey('language', $variables); + $this->assertSame($expected, $variables); } + /** + * @return array + */ public function indexActionDataProvider() { - $timezones = ['America/New_York'=>'EST', 'America/Chicago' => 'CST']; - $currency = ['USD'=>'US Dollar', 'EUR' => 'Euro']; - $language = ['en_US'=>'English (USA)', 'en_UK' => 'English (UK)']; + $timezones = ['timezone' => ['America/New_York'=>'EST', 'America/Chicago' => 'CST']]; + $currency = ['currency' => ['USD'=>'US Dollar', 'EUR' => 'Euro']]; + $language = ['language' => ['en_US'=>'English (USA)', 'en_UK' => 'English (UK)']]; + $sampleDataTrue = ['isSampledataEnabled' => true]; + $sampleDataFalse = ['isSampledataEnabled' => false]; return [ - 'with_all_data' => [$timezones, $currency, $language, true], - 'no_currency_data' => [$timezones, null, $language, true], - 'no_timezone_data' => [null, $currency, $language, true], - 'no_language_data' => [$timezones, $currency, null, true], - 'empty_currency_data' => [$timezones, [], $language, true], - 'empty_timezone_data' => [[], $currency, $language, true], - 'empty_language_data' => [$timezones, $currency, [], true], - 'no_sample_data' => [$timezones, $currency, $language, false], + 'with_all_data' => [array_merge($timezones, $currency, $language, $sampleDataTrue)], + 'no_currency_data' => [array_merge($timezones, ['currency' => null], $language, $sampleDataTrue)], + 'no_timezone_data' => [array_merge(['timezone' => null], $currency, $language, $sampleDataTrue)], + 'no_language_data' => [array_merge($timezones, $currency, ['language' => null], $sampleDataTrue)], + 'empty_currency_data' => [array_merge($timezones, ['currency' => []], $language, $sampleDataTrue)], + 'empty_timezone_data' => [array_merge(['timezone' => []], $currency, $language, $sampleDataTrue)], + 'empty_language_data' => [array_merge($timezones, $currency, ['language' => []], $sampleDataTrue)], + 'false_sample_data' => [array_merge($timezones, $currency, $language, $sampleDataFalse)], + 'no_sample_data' => [array_merge($timezones, $currency, $language, ['isSampledataEnabled' => null])], ]; } } - diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/DatabaseCheckTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/DatabaseCheckTest.php new file mode 100644 index 0000000000000..3f39fcb23ff09 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/DatabaseCheckTest.php @@ -0,0 +1,55 @@ +getMock('\Magento\Setup\Model\WebLogger', [], [], '', false); + $installerFactory = $this->getMock('\Magento\Setup\Model\InstallerFactory', [], [], '', false); + $this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false); + $installerFactory->expects($this->once())->method('create')->with($webLogger)->willReturn( + $this->installer + ); + $this->controller = new DatabaseCheck($installerFactory, $webLogger); + } + + public function testIndexAction() + { + $this->installer->expects($this->once())->method('checkDatabaseConnection'); + $jsonModel = $this->controller->indexAction(); + $this->assertInstanceOf('Zend\View\Model\ViewModel', $jsonModel); + $variables = $jsonModel->getVariables(); + $this->assertArrayHasKey('success', $variables); + $this->assertTrue($variables['success']); + } + + public function testIndexActionWithError() + { + $this->installer->expects($this->once())->method('checkDatabaseConnection')->will( + $this->throwException(new \Exception) + ); + $jsonModel = $this->controller->indexAction(); + $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); + $variables = $jsonModel->getVariables(); + $this->assertArrayHasKey('success', $variables); + $this->assertArrayHasKey('error', $variables); + $this->assertFalse($variables['success']); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php index b7aaf7ad54b8a..7ee05d15d1621 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php @@ -25,8 +25,9 @@ public function setUp() public function testIndexActionWithLicense() { - $this->licenseModel->expects($this->once())->method('getContents')->with()->will( - $this->returnValue('some license string')); + $this->licenseModel->expects($this->once())->method('getContents')->will( + $this->returnValue('some license string') + ); $viewModel = $this->controller->indexAction(); $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); $this->assertArrayHasKey('license', $viewModel->getVariables()); @@ -34,11 +35,10 @@ public function testIndexActionWithLicense() public function testIndexActionNoLicense() { - $this->licenseModel->expects($this->once())->method('getContents')->with()->will($this->returnValue(false)); + $this->licenseModel->expects($this->once())->method('getContents')->will($this->returnValue(false)); $viewModel = $this->controller->indexAction(); $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); $this->assertArrayHasKey('message', $viewModel->getVariables()); $this->assertEquals('error/404', $viewModel->getTemplate()); - } } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php index 142bb5b26bbc5..abf9e8eed068a 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php @@ -7,6 +7,23 @@ class WebConfigurationTest extends \PHPUnit_Framework_TestCase { + /** + * To prevent save value of $SERVER, which is modified in this test + * + * @var array + */ + private $serverArray; + + public function setUp() + { + $this->serverArray = $_SERVER; + } + + public function tearDown() + { + $_SERVER = $this->serverArray; + } + public function testIndexAction() { /** @var $controller WebConfiguration */ From 9a44dbb5af52d7260ea762050bb55b630a28b1f2 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 7 Jan 2015 12:12:44 -0600 Subject: [PATCH 18/89] MAGETWO-32085: Setup Controllers Unit Test Coverage - removing verbose code --- .../Setup/Controller/CustomizeYourStoreTest.php | 6 +++--- .../Magento/Setup/Controller/InstallTest.php | 15 +++++++-------- .../Magento/Setup/Controller/LicenseTest.php | 2 +- .../Magento/Setup/Controller/NavigationTest.php | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php index 922c0a514be6d..a131d865897fe 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php @@ -21,9 +21,9 @@ public function testIndexAction($expected) $sampleData->expects($this->once())->method('isDeployed')->will( $this->returnValue($expected['isSampledataEnabled'])); - $lists->expects($this->once())->method('getTimezoneList')->will($this->returnValue($expected['timezone'])); - $lists->expects($this->once())->method('getCurrencyList')->will($this->returnValue($expected['currency'])); - $lists->expects($this->once())->method('getLocaleList')->will($this->returnValue($expected['language'])); + $lists->expects($this->once())->method('getTimezoneList')->willReturn($expected['timezone']); + $lists->expects($this->once())->method('getCurrencyList')->willReturn($expected['currency']); + $lists->expects($this->once())->method('getLocaleList')->willReturn($expected['language']); $viewModel = $controller->indexAction(); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php index 77776dde0a089..b877672806021 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php @@ -78,8 +78,8 @@ public function testProgressAction() $progress = $this->getMock('\Magento\Setup\Model\Installer\Progress', [], [], '', false); $this->progressFactory->expects($this->once())->method('createFromLog')->with($this->webLogger)->will( $this->returnValue($progress)); - $progress->expects($this->once())->method('getRatio')->will($this->returnValue($someNumber)); - $this->webLogger->expects($this->once())->method('get')->will($this->returnValue($consoleMessages)); + $progress->expects($this->once())->method('getRatio')->willReturn($someNumber); + $this->webLogger->expects($this->once())->method('get')->willReturn($consoleMessages); $jsonModel = $this->controller->progressAction(); $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); @@ -112,14 +112,13 @@ public function testDispatch() $routeMatch = $this->getMock('\Zend\Mvc\Router\RouteMatch', [], [], '', false); $mvcEvent = $this->getMock('\Zend\Mvc\MvcEvent', [], [], '', false); - $mvcEvent->expects($this->once())->method('setRequest')->with($request)->will($this->returnValue($mvcEvent)); - $mvcEvent->expects($this->once())->method('setResponse')->with($response)->will($this->returnValue($mvcEvent)); - $mvcEvent->expects($this->once())->method('setTarget')->with($this->controller) - ->will($this->returnValue($mvcEvent)); - $mvcEvent->expects($this->any())->method('getRouteMatch')->will($this->returnValue($routeMatch)); + $mvcEvent->expects($this->once())->method('setRequest')->with($request)->willReturn($mvcEvent); + $mvcEvent->expects($this->once())->method('setResponse')->with($response)->willReturn($mvcEvent); + $mvcEvent->expects($this->once())->method('setTarget')->with($this->controller)->willReturn($mvcEvent); + $mvcEvent->expects($this->any())->method('getRouteMatch')->willReturn($routeMatch); $contentArray = '{"config": { "address": { "base_url": "http://123.45.678.12"}}}'; - $request->expects($this->any())->method('getContent')->will($this->returnValue($contentArray)); + $request->expects($this->any())->method('getContent')->willReturn($contentArray); $this->controller->setEvent($mvcEvent); $this->controller->dispatch($request, $response); $this->controller->startAction(); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php index 7ee05d15d1621..29b1d8b4b262e 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php @@ -35,7 +35,7 @@ public function testIndexActionWithLicense() public function testIndexActionNoLicense() { - $this->licenseModel->expects($this->once())->method('getContents')->will($this->returnValue(false)); + $this->licenseModel->expects($this->once())->method('getContents')->willReturn(false); $viewModel = $this->controller->indexAction(); $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); $this->assertArrayHasKey('message', $viewModel->getVariables()); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/NavigationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/NavigationTest.php index 7fc3631f929b2..cd40149ed2557 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/NavigationTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/NavigationTest.php @@ -25,7 +25,7 @@ public function setUp() public function testIndexAction() { - $this->navigationModel->expects($this->once())->method('getData')->will($this->returnValue('some data')); + $this->navigationModel->expects($this->once())->method('getData')->willReturn('some data'); $viewModel = $this->controller->indexAction(); $this->assertInstanceOf('\Zend\View\Model\JsonModel', $viewModel); $this->assertArrayHasKey('nav', $viewModel->getVariables()); From 71af3687398220ad0281d7a6d28691c602aca20c Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 7 Jan 2015 13:00:08 -0600 Subject: [PATCH 19/89] MAGETWO-32085: Setup Controllers Unit Test Coverage - removing verbose code --- .../Magento/Setup/Controller/CustomizeYourStoreTest.php | 4 +--- .../testsuite/Magento/Setup/Controller/InstallTest.php | 8 ++++---- .../testsuite/Magento/Setup/Controller/LicenseTest.php | 4 +--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php index a131d865897fe..b7aafb22bea08 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/CustomizeYourStoreTest.php @@ -18,9 +18,7 @@ public function testIndexAction($expected) $lists = $this->getMock('\Magento\Setup\Model\Lists', [], [], '', false); $controller = new CustomizeYourStore($lists, $sampleData); - $sampleData->expects($this->once())->method('isDeployed')->will( - $this->returnValue($expected['isSampledataEnabled'])); - + $sampleData->expects($this->once())->method('isDeployed')->willReturn($expected['isSampledataEnabled']); $lists->expects($this->once())->method('getTimezoneList')->willReturn($expected['timezone']); $lists->expects($this->once())->method('getCurrencyList')->willReturn($expected['currency']); $lists->expects($this->once())->method('getLocaleList')->willReturn($expected['language']); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php index b877672806021..de453d6cbaa33 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php @@ -33,8 +33,8 @@ public function setUp() $installerFactory = $this->getMock('\Magento\Setup\Model\InstallerFactory', [], [], '', false); $this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false); $this->progressFactory = $this->getMock('\Magento\Setup\Model\Installer\ProgressFactory', [], [], '', false); - $installerFactory->expects($this->once())->method('create')->with($this->webLogger)->will( - $this->returnValue($this->installer)); + $installerFactory->expects($this->once())->method('create')->with($this->webLogger) + ->willReturn($this->installer); $this->controller = new Install($this->webLogger, $installerFactory, $this->progressFactory); } @@ -76,8 +76,8 @@ public function testProgressAction() $someNumber = 42; $consoleMessages = ['key1' => 'log message 1', 'key2' => 'log message 2']; $progress = $this->getMock('\Magento\Setup\Model\Installer\Progress', [], [], '', false); - $this->progressFactory->expects($this->once())->method('createFromLog')->with($this->webLogger)->will( - $this->returnValue($progress)); + $this->progressFactory->expects($this->once())->method('createFromLog')->with($this->webLogger) + ->willReturn($progress); $progress->expects($this->once())->method('getRatio')->willReturn($someNumber); $this->webLogger->expects($this->once())->method('get')->willReturn($consoleMessages); $jsonModel = $this->controller->progressAction(); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php index 29b1d8b4b262e..c4ac3faa8c583 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/LicenseTest.php @@ -25,9 +25,7 @@ public function setUp() public function testIndexActionWithLicense() { - $this->licenseModel->expects($this->once())->method('getContents')->will( - $this->returnValue('some license string') - ); + $this->licenseModel->expects($this->once())->method('getContents')->willReturn('some license string'); $viewModel = $this->controller->indexAction(); $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); $this->assertArrayHasKey('license', $viewModel->getVariables()); From 30d8d7a06f5e02f0093513a9898c7ecfcf219739 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 6 Jan 2015 18:10:46 -0600 Subject: [PATCH 20/89] MAGETWO-32089: Setup Models Unit Test Coverage - added unit test coverage to Setup Models except Installer class --- .../Setup/Model/AdminAccountFactoryTest.php | 31 ++ .../Magento/Setup/Model/AdminAccountTest.php | 313 ++++++++++++++++++ .../Setup/Model/FilePermissionsTest.php | 260 +++++++++++++++ .../Model/Installer/ProgressFactoryTest.php | 28 ++ .../Setup/Model/Installer/ProgressTest.php | 82 +++++ .../Setup/Model/InstallerFactoryTest.php | 116 +++++++ .../Magento/Setup/Model/LicenseTest.php | 64 ++++ .../Magento/Setup/Model/ListsTest.php | 113 +++++++ .../Magento/Setup/Model/NavigationTest.php | 84 +++++ .../Setup/Model/PhpInformationTest.php | 161 +++++++++ .../Model/UserConfigurationDataMapperTest.php | 176 ++++++++++ .../Magento/Setup/Model/WebLoggerTest.php | 183 ++++++++++ .../Magento/Setup/Model/FilePermissions.php | 2 - 13 files changed, 1611 insertions(+), 2 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressFactoryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/NavigationTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/PhpInformationTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php new file mode 100644 index 0000000000000..beca884c7f913 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php @@ -0,0 +1,31 @@ +getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); + $serviceLocatorMock + ->expects($this->once()) + ->method('get') + ->with('Magento\Framework\Math\Random') + ->will( + $this->returnValue( + $this->getMockBuilder('Magento\Framework\Math\Random') + ->disableOriginalConstructor() + ->getMock() + ) + ); + $adminAccountFactory = new AdminAccountFactory($serviceLocatorMock); + $adminAccount = $adminAccountFactory->create( + $this->getMockBuilder('Magento\Setup\Module\Setup')->disableOriginalConstructor()->getMock(), + [] + ); + $this->assertInstanceOf('Magento\Setup\Model\AdminAccount', $adminAccount); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php new file mode 100644 index 0000000000000..3a28731cdb35b --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php @@ -0,0 +1,313 @@ +setUpMock = $this->getMockBuilder('Magento\Setup\Module\Setup') + ->disableOriginalConstructor() + ->setMethods(['getConnection', 'getTable']) + ->getMock(); + + $this->dbAdapterMock = $this->getMockBuilder('Magento\Framework\DB\Adapter\Pdo\Mysql') + ->disableOriginalConstructor() + ->setMethods(['fetchRow', 'update', 'insert', 'quoteInto', 'lastInsertId']) + ->getMock(); + + $this->setUpMock + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue($this->dbAdapterMock)); + + $this->setUpMock + ->expects($this->any()) + ->method('getTable') + ->will($this->returnCallback(function ($table) {return $table;})); + + $this->randomMock = $this->getMock('Magento\Framework\Math\Random', ['getRandomString']); + $this->randomMock->expects($this->any())->method('getRandomString')->will($this->returnValue('salt')); + + $data = [ + AdminAccount::KEY_FIRST_NAME => 'John', + AdminAccount::KEY_LAST_NAME => 'Doe', + AdminAccount::KEY_EMAIL => 'john.doe@test.com', + AdminAccount::KEY_PASSWORD => '123123q', + AdminAccount::KEY_USERNAME => 'admin', + ]; + + $this->adminAccount = new AdminAccount($this->setUpMock, $this->randomMock, $data); + } + + public function testSaveUserExistsAdminRoleExists() + { + // existing user data + $result = [ + 'email' => 'john.doe@test.com', + 'username' => 'admin', + 'user_id' => 1, + ]; + + $this->dbAdapterMock + ->expects($this->at(0)) + ->method('fetchRow') + ->will($this->returnValue($result)); + + $this->dbAdapterMock + ->expects($this->once()) + ->method('quoteInto') + ->will($this->returnValue('')); + + $this->dbAdapterMock + ->expects($this->once()) + ->method('update') + ->will($this->returnValue(1)); + + // existing admin role data + $this->dbAdapterMock + ->expects($this->at(3)) + ->method('fetchRow') + ->will($this->returnValue([ + 'parent_id' => 0, + 'tree_level' => 2, + 'role_type' => 'U', + 'user_id' => 1, + 'user_type' => 2, + 'role_name' => 'admin', + 'role_id' => 1, + ])); + + // should never insert new row + $this->dbAdapterMock + ->expects($this->never()) + ->method('insert'); + + $this->adminAccount->save(); + } + + public function testSaveUserExistsNewAdminRole() + { + // existing user data + $result = [ + 'email' => 'john.doe@test.com', + 'username' => 'admin', + 'user_id' => 1, + ]; + + $this->dbAdapterMock + ->expects($this->at(0)) + ->method('fetchRow') + ->will($this->returnValue($result)); + + $this->dbAdapterMock + ->expects($this->once()) + ->method('quoteInto') + ->will($this->returnValue('')); + + $this->dbAdapterMock + ->expects($this->once()) + ->method('update') + ->will($this->returnValue(1)); + + // no admin role found + $this->dbAdapterMock + ->expects($this->at(3)) + ->method('fetchRow') + ->will($this->returnValue([])); + + // Special admin role created by data fixture + $this->dbAdapterMock + ->expects($this->at(4)) + ->method('fetchRow') + ->will($this->returnValue([ + 'parent_id' => 0, + 'tree_level' => 1, + 'role_type' => 'G', + 'user_id' => 0, + 'user_type' => 2, + 'role_name' => 'Administrators', + 'role_id' => 0, + ])); + + // should only insert once (admin role) + $this->dbAdapterMock + ->expects($this->once()) + ->method('insert'); + + $this->adminAccount->save(); + } + + public function testSaveNewUserAdminRoleExists() + { + // no existing user + $this->dbAdapterMock + ->expects($this->at(0)) + ->method('fetchRow') + ->will($this->returnValue([])); + + // insert only once (new user) + $this->dbAdapterMock + ->expects($this->once()) + ->method('insert'); + + // after inserting new user + $this->dbAdapterMock + ->expects($this->once()) + ->method('lastInsertId') + ->will($this->returnValue(1)); + + // existing admin role data + $this->dbAdapterMock + ->expects($this->at(3)) + ->method('fetchRow') + ->will($this->returnValue([ + 'parent_id' => 0, + 'tree_level' => 2, + 'role_type' => 'U', + 'user_id' => 1, + 'user_type' => 2, + 'role_name' => 'admin', + 'role_id' => 1, + ])); + + $this->adminAccount->save(); + } + + public function testSaveNewUserNewAdminRole() + { + // no existing user + $this->dbAdapterMock + ->expects($this->at(0)) + ->method('fetchRow') + ->will($this->returnValue([])); + + // after inserting new user + $this->dbAdapterMock + ->expects($this->once()) + ->method('lastInsertId') + ->will($this->returnValue(1)); + + // no existing admin role + $this->dbAdapterMock + ->expects($this->at(3)) + ->method('fetchRow') + ->will($this->returnValue([])); + + // Special admin role created by data fixture + $this->dbAdapterMock + ->expects($this->at(4)) + ->method('fetchRow') + ->will($this->returnValue([ + 'parent_id' => 0, + 'tree_level' => 2, + 'role_type' => 'U', + 'user_id' => 1, + 'user_type' => 2, + 'role_name' => 'admin', + 'role_id' => 1, + ])); + + // insert twice once (new user and new admin role) + $this->dbAdapterMock + ->expects($this->exactly(2)) + ->method('insert'); + + $this->adminAccount->save(); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage An existing user has the given email but different username. + */ + public function testSaveExceptionUsernameNotMatch() + { + // existing user in db + $result = [ + 'email' => 'john.doe@test.com', + 'username' => 'Another.name', + ]; + + $this->dbAdapterMock + ->expects($this->once()) + ->method('fetchRow') + ->will($this->returnValue($result)); + + // should not alter db + $this->dbAdapterMock + ->expects($this->never()) + ->method('update'); + + $this->dbAdapterMock + ->expects($this->never()) + ->method('insert'); + + $this->adminAccount->save(); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage An existing user has the given username but different email. + */ + public function testSaveExceptionEmailNotMatch() + { + $result = [ + 'email' => 'another.email@test.com', + 'username' => 'admin', + ]; + + $this->dbAdapterMock + ->expects($this->once()) + ->method('fetchRow') + ->will($this->returnValue($result)); + + // should not alter db + $this->dbAdapterMock + ->expects($this->never()) + ->method('update'); + + $this->dbAdapterMock + ->expects($this->never()) + ->method('insert'); + + $this->adminAccount->save(); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage No Administrators role was found, data fixture needs to be run + */ + public function testSaveExceptionSpecialAdminRoleNotFound() + { + $this->dbAdapterMock->expects($this->once())->method('lastInsertId')->will($this->returnValue(1)); + $this->dbAdapterMock + ->expects($this->exactly(3)) + ->method('fetchRow') + ->will($this->returnValue([])); + + $this->adminAccount->save(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php new file mode 100644 index 0000000000000..2c353c993e571 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php @@ -0,0 +1,260 @@ +directoryWriteMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Write') + ->disableOriginalConstructor() + ->setMethods(['isWritable', 'isExist', 'isDirectory', 'isReadable']) + ->getMock(); + $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') + ->disableOriginalConstructor() + ->setMethods(['getDirectoryWrite']) + ->getMock(); + $this->filesystemMock + ->expects($this->any()) + ->method('getDirectoryWrite') + ->will($this->returnValue($this->directoryWriteMock)); + $this->directoryListMock = $this->getMockBuilder('Magento\Framework\App\Filesystem\DirectoryList') + ->disableOriginalConstructor() + ->setMethods(['getPath']) + ->getMock(); + $this->filePermissions = new FilePermissions($this->filesystemMock, $this->directoryListMock); + } + + public function testGetInstallationWritableDirectories() + { + $this->setUpDirectoryListInstallation(); + + $expected = [ + BP . '/app/etc', + BP . '/var', + BP . '/pub/media', + BP . '/pub/static', + ]; + + $this->assertEquals($expected, $this->filePermissions->getInstallationWritableDirectories()); + } + + public function testGetApplicationNonWritableDirectories() + { + $this->directoryListMock + ->expects($this->once()) + ->method('getPath') + ->with(DirectoryList::CONFIG) + ->will($this->returnValue(BP . '/app/etc')); + + $expected = [BP . '/app/etc']; + $this->assertEquals($expected, $this->filePermissions->getApplicationNonWritableDirectories()); + } + + public function testGetInstallationCurrentWritableDirectories() + { + $this->setUpDirectoryListInstallation(); + $this->setUpDirectoryWriteInstallation(); + + $expected = [ + BP . '/app/etc', + ]; + $this->filePermissions->getInstallationWritableDirectories(); + $this->assertEquals($expected, $this->filePermissions->getInstallationCurrentWritableDirectories()); + } + + /** + * @dataProvider getApplicationCurrentNonWritableDirectoriesDataProvider + */ + public function testGetApplicationCurrentNonWritableDirectories(array $mockMethods, $expected) + { + $this->directoryListMock + ->expects($this->at(0)) + ->method('getPath') + ->with(DirectoryList::CONFIG) + ->will($this->returnValue(BP . '/app/etc')); + + $index = 0; + foreach ($mockMethods as $mockMethod => $returnValue) { + $this->directoryWriteMock + ->expects($this->at($index)) + ->method($mockMethod) + ->will($this->returnValue($returnValue)); + $index += 1; + } + + $this->filePermissions->getApplicationNonWritableDirectories(); + $this->assertEquals($expected, $this->filePermissions->getApplicationCurrentNonWritableDirectories()); + } + + /** + * @return array + */ + public function getApplicationCurrentNonWritableDirectoriesDataProvider() + { + return [ + [['isExist' => true, 'isDirectory' => true, 'isReadable' => true, 'isWritable' => false], [BP . '/app/etc']], + [['isExist' => false], []], + [['isExist' => true, 'isDirectory' => false], []], + [['isExist' => true, 'isDirectory' => true, 'isReadable' => true, 'isWritable' => true], []], + ]; + } + + public function testGetMissingWritableDirectoriesForInstallation() + { + $this->setUpDirectoryListInstallation(); + $this->setUpDirectoryWriteInstallation(); + + $expected = [ + BP . '/var', + BP . '/pub/media', + BP . '/pub/static', + ]; + + $this->assertEquals( + $expected, + array_values($this->filePermissions->getMissingWritableDirectoriesForInstallation()) + ); + } + + /** + * @dataProvider getUnnecessaryWritableDirectoriesForApplicationDataProvider + */ + public function testGetUnnecessaryWritableDirectoriesForApplication($mockMethods, $expected) + { + $this->directoryListMock + ->expects($this->at(0)) + ->method('getPath') + ->with(DirectoryList::CONFIG) + ->will($this->returnValue(BP . '/app/etc')); + + $index = 0; + foreach ($mockMethods as $mockMethod => $returnValue) { + $this->directoryWriteMock + ->expects($this->at($index)) + ->method($mockMethod) + ->will($this->returnValue($returnValue)); + $index += 1; + } + + $this->assertEquals( + $expected, + array_values($this->filePermissions->getUnnecessaryWritableDirectoriesForApplication()) + ); + } + + /** + * @return array + */ + public function getUnnecessaryWritableDirectoriesForApplicationDataProvider() + { + return [ + [['isExist' => true, 'isDirectory' => true, 'isReadable' => true, 'isWritable' => false], []], + [['isExist' => false], [BP . '/app/etc']], + ]; + } + + public function setUpDirectoryListInstallation() + { + $this->directoryListMock + ->expects($this->at(0)) + ->method('getPath') + ->with(DirectoryList::CONFIG) + ->will($this->returnValue(BP . '/app/etc')); + $this->directoryListMock + ->expects($this->at(1)) + ->method('getPath') + ->with(DirectoryList::VAR_DIR) + ->will($this->returnValue(BP . '/var')); + $this->directoryListMock + ->expects($this->at(2)) + ->method('getPath') + ->with(DirectoryList::MEDIA) + ->will($this->returnValue(BP . '/pub/media')); + $this->directoryListMock + ->expects($this->at(3)) + ->method('getPath') + ->with(DirectoryList::STATIC_VIEW) + ->will($this->returnValue(BP . '/pub/static')); + } + + public function setUpDirectoryWriteInstallation() + { + // CONFIG + $this->directoryWriteMock + ->expects($this->at(0)) + ->method('isExist') + ->will($this->returnValue(true)); + $this->directoryWriteMock + ->expects($this->at(1)) + ->method('isDirectory') + ->will($this->returnValue(true)); + $this->directoryWriteMock + ->expects($this->at(2)) + ->method('isReadable') + ->will($this->returnValue(true)); + $this->directoryWriteMock + ->expects($this->at(3)) + ->method('isWritable') + ->will($this->returnValue(true)); + + // VAR + $this->directoryWriteMock + ->expects($this->at(4)) + ->method('isExist') + ->will($this->returnValue(false)); + + // MEDIA + $this->directoryWriteMock + ->expects($this->at(5)) + ->method('isExist') + ->will($this->returnValue(true)); + $this->directoryWriteMock + ->expects($this->at(6)) + ->method('isDirectory') + ->will($this->returnValue(false)); + + // STATIC_VIEW + $this->directoryWriteMock + ->expects($this->at(7)) + ->method('isExist') + ->will($this->returnValue(true)); + $this->directoryWriteMock + ->expects($this->at(8)) + ->method('isDirectory') + ->will($this->returnValue(true)); + $this->directoryWriteMock + ->expects($this->at(9)) + ->method('isReadable') + ->will($this->returnValue(true)); + $this->directoryWriteMock + ->expects($this->at(10)) + ->method('isWritable') + ->will($this->returnValue(false)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressFactoryTest.php new file mode 100644 index 0000000000000..622915bfe2595 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressFactoryTest.php @@ -0,0 +1,28 @@ +getMockBuilder('Magento\Setup\Model\WebLogger')->disableOriginalConstructor()->getMock(); + $logger->expects($this->once())->method('get')->will($this->returnValue($contents)); + + $progressFactory = new ProgressFactory(); + $progress = $progressFactory->createFromLog($logger); + $this->assertEquals(3, $progress->getCurrent()); + $this->assertEquals(5, $progress->getTotal()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php new file mode 100644 index 0000000000000..0d708485a328f --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php @@ -0,0 +1,82 @@ +setNext(); + $this->assertEquals(1, $progress->getCurrent()); + } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage Current cannot exceed total number. + */ + public function testSetNextException() + { + $progress = new Progress(10, 10); + $progress->setNext(); + } + + public function testFinish() + { + $progress = new Progress(10); + $progress->finish(); + $this->assertEquals(10, $progress->getCurrent()); + } + + public function testGetCurrent() + { + $progress = new Progress(10, 5); + $this->assertEquals(5, $progress->getCurrent()); + } + + public function testGetTotal() + { + $progress = new Progress(10); + $this->assertEquals(10, $progress->getTotal()); + } + + public function testRatio() + { + for ($i = 10; $i <= 20; $i++) { + for ($j = 0; $j <= $i; $j++) { + $progress = new Progress($i, $j); + $this->assertEquals($j / $i, $progress->getRatio()); + } + } + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php new file mode 100644 index 0000000000000..fb15276a2a564 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php @@ -0,0 +1,116 @@ +getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); + $serviceLocatorMock + ->expects($this->at(0)) + ->method('get') + ->with('Magento\Setup\Model\FilePermissions') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Setup\Model\FilePermissions')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(1)) + ->method('get') + ->with('Magento\Framework\App\DeploymentConfig\Writer') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Framework\App\DeploymentConfig\Writer')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(2)) + ->method('get') + ->with('Magento\Framework\App\DeploymentConfig') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Framework\App\DeploymentConfig')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(3)) + ->method('get') + ->with('Magento\Setup\Module\SetupFactory') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Setup\Module\SetupFactory')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(4)) + ->method('get') + ->with('Magento\Framework\Module\ModuleList') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Framework\Module\ModuleList')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(5)) + ->method('get') + ->with('Magento\Framework\Module\ModuleList\Loader') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Framework\Module\ModuleList\Loader') + ->disableOriginalConstructor() + ->getMock() + )); + $serviceLocatorMock + ->expects($this->at(6)) + ->method('get') + ->with('Magento\Framework\App\Filesystem\DirectoryList') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Framework\App\Filesystem\DirectoryList') + ->disableOriginalConstructor() + ->getMock() + )); + $serviceLocatorMock + ->expects($this->at(7)) + ->method('get') + ->with('Magento\Setup\Model\AdminAccountFactory') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Setup\Model\AdminAccountFactory') + ->disableOriginalConstructor() + ->getMock() + )); + $serviceLocatorMock + ->expects($this->at(8)) + ->method('get') + ->with('Magento\Framework\Math\Random') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Framework\Math\Random')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(9)) + ->method('get') + ->with('Magento\Setup\Module\ConnectionFactory') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Setup\Module\ConnectionFactory')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(10)) + ->method('get') + ->with('Magento\Framework\App\MaintenanceMode') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Framework\App\MaintenanceMode')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(11)) + ->method('get') + ->with('Magento\Framework\Filesystem') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Framework\Filesystem')->disableOriginalConstructor()->getMock() + )); + $serviceLocatorMock + ->expects($this->at(12)) + ->method('get') + ->with('Magento\Setup\Model\SampleData') + ->will($this->returnValue( + $this->getMockBuilder('Magento\Setup\Model\SampleData')->disableOriginalConstructor()->getMock() + )); + + $log = $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface'); + $installerFactory = new InstallerFactory($serviceLocatorMock); + $installer = $installerFactory->create($log); + $this->assertInstanceOf('Magento\Setup\Model\Installer', $installer); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php new file mode 100644 index 0000000000000..4b208564d8b8a --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php @@ -0,0 +1,64 @@ +directoryReadMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Read') + ->disableOriginalConstructor() + ->setMethods(['readFile', 'isFile']) + ->getMock(); + $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') + ->disableOriginalConstructor() + ->setMethods(['getDirectoryRead']) + ->getMock(); + $this->filesystemMock + ->expects($this->once()) + ->method('getDirectoryRead') + ->will($this->returnValue($this->directoryReadMock)); + } + + public function testGetContents() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('readFile') + ->with(License::LICENSE_FILENAME) + ->will($this->returnValue(file_get_contents(BP . '/' . License::LICENSE_FILENAME))); + $this->directoryReadMock + ->expects($this->once()) + ->method('isFile') + ->with(License::LICENSE_FILENAME) + ->will($this->returnValue(true)); + + $license = new License($this->filesystemMock); + $this->assertSame(file_get_contents(BP . '/' . License::LICENSE_FILENAME), $license->getContents()); + } + + public function testGetContentsNoFile() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('isFile') + ->with(License::LICENSE_FILENAME) + ->will($this->returnValue(false)); + + $license = new License($this->filesystemMock); + $this->assertFalse($license->getContents()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php new file mode 100644 index 0000000000000..0e702a0cc572e --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php @@ -0,0 +1,113 @@ +lists = new Lists($objectManager->getObject('Zend_Locale'), $objectManager->getObject('Magento\Framework\Locale\Config')); + } + + public function testGetTimezoneList() + { + $expected = [ + 'Australia/Darwin' => 'AUS Central Standard Time (Australia/Darwin)', + 'America/Regina' => 'Canada Central Standard Time (America/Regina)', + 'Europe/Kiev' => 'FLE Standard Time (Europe/Kiev)', + 'Africa/Windhoek' => 'Namibia Standard Time (Africa/Windhoek)', + 'Asia/Katmandu' => 'Nepal Standard Time (Asia/Katmandu)', + 'Etc/GMT+2' => 'UTC-02 (Etc/GMT+2)', + 'Pacific/Port_Moresby' => 'West Pacific Standard Time (Pacific/Port_Moresby)', + 'Asia/Yakutsk' => 'Yakutsk Standard Time (Asia/Yakutsk)', + ]; + + $this->assertTrue(array_intersect_assoc($expected, $this->lists->getTimezoneList()) == $expected); + } + + public function testGetCurrencyList() + { + $expected = [ + 'XUA' => 'ADB Unit of Account (XUA)', + 'AFA' => 'Afghan Afghani (1927–2002) (AFA)', + 'AZM' => 'Azerbaijani Manat (1993–2006) (AZM)', + 'AZN' => 'Azerbaijani Manat (AZN)', + 'BOB' => 'Bolivian Boliviano (BOB)', + 'CUC' => 'Cuban Convertible Peso (CUC)', + 'CUP' => 'Cuban Peso (CUP)', + 'CYP' => 'Cypriot Pound (CYP)', + 'CZK' => 'Czech Republic Koruna (CZK)', + 'CSK' => 'Czechoslovak Hard Koruna (CSK)', + 'DKK' => 'Danish Krone (DKK)', + 'ZRN' => 'Zairean New Zaire (1993–1998) (ZRN)', + 'ZRZ' => 'Zairean Zaire (1971–1993) (ZRZ)', + 'ZMK' => 'Zambian Kwacha (1968–2012) (ZMK)', + 'ZMW' => 'Zambian Kwacha (ZMW)', + 'ZWD' => 'Zimbabwean Dollar (1980–2008) (ZWD)', + ]; + $this->assertTrue(array_intersect_assoc($expected, $this->lists->getCurrencyList()) == $expected); + } + + public function testGetLocaleList() + { + $expected = [ + 'aa_DJ' => 'Afar (Djibouti)', + 'ar_ER' => 'Arabic (Eritrea)', + 'ar_TN' => 'Arabic (Tunisia)', + 'bn_BD' => 'Bengali (Bangladesh)', + 'bn_IN' => 'Bengali (India)', + 'byn_ER' => 'Blin (Eritrea)', + 'brx_IN' => 'Bodo (India)', + 'zh_CN' => 'Chinese (China)', + 'zh_HK' => 'Chinese (Hong Kong SAR China)', + 'nl_NL' => 'Dutch (Netherlands)', + 'nl_SX' => 'Dutch (Sint Maarten)', + 'en_BW' => 'English (Botswana)', + 'fr_BJ' => 'French (Benin)', + 'fr_BF' => 'French (Burkina Faso)', + 'ia_FR' => 'Interlingua (France)', + 'ga_IE' => 'Irish (Ireland)', + 'it_IT' => 'Italian (Italy)', + 'lag_TZ' => 'Langi (Tanzania)', + 'lo_LA' => 'Lao (Laos)', + 'lv_LV' => 'Latvian (Latvia)', + 'ln_AO' => 'Lingala (Angola)', + 'nso_ZA' => 'Northern Sotho (South Africa)', + 'pt_TL' => 'Portuguese (Timor-Leste)', + 'ro_MD' => 'Romanian (Moldova)', + 'ro_RO' => 'Romanian (Romania)', + 'rm_CH' => 'Romansh (Switzerland)', + 'rof_TZ' => 'Rombo (Tanzania)', + 'rn_BI' => 'Rundi (Burundi)', + 'ru_UA' => 'Russian (Ukraine)', + 'rwk_TZ' => 'Rwa (Tanzania)', + 'so_ET' => 'Somali (Ethiopia)', + 'es_ES' => 'Spanish (Spain)', + 'es_US' => 'Spanish (United States)', + 'teo_UG' => 'Teso (Uganda)', + 'th_TH' => 'Thai (Thailand)', + 'bo_CN' => 'Tibetan (China)', + 'fy_NL' => 'Western Frisian (Netherlands)', + 'wal_ET' => 'Wolaytta (Ethiopia)', + 'xh_ZA' => 'Xhosa (South Africa)', + 'yav_CM' => 'Yangben (Cameroon)', + 'yo_BJ' => 'Yoruba (Benin)', + 'yo_NG' => 'Yoruba (Nigeria)', + 'dje_NE' => 'Zarma (Niger)', + 'zu_ZA' => 'Zulu (South Africa)', + ]; + + $this->assertTrue(array_intersect_assoc($expected, $this->lists->getLocaleList()) == $expected); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/NavigationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/NavigationTest.php new file mode 100644 index 0000000000000..4ce356e644524 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/NavigationTest.php @@ -0,0 +1,84 @@ +serviceLocatorMock = + $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); + + $this->navigation = new Navigation($this->serviceLocatorMock); + } + + public function testGetData() + { + $this->serviceLocatorMock + ->expects($this->once()) + ->method('get') + ->with('config') + ->will($this->returnValue([ + 'nav' => [ + ['key1' => 'value1'], + ['key2' => 'value2'], + ] + ])); + + $this->assertEquals([['key1' => 'value1'], ['key2' => 'value2']], $this->navigation->getData()); + } + + public function testGetMenuItems() + { + $this->serviceLocatorMock + ->expects($this->once()) + ->method('get') + ->with('config') + ->will($this->returnValue([ + 'nav' => [ + ['key1' => 'value1'], + ['key2' => 'value2'], + ['nav-bar' => 'abc', 'key3' => 'value3'], + ['nav-bar' => ''], + ['nav-bar' => false], + ] + ])); + + $this->assertEquals( + [['nav-bar' => 'abc', 'key3' => 'value3']], + array_values($this->navigation->getMenuItems()) + ); + } + + public function testGetMainItems() + { + $this->serviceLocatorMock + ->expects($this->once()) + ->method('get') + ->with('config') + ->will($this->returnValue([ + 'nav' => [ + ['key1' => 'value1'], + ['key2' => 'value2'], + ['main' => 'abc', 'key3' => 'value3'], + ['main' => ''], + ['main' => false], + ] + ])); + + $this->assertEquals([['main' => 'abc', 'key3' => 'value3']], array_values($this->navigation->getMainItems())); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/PhpInformationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/PhpInformationTest.php new file mode 100644 index 0000000000000..9910e30df3c72 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/PhpInformationTest.php @@ -0,0 +1,161 @@ +directoryReadMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Read') + ->disableOriginalConstructor() + ->setMethods(['isExist', 'readFile']) + ->getMock(); + $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') + ->disableOriginalConstructor() + ->setMethods(['getDirectoryRead']) + ->getMock(); + $this->filesystemMock + ->expects($this->once()) + ->method('getDirectoryRead') + ->will($this->returnValue($this->directoryReadMock)); + } + + public function testGetRequiredPhpVersion() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('isExist') + ->will($this->returnValue(true)); + $this->directoryReadMock + ->expects($this->once()) + ->method('readFile') + ->with('composer.lock') + ->will($this->returnValue('{"platform":{"php":"~5.4.11|~5.5.0"}}')); + + $phpInfo = new PhpInformation($this->filesystemMock); + $this->assertEquals("~5.4.11|~5.5.0", $phpInfo->getRequiredPhpVersion()); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Cannot read 'composer.lock' file + */ + public function testGetRequiredPhpVersionExceptionNoComposerLock() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('isExist') + ->will($this->returnValue(false)); + + $phpInfo = new PhpInformation($this->filesystemMock); + $phpInfo->getRequiredPhpVersion(); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Missing key 'platform=>php' in 'composer.lock' file + */ + public function testGetRequiredPhpVersionExceptionMissingKey() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('isExist') + ->will($this->returnValue(true)); + $this->directoryReadMock + ->expects($this->once()) + ->method('readFile') + ->with('composer.lock') + ->will($this->returnValue('{}')); + + $phpInfo = new PhpInformation($this->filesystemMock); + $phpInfo->getRequiredPhpVersion(); + } + + public function testGetRequired() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('isExist') + ->will($this->returnValue(true)); + $this->directoryReadMock + ->expects($this->once()) + ->method('readFile') + ->with('composer.lock') + ->will($this->returnValue( + '{"platform-dev":{"ext-e":"*", "f":"*"}, ' . + '"packages":[{"name":"a","require":{"c":"*"}}, {"name":"b","require":{"ext-d":"*"}}]}' + )); + $phpInfo = new PhpInformation($this->filesystemMock); + $this->assertEquals(['e', 'd'], $phpInfo->getRequired()); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Cannot read 'composer.lock' file + */ + public function testGetRequiredNoComposerLock() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('isExist') + ->will($this->returnValue(false)); + + $phpInfo = new PhpInformation($this->filesystemMock); + $phpInfo->getRequired(); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Missing key 'platform-dev' in 'composer.lock' file + */ + public function testGetRequiredExceptionMissingPlatformDev() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('isExist') + ->will($this->returnValue(true)); + $this->directoryReadMock + ->expects($this->once()) + ->method('readFile') + ->with('composer.lock') + ->will( + $this->returnValue( + '{"packages":[{"name":"a","require":{"c":"*"}}, {"name":"b","require":{"ext-d":"*"}}]}' + ) + ); + $phpInfo = new PhpInformation($this->filesystemMock); + $phpInfo->getRequired(); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Missing key 'packages' in 'composer.lock' file + */ + public function testGetRequiredExceptionMissingPackages() + { + $this->directoryReadMock + ->expects($this->once()) + ->method('isExist') + ->will($this->returnValue(true)); + $this->directoryReadMock + ->expects($this->once()) + ->method('readFile') + ->with('composer.lock') + ->will($this->returnValue('{"platform-dev":{"ext-e":"*", "f":"*"}}')); + $phpInfo = new PhpInformation($this->filesystemMock); + $phpInfo->getRequired(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php new file mode 100644 index 0000000000000..416793a280854 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php @@ -0,0 +1,176 @@ +assertEquals($expected, $userConfigurationDataMapper->getConfigData($data)); + } + + /** + * return array + */ + public function getConfigDataDataProvider() + { + return [ + 'valid' => + [ + [ + UserConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => '1', + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1/', + UserConfigurationDataMapper::KEY_CURRENCY => 'USD', + UserConfigurationDataMapper::KEY_IS_SECURE => '1', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + UserConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + UserConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + UserConfigurationDataMapper::KEY_USE_SEF_URL => '1', + ], + [ + Store::XML_PATH_USE_REWRITES => '1', + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + Store::XML_PATH_SECURE_IN_FRONTEND => '1', + Store::XML_PATH_SECURE_BASE_URL => 'https://127.0.0.1/', + Store::XML_PATH_SECURE_IN_ADMINHTML => '1', + Data::XML_PATH_DEFAULT_LOCALE => 'en_US', + Data::XML_PATH_DEFAULT_TIMEZONE => 'America/Chicago', + Currency::XML_PATH_CURRENCY_BASE => 'USD', + Currency::XML_PATH_CURRENCY_DEFAULT => 'USD', + Currency::XML_PATH_CURRENCY_ALLOW => 'USD', + Url::XML_PATH_USE_SECURE_KEY => '1', + ], + ], + 'no trailing slash' => + [ + [ + UserConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => '1', + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1', + UserConfigurationDataMapper::KEY_CURRENCY => 'USD', + UserConfigurationDataMapper::KEY_IS_SECURE => '1', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + UserConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + UserConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + UserConfigurationDataMapper::KEY_USE_SEF_URL => '1', + ], + [ + Store::XML_PATH_USE_REWRITES => '1', + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + Store::XML_PATH_SECURE_IN_FRONTEND => '1', + Store::XML_PATH_SECURE_BASE_URL => 'https://127.0.0.1/', + Store::XML_PATH_SECURE_IN_ADMINHTML => '1', + Data::XML_PATH_DEFAULT_LOCALE => 'en_US', + Data::XML_PATH_DEFAULT_TIMEZONE => 'America/Chicago', + Currency::XML_PATH_CURRENCY_BASE => 'USD', + Currency::XML_PATH_CURRENCY_DEFAULT => 'USD', + Currency::XML_PATH_CURRENCY_ALLOW => 'USD', + Url::XML_PATH_USE_SECURE_KEY => '1', + ], + ], + 'is_secure, is_secure_admin set but no secure base url' => + [ + [ + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + UserConfigurationDataMapper::KEY_IS_SECURE => '1', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + ], + [ + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + ], + ], + 'secure base url set but is_secure and is_secure_admin set to 0' => + [ + [ + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1', + UserConfigurationDataMapper::KEY_IS_SECURE => '0', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '0', + ], + [ + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + ], + ], + 'secure base url set but is_secure and is_secure_admin not set' => + [ + [ + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1', + ], + [ + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + ], + ], + 'secure base url set, is_secure set to 0, is_secure_admin set to 1' => + [ + [ + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1', + UserConfigurationDataMapper::KEY_IS_SECURE => '0', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + ], + [ + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + Store::XML_PATH_SECURE_IN_FRONTEND => '0', + Store::XML_PATH_SECURE_BASE_URL => 'https://127.0.0.1/', + Store::XML_PATH_SECURE_IN_ADMINHTML => '1', + ], + ], + 'secure base url set, is_secure set to 1, is_secure_admin set to 0' => + [ + [ + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1', + UserConfigurationDataMapper::KEY_IS_SECURE => '1', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '0', + ], + [ + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + Store::XML_PATH_SECURE_IN_FRONTEND => '1', + Store::XML_PATH_SECURE_BASE_URL => 'https://127.0.0.1/', + Store::XML_PATH_SECURE_IN_ADMINHTML => '0', + ], + ], + 'secure base url set, is_secure not set, is_secure_admin set to 1' => + [ + [ + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + ], + [ + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + Store::XML_PATH_SECURE_BASE_URL => 'https://127.0.0.1/', + Store::XML_PATH_SECURE_IN_ADMINHTML => '1', + ], + ], + 'secure base url set, is_secure set to 1, is_secure_admin not set' => + [ + [ + UserConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1', + UserConfigurationDataMapper::KEY_IS_SECURE => '1', + ], + [ + Store::XML_PATH_UNSECURE_BASE_URL => 'http://127.0.0.1/', + Store::XML_PATH_SECURE_IN_FRONTEND => '1', + Store::XML_PATH_SECURE_BASE_URL => 'https://127.0.0.1/', + ], + ], + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php new file mode 100644 index 0000000000000..474ad540c8b89 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php @@ -0,0 +1,183 @@ +directoryWriteMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Read') + ->disableOriginalConstructor() + ->setMethods(['readFile', 'writeFile', 'delete', 'isExist']) + ->getMock(); + $this->directoryWriteMock + ->expects($this->any()) + ->method('readFile') + ->will($this->returnCallback(['Magento\Setup\Model\WebLoggerTest', 'readLog'])); + $this->directoryWriteMock + ->expects($this->any()) + ->method('writeFile') + ->will($this->returnCallback(['Magento\Setup\Model\WebLoggerTest', 'writeToLog'])); + $this->directoryWriteMock + ->expects($this->any()) + ->method('isExist') + ->will($this->returnCallback(['Magento\Setup\Model\WebLoggerTest', 'isExist'])); + + $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') + ->disableOriginalConstructor() + ->setMethods(['getDirectoryWrite']) + ->getMock(); + $this->filesystemMock + ->expects($this->once()) + ->method('getDirectoryWrite') + ->will($this->returnValue($this->directoryWriteMock)); + + $this->webLogger = new WebLogger($this->filesystemMock); + } + + public function testLogSuccess() + { + $this->webLogger->logSuccess('Success1'); + $this->assertEquals('[SUCCESS] ' . 'Success1' . '
    ', self::$log); + + $this->webLogger->logSuccess('Success2'); + $this->assertEquals( + '[SUCCESS] ' . 'Success1' . '
    ' . + '[SUCCESS] ' . 'Success2' . '
    ' + , self::$log); + } + + public function testLogError() + { + $e1 = new \Exception('Dummy Exception1'); + $e2 = new \Exception('Dummy Exception2'); + + $this->webLogger->logError($e1); + $this->assertContains('[ERROR] exception \'Exception\' with message \'Dummy Exception1\'', self::$log); + + $this->webLogger->logError($e2); + $this->assertContains('[ERROR] exception \'Exception\' with message \'Dummy Exception1\'', self::$log); + $this->assertContains('[ERROR] exception \'Exception\' with message \'Dummy Exception2\'', self::$log); + } + + public function testLog() + { + $this->webLogger->log('Message1'); + $this->assertEquals('Message1
    ', self::$log); + + $this->webLogger->log('Message2'); + $this->assertEquals( + 'Message1
    Message2
    ', + self::$log + ); + } + + public function testLogAfterInline() + { + $this->webLogger->logInline('*'); + $this->webLogger->log('Message'); + $this->assertEquals( + '*
    Message
    ', + self::$log + ); + } + + public function testLogInline() + { + $this->webLogger->logInline('*'); + $this->assertEquals('*', self::$log); + + $this->webLogger->logInline('*'); + $this->assertEquals('**', self::$log); + } + + public function testLogMeta() + { + $this->webLogger->logMeta('Meta1'); + $this->assertEquals('
    ', self::$log); + + $this->webLogger->logMeta('Meta2'); + $this->assertEquals('

    ', self::$log); + } + + public function testGet() + { + $this->webLogger->log("Message1\n"); + $this->webLogger->log('Message2'); + + $expected = [ + 'Message1', + '
    Message2
    ', + ]; + + $this->assertEquals($expected, $this->webLogger->get()); + } + + public function testClear() + { + $this->directoryWriteMock + ->expects($this->once()) + ->method('delete') + ->will($this->returnCallback(['Magento\Setup\Model\WebLoggerTest', 'deleteLog'])); + + $this->webLogger->log('Message1'); + $this->assertEquals('Message1
    ', self::$log); + + $this->webLogger->clear(); + $this->assertEquals('', self::$log); + } + + public function testClearNotExist() + { + $this->directoryWriteMock + ->expects($this->never()) + ->method('delete'); + + $this->webLogger->clear(); + } + + public static function readLog() + { + return self::$log; + } + + public static function writeToLog($logFile, $message) + { + self::$log .= $message; + } + + public static function deleteLog() + { + self::$log = ''; + } + + public static function isExist() + { + return self::$log != ''; + } +} diff --git a/setup/src/Magento/Setup/Model/FilePermissions.php b/setup/src/Magento/Setup/Model/FilePermissions.php index 820ec83f330ef..2dd3ce5aa840e 100644 --- a/setup/src/Magento/Setup/Model/FilePermissions.php +++ b/setup/src/Magento/Setup/Model/FilePermissions.php @@ -102,7 +102,6 @@ public function getApplicationNonWritableDirectories() /** * Retrieve list of currently writable directories for installation * - * @param bool * @return array */ public function getInstallationCurrentWritableDirectories() @@ -120,7 +119,6 @@ public function getInstallationCurrentWritableDirectories() /** * Retrieve list of currently non-writable directories for application * - * @param bool * @return array */ public function getApplicationCurrentNonWritableDirectories() From 43d118629d9fa908eb89cf27130f9520b319f812 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 7 Jan 2015 15:56:56 -0600 Subject: [PATCH 21/89] MAGETWO-32089: Setup Models Unit Test Coverage - corrected docblock --- .../Setup/Model/FilePermissionsTest.php | 18 +++++++++++++++--- .../Setup/Model/Installer/ProgressTest.php | 2 ++ .../Model/UserConfigurationDataMapperTest.php | 4 +++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php index 2c353c993e571..d97e7e9103c72 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php @@ -89,9 +89,11 @@ public function testGetInstallationCurrentWritableDirectories() } /** + * @param array $mockMethods + * @param array $expected * @dataProvider getApplicationCurrentNonWritableDirectoriesDataProvider */ - public function testGetApplicationCurrentNonWritableDirectories(array $mockMethods, $expected) + public function testGetApplicationCurrentNonWritableDirectories(array $mockMethods, array $expected) { $this->directoryListMock ->expects($this->at(0)) @@ -118,7 +120,15 @@ public function testGetApplicationCurrentNonWritableDirectories(array $mockMetho public function getApplicationCurrentNonWritableDirectoriesDataProvider() { return [ - [['isExist' => true, 'isDirectory' => true, 'isReadable' => true, 'isWritable' => false], [BP . '/app/etc']], + [ + [ + 'isExist' => true, + 'isDirectory' => true, + 'isReadable' => true, + 'isWritable' => false + ], + [BP . '/app/etc'], + ], [['isExist' => false], []], [['isExist' => true, 'isDirectory' => false], []], [['isExist' => true, 'isDirectory' => true, 'isReadable' => true, 'isWritable' => true], []], @@ -143,9 +153,11 @@ public function testGetMissingWritableDirectoriesForInstallation() } /** + * @param array $mockMethods + * @param array $expected * @dataProvider getUnnecessaryWritableDirectoriesForApplicationDataProvider */ - public function testGetUnnecessaryWritableDirectoriesForApplication($mockMethods, $expected) + public function testGetUnnecessaryWritableDirectoriesForApplication(array $mockMethods, array $expected) { $this->directoryListMock ->expects($this->at(0)) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php index 0d708485a328f..0b9a923ede84d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php @@ -8,6 +8,8 @@ class ProgressTest extends \PHPUnit_Framework_TestCase { /** + * @param int $total + * @param int $current * @dataProvider constructorExceptionInvalidTotalDataProvider * @expectedException \LogicException * @expectedExceptionMessage Total number must be more than zero. diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php index 416793a280854..28302a9ce191d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php @@ -14,9 +14,11 @@ class UserConfigurationDataMapperTest extends \PHPUnit_Framework_TestCase { /** + * @param array $data + * @param array $expected * @dataProvider getConfigDataDataProvider */ - public function testGetConfigData($data, $expected) + public function testGetConfigData(array $data, array $expected) { $userConfigurationDataMapper = new UserConfigurationDataMapper(); $this->assertEquals($expected, $userConfigurationDataMapper->getConfigData($data)); From 606bf31eafcbe1030f751a16374c56766314b2e6 Mon Sep 17 00:00:00 2001 From: Anton Makarenko Date: Wed, 7 Jan 2015 18:11:06 -0600 Subject: [PATCH 22/89] MAGETWO-32088: Setup "Installer" Model Unit Test Coverage - covered the Installer model with unit tests - related minor refactoring --- .../Setup/Model/InstallerFactoryTest.php | 31 +- .../Magento/Setup/Model/InstallerTest.php | 334 ++++++++++++++++++ setup/src/Magento/Setup/Model/Installer.php | 93 ++--- .../Magento/Setup/Model/InstallerFactory.php | 6 +- 4 files changed, 410 insertions(+), 54 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php index fb15276a2a564..7fb890fe96ade 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php @@ -5,6 +5,8 @@ namespace Magento\Setup\Model; +use Magento\Setup\Mvc\Bootstrap\InitParamListener; + class InstallerFactoryTest Extends \PHPUnit_Framework_TestCase { public function testCreate() @@ -13,40 +15,45 @@ public function testCreate() $serviceLocatorMock ->expects($this->at(0)) ->method('get') + ->with(InitParamListener::BOOTSTRAP_PARAM) + ->willReturn([]); + $serviceLocatorMock + ->expects($this->at(1)) + ->method('get') ->with('Magento\Setup\Model\FilePermissions') ->will($this->returnValue( $this->getMockBuilder('Magento\Setup\Model\FilePermissions')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(1)) + ->expects($this->at(2)) ->method('get') ->with('Magento\Framework\App\DeploymentConfig\Writer') ->will($this->returnValue( $this->getMockBuilder('Magento\Framework\App\DeploymentConfig\Writer')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(2)) + ->expects($this->at(3)) ->method('get') ->with('Magento\Framework\App\DeploymentConfig') ->will($this->returnValue( $this->getMockBuilder('Magento\Framework\App\DeploymentConfig')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(3)) + ->expects($this->at(4)) ->method('get') ->with('Magento\Setup\Module\SetupFactory') ->will($this->returnValue( $this->getMockBuilder('Magento\Setup\Module\SetupFactory')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(4)) + ->expects($this->at(5)) ->method('get') ->with('Magento\Framework\Module\ModuleList') ->will($this->returnValue( $this->getMockBuilder('Magento\Framework\Module\ModuleList')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(5)) + ->expects($this->at(6)) ->method('get') ->with('Magento\Framework\Module\ModuleList\Loader') ->will($this->returnValue( @@ -55,7 +62,7 @@ public function testCreate() ->getMock() )); $serviceLocatorMock - ->expects($this->at(6)) + ->expects($this->at(7)) ->method('get') ->with('Magento\Framework\App\Filesystem\DirectoryList') ->will($this->returnValue( @@ -64,7 +71,7 @@ public function testCreate() ->getMock() )); $serviceLocatorMock - ->expects($this->at(7)) + ->expects($this->at(8)) ->method('get') ->with('Magento\Setup\Model\AdminAccountFactory') ->will($this->returnValue( @@ -73,35 +80,35 @@ public function testCreate() ->getMock() )); $serviceLocatorMock - ->expects($this->at(8)) + ->expects($this->at(9)) ->method('get') ->with('Magento\Framework\Math\Random') ->will($this->returnValue( $this->getMockBuilder('Magento\Framework\Math\Random')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(9)) + ->expects($this->at(10)) ->method('get') ->with('Magento\Setup\Module\ConnectionFactory') ->will($this->returnValue( $this->getMockBuilder('Magento\Setup\Module\ConnectionFactory')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(10)) + ->expects($this->at(11)) ->method('get') ->with('Magento\Framework\App\MaintenanceMode') ->will($this->returnValue( $this->getMockBuilder('Magento\Framework\App\MaintenanceMode')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(11)) + ->expects($this->at(12)) ->method('get') ->with('Magento\Framework\Filesystem') ->will($this->returnValue( $this->getMockBuilder('Magento\Framework\Filesystem')->disableOriginalConstructor()->getMock() )); $serviceLocatorMock - ->expects($this->at(12)) + ->expects($this->at(13)) ->method('get') ->with('Magento\Setup\Model\SampleData') ->will($this->returnValue( diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php new file mode 100644 index 0000000000000..0c4ed6c3063c9 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php @@ -0,0 +1,334 @@ + '', + 'connection' => [ + 'default' => [ + DbConfig::KEY_HOST => '127.0.0.1', + DbConfig::KEY_NAME => 'magento', + DbConfig::KEY_USER => 'magento', + DbConfig::KEY_PASS => '', + ], + ], + ]; + + protected function setUp() + { + $this->filePermissions = $this->getMock('Magento\Setup\Model\FilePermissions', [], [], '', false); + $this->configWriter = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); + $this->config = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $this->setupFactory = $this->getMock('Magento\Setup\Module\SetupFactory', [], [], '', false); + $this->setupFactory->expects($this->any())->method('createSetupModule')->willReturn( + $this->getMock('Magento\Setup\Module\SetupModule', [], [], '', false) + ); + $this->setupFactory->expects($this->any())->method('createSetup')->willReturn( + $this->getMock('Magento\Setup\Module\Setup', [], [], '', false) + ); + $this->moduleList = $this->getMockForAbstractClass('Magento\Framework\Module\ModuleListInterface'); + $this->moduleList->expects($this->any())->method('getNames')->willReturn( + ['Foo_One', 'Bar_Two'] + ); + $this->moduleLoader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); + $allModules = [ + 'Foo_One' => [], + 'Bar_Two' => [], + ]; + $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules); + $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'); + $this->random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); + $connectionFactory = $this->getMock('Magento\Setup\Module\ConnectionFactory', [], [], '', false); + $this->connection = $this->getMockForAbstractClass('Magento\Framework\DB\Adapter\AdapterInterface'); + $connectionFactory->expects($this->any())->method('create')->willReturn($this->connection); + $this->maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false); + $this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); + $serviceLocator = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface'); + $serviceLocator->expects($this->once()) + ->method('get') + ->with(InitParamListener::BOOTSTRAP_PARAM) + ->willReturn([]); + $this->sampleData = $this->getMock('Magento\Setup\Model\SampleData', [], [], '', false); + $objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); + $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $objectManagerFactory->expects($this->any())->method('create')->willReturn($this->objectManager); + $this->object = new Installer( + $this->filePermissions, + $this->configWriter, + $this->config, + $this->setupFactory, + $this->moduleList, + $this->moduleLoader, + $this->directoryList, + $this->adminFactory, + $this->logger, + $this->random, + $connectionFactory, + $this->maintenanceMode, + $this->filesystem, + $serviceLocator, + $this->sampleData, + $objectManagerFactory + ); + } + + 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', + ]; + $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']] + ])); + $this->objectManager->expects($this->at(0)) + ->method('create') + ->with('Magento\Framework\Module\Updater') + ->willReturn($this->getMock('Magento\Framework\Module\Updater', [], [], '', false)); + $cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); + $cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']); + $this->objectManager->expects($this->at(1)) + ->method('create') + ->with('Magento\Framework\App\Cache\Manager') + ->willReturn($cacheManager); + $this->adminFactory->expects($this->once())->method('create')->willReturn( + $this->getMock('Magento\Setup\Model\AdminAccount', [], [], '', false) + ); + + $this->logger->expects($this->at(0))->method('log')->with('Starting Magento installation:'); + $this->logger->expects($this->at(1))->method('log')->with('File permissions check...'); + // at(2) invokes logMeta() + $this->logger->expects($this->at(3))->method('log')->with('Enabling Maintenance Mode...'); + // at(4) - logMeta and so on... + $this->logger->expects($this->at(5))->method('log')->with('Installing deployment configuration...'); + $this->logger->expects($this->at(7))->method('log')->with('Installing database schema:'); + $this->logger->expects($this->at(9))->method('log')->with("Module 'Foo_One':"); + $this->logger->expects($this->at(11))->method('log')->with("Module 'Bar_Two':"); + $this->logger->expects($this->at(13))->method('log')->with('Schema post-updates:'); + $this->logger->expects($this->at(14))->method('log')->with("Module 'Foo_One':"); + $this->logger->expects($this->at(15))->method('log')->with("Module 'Bar_Two':"); + $this->logger->expects($this->at(17))->method('log')->with('Installing user configuration...'); + $this->logger->expects($this->at(19))->method('log')->with('Installing data...'); + $this->logger->expects($this->at(21))->method('log')->with('Installing admin user...'); + $this->logger->expects($this->at(23))->method('log')->with('Enabling caches:'); + $this->logger->expects($this->at(24))->method('log')->with('Current status:'); + $this->logger->expects($this->at(27))->method('log')->with('Disabling Maintenance Mode:'); + $this->logger->expects($this->at(29))->method('log')->with('Post installation file permissions check...'); + $this->logger->expects($this->once())->method('logSuccess')->with('Magento installation complete.'); + $this->object->install($request); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Missing writing permissions to the following directories: 'foo' 'bar' + */ + public function testCheckInstallationFilePermissions() + { + $this->filePermissions + ->expects($this->once()) + ->method('getMissingWritableDirectoriesForInstallation') + ->willReturn(['foo', 'bar']); + $this->object->checkInstallationFilePermissions(); + } + + public function testCheckApplicationFilePermissions() + { + $this->filePermissions + ->expects($this->once()) + ->method('getUnnecessaryWritableDirectoriesForApplication') + ->willReturn(['foo', 'bar']); + $expectedMessage = "For security, remove write permissions from these directories: 'foo' 'bar'"; + $this->logger->expects($this->once())->method('log')->with($expectedMessage); + $this->object->checkApplicationFilePermissions(); + $this->assertSame(['message' => [$expectedMessage]], $this->object->getInstallInfo()); + } + + public function testUninstall() + { + $this->config->expects($this->once())->method('isAvailable')->willReturn(false); + $varDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); + $varDir->expects($this->once())->method('getAbsolutePath')->willReturn('/var'); + $this->filesystem + ->expects($this->at(0)) + ->method('getDirectoryWrite') + ->with(DirectoryList::VAR_DIR) + ->willReturn($varDir); + $staticDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); + $staticDir->expects($this->once())->method('getAbsolutePath')->willReturn('/static'); + $this->filesystem + ->expects($this->at(1)) + ->method('getDirectoryWrite') + ->with(DirectoryList::STATIC_VIEW) + ->willReturn($staticDir); + $configDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); + $configDir->expects($this->once())->method('getAbsolutePath')->willReturn('/config/config.php'); + $this->filesystem + ->expects($this->at(2)) + ->method('getDirectoryWrite') + ->with(DirectoryList::CONFIG) + ->willReturn($configDir); + + $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); + $this->logger + ->expects($this->at(1)) + ->method('log') + ->with('No database connection defined - skipping database cleanup'); + $this->logger->expects($this->at(2))->method('log')->with('File system cleanup:'); + $this->logger + ->expects($this->at(3)) + ->method('log') + ->with("The directory '/var' doesn't exist - skipping cleanup"); + $this->logger + ->expects($this->at(4)) + ->method('log') + ->with("The directory '/static' doesn't exist - skipping cleanup"); + $this->logger + ->expects($this->at(5)) + ->method('log') + ->with("The file '/config/config.php' doesn't exist - skipping cleanup"); + $this->logger->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); + + $this->object->uninstall(); + } + + public function testCleanupDb() + { + $this->config->expects($this->once())->method('isAvailable')->willReturn(true); + $this->config->expects($this->once()) + ->method('getSegment') + ->with(DbConfig::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`'); + $this->connection->expects($this->at(2))->method('query')->with('CREATE DATABASE IF NOT EXISTS `magento`'); + $this->logger->expects($this->once())->method('log')->with('Recreating database `magento`'); + $this->object->cleanupDb(); + } + + public function testCheckDatabaseConnection() + { + $this->connection + ->expects($this->once()) + ->method('fetchOne') + ->with('SELECT version()') + ->willReturn('5.6.0-0ubuntu0.12.04.1'); + $this->assertEquals(true, $this->object->checkDatabaseConnection('name', 'host', 'user', 'password')); + } + + /** + * @expectedException \Magento\Setup\Exception + * @expectedExceptionMessage Sorry, but we support MySQL version + */ + public function testCheckDatabaseConnectionIncompatible() + { + $this->connection + ->expects($this->once()) + ->method('fetchOne') + ->with('SELECT version()') + ->willReturn('5.5.40-0ubuntu0.12.04.1'); + $this->object->checkDatabaseConnection('name', 'host', 'user', 'password'); + } +} diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index dc215a7db0cd9..d75846f95f317 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -27,6 +27,7 @@ use Magento\Setup\Mvc\Bootstrap\InitParamListener; use Magento\Store\Model\Store; use Zend\ServiceManager\ServiceLocatorInterface; +use Magento\Framework\App\ObjectManagerFactory; /** * Class Installer contains the logic to install Magento application. @@ -197,6 +198,11 @@ class Installer */ private $sampleData; + /** + * @var ObjectManagerFactory + */ + private $objectManagerFactory; + /** * Constructor * @@ -215,6 +221,7 @@ class Installer * @param Filesystem $filesystem * @param ServiceLocatorInterface $serviceManager * @param SampleData $sampleData + * @param ObjectManagerFactory $objectManagerFactory */ public function __construct( FilePermissions $filePermissions, @@ -231,7 +238,8 @@ public function __construct( MaintenanceMode $maintenanceMode, Filesystem $filesystem, ServiceLocatorInterface $serviceManager, - SampleData $sampleData + SampleData $sampleData, + ObjectManagerFactory $objectManagerFactory ) { $this->filePermissions = $filePermissions; $this->deploymentConfigWriter = $deploymentConfigWriter; @@ -250,6 +258,7 @@ public function __construct( $this->sampleData = $sampleData; $this->installInfo[self::INFO_MESSAGE] = array(); $this->deploymentConfig = $deploymentConfig; + $this->objectManagerFactory = $objectManagerFactory; } /** @@ -333,14 +342,15 @@ private function createModulesConfig($request) * * @param \ArrayObject|array $data * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface + * @throws \InvalidArgumentException */ private function createBackendConfig($data) { - $backendConfigData = array( - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_BACKEND_FRONTNAME] => - $data[DeploymentConfigMapper::KEY_BACKEND_FRONTNAME] - ); - return new BackendConfig($backendConfigData); + $key = DeploymentConfigMapper::KEY_BACKEND_FRONTNAME; + if (empty($data[$key])) { + throw new \InvalidArgumentException("Missing value for: '{$key}'"); + } + return new BackendConfig([DeploymentConfigMapper::$paramMap[$key] => $data[$key]]); } /** @@ -351,9 +361,13 @@ private function createBackendConfig($data) * * @param \ArrayObject|array $data * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface + * @throws \InvalidArgumentException */ private function createEncryptConfig($data) { + if (!isset($data[DeploymentConfigMapper::KEY_ENCRYPTION_KEY])) { + throw new \InvalidArgumentException("Missing key: '" . DeploymentConfigMapper::KEY_ENCRYPTION_KEY . "'"); + } $key = $data[DeploymentConfigMapper::KEY_ENCRYPTION_KEY]; // retrieve old encryption keys if ($this->deploymentConfig->isAvailable()) { @@ -377,34 +391,36 @@ private function createEncryptConfig($data) * * @param \ArrayObject|array $data * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface + * @throws \InvalidArgumentException */ private function createDbConfig($data) { - $defaultConnection = [ - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DB_HOST] => - $data[DeploymentConfigMapper::KEY_DB_HOST], - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DB_INIT_STATEMENTS] => - isset($data[DeploymentConfigMapper::KEY_DB_INIT_STATEMENTS]) ? - $data[DeploymentConfigMapper::KEY_DB_INIT_STATEMENTS] : null, - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DB_MODEL] => - isset($data[DeploymentConfigMapper::KEY_DB_MODEL]) ? $data[DeploymentConfigMapper::KEY_DB_MODEL] : null, - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DB_NAME] => - $data[DeploymentConfigMapper::KEY_DB_NAME], - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DB_PASS] => - isset($data[DeploymentConfigMapper::KEY_DB_PASS]) ? $data[DeploymentConfigMapper::KEY_DB_PASS] : null, - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DB_USER] => - $data[DeploymentConfigMapper::KEY_DB_USER], + $connection = []; + $required = [ + DeploymentConfigMapper::KEY_DB_HOST, + DeploymentConfigMapper::KEY_DB_NAME, + DeploymentConfigMapper::KEY_DB_USER, ]; - - $dbConfigData = [ - DeploymentConfigMapper::$paramMap[DeploymentConfigMapper::KEY_DB_PREFIX] => - isset($data[DeploymentConfigMapper::KEY_DB_PREFIX]) ? - $data[DeploymentConfigMapper::KEY_DB_PREFIX] : null, - 'connection' => [ - 'default' => $defaultConnection, - ], + 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($dbConfigData); + return new DbConfig($config); } /** @@ -491,10 +507,7 @@ public function checkInstallationFilePermissions() { $results = $this->filePermissions->getMissingWritableDirectoriesForInstallation(); if ($results) { - $errorMsg = 'Missing writing permissions to the following directories: '; - foreach ($results as $result) { - $errorMsg .= '\'' . $result . '\' '; - } + $errorMsg = "Missing writing permissions to the following directories: '" . implode("' '", $results) . "'"; throw new \Exception($errorMsg); } } @@ -508,10 +521,8 @@ public function checkApplicationFilePermissions() { $results = $this->filePermissions->getUnnecessaryWritableDirectoriesForApplication(); if ($results) { - $errorMsg = 'For security, remove write permissions from these directories: '; - foreach ($results as $result) { - $errorMsg .= '\'' . $result . '\' '; - } + $errorMsg = "For security, remove write permissions from these directories: '" + . implode("' '", $results) . "'"; $this->log->log($errorMsg); $this->installInfo[self::INFO_MESSAGE][] = $errorMsg; } @@ -764,7 +775,7 @@ public function getInstallInfo() * * @return void */ - private function cleanupDb() + public function cleanupDb() { // stops cleanup if app/etc/config.php does not exist if ($this->deploymentConfig->isAvailable()) { @@ -848,8 +859,7 @@ private function getObjectManager() { if (null === $this->objectManager) { $this->assertDeploymentConfigExists(); - $factory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $this->initParams); - $this->objectManager = $factory->create($this->initParams); + $this->objectManager = $this->objectManagerFactory->create($this->initParams); } return $this->objectManager; } @@ -873,7 +883,8 @@ private function assertDeploymentConfigExists() */ private function assertDbAccessible() { - $dbConfig = new DbConfig($this->deploymentConfig->getSegment(DbConfig::CONFIG_KEY)); + $segment = $this->deploymentConfig->getSegment(DbConfig::CONFIG_KEY); + $dbConfig = new DbConfig($segment); $config = $dbConfig->getConnection(\Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION); $this->checkDatabaseConnection( $config[DbConfig::KEY_NAME], diff --git a/setup/src/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php index 84b8b76bb0321..53546530a9888 100644 --- a/setup/src/Magento/Setup/Model/InstallerFactory.php +++ b/setup/src/Magento/Setup/Model/InstallerFactory.php @@ -6,6 +6,8 @@ namespace Magento\Setup\Model; use Zend\ServiceManager\ServiceLocatorInterface; +use Magento\Setup\Mvc\Bootstrap\InitParamListener; +use Magento\Framework\App\Bootstrap; class InstallerFactory { @@ -34,6 +36,7 @@ public function __construct(ServiceLocatorInterface $serviceLocator) */ public function create(LoggerInterface $log) { + $params = $this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM); return new Installer( $this->serviceLocator->get('Magento\Setup\Model\FilePermissions'), $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig\Writer'), @@ -49,7 +52,8 @@ public function create(LoggerInterface $log) $this->serviceLocator->get('Magento\Framework\App\MaintenanceMode'), $this->serviceLocator->get('Magento\Framework\Filesystem'), $this->serviceLocator, - $this->serviceLocator->get('Magento\Setup\Model\SampleData') + $this->serviceLocator->get('Magento\Setup\Model\SampleData'), + Bootstrap::createObjectManagerFactory(BP, $params) ); } } From 2f95e1f8ad6ccbb4f95b2b73f10b6365915dfe34 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Thu, 8 Jan 2015 09:12:51 -0600 Subject: [PATCH 23/89] MAGETWO-28514: Test Coverage for Setup tool - add tests for Magento\Setup\Mvc\Bootstrap\InitParamListener - Correct path to setup source directory for code coverage filter in phpunit.xml.dist --- dev/tests/unit/phpunit.xml.dist | 2 +- .../Mvc/Bootstrap/InitParamListenerTest.php | 247 ++++++++++++++++++ .../Setup/Mvc/Bootstrap/InitParamListener.php | 8 +- 3 files changed, 253 insertions(+), 4 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php diff --git a/dev/tests/unit/phpunit.xml.dist b/dev/tests/unit/phpunit.xml.dist index 53c925cebb62e..90c6337b27a12 100644 --- a/dev/tests/unit/phpunit.xml.dist +++ b/dev/tests/unit/phpunit.xml.dist @@ -19,7 +19,7 @@ ../../../app/code/Magento ../../../lib/internal/Magento - ../../../setup/module/Magento + ../../../setup/src/Magento ../../../app/code/Magento/*/sql ../../../app/code/Magento/*/data diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php new file mode 100644 index 0000000000000..9b82557b88c1c --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php @@ -0,0 +1,247 @@ +assertEquals( + $expectedConfig, + InitParamListener::attachToConsoleRoutes($inputConfig) + ); + } + + public function testAttachToConsoleRoutesOneRoute() + { + $inputConfig = [ + 'console' => ['router' => ['routes' => [['options' => ['route' =>'one_route']]]]] + ]; + $expectedConfig = [ + 'console' => ['router' => ['routes' => [['options' => ['route' => 'one_route [--magento_init_params=]']]]]] + ]; + + $this->assertEquals( + $expectedConfig, + InitParamListener::attachToConsoleRoutes($inputConfig) + ); + } + + public function testAttachToConsoleRoutesManyRoute() + { + $inputConfig = [ + 'console' => ['router' => ['routes' => [ + ['options' => ['route' =>'one_route']], + ['options' => ['route' =>'two_route']], + ['options' => ['route' =>'three_route']], + ['options' => ['route' =>'four_route']], + ['options' => ['route' =>'five_route']], + ]]] + ]; + $expectedConfig = [ + 'console' => ['router' => ['routes' => [ + ['options' => ['route' => 'one_route [--magento_init_params=]']], + ['options' => ['route' =>'two_route [--magento_init_params=]']], + ['options' => ['route' =>'three_route [--magento_init_params=]']], + ['options' => ['route' =>'four_route [--magento_init_params=]']], + ['options' => ['route' =>'five_route [--magento_init_params=]']], + ]]] + ]; + + $this->assertEquals( + $expectedConfig, + InitParamListener::attachToConsoleRoutes($inputConfig) + ); + } + + public function testGetConsoleUsage() + { + $usage = InitParamListener::getConsoleUsage(); + // First element should be blank line + $this->assertEquals('', $usage[0]); + // Only one parameter definition is added to usage statement + $this->assertContains('[--magento_init_params=""]', $usage[1][0]); + } + + public function testAttach() + { + $listener = new InitParamListener(); + /** @var \Zend\EventManager\EventManagerInterface | \PHPUnit_Framework_MockObject_MockObject $events */ + $events = $this->getMockBuilder('Zend\EventManager\EventManagerInterface')->getMock(); + $sharedManager = $this->getMockBuilder('Zend\EventManager\SharedEventManager')->getMock(); + $sharedManager->expects($this->once())->method('attach')->with( + 'Zend\Mvc\Application', + MvcEvent::EVENT_BOOTSTRAP, + [$listener, 'onBootstrap'] + ); + $events->expects($this->once())->method('getSharedManager')->willReturn($sharedManager); + + $listener->attach($events); + } + + public function testDetach() + { + $callbackHandler = $this->getMockBuilder('Zend\Stdlib\CallbackHandler')->disableOriginalConstructor() + ->getMock(); + + $listener = new InitParamListener(); + /** @var \Zend\EventManager\EventManagerInterface | \PHPUnit_Framework_MockObject_MockObject $events */ + $events = $this->getMockBuilder('Zend\EventManager\EventManagerInterface')->getMock(); + $sharedManager = $this->getMockBuilder('Zend\EventManager\SharedEventManager')->getMock(); + $sharedManager->expects($this->once())->method('attach') + ->with('Zend\Mvc\Application', MvcEvent::EVENT_BOOTSTRAP, [$listener, 'onBootstrap']) + ->willReturn($callbackHandler); + $events->expects($this->once())->method('getSharedManager')->willReturn($sharedManager); + $events->expects($this->once())->method('detach')->with($callbackHandler)->willReturn(true); + $listener->attach($events); + $listener->detach($events); + } + + public function testOnBootstrap() + { + $listener = new InitParamListener(); + /** @var \Zend\Mvc\MvcEvent | \PHPUnit_Framework_MockObject_MockObject $mvcEvent */ + $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->getMock(); + /** @var \Zend\Mvc\Application | \PHPUnit_Framework_MockObject_MockObject $mvcApplication */ + $mvcApplication = $this->getMockBuilder('Zend\Mvc\Application')->disableOriginalConstructor()->getMock(); + $mvcEvent->expects($this->once())->method('getApplication')->willReturn($mvcApplication); + /** @var \Zend\ServiceManager\ServiceManager | \PHPUnit_Framework_MockObject_MockObject $mvcApplication */ + $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceManager')->getMock(); + $initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS][DirectoryList::ROOT] = ['path' => '/test']; + $serviceManager->expects($this->once())->method('get') + ->willReturn($initParams); + $serviceManager->expects($this->exactly(2))->method('setService') + ->withConsecutive( + ['Magento\Framework\App\Filesystem\DirectoryList', + $this->isInstanceOf('Magento\Framework\App\Filesystem\DirectoryList')], + ['Magento\Framework\Filesystem', $this->isInstanceOf('Magento\Framework\Filesystem')] + ); + $mvcApplication->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); + + $listener->onBootstrap($mvcEvent); + } + + /** + * @expectedException LogicException + * @expectedExceptionMessage Magento root directory is not specified. + */ + public function testOnBootstrapException() + { + $listener = new InitParamListener(); + /** @var \Zend\Mvc\MvcEvent | \PHPUnit_Framework_MockObject_MockObject $mvcEvent */ + $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->getMock(); + $mvcApplication = $this->getMockBuilder('Zend\Mvc\Application')->disableOriginalConstructor()->getMock(); + $mvcEvent->expects($this->once())->method('getApplication')->willReturn($mvcApplication); + $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceManager')->getMock(); + $mvcApplication->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); + $listener->onBootstrap($mvcEvent); + } + + public function testCreateServiceNotConsole() + { + $listener = new InitParamListener(); + /** + * @var \Zend\ServiceManager\ServiceLocatorInterface | \PHPUnit_Framework_MockObject_MockObject $serviceLocator + */ + $serviceLocator = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); + $mvcApplication = $this->getMockBuilder('Zend\Mvc\Application')->disableOriginalConstructor()->getMock(); + $request = $this->getMockBuilder('Zend\Stdlib\RequestInterface')->getMock(); + $mvcApplication->expects($this->any())->method('getRequest')->willReturn($request); + $serviceLocator->expects($this->once())->method('get')->with('Application') + ->willReturn($mvcApplication); + $listener->createService($serviceLocator); + } + + /** + * @param array $zfAppConfig Data that comes from Zend Framework Application config + * @param array $env Config that comes from SetEnv + * @param string $cliParam Parameter string + * @param array $expectedArray Expected result array + * + * @dataProvider createServiceDataProvider + */ + public function testCreateService($zfAppConfig, $env, $cliParam, $expectedArray) + { + foreach ($env as $envKey => $envValue) { + $_SERVER[$envKey] = $envValue; + } + $listener = new InitParamListener(); + /** + * @var \Zend\ServiceManager\ServiceLocatorInterface | \PHPUnit_Framework_MockObject_MockObject $serviceLocator + */ + $serviceLocator = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); + $mvcApplication = $this->getMockBuilder('Zend\Mvc\Application')->disableOriginalConstructor()->getMock(); + $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); + $request->expects($this->any()) + ->method('getContent') + ->willReturn( + $cliParam ? ['install', '--magento_init_params=' . $cliParam ] : ['install'] + ); + $mvcApplication->expects($this->any())->method('getConfig')->willReturn( + $zfAppConfig ? [InitParamListener::BOOTSTRAP_PARAM => $zfAppConfig]:[] + ); + + $mvcApplication->expects($this->any())->method('getRequest')->willReturn($request); + $serviceLocator->expects($this->once())->method('get')->with('Application') + ->willReturn($mvcApplication); + + $this->assertEquals($expectedArray, $listener->createService($serviceLocator)); + } + + public function createServiceDataProvider() + { + return [ + 'none' => [[], [], '', []], + 'mage_mode App' => [['MAGE_MODE' => 'developer'], [], '', ['MAGE_MODE' => 'developer']], + 'mage_mode Env' => [[], ['MAGE_MODE' => 'developer'], '', ['MAGE_MODE' => 'developer']], + 'mage_mode CLI' => [[], [], 'MAGE_MODE=developer', ['MAGE_MODE' => 'developer']], + 'one MAGE_DIRS CLI' => [[], [], 'MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/magento2', + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2']], 'MAGE_MODE' => 'developer']], + 'two MAGE_DIRS CLI' => [ + [], + [], + 'MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/magento2&MAGE_DIRS[cache][path]=/tmp/cache', + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2'], 'cache' => ['path' => '/tmp/cache']], + 'MAGE_MODE' => 'developer']], + 'mage_mode only' => [[], [], 'MAGE_MODE=developer', ['MAGE_MODE' => 'developer']], + 'MAGE_DIRS Env' => [ + [], + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2']], 'MAGE_MODE' => 'developer'], + '', + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2']], 'MAGE_MODE' => 'developer']], + 'two MAGE_DIRS' => [ + [], + [], + 'MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/magento2&MAGE_DIRS[cache][path]=/tmp/cache', + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2'], 'cache' => ['path' => '/tmp/cache']], + 'MAGE_MODE' => 'developer']], + 'Env overwrites App' => [ + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/App']], 'MAGE_MODE' => 'developer'], + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/Env']], 'MAGE_MODE' => 'developer'], + '', + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/Env']], 'MAGE_MODE' => 'developer']], + 'CLI overwrites Env' => [ + ['MAGE_MODE' => 'developerApp'], + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/Env']]], + 'MAGE_DIRS[base][path]=/var/www/magento2/CLI', + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/CLI']], 'MAGE_MODE' => 'developerApp']], + 'CLI overwrites All' => [ + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/App']], 'MAGE_MODE' => 'production'], + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/Env']]], + 'MAGE_DIRS[base][path]=/var/www/magento2/CLI', + ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/CLI']], 'MAGE_MODE' => 'production']], + ]; + } +} diff --git a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php index 8d5fdd802944a..72d1c3188fd98 100644 --- a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php +++ b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php @@ -44,8 +44,10 @@ class InitParamListener implements ListenerAggregateInterface, FactoryInterface */ public static function attachToConsoleRoutes($config) { - foreach ($config['console']['router']['routes'] as &$route) { - $route['options']['route'] .= ' [--' . self::BOOTSTRAP_PARAM . '=]'; + if (isset($config['console']['router']['routes'])) { + foreach ($config['console']['router']['routes'] as &$route) { + $route['options']['route'] .= ' [--' . self::BOOTSTRAP_PARAM . '=]'; + } } return $config; } @@ -104,7 +106,7 @@ public function detach(EventManagerInterface $events) * @param MvcEvent $e * @return void */ - public function onBootstrap(\Zend\Mvc\MvcEvent $e) + public function onBootstrap(MvcEvent $e) { /** @var Application $application */ $application = $e->getApplication(); From b1bf5fbfdf67e6622a89d599f52cdef31505c101 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Fri, 9 Jan 2015 16:31:29 -0600 Subject: [PATCH 24/89] MAGETWO-32085: Setup Controllers Unit Test Coverage - Comfirmed that PHPUnit resets $_SERVER variable, so removing setUp and tearDown methods. --- .../Setup/Controller/WebConfigurationTest.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php index abf9e8eed068a..142bb5b26bbc5 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/WebConfigurationTest.php @@ -7,23 +7,6 @@ class WebConfigurationTest extends \PHPUnit_Framework_TestCase { - /** - * To prevent save value of $SERVER, which is modified in this test - * - * @var array - */ - private $serverArray; - - public function setUp() - { - $this->serverArray = $_SERVER; - } - - public function tearDown() - { - $_SERVER = $this->serverArray; - } - public function testIndexAction() { /** @var $controller WebConfiguration */ From 1c81fd370052464736dba1bd942fa043f8e0e8f1 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Mon, 12 Jan 2015 11:47:57 -0600 Subject: [PATCH 25/89] MAGETWO-32091: Setup "Module" Models Unit Test Coverage - Covered two classes with unit tests. --- .../Setup/Module/Setup/FileResolverTest.php | 76 +++++++++++++++++++ .../Setup/Module/Setup/ResourceConfigTest.php | 32 ++++++++ 2 files changed, 108 insertions(+) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/Setup/ResourceConfigTest.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php new file mode 100644 index 0000000000000..b72bbf2436caa --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php @@ -0,0 +1,76 @@ +directoryListMock = $this->getMockBuilder('Magento\Framework\App\Filesystem\DirectoryList') + ->disableOriginalConstructor() + ->setMethods(['getPath']) + ->getMock(); + + $this->fileResolver = new FileResolver($this->directoryListMock); + } + + public function testGetSqlSetupFiles() + { + $this->directoryListMock + ->expects($this->any()) + ->method('getPath') + ->with(DirectoryList::MODULES) + ->will($this->returnValue(BP . '/app/code')); + + // All valid data + $this->assertGreaterThan(0, count($this->fileResolver->getSqlSetupFiles('Magento_Core', '*.php'))); + + // Valid module name with default filename pattern + $this->assertGreaterThan(0, count($this->fileResolver->getSqlSetupFiles('Magento_Core'))); + + // Invalid module name + $this->assertCount(0, $this->fileResolver->getSqlSetupFiles('Magento_NonCore', '*.php')); + + // Invalid filename pattern for SQL files + $this->assertCount(0, $this->fileResolver->getSqlSetupFiles('Magento_NonCore', '*.text')); + } + + public function testGetResourceCode() + { + $this->directoryListMock + ->expects($this->any()) + ->method('getPath') + ->with(DirectoryList::MODULES) + ->will($this->returnValue(BP . '/app/code')); + + // Valid module name with both 'data' and 'sql' directories + $this->assertSame('core_setup', $this->fileResolver->getResourceCode('Magento_Core')); + + // Valid module name with only 'sql' directories (no 'data') + $this->assertSame('adminnotification_setup', $this->fileResolver->getResourceCode('Magento_AdminNotification')); + + // Valid module name with only 'data' directories (no 'sql') + $this->assertSame('checkout_setup', $this->fileResolver->getResourceCode('Magento_Checkout')); + + // Valid module name with no 'data' and 'sql' directories + $this->assertNull($this->fileResolver->getResourceCode('Magento_Backend')); + + // Invalid module name + $this->assertNull($this->fileResolver->getResourceCode('Magento_SomeModule')); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/ResourceConfigTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/ResourceConfigTest.php new file mode 100644 index 0000000000000..87581f4fa6b4e --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/ResourceConfigTest.php @@ -0,0 +1,32 @@ +assertEquals($connectionName, $resourceConfig->getConnectionName($resourceName)); + } + + /** + * @return array + */ + public function getConnectionNameDataProvider() + { + return [ + 'validResourceName' => ['validResourceName'], + 'invalidResourceName' => ['invalidResourceName'], + 'blankResourceName' => [''] + ]; + } +} From ee33133d92f64929fae705392d663161e5b0304f Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 9 Jan 2015 13:57:24 -0600 Subject: [PATCH 26/89] MAGETWO-32089: Setup Models Unit Test Coverage - made changes according to CR --- composer.lock | 98 +++--- .../Setup/Model/AdminAccountFactoryTest.php | 10 +- .../Magento/Setup/Model/AdminAccountTest.php | 326 +++++++++--------- .../Setup/Model/FilePermissionsTest.php | 23 +- .../Model/Installer/ProgressFactoryTest.php | 2 +- .../Setup/Model/Installer/ProgressTest.php | 21 +- .../Setup/Model/InstallerFactoryTest.php | 157 +++------ .../Magento/Setup/Model/LicenseTest.php | 18 +- .../Magento/Setup/Model/NavigationTest.php | 2 +- .../Setup/Model/PhpInformationTest.php | 18 +- .../Model/UserConfigurationDataMapperTest.php | 53 +++ .../Magento/Setup/Model/WebLoggerTest.php | 40 ++- 12 files changed, 391 insertions(+), 377 deletions(-) diff --git a/composer.lock b/composer.lock index ad7d727f7520f..8c52e3e0c5bfd 100644 --- a/composer.lock +++ b/composer.lock @@ -336,17 +336,17 @@ }, { "name": "symfony/console", - "version": "v2.6.1", + "version": "v2.6.3", "target-dir": "Symfony/Component/Console", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "ef825fd9f809d275926547c9e57cbf14968793e8" + "reference": "6ac6491ff60c0e5a941db3ccdc75a07adbb61476" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/ef825fd9f809d275926547c9e57cbf14968793e8", - "reference": "ef825fd9f809d275926547c9e57cbf14968793e8", + "url": "https://api.github.com/repos/symfony/Console/zipball/6ac6491ff60c0e5a941db3ccdc75a07adbb61476", + "reference": "6ac6491ff60c0e5a941db3ccdc75a07adbb61476", "shasum": "" }, "require": { @@ -389,21 +389,21 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2014-12-02 20:19:20" + "time": "2015-01-06 17:50:02" }, { "name": "symfony/finder", - "version": "v2.6.1", + "version": "v2.6.3", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", "url": "https://github.com/symfony/Finder.git", - "reference": "0d3ef7f6ec55a7af5eca7914eaa0dacc04ccc721" + "reference": "16513333bca64186c01609961a2bb1b95b5e1355" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/0d3ef7f6ec55a7af5eca7914eaa0dacc04ccc721", - "reference": "0d3ef7f6ec55a7af5eca7914eaa0dacc04ccc721", + "url": "https://api.github.com/repos/symfony/Finder/zipball/16513333bca64186c01609961a2bb1b95b5e1355", + "reference": "16513333bca64186c01609961a2bb1b95b5e1355", "shasum": "" }, "require": { @@ -436,21 +436,21 @@ ], "description": "Symfony Finder Component", "homepage": "http://symfony.com", - "time": "2014-12-02 20:19:20" + "time": "2015-01-03 08:01:59" }, { "name": "symfony/process", - "version": "v2.6.1", + "version": "v2.6.3", "target-dir": "Symfony/Component/Process", "source": { "type": "git", "url": "https://github.com/symfony/Process.git", - "reference": "bf0c9bd625f13b0b0bbe39919225cf145dfb935a" + "reference": "319794f611bd8bdefbac72beb3f05e847f8ebc92" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/bf0c9bd625f13b0b0bbe39919225cf145dfb935a", - "reference": "bf0c9bd625f13b0b0bbe39919225cf145dfb935a", + "url": "https://api.github.com/repos/symfony/Process/zipball/319794f611bd8bdefbac72beb3f05e847f8ebc92", + "reference": "319794f611bd8bdefbac72beb3f05e847f8ebc92", "shasum": "" }, "require": { @@ -483,7 +483,7 @@ ], "description": "Symfony Process Component", "homepage": "http://symfony.com", - "time": "2014-12-02 20:19:20" + "time": "2015-01-06 22:47:52" }, { "name": "zendframework/zend-code", @@ -1876,16 +1876,16 @@ }, { "name": "league/climate", - "version": "2.5.0", + "version": "2.6.0", "source": { "type": "git", "url": "https://github.com/thephpleague/climate.git", - "reference": "8687265629baaedd0fadc75350950ffc5ea53ae6" + "reference": "776b6c3b32837832a9f6d94f134b55cb7910ece6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/climate/zipball/8687265629baaedd0fadc75350950ffc5ea53ae6", - "reference": "8687265629baaedd0fadc75350950ffc5ea53ae6", + "url": "https://api.github.com/repos/thephpleague/climate/zipball/776b6c3b32837832a9f6d94f134b55cb7910ece6", + "reference": "776b6c3b32837832a9f6d94f134b55cb7910ece6", "shasum": "" }, "require": { @@ -1921,7 +1921,7 @@ "php", "terminal" ], - "time": "2014-11-08 02:33:31" + "time": "2015-01-08 02:28:23" }, { "name": "pdepend/pdepend", @@ -2771,17 +2771,17 @@ }, { "name": "symfony/config", - "version": "v2.5.8", + "version": "v2.5.9", "target-dir": "Symfony/Component/Config", "source": { "type": "git", "url": "https://github.com/symfony/Config.git", - "reference": "92f0b4c625b8c42d394b53f879d2795d84bb8c4f" + "reference": "c7309e33b719433d5cf3845d0b5b9608609d8c8e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/92f0b4c625b8c42d394b53f879d2795d84bb8c4f", - "reference": "92f0b4c625b8c42d394b53f879d2795d84bb8c4f", + "url": "https://api.github.com/repos/symfony/Config/zipball/c7309e33b719433d5cf3845d0b5b9608609d8c8e", + "reference": "c7309e33b719433d5cf3845d0b5b9608609d8c8e", "shasum": "" }, "require": { @@ -2815,21 +2815,21 @@ ], "description": "Symfony Config Component", "homepage": "http://symfony.com", - "time": "2014-12-02 20:15:53" + "time": "2015-01-03 08:01:13" }, { "name": "symfony/dependency-injection", - "version": "v2.5.8", + "version": "v2.5.9", "target-dir": "Symfony/Component/DependencyInjection", "source": { "type": "git", "url": "https://github.com/symfony/DependencyInjection.git", - "reference": "b4afda3c24867a17f93237ac1fcce917cc9d7695" + "reference": "b04e6782962f8e3312274fd16fb6b37a8210a1c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/b4afda3c24867a17f93237ac1fcce917cc9d7695", - "reference": "b4afda3c24867a17f93237ac1fcce917cc9d7695", + "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/b04e6782962f8e3312274fd16fb6b37a8210a1c3", + "reference": "b04e6782962f8e3312274fd16fb6b37a8210a1c3", "shasum": "" }, "require": { @@ -2837,8 +2837,8 @@ }, "require-dev": { "symfony/config": "~2.2", - "symfony/expression-language": "~2.4", - "symfony/yaml": "~2.0" + "symfony/expression-language": "~2.4,>=2.4.10", + "symfony/yaml": "~2.1" }, "suggest": { "symfony/config": "", @@ -2872,21 +2872,21 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "http://symfony.com", - "time": "2014-12-02 21:48:32" + "time": "2015-01-05 08:51:41" }, { "name": "symfony/event-dispatcher", - "version": "v2.6.1", + "version": "v2.6.3", "target-dir": "Symfony/Component/EventDispatcher", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "720fe9bca893df7ad1b4546649473b5afddf0216" + "reference": "40ff70cadea3785d83cac1c8309514b36113064e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/720fe9bca893df7ad1b4546649473b5afddf0216", - "reference": "720fe9bca893df7ad1b4546649473b5afddf0216", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/40ff70cadea3785d83cac1c8309514b36113064e", + "reference": "40ff70cadea3785d83cac1c8309514b36113064e", "shasum": "" }, "require": { @@ -2894,10 +2894,10 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~2.0", + "symfony/config": "~2.0,>=2.0.5", "symfony/dependency-injection": "~2.6", "symfony/expression-language": "~2.6", - "symfony/stopwatch": "~2.2" + "symfony/stopwatch": "~2.3" }, "suggest": { "symfony/dependency-injection": "", @@ -2930,21 +2930,21 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "http://symfony.com", - "time": "2014-12-02 20:19:20" + "time": "2015-01-05 14:28:40" }, { "name": "symfony/filesystem", - "version": "v2.5.8", + "version": "v2.5.9", "target-dir": "Symfony/Component/Filesystem", "source": { "type": "git", "url": "https://github.com/symfony/Filesystem.git", - "reference": "e5fc05a3a1dbb4ea0bed80fe7bd21ba3cab88c42" + "reference": "d3c24d7d6e9c342008d8421b2fade460311647ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/e5fc05a3a1dbb4ea0bed80fe7bd21ba3cab88c42", - "reference": "e5fc05a3a1dbb4ea0bed80fe7bd21ba3cab88c42", + "url": "https://api.github.com/repos/symfony/Filesystem/zipball/d3c24d7d6e9c342008d8421b2fade460311647ea", + "reference": "d3c24d7d6e9c342008d8421b2fade460311647ea", "shasum": "" }, "require": { @@ -2977,21 +2977,21 @@ ], "description": "Symfony Filesystem Component", "homepage": "http://symfony.com", - "time": "2014-12-02 20:15:53" + "time": "2015-01-03 21:04:44" }, { "name": "symfony/stopwatch", - "version": "v2.6.1", + "version": "v2.6.3", "target-dir": "Symfony/Component/Stopwatch", "source": { "type": "git", "url": "https://github.com/symfony/Stopwatch.git", - "reference": "261abd360cfb6ac65ea93ffd82073e2011d034fc" + "reference": "e8da5286132ba75ce4b4275fbf0f4cd369bfd71c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/261abd360cfb6ac65ea93ffd82073e2011d034fc", - "reference": "261abd360cfb6ac65ea93ffd82073e2011d034fc", + "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/e8da5286132ba75ce4b4275fbf0f4cd369bfd71c", + "reference": "e8da5286132ba75ce4b4275fbf0f4cd369bfd71c", "shasum": "" }, "require": { @@ -3024,7 +3024,7 @@ ], "description": "Symfony Stopwatch Component", "homepage": "http://symfony.com", - "time": "2014-12-02 20:19:20" + "time": "2015-01-03 08:01:59" } ], "aliases": [], diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php index beca884c7f913..73a211911de8d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php @@ -14,16 +14,10 @@ public function testCreate() ->expects($this->once()) ->method('get') ->with('Magento\Framework\Math\Random') - ->will( - $this->returnValue( - $this->getMockBuilder('Magento\Framework\Math\Random') - ->disableOriginalConstructor() - ->getMock() - ) - ); + ->will($this->returnValue($this->getMock('Magento\Framework\Math\Random'))); $adminAccountFactory = new AdminAccountFactory($serviceLocatorMock); $adminAccount = $adminAccountFactory->create( - $this->getMockBuilder('Magento\Setup\Module\Setup')->disableOriginalConstructor()->getMock(), + $this->getMock('Magento\Setup\Module\Setup', [], [], '', false), [] ); $this->assertInstanceOf('Magento\Setup\Model\AdminAccount', $adminAccount); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php index 3a28731cdb35b..59e32f36e1c57 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php @@ -8,17 +8,17 @@ class AdminAccountTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Module\Setup */ private $setUpMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Adapter\Pdo\Mysql */ private $dbAdapterMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Math\Random */ private $randomMock; @@ -29,15 +29,9 @@ class AdminAccountTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->setUpMock = $this->getMockBuilder('Magento\Setup\Module\Setup') - ->disableOriginalConstructor() - ->setMethods(['getConnection', 'getTable']) - ->getMock(); + $this->setUpMock = $this->getMock('Magento\Setup\Module\Setup', [], [], '', false); - $this->dbAdapterMock = $this->getMockBuilder('Magento\Framework\DB\Adapter\Pdo\Mysql') - ->disableOriginalConstructor() - ->setMethods(['fetchRow', 'update', 'insert', 'quoteInto', 'lastInsertId']) - ->getMock(); + $this->dbAdapterMock = $this->getMock('Magento\Framework\DB\Adapter\Pdo\Mysql', [], [], '', false); $this->setUpMock ->expects($this->any()) @@ -49,7 +43,7 @@ public function setUp() ->method('getTable') ->will($this->returnCallback(function ($table) {return $table;})); - $this->randomMock = $this->getMock('Magento\Framework\Math\Random', ['getRandomString']); + $this->randomMock = $this->getMock('Magento\Framework\Math\Random'); $this->randomMock->expects($this->any())->method('getRandomString')->will($this->returnValue('salt')); $data = [ @@ -66,45 +60,43 @@ public function setUp() public function testSaveUserExistsAdminRoleExists() { // existing user data - $result = [ + $existingUserData = [ 'email' => 'john.doe@test.com', 'username' => 'admin', 'user_id' => 1, ]; - $this->dbAdapterMock - ->expects($this->at(0)) - ->method('fetchRow') - ->will($this->returnValue($result)); - - $this->dbAdapterMock - ->expects($this->once()) - ->method('quoteInto') - ->will($this->returnValue('')); - - $this->dbAdapterMock - ->expects($this->once()) - ->method('update') - ->will($this->returnValue(1)); - // existing admin role data - $this->dbAdapterMock - ->expects($this->at(3)) - ->method('fetchRow') - ->will($this->returnValue([ - 'parent_id' => 0, - 'tree_level' => 2, - 'role_type' => 'U', - 'user_id' => 1, - 'user_type' => 2, - 'role_name' => 'admin', - 'role_id' => 1, - ])); + $existingAdminRoleData = [ + 'parent_id' => 0, + 'tree_level' => 2, + 'role_type' => 'U', + 'user_id' => 1, + 'user_type' => 2, + 'role_name' => 'admin', + 'role_id' => 1, + ]; + + $returnValueMap = [ + [ + 'SELECT user_id, username, email FROM admin_user WHERE username = :username OR email = :email', + ['username' => 'admin', 'email' => 'john.doe@test.com'], + null, + $existingUserData, + ], + [ + 'SELECT * FROM authorization_role WHERE user_id = :user_id', + ['user_id' => 1], + null, + $existingAdminRoleData, + ], + ]; + $this->dbAdapterMock->expects($this->any())->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock->expects($this->once())->method('quoteInto')->will($this->returnValue('')); + $this->dbAdapterMock->expects($this->once())->method('update')->will($this->returnValue(1)); // should never insert new row - $this->dbAdapterMock - ->expects($this->never()) - ->method('insert'); + $this->dbAdapterMock->expects($this->never())->method('insert'); $this->adminAccount->save(); } @@ -112,46 +104,56 @@ public function testSaveUserExistsAdminRoleExists() public function testSaveUserExistsNewAdminRole() { // existing user data - $result = [ + $existingUserData = [ 'email' => 'john.doe@test.com', 'username' => 'admin', 'user_id' => 1, ]; - $this->dbAdapterMock - ->expects($this->at(0)) - ->method('fetchRow') - ->will($this->returnValue($result)); - - $this->dbAdapterMock - ->expects($this->once()) - ->method('quoteInto') - ->will($this->returnValue('')); - - $this->dbAdapterMock - ->expects($this->once()) - ->method('update') - ->will($this->returnValue(1)); + // speical admin role data + $administratorRoleData = [ + 'parent_id' => 0, + 'tree_level' => 1, + 'role_type' => 'G', + 'user_id' => 0, + 'user_type' => 2, + 'role_name' => 'Administrators', + 'role_id' => 0, + ]; - // no admin role found - $this->dbAdapterMock - ->expects($this->at(3)) - ->method('fetchRow') - ->will($this->returnValue([])); + $returnValueMap = [ + [ + 'SELECT user_id, username, email FROM admin_user WHERE username = :username OR email = :email', + ['username' => 'admin', 'email' => 'john.doe@test.com'], + null, + $existingUserData, + ], + [ + 'SELECT * FROM authorization_role WHERE user_id = :user_id', + ['user_id' => 1], + null, + [], + ], + [ + 'SELECT * FROM authorization_role WHERE parent_id = :parent_id AND tree_level = :tree_level ' . + 'AND role_type = :role_type AND user_id = :user_id ' . + 'AND user_type = :user_type AND role_name = :role_name', + [ + 'parent_id' => 0, + 'tree_level' => 1, + 'role_type' => 'G', + 'user_id' => 0, + 'user_type' => 2, + 'role_name' => 'Administrators', + ], + null, + $administratorRoleData, + ], + ]; - // Special admin role created by data fixture - $this->dbAdapterMock - ->expects($this->at(4)) - ->method('fetchRow') - ->will($this->returnValue([ - 'parent_id' => 0, - 'tree_level' => 1, - 'role_type' => 'G', - 'user_id' => 0, - 'user_type' => 2, - 'role_name' => 'Administrators', - 'role_id' => 0, - ])); + $this->dbAdapterMock->expects($this->any())->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock->expects($this->once())->method('quoteInto')->will($this->returnValue('')); + $this->dbAdapterMock->expects($this->once())->method('update')->will($this->returnValue(1)); // should only insert once (admin role) $this->dbAdapterMock @@ -163,78 +165,91 @@ public function testSaveUserExistsNewAdminRole() public function testSaveNewUserAdminRoleExists() { - // no existing user - $this->dbAdapterMock - ->expects($this->at(0)) - ->method('fetchRow') - ->will($this->returnValue([])); + // existing admin role data + $existingAdminRoleData = [ + 'parent_id' => 0, + 'tree_level' => 2, + 'role_type' => 'U', + 'user_id' => 1, + 'user_type' => 2, + 'role_name' => 'admin', + 'role_id' => 1, + ]; - // insert only once (new user) - $this->dbAdapterMock - ->expects($this->once()) - ->method('insert'); + $returnValueMap = [ + [ + 'SELECT user_id, username, email FROM admin_user WHERE username = :username OR email = :email', + ['username' => 'admin', 'email' => 'john.doe@test.com'], + null, + [], + ], + [ + 'SELECT * FROM authorization_role WHERE user_id = :user_id', + ['user_id' => 1], + null, + $existingAdminRoleData, + ], + ]; + $this->dbAdapterMock->expects($this->any())->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + // insert only once (new user) + $this->dbAdapterMock->expects($this->once())->method('insert'); // after inserting new user - $this->dbAdapterMock - ->expects($this->once()) - ->method('lastInsertId') - ->will($this->returnValue(1)); - - // existing admin role data - $this->dbAdapterMock - ->expects($this->at(3)) - ->method('fetchRow') - ->will($this->returnValue([ - 'parent_id' => 0, - 'tree_level' => 2, - 'role_type' => 'U', - 'user_id' => 1, - 'user_type' => 2, - 'role_name' => 'admin', - 'role_id' => 1, - ])); + $this->dbAdapterMock->expects($this->once())->method('lastInsertId')->will($this->returnValue(1)); $this->adminAccount->save(); } public function testSaveNewUserNewAdminRole() { - // no existing user - $this->dbAdapterMock - ->expects($this->at(0)) - ->method('fetchRow') - ->will($this->returnValue([])); + // special admin role data + $administratorRoleData = [ + 'parent_id' => 0, + 'tree_level' => 1, + 'role_type' => 'G', + 'user_id' => 0, + 'user_type' => 2, + 'role_name' => 'Administrators', + 'role_id' => 0, + ]; - // after inserting new user - $this->dbAdapterMock - ->expects($this->once()) - ->method('lastInsertId') - ->will($this->returnValue(1)); + $returnValueMap = [ + [ + 'SELECT user_id, username, email FROM admin_user WHERE username = :username OR email = :email', + ['username' => 'admin', 'email' => 'john.doe@test.com'], + null, + [], + ], + [ + 'SELECT * FROM authorization_role WHERE user_id = :user_id', + ['user_id' => 1], + null, + [], + ], + [ + 'SELECT * FROM authorization_role WHERE parent_id = :parent_id AND tree_level = :tree_level ' . + 'AND role_type = :role_type AND user_id = :user_id ' . + 'AND user_type = :user_type AND role_name = :role_name', + [ + 'parent_id' => 0, + 'tree_level' => 1, + 'role_type' => 'G', + 'user_id' => 0, + 'user_type' => 2, + 'role_name' => 'Administrators', + ], + null, + $administratorRoleData, + ] - // no existing admin role - $this->dbAdapterMock - ->expects($this->at(3)) - ->method('fetchRow') - ->will($this->returnValue([])); + ]; - // Special admin role created by data fixture - $this->dbAdapterMock - ->expects($this->at(4)) - ->method('fetchRow') - ->will($this->returnValue([ - 'parent_id' => 0, - 'tree_level' => 2, - 'role_type' => 'U', - 'user_id' => 1, - 'user_type' => 2, - 'role_name' => 'admin', - 'role_id' => 1, - ])); - - // insert twice once (new user and new admin role) - $this->dbAdapterMock - ->expects($this->exactly(2)) - ->method('insert'); + $this->dbAdapterMock->expects($this->any())->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + // after inserting new user + $this->dbAdapterMock->expects($this->once())->method('lastInsertId')->will($this->returnValue(1)); + + // insert twice only (new user and new admin role) + $this->dbAdapterMock->expects($this->exactly(2))->method('insert'); $this->adminAccount->save(); } @@ -246,24 +261,15 @@ public function testSaveNewUserNewAdminRole() public function testSaveExceptionUsernameNotMatch() { // existing user in db - $result = [ + $existingUserData = [ 'email' => 'john.doe@test.com', 'username' => 'Another.name', ]; - $this->dbAdapterMock - ->expects($this->once()) - ->method('fetchRow') - ->will($this->returnValue($result)); - + $this->dbAdapterMock->expects($this->once())->method('fetchRow')->will($this->returnValue($existingUserData)); // should not alter db - $this->dbAdapterMock - ->expects($this->never()) - ->method('update'); - - $this->dbAdapterMock - ->expects($this->never()) - ->method('insert'); + $this->dbAdapterMock->expects($this->never())->method('update'); + $this->dbAdapterMock->expects($this->never())->method('insert'); $this->adminAccount->save(); } @@ -274,24 +280,15 @@ public function testSaveExceptionUsernameNotMatch() */ public function testSaveExceptionEmailNotMatch() { - $result = [ + $existingUserData = [ 'email' => 'another.email@test.com', 'username' => 'admin', ]; - $this->dbAdapterMock - ->expects($this->once()) - ->method('fetchRow') - ->will($this->returnValue($result)); - + $this->dbAdapterMock->expects($this->once())->method('fetchRow')->will($this->returnValue($existingUserData)); // should not alter db - $this->dbAdapterMock - ->expects($this->never()) - ->method('update'); - - $this->dbAdapterMock - ->expects($this->never()) - ->method('insert'); + $this->dbAdapterMock->expects($this->never())->method('update'); + $this->dbAdapterMock->expects($this->never())->method('insert'); $this->adminAccount->save(); } @@ -303,10 +300,7 @@ public function testSaveExceptionEmailNotMatch() public function testSaveExceptionSpecialAdminRoleNotFound() { $this->dbAdapterMock->expects($this->once())->method('lastInsertId')->will($this->returnValue(1)); - $this->dbAdapterMock - ->expects($this->exactly(3)) - ->method('fetchRow') - ->will($this->returnValue([])); + $this->dbAdapterMock->expects($this->exactly(3))->method('fetchRow')->will($this->returnValue([])); $this->adminAccount->save(); } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php index d97e7e9103c72..6eb4721253445 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php @@ -10,17 +10,17 @@ class FilePermissionsTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem\Directory\Write */ private $directoryWriteMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem */ private $filesystemMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Filesystem\DirectoryList */ private $directoryListMock; @@ -31,22 +31,15 @@ class FilePermissionsTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->directoryWriteMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Write') - ->disableOriginalConstructor() - ->setMethods(['isWritable', 'isExist', 'isDirectory', 'isReadable']) - ->getMock(); - $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') - ->disableOriginalConstructor() - ->setMethods(['getDirectoryWrite']) - ->getMock(); + $this->directoryWriteMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false); + $this->filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); + $this->filesystemMock ->expects($this->any()) ->method('getDirectoryWrite') ->will($this->returnValue($this->directoryWriteMock)); - $this->directoryListMock = $this->getMockBuilder('Magento\Framework\App\Filesystem\DirectoryList') - ->disableOriginalConstructor() - ->setMethods(['getPath']) - ->getMock(); + $this->directoryListMock = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); + $this->filePermissions = new FilePermissions($this->filesystemMock, $this->directoryListMock); } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressFactoryTest.php index 622915bfe2595..11c8d0c63b8d3 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressFactoryTest.php @@ -17,7 +17,7 @@ public function testCreateFromLog() '[Progress: 3 / 5] Installing C...', 'Output from C...', ]; - $logger = $this->getMockBuilder('Magento\Setup\Model\WebLogger')->disableOriginalConstructor()->getMock(); + $logger = $this->getMock('Magento\Setup\Model\WebLogger', [], [], '', false); $logger->expects($this->once())->method('get')->will($this->returnValue($contents)); $progressFactory = new ProgressFactory(); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php index 0b9a923ede84d..3b61cbef767c7 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php @@ -72,13 +72,28 @@ public function testGetTotal() $this->assertEquals(10, $progress->getTotal()); } - public function testRatio() + /** + * @param int $total + * @param int $current + * @dataProvider ratioDataProvider + */ + public function testRatio($total, $current) + { + $progress = new Progress($total, $current); + $this->assertEquals($current / $total, $progress->getRatio()); + } + + /** + * @return array + */ + public function ratioDataProvider() { + $data = []; for ($i = 10; $i <= 20; $i++) { for ($j = 0; $j <= $i; $j++) { - $progress = new Progress($i, $j); - $this->assertEquals($j / $i, $progress->getRatio()); + $data[] = [$i, $j]; } } + return $data; } } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php index 7fb890fe96ade..cbda233d9e4f5 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php @@ -11,109 +11,66 @@ class InstallerFactoryTest Extends \PHPUnit_Framework_TestCase { public function testCreate() { + $returnValueMap = [ + [InitParamListener::BOOTSTRAP_PARAM, []], + [ + 'Magento\Setup\Model\FilePermissions', + $this->getMock('Magento\Setup\Model\FilePermissions', [], [], '', false), + ], + [ + 'Magento\Framework\App\DeploymentConfig\Writer', + $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false), + ], + [ + 'Magento\Framework\App\DeploymentConfig', + $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false), + ], + [ + 'Magento\Setup\Module\SetupFactory', + $this->getMock('Magento\Setup\Module\SetupFactory', [], [], '', false), + ], + [ + 'Magento\Framework\Module\ModuleList', + $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false), + ], + [ + '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), + ], + [ + 'Magento\Framework\App\MaintenanceMode', + $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false), + ], + [ + 'Magento\Framework\Filesystem', + $this->getMock('Magento\Framework\Filesystem', [], [], '', false), + ], + [ + 'Magento\Setup\Model\SampleData', + $this->getMock('Magento\Setup\Model\SampleData', [], [], '', false), + ], + ]; $serviceLocatorMock = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); $serviceLocatorMock - ->expects($this->at(0)) + ->expects($this->any()) ->method('get') - ->with(InitParamListener::BOOTSTRAP_PARAM) - ->willReturn([]); - $serviceLocatorMock - ->expects($this->at(1)) - ->method('get') - ->with('Magento\Setup\Model\FilePermissions') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Setup\Model\FilePermissions')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(2)) - ->method('get') - ->with('Magento\Framework\App\DeploymentConfig\Writer') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Framework\App\DeploymentConfig\Writer')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(3)) - ->method('get') - ->with('Magento\Framework\App\DeploymentConfig') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Framework\App\DeploymentConfig')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(4)) - ->method('get') - ->with('Magento\Setup\Module\SetupFactory') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Setup\Module\SetupFactory')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(5)) - ->method('get') - ->with('Magento\Framework\Module\ModuleList') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Framework\Module\ModuleList')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(6)) - ->method('get') - ->with('Magento\Framework\Module\ModuleList\Loader') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Framework\Module\ModuleList\Loader') - ->disableOriginalConstructor() - ->getMock() - )); - $serviceLocatorMock - ->expects($this->at(7)) - ->method('get') - ->with('Magento\Framework\App\Filesystem\DirectoryList') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Framework\App\Filesystem\DirectoryList') - ->disableOriginalConstructor() - ->getMock() - )); - $serviceLocatorMock - ->expects($this->at(8)) - ->method('get') - ->with('Magento\Setup\Model\AdminAccountFactory') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Setup\Model\AdminAccountFactory') - ->disableOriginalConstructor() - ->getMock() - )); - $serviceLocatorMock - ->expects($this->at(9)) - ->method('get') - ->with('Magento\Framework\Math\Random') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Framework\Math\Random')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(10)) - ->method('get') - ->with('Magento\Setup\Module\ConnectionFactory') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Setup\Module\ConnectionFactory')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(11)) - ->method('get') - ->with('Magento\Framework\App\MaintenanceMode') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Framework\App\MaintenanceMode')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(12)) - ->method('get') - ->with('Magento\Framework\Filesystem') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Framework\Filesystem')->disableOriginalConstructor()->getMock() - )); - $serviceLocatorMock - ->expects($this->at(13)) - ->method('get') - ->with('Magento\Setup\Model\SampleData') - ->will($this->returnValue( - $this->getMockBuilder('Magento\Setup\Model\SampleData')->disableOriginalConstructor()->getMock() - )); + ->will($this->returnValueMap($returnValueMap)); $log = $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface'); $installerFactory = new InstallerFactory($serviceLocatorMock); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php index 4b208564d8b8a..06901f09df6f9 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php @@ -8,25 +8,19 @@ class LicenseTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem\Directory\Read */ private $directoryReadMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem */ private $filesystemMock; public function setUp() { - $this->directoryReadMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Read') - ->disableOriginalConstructor() - ->setMethods(['readFile', 'isFile']) - ->getMock(); - $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') - ->disableOriginalConstructor() - ->setMethods(['getDirectoryRead']) - ->getMock(); + $this->directoryReadMock = $this->getMock('Magento\Framework\Filesystem\Directory\Read', [], [], '', false); + $this->filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); $this->filesystemMock ->expects($this->once()) ->method('getDirectoryRead') @@ -39,7 +33,7 @@ public function testGetContents() ->expects($this->once()) ->method('readFile') ->with(License::LICENSE_FILENAME) - ->will($this->returnValue(file_get_contents(BP . '/' . License::LICENSE_FILENAME))); + ->will($this->returnValue('License text')); $this->directoryReadMock ->expects($this->once()) ->method('isFile') @@ -47,7 +41,7 @@ public function testGetContents() ->will($this->returnValue(true)); $license = new License($this->filesystemMock); - $this->assertSame(file_get_contents(BP . '/' . License::LICENSE_FILENAME), $license->getContents()); + $this->assertSame('License text', $license->getContents()); } public function testGetContentsNoFile() diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/NavigationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/NavigationTest.php index 4ce356e644524..98298c3f46115 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/NavigationTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/NavigationTest.php @@ -8,7 +8,7 @@ class NavigationTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Zend\ServiceManager\ServiceLocatorInterface */ private $serviceLocatorMock; diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/PhpInformationTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/PhpInformationTest.php index 9910e30df3c72..8114a88a3cbed 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/PhpInformationTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/PhpInformationTest.php @@ -8,25 +8,19 @@ class PhpInformationTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem\Directory\Read */ private $directoryReadMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem */ private $filesystemMock; public function setUp() { - $this->directoryReadMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Read') - ->disableOriginalConstructor() - ->setMethods(['isExist', 'readFile']) - ->getMock(); - $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') - ->disableOriginalConstructor() - ->setMethods(['getDirectoryRead']) - ->getMock(); + $this->directoryReadMock = $this->getMock('Magento\Framework\Filesystem\Directory\Read', [], [], '', false); + $this->filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); $this->filesystemMock ->expects($this->once()) ->method('getDirectoryRead') @@ -43,10 +37,10 @@ public function testGetRequiredPhpVersion() ->expects($this->once()) ->method('readFile') ->with('composer.lock') - ->will($this->returnValue('{"platform":{"php":"~5.4.11|~5.5.0"}}')); + ->will($this->returnValue('{"platform":{"php":"~a.b.c|~a.e.f"}}')); $phpInfo = new PhpInformation($this->filesystemMock); - $this->assertEquals("~5.4.11|~5.5.0", $phpInfo->getRequiredPhpVersion()); + $this->assertEquals("~a.b.c|~a.e.f", $phpInfo->getRequiredPhpVersion()); } /** diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php index 28302a9ce191d..83dd1773cb7cf 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php @@ -57,6 +57,32 @@ public function getConfigDataDataProvider() Url::XML_PATH_USE_SECURE_KEY => '1', ], ], + 'valid alphabet url' => [ + [ + UserConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => '1', + UserConfigurationDataMapper::KEY_BASE_URL => 'http://example.com/', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://example.com/', + UserConfigurationDataMapper::KEY_CURRENCY => 'USD', + UserConfigurationDataMapper::KEY_IS_SECURE => '1', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + UserConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + UserConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + UserConfigurationDataMapper::KEY_USE_SEF_URL => '1', + ], + [ + Store::XML_PATH_USE_REWRITES => '1', + Store::XML_PATH_UNSECURE_BASE_URL => 'http://example.com/', + Store::XML_PATH_SECURE_IN_FRONTEND => '1', + Store::XML_PATH_SECURE_BASE_URL => 'https://example.com/', + Store::XML_PATH_SECURE_IN_ADMINHTML => '1', + Data::XML_PATH_DEFAULT_LOCALE => 'en_US', + Data::XML_PATH_DEFAULT_TIMEZONE => 'America/Chicago', + Currency::XML_PATH_CURRENCY_BASE => 'USD', + Currency::XML_PATH_CURRENCY_DEFAULT => 'USD', + Currency::XML_PATH_CURRENCY_ALLOW => 'USD', + Url::XML_PATH_USE_SECURE_KEY => '1', + ], + ], 'no trailing slash' => [ [ @@ -84,6 +110,33 @@ public function getConfigDataDataProvider() Url::XML_PATH_USE_SECURE_KEY => '1', ], ], + 'no trailing slash, alphabet url' => + [ + [ + UserConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => '1', + UserConfigurationDataMapper::KEY_BASE_URL => 'http://example.com', + UserConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://example.com', + UserConfigurationDataMapper::KEY_CURRENCY => 'USD', + UserConfigurationDataMapper::KEY_IS_SECURE => '1', + UserConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + UserConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + UserConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + UserConfigurationDataMapper::KEY_USE_SEF_URL => '1', + ], + [ + Store::XML_PATH_USE_REWRITES => '1', + Store::XML_PATH_UNSECURE_BASE_URL => 'http://example.com/', + Store::XML_PATH_SECURE_IN_FRONTEND => '1', + Store::XML_PATH_SECURE_BASE_URL => 'https://example.com/', + Store::XML_PATH_SECURE_IN_ADMINHTML => '1', + Data::XML_PATH_DEFAULT_LOCALE => 'en_US', + Data::XML_PATH_DEFAULT_TIMEZONE => 'America/Chicago', + Currency::XML_PATH_CURRENCY_BASE => 'USD', + Currency::XML_PATH_CURRENCY_DEFAULT => 'USD', + Currency::XML_PATH_CURRENCY_ALLOW => 'USD', + Url::XML_PATH_USE_SECURE_KEY => '1', + ], + ], 'is_secure, is_secure_admin set but no secure base url' => [ [ diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php index 474ad540c8b89..1e2d7418475f9 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php @@ -8,12 +8,12 @@ class WebLoggerTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem\Directory\Write */ private $directoryWriteMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem */ private $filesystemMock; @@ -31,27 +31,23 @@ public function setUp() { self::$log = ''; - $this->directoryWriteMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Read') - ->disableOriginalConstructor() - ->setMethods(['readFile', 'writeFile', 'delete', 'isExist']) - ->getMock(); + $this->directoryWriteMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false); $this->directoryWriteMock ->expects($this->any()) ->method('readFile') + ->with('install.log') ->will($this->returnCallback(['Magento\Setup\Model\WebLoggerTest', 'readLog'])); $this->directoryWriteMock ->expects($this->any()) ->method('writeFile') + ->with('install.log') ->will($this->returnCallback(['Magento\Setup\Model\WebLoggerTest', 'writeToLog'])); $this->directoryWriteMock ->expects($this->any()) ->method('isExist') ->will($this->returnCallback(['Magento\Setup\Model\WebLoggerTest', 'isExist'])); - $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') - ->disableOriginalConstructor() - ->setMethods(['getDirectoryWrite']) - ->getMock(); + $this->filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); $this->filesystemMock ->expects($this->once()) ->method('getDirectoryWrite') @@ -60,6 +56,30 @@ public function setUp() $this->webLogger = new WebLogger($this->filesystemMock); } + public function testConstructorLogFileSpecified() + { + $logFile = 'custom.log'; + $directoryWriteMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false); + $directoryWriteMock->expects($this->once()) + ->method('readFile') + ->with($logFile); + $directoryWriteMock + ->expects($this->once()) + ->method('writeFile') + ->with($logFile); + + $filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); + $filesystemMock + ->expects($this->once()) + ->method('getDirectoryWrite') + ->will($this->returnValue($directoryWriteMock)); + + $webLogger = new WebLogger($filesystemMock, $logFile); + + $webLogger->log('Message'); + $webLogger->get(); + } + public function testLogSuccess() { $this->webLogger->logSuccess('Success1'); From 1e6b07070637ae6a463fee5ac064809291373504 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Mon, 12 Jan 2015 18:27:54 -0600 Subject: [PATCH 27/89] MAGETWO-32091: Setup "Module" Models Unit Test Coverage - Covered more classes for unit tests. --- composer.lock | 3 +- .../Setup/Module/ConnectionFactoryTest.php | 41 ++++++++++++ .../Setup/Module/ResourceFactoryTest.php | 34 ++++++++++ .../Magento/Setup/Module/SetupFactoryTest.php | 59 ++++++++++++++++++ .../Magento/Setup/Module/SetupTest.php | 62 +++++++++++++++++++ 5 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/ConnectionFactoryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/ResourceFactoryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/SetupFactoryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/SetupTest.php diff --git a/composer.lock b/composer.lock index 8c52e3e0c5bfd..3591be422aa54 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": "608b2d952440f602fcfef93ee0ac3a09", + "hash": "6d527b7aedb6e335fb6cf3a913ee75e7", "packages": [ { "name": "composer/composer", @@ -3034,7 +3034,6 @@ "phpmd/phpmd": 0 }, "prefer-stable": false, - "prefer-lowest": false, "platform": { "php": "~5.4.11|~5.5.0" }, diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/ConnectionFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/ConnectionFactoryTest.php new file mode 100644 index 0000000000000..b35329d6e77ac --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/ConnectionFactoryTest.php @@ -0,0 +1,41 @@ +getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); + $this->connectionFactory = new ConnectionFactory($serviceLocatorMock); + } + + /** + * @param array $config + * @dataProvider dataProviderCreateNoActiveConfig + */ + public function testCreateNoActiveConfig($config) + { + $this->assertNull($this->connectionFactory->create($config)); + } + + /** + * @return array + */ + public function dataProviderCreateNoActiveConfig() + { + return [ + [[]], + [['value']], + [['active' => 0]], + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/ResourceFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/ResourceFactoryTest.php new file mode 100644 index 0000000000000..1a8f4e48b7733 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/ResourceFactoryTest.php @@ -0,0 +1,34 @@ +getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); + $connectionFactory = new ConnectionFactory($serviceLocatorMock); + $serviceLocatorMock + ->expects($this->once()) + ->method('get') + ->with('Magento\Setup\Module\ConnectionFactory') + ->will($this->returnValue($connectionFactory)); + $this->resourceFactory = new ResourceFactory($serviceLocatorMock); + } + + public function testCreate() + { + $resource = $this->resourceFactory->create( + $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false) + ); + $this->assertInstanceOf('Magento\Framework\App\Resource', $resource); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupFactoryTest.php new file mode 100644 index 0000000000000..304a8187902c7 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupFactoryTest.php @@ -0,0 +1,59 @@ +getMock('Magento\Framework\Module\ModuleList', [], [], '', false), + ], + [ + 'Magento\Setup\Module\Setup\FileResolver', + $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false), + ], + [ + 'Magento\Framework\App\DeploymentConfig\Reader', + $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false), + ], + ]; + + $serviceLocatorMock = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); + $serviceLocatorMock + ->expects($this->any()) + ->method('get') + ->will($this->returnValueMap($returnValueMap)); + $resourceFactory = $this->getMock('Magento\Setup\Module\ResourceFactory', [], [], '', false); + $resourceFactory + ->expects($this->any()) + ->method('create') + ->will($this->returnValue($this->getMock('Magento\Framework\App\Resource', [], [], '', false))); + $this->setupFactory = new SetupFactory($serviceLocatorMock, $resourceFactory); + } + + public function testCreateSetup() + { + $setup = $this->setupFactory->createSetup(); + $this->assertInstanceOf('Magento\Setup\Module\Setup', $setup); + } + + public function testCreateSetupModule() + { + $setup = $this->setupFactory->createSetupModule( + $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface'), + 'sampleModuleName' + ); + $this->assertInstanceOf('Magento\Setup\Module\Setup', $setup); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupTest.php new file mode 100644 index 0000000000000..ea9ead5c29519 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupTest.php @@ -0,0 +1,62 @@ +getMock('\Magento\Framework\App\Resource', [], [], '', false); + $this->connection = $this->getMockForAbstractClass('\Magento\Framework\DB\Adapter\AdapterInterface'); + $resourceModel->expects($this->any()) + ->method('getConnection') + ->with(self::CONNECTION_NAME) + ->will($this->returnValue($this->connection)); + $this->setup = new Setup($resourceModel, self::CONNECTION_NAME); + } + + public function testGetIdxName() + { + $tableName = 'table'; + $fields = ['field']; + $indexType = 'index_type'; + $expectedIdxName = 'idxName'; + + $this->connection->expects($this->once()) + ->method('getIndexName') + ->with($tableName, $fields, $indexType) + ->will($this->returnValue($expectedIdxName)); + + $this->assertEquals('idxName', $this->setup->getIdxName($tableName, $fields, $indexType)); + } + + public function testGetFkName() + { + $tableName = 'table'; + $refTable = 'ref_table'; + $columnName = 'columnName'; + $refColumnName = 'refColumnName'; + + $this->connection->expects($this->once()) + ->method('getForeignKeyName') + ->with($tableName, $columnName, $refTable, $refColumnName) + ->will($this->returnValue('fkName')); + + $this->assertEquals('fkName', $this->setup->getFkName($tableName, $columnName, $refTable, $refColumnName)); + } +} From 61b93ab76615309f7db3c62836a8a2671c42b6d1 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Mon, 12 Jan 2015 15:18:12 -0600 Subject: [PATCH 28/89] MAGETWO-32089: Setup Models Unit Test Coverage - made changes according to CR --- .../Magento/Setup/Model/AdminAccountTest.php | 12 +++++------- .../testsuite/Magento/Setup/Model/WebLoggerTest.php | 9 ++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php index 59e32f36e1c57..164a18cd9ef3d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php @@ -91,7 +91,7 @@ public function testSaveUserExistsAdminRoleExists() $existingAdminRoleData, ], ]; - $this->dbAdapterMock->expects($this->any())->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock->expects($this->exactly(2))->method('fetchRow')->will($this->returnValueMap($returnValueMap)); $this->dbAdapterMock->expects($this->once())->method('quoteInto')->will($this->returnValue('')); $this->dbAdapterMock->expects($this->once())->method('update')->will($this->returnValue(1)); @@ -151,14 +151,12 @@ public function testSaveUserExistsNewAdminRole() ], ]; - $this->dbAdapterMock->expects($this->any())->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock->expects($this->exactly(3))->method('fetchRow')->will($this->returnValueMap($returnValueMap)); $this->dbAdapterMock->expects($this->once())->method('quoteInto')->will($this->returnValue('')); $this->dbAdapterMock->expects($this->once())->method('update')->will($this->returnValue(1)); // should only insert once (admin role) - $this->dbAdapterMock - ->expects($this->once()) - ->method('insert'); + $this->dbAdapterMock->expects($this->once())->method('insert'); $this->adminAccount->save(); } @@ -191,7 +189,7 @@ public function testSaveNewUserAdminRoleExists() ], ]; - $this->dbAdapterMock->expects($this->any())->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock->expects($this->exactly(2))->method('fetchRow')->will($this->returnValueMap($returnValueMap)); // insert only once (new user) $this->dbAdapterMock->expects($this->once())->method('insert'); // after inserting new user @@ -244,7 +242,7 @@ public function testSaveNewUserNewAdminRole() ]; - $this->dbAdapterMock->expects($this->any())->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock->expects($this->exactly(3))->method('fetchRow')->will($this->returnValueMap($returnValueMap)); // after inserting new user $this->dbAdapterMock->expects($this->once())->method('lastInsertId')->will($this->returnValue(1)); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php index 1e2d7418475f9..ee65c974e0536 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php @@ -60,13 +60,8 @@ public function testConstructorLogFileSpecified() { $logFile = 'custom.log'; $directoryWriteMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false); - $directoryWriteMock->expects($this->once()) - ->method('readFile') - ->with($logFile); - $directoryWriteMock - ->expects($this->once()) - ->method('writeFile') - ->with($logFile); + $directoryWriteMock->expects($this->once())->method('readFile')->with($logFile); + $directoryWriteMock->expects($this->once())->method('writeFile')->with($logFile); $filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); $filesystemMock From c50fd5181748376e79955f83afdd4e32197ae909 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 12 Jan 2015 17:01:55 -0600 Subject: [PATCH 29/89] MAGETWO-32090: Setup "Mvc" Models Unit Test Coverage - fixing test since it was system specific. --- .../Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php index 9b82557b88c1c..0d01fc9cd3ef9 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php @@ -72,7 +72,7 @@ public function testGetConsoleUsage() // First element should be blank line $this->assertEquals('', $usage[0]); // Only one parameter definition is added to usage statement - $this->assertContains('[--magento_init_params=""]', $usage[1][0]); + $this->assertContains(escapeshellarg('[--magento_init_params=\'\']'), escapeshellarg($usage[1][0])); } public function testAttach() From d106dcebc0585661a3ea93270e0feaa6e24d85ad Mon Sep 17 00:00:00 2001 From: Anton Makarenko Date: Mon, 12 Jan 2015 18:07:01 -0600 Subject: [PATCH 30/89] MAGETWO-32088: Setup "Installer" Model Unit Test Coverage - addressed CR notes - reverted erroneous logic change with encryption key in installer --- .../Magento/Setup/Model/InstallerTest.php | 96 ++++++++++++------- setup/src/Magento/Setup/Model/Installer.php | 7 +- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php index 0c4ed6c3063c9..a1814152dd102 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php @@ -135,21 +135,40 @@ protected function setUp() $this->adminFactory = $this->getMock('Magento\Setup\Model\AdminAccountFactory', [], [], '', false); $this->logger = $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface'); $this->random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); - $connectionFactory = $this->getMock('Magento\Setup\Module\ConnectionFactory', [], [], '', false); $this->connection = $this->getMockForAbstractClass('Magento\Framework\DB\Adapter\AdapterInterface'); - $connectionFactory->expects($this->any())->method('create')->willReturn($this->connection); $this->maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false); $this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); - $serviceLocator = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface'); - $serviceLocator->expects($this->once()) - ->method('get') - ->with(InitParamListener::BOOTSTRAP_PARAM) - ->willReturn([]); $this->sampleData = $this->getMock('Magento\Setup\Model\SampleData', [], [], '', false); - $objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); - $objectManagerFactory->expects($this->any())->method('create')->willReturn($this->objectManager); - $this->object = new Installer( + $this->object = $this->createObject(); + } + + /** + * Instantiates the object with mocks + * + * @param \PHPUnit_Framework_MockObject_MockObject|bool $connectionFactory + * @param \PHPUnit_Framework_MockObject_MockObject|bool $serviceLocator + * @param \PHPUnit_Framework_MockObject_MockObject|bool $objectManagerFactory + * @return Installer + */ + private function createObject($connectionFactory = false, $serviceLocator = false, $objectManagerFactory = false) + { + if (!$connectionFactory) { + $connectionFactory = $this->getMock('Magento\Setup\Module\ConnectionFactory', [], [], '', false); + $connectionFactory->expects($this->any())->method('create')->willReturn($this->connection); + } + if (!$serviceLocator) { + $serviceLocator = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface'); + $serviceLocator->expects($this->once()) + ->method('get') + ->with(InitParamListener::BOOTSTRAP_PARAM) + ->willReturn([]); + } + if (!$objectManagerFactory) { + $objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); + $objectManagerFactory->expects($this->any())->method('create')->willReturn($this->objectManager); + } + return new Installer( $this->filePermissions, $this->configWriter, $this->config, @@ -183,17 +202,17 @@ public function testInstall() [DbConfig::CONFIG_KEY, self::$dbConfig], [EncryptConfig::CONFIG_KEY, [EncryptConfig::KEY_ENCRYPTION_KEY => 'encryption_key']] ])); - $this->objectManager->expects($this->at(0)) - ->method('create') - ->with('Magento\Framework\Module\Updater') - ->willReturn($this->getMock('Magento\Framework\Module\Updater', [], [], '', false)); + $moduleUpdater = $this->getMock('Magento\Framework\Module\Updater', [], [], '', false); + $moduleUpdater->expects($this->once())->method('updateData'); $cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); $cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']); - $this->objectManager->expects($this->at(1)) + $this->objectManager->expects($this->any()) ->method('create') - ->with('Magento\Framework\App\Cache\Manager') - ->willReturn($cacheManager); + ->will($this->returnValueMap([ + ['Magento\Framework\Module\Updater', [], $moduleUpdater], + ['Magento\Framework\App\Cache\Manager', [], $cacheManager], + ])); $this->adminFactory->expects($this->once())->method('create')->willReturn( $this->getMock('Magento\Setup\Model\AdminAccount', [], [], '', false) ); @@ -221,11 +240,20 @@ public function testInstall() $this->object->install($request); } + public function testCheckInstallationFilePermissions() + { + $this->filePermissions + ->expects($this->once()) + ->method('getMissingWritableDirectoriesForInstallation') + ->willReturn([]); + $this->object->checkInstallationFilePermissions(); + } + /** * @expectedException \Exception * @expectedExceptionMessage Missing writing permissions to the following directories: 'foo' 'bar' */ - public function testCheckInstallationFilePermissions() + public function testCheckInstallationFilePermissionsError() { $this->filePermissions ->expects($this->once()) @@ -251,26 +279,18 @@ public function testUninstall() $this->config->expects($this->once())->method('isAvailable')->willReturn(false); $varDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $varDir->expects($this->once())->method('getAbsolutePath')->willReturn('/var'); - $this->filesystem - ->expects($this->at(0)) - ->method('getDirectoryWrite') - ->with(DirectoryList::VAR_DIR) - ->willReturn($varDir); $staticDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $staticDir->expects($this->once())->method('getAbsolutePath')->willReturn('/static'); - $this->filesystem - ->expects($this->at(1)) - ->method('getDirectoryWrite') - ->with(DirectoryList::STATIC_VIEW) - ->willReturn($staticDir); $configDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $configDir->expects($this->once())->method('getAbsolutePath')->willReturn('/config/config.php'); $this->filesystem - ->expects($this->at(2)) + ->expects($this->any()) ->method('getDirectoryWrite') - ->with(DirectoryList::CONFIG) - ->willReturn($configDir); - + ->will($this->returnValueMap([ + [DirectoryList::VAR_DIR, $varDir], + [DirectoryList::STATIC_VIEW, $staticDir], + [DirectoryList::CONFIG, $configDir], + ])); $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); $this->logger ->expects($this->at(1)) @@ -318,6 +338,18 @@ public function testCheckDatabaseConnection() $this->assertEquals(true, $this->object->checkDatabaseConnection('name', 'host', 'user', 'password')); } + /** + * @expectedException \Magento\Setup\Exception + * @expectedException Database connection failure. + */ + public function testCheckDatabaseConnectionFailed() + { + $connectionFactory = $this->getMock('Magento\Setup\Module\ConnectionFactory', [], [], '', false); + $connectionFactory->expects($this->once())->method('create')->willReturn(false); + $object = $this->createObject($connectionFactory); + $object->checkDatabaseConnection('name', 'host', 'user', 'password'); + } + /** * @expectedException \Magento\Setup\Exception * @expectedExceptionMessage Sorry, but we support MySQL version diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index d75846f95f317..62a82f7919f8f 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -361,14 +361,13 @@ private function createBackendConfig($data) * * @param \ArrayObject|array $data * @return \Magento\Framework\App\DeploymentConfig\SegmentInterface - * @throws \InvalidArgumentException */ private function createEncryptConfig($data) { - if (!isset($data[DeploymentConfigMapper::KEY_ENCRYPTION_KEY])) { - throw new \InvalidArgumentException("Missing key: '" . DeploymentConfigMapper::KEY_ENCRYPTION_KEY . "'"); + $key = ''; + if (isset($data[DeploymentConfigMapper::KEY_ENCRYPTION_KEY])) { + $key = $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); From 43301516a63993076f8671a84a408d49d125be8c Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 13 Jan 2015 11:49:19 -0600 Subject: [PATCH 31/89] MAGETWO-32087: Setup "Install" Controller Unit Test Coverage - minor change based on CR. --- .../unit/testsuite/Magento/Setup/Controller/InstallTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php index de453d6cbaa33..4080c35b303e0 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/InstallTest.php @@ -41,7 +41,7 @@ public function setUp() public function testIndexAction() { $viewModel = $this->controller->indexAction(); - $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); + $this->assertInstanceOf('\Zend\View\Model\ViewModel', $viewModel); $this->assertTrue($viewModel->terminate()); } From 499d5f0b29e666f2639a3feb9a68579548845d4e Mon Sep 17 00:00:00 2001 From: Anton Makarenko Date: Tue, 13 Jan 2015 19:19:26 -0600 Subject: [PATCH 32/89] MAGETWO-32606: Enable/Disable Modules for Existing Application - added ability to enable or disable modules via Setup CLI - performs routines of cache cleanup automatically --- .../Framework/App/State/CleanupTest.php | 100 ++++++++++++++ .../Magento/Framework/Module/StatusTest.php | 71 ++++++++++ .../Controller/ConsoleControllerTest.php | 81 +++++++++++- .../Setup/Model/InstallerFactoryTest.php | 7 +- .../Magento/Setup/Model/InstallerTest.php | 13 +- .../Magento/Framework/App/State/Cleanup.php | 106 +++++++++++++++ .../Magento/Framework/Module/Status.php | 125 ++++++++++++++++++ .../Setup/Controller/ConsoleController.php | 77 ++++++++++- setup/src/Magento/Setup/Model/Installer.php | 15 +-- .../Magento/Setup/Model/InstallerFactory.php | 6 +- .../Setup/Model/ObjectManagerFactory.php | 43 ++++++ 11 files changed, 608 insertions(+), 36 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php create mode 100644 lib/internal/Magento/Framework/App/State/Cleanup.php create mode 100644 lib/internal/Magento/Framework/Module/Status.php create mode 100644 setup/src/Magento/Setup/Model/ObjectManagerFactory.php diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php new file mode 100644 index 0000000000000..7aa89f89b3e18 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php @@ -0,0 +1,100 @@ +cachePool = $this->getMock('Magento\Framework\App\Cache\Frontend\Pool', [], [], '', false); + $this->cache = [ + $this->getMockForAbstractClass('Magento\Framework\Cache\FrontendInterface'), + $this->getMockForAbstractClass('Magento\Framework\Cache\FrontendInterface'), + ]; + $this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); + $this->object = new Cleanup($this->cachePool, $this->filesystem); + } + + public function testClearCaches() + { + $this->mockCachePoolIterator(); + $this->cache[0]->expects($this->once())->method('clean'); + $this->cache[1]->expects($this->once())->method('clean'); + $this->object->clearCaches(); + } + + /** + * Mocks cache pool iteration through 2 items + * + * @return void + */ + private function mockCachePoolIterator() + { + $this->cachePool->expects($this->any())->method('valid')->will($this->onConsecutiveCalls(true, true, false)); + $this->cachePool->expects($this->any()) + ->method('current') + ->will($this->onConsecutiveCalls($this->cache[0], $this->cache[1])); + } + + public function testClearCodeGeneratedClasses() + { + $dir = $this->getDirectoryCleanMock(); + $this->filesystem->expects($this->once()) + ->method('getDirectoryWrite') + ->with(DirectoryList::GENERATION) + ->willReturn($dir); + $this->object->clearCodeGeneratedClasses(); + } + + public function testClearMaterializedViewFiles() + { + $static = $this->getDirectoryCleanMock(); + $var = $this->getDirectoryCleanMock(Source::TMP_MATERIALIZATION_DIR); + $this->filesystem->expects($this->exactly(2))->method('getDirectoryWrite')->will($this->returnValueMap([ + [DirectoryList::STATIC_VIEW, $static], + [DirectoryList::VAR_DIR, $var], + ])); + $this->object->clearMaterializedViewFiles(); + } + + /** + * Gets a mock of directory with expectation to be cleaned + * + * @param string|null $subPath + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function getDirectoryCleanMock($subPath = null) + { + $dir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); + $dir->expects($this->once())->method('search')->with('*', $subPath)->willReturn(['one', 'two']); + $dir->expects($this->exactly(2))->method('delete'); + return $dir; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php new file mode 100644 index 0000000000000..6587cbf75c43d --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php @@ -0,0 +1,71 @@ +loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); + $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $this->writer = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); + $this->cleanup = $this->getMock('Magento\Framework\App\State\Cleanup', [], [], '', false); + $this->object = new Status($this->loader, $this->moduleList, $this->writer, $this->cleanup); + } + + public function testSetEnabled() + { + $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; + $this->loader->expects($this->once())->method('load')->willReturn($modules); + $this->moduleList->expects($this->once())->method('has')->with('Module_Baz'); + $constraint = new \PHPUnit_Framework_Constraint_IsInstanceOf( + 'Magento\Framework\Module\ModuleList\DeploymentConfig' + ); + $this->writer->expects($this->once())->method('update')->with($constraint); + $this->cleanup->expects($this->once())->method('clearCaches'); + $this->cleanup->expects($this->once())->method('clearCodeGeneratedFiles'); + $this->assertEquals([], $this->object->getErrors()); + $this->object->setEnabled(true, ['Module_Foo', 'Module_Bar']); + $this->assertEquals([], $this->object->getErrors()); + } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage Unknown module: 'Module_Baz' + */ + public function testSetEnabledUnknown() + { + $modules = ['Module_Foo' => '', 'Module_Bar' => '']; + $this->loader->expects($this->once())->method('load')->willReturn($modules); + $this->object->setEnabled(true, ['Module_Baz']); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index fa2b4c959c291..f3307fc72ea54 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -49,6 +49,11 @@ class ConsoleControllerTest extends \PHPUnit_Framework_TestCase */ private $controller; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface + */ + private $objectManager; + public function setUp() { $this->consoleLogger = $this->getMock('\Magento\Setup\Model\ConsoleLogger', [], [], '', false); @@ -76,8 +81,16 @@ public function setUp() $routeMatch->expects($this->any())->method('getParam')->willReturn('install'); $this->mvcEvent->expects($this->any())->method('getRouteMatch')->willReturn($routeMatch); + $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $objectManagerFactory = $this->getMock('Magento\Setup\Model\ObjectManagerFactory', [], [], '', false); + $objectManagerFactory->expects($this->any())->method('create')->willReturn($this->objectManager); + $this->controller = new ConsoleController( - $this->consoleLogger, $this->options, $installerFactory, $this->maintenanceMode + $this->consoleLogger, + $this->options, + $installerFactory, + $this->maintenanceMode, + $objectManagerFactory ); $this->controller->setEvent($this->mvcEvent); $this->controller->dispatch($this->request, $response); @@ -260,6 +273,72 @@ public function testHelpActionNoType() $this->assertStringStartsWith($beginHelpString, $returnValue); } + /** + * @param string $command + * @param string $modules + * @param bool $isForce + * @param bool $expectedIsEnabled + * @param string[] $expectedModules + * @dataProvider moduleActionDataProvider + */ + public function testModuleAction($command, $modules, $isForce, $expectedIsEnabled, $expectedModules) + { + $status = $this->getModuleActionMocks($command, $modules, $isForce); + if (!$isForce) { + $status->expects($this->once())->method('isSetEnabledAllowed')->willReturn(true); + } + $status->expects($this->once())->method('setEnabled')->with($expectedIsEnabled, $expectedModules); + $this->consoleLogger->expects($this->once())->method('log'); + $this->controller->moduleAction(); + } + + /** + * @return array + */ + public function moduleActionDataProvider() + { + return [ + [ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', false, true, ['Module_Foo', 'Module_Bar']], + [ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', true, true, ['Module_Foo', 'Module_Bar']], + [ConsoleController::CMD_MODULE_DISABLE, 'Module_Foo', false, false, ['Module_Foo']], + [ConsoleController::CMD_MODULE_DISABLE, 'Module_Bar', true, false, ['Module_Bar']], + ]; + } + + /** + * Prepares a set of mocks for testing module action + * + * @param string $command + * @param string $modules + * @param bool $isForce + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function getModuleActionMocks($command, $modules, $isForce) + { + $this->request->expects($this->at(0))->method('getParam')->with(0)->willReturn($command); + $this->request->expects($this->at(1))->method('getParam')->with('modules')->willReturn($modules); + $this->request->expects($this->at(2))->method('getParam')->with('force')->willReturn($isForce); + $status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); + $this->objectManager->expects($this->once()) + ->method('get') + ->with('Magento\Framework\Module\Status') + ->willReturn($status); + return $status; + } + + /** + * @expectedException \Magento\Setup\Exception + * @expectedExceptionMessage Unable to change status of modules because of the following errors: + */ + public function testModuleActionNotAllowed() + { + $status = $this->getModuleActionMocks(ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', false); + $status->expects($this->once())->method('isSetEnabledAllowed')->willReturn(false); + $status->expects($this->once())->method('getErrors')->willReturn(['Circular dependency of Foo and Bar']); + $status->expects($this->never())->method('setEnabled'); + $this->controller->moduleAction(); + } + /** * @param string $option * @param string $noParameters diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php index cbda233d9e4f5..d53163931e904 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php @@ -5,14 +5,11 @@ namespace Magento\Setup\Model; -use Magento\Setup\Mvc\Bootstrap\InitParamListener; - class InstallerFactoryTest Extends \PHPUnit_Framework_TestCase { public function testCreate() { $returnValueMap = [ - [InitParamListener::BOOTSTRAP_PARAM, []], [ 'Magento\Setup\Model\FilePermissions', $this->getMock('Magento\Setup\Model\FilePermissions', [], [], '', false), @@ -65,6 +62,10 @@ public function testCreate() 'Magento\Setup\Model\SampleData', $this->getMock('Magento\Setup\Model\SampleData', [], [], '', false), ], + [ + 'Magento\Setup\Model\ObjectManagerFactory', + $this->getMock('Magento\Setup\Model\ObjectManagerFactory', [], [], '', false), + ], ]; $serviceLocatorMock = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); $serviceLocatorMock diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php index a1814152dd102..df94492c0451d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php @@ -147,25 +147,17 @@ protected function setUp() * Instantiates the object with mocks * * @param \PHPUnit_Framework_MockObject_MockObject|bool $connectionFactory - * @param \PHPUnit_Framework_MockObject_MockObject|bool $serviceLocator * @param \PHPUnit_Framework_MockObject_MockObject|bool $objectManagerFactory * @return Installer */ - private function createObject($connectionFactory = false, $serviceLocator = false, $objectManagerFactory = false) + private function createObject($connectionFactory = false, $objectManagerFactory = false) { if (!$connectionFactory) { $connectionFactory = $this->getMock('Magento\Setup\Module\ConnectionFactory', [], [], '', false); $connectionFactory->expects($this->any())->method('create')->willReturn($this->connection); } - if (!$serviceLocator) { - $serviceLocator = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface'); - $serviceLocator->expects($this->once()) - ->method('get') - ->with(InitParamListener::BOOTSTRAP_PARAM) - ->willReturn([]); - } if (!$objectManagerFactory) { - $objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); + $objectManagerFactory = $this->getMock('Magento\Setup\Model\ObjectManagerFactory', [], [], '', false); $objectManagerFactory->expects($this->any())->method('create')->willReturn($this->objectManager); } return new Installer( @@ -182,7 +174,6 @@ private function createObject($connectionFactory = false, $serviceLocator = fals $connectionFactory, $this->maintenanceMode, $this->filesystem, - $serviceLocator, $this->sampleData, $objectManagerFactory ); diff --git a/lib/internal/Magento/Framework/App/State/Cleanup.php b/lib/internal/Magento/Framework/App/State/Cleanup.php new file mode 100644 index 0000000000000..8b23112b6c060 --- /dev/null +++ b/lib/internal/Magento/Framework/App/State/Cleanup.php @@ -0,0 +1,106 @@ +cachePool = $cachePool; + $this->filesystem = $filesystem; + } + + /** + * Clears all caches + * + * @return void + */ + public function clearCaches() + { + /** @var \Magento\Framework\Cache\FrontendInterface $frontend */ + foreach ($this->cachePool as $frontend) { + $frontend->clean(); + } + } + + /** + * Clears all files that are subject of code generation + * + * @return void + */ + public function clearCodeGeneratedFiles() + { + $this->clearCodeGeneratedClasses(); + $this->clearMaterializedViewFiles(); + } + + /** + * Clears code-generated classes + * + * @return void + */ + public function clearCodeGeneratedClasses() + { + $this->emptyDir(DirectoryList::GENERATION); + } + + /** + * Clears materialized static view files + * + * @return void + */ + public function clearMaterializedViewFiles() + { + $this->emptyDir(DirectoryList::STATIC_VIEW); + $this->emptyDir(DirectoryList::VAR_DIR, Source::TMP_MATERIALIZATION_DIR); + } + + /** + * Deletes contents of specified directory + * + * @param string $code + * @param string|null $subPath + * @return void + */ + private function emptyDir($code, $subPath = null) + { + $dir = $this->filesystem->getDirectoryWrite($code); + foreach ($dir->search('*', $subPath) as $path) { + if (false === strpos($path, '.')) { + $dir->delete($path); + } + } + } +} diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php new file mode 100644 index 0000000000000..dab2e14a0fe5d --- /dev/null +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -0,0 +1,125 @@ +loader = $loader; + $this->list = $list; + $this->writer = $writer; + $this->cleanup = $cleanup; + } + + /** + * Whether it is allowed to enable or disable specified modules + * + * TODO: not implemented yet (MAGETWO-32613) + * + * @param bool $isEnable + * @param string[] $modules + * @return bool + */ + public function isSetEnabledAllowed($isEnable, $modules) + { + $this->errors = []; + return true; + } + + /** + * Gets error messages that may have occurred during last command + * + * @return string[] + */ + public function getErrors() + { + return $this->errors; + } + + /** + * Sets specified modules to enabled or disabled state + * + * Performs other necessary routines, such as cache cleanup + * + * @param bool $isEnable + * @param string[] $modules + * @return void + * @throws \LogicException + */ + public function setEnabled($isEnable, $modules) + { + $this->errors = []; + $all = $this->loader->load(); + foreach ($modules as $name) { + if (!isset($all[$name])) { + throw new \LogicException("Unknown module: '{$name}'"); + } + } + $result = []; + foreach (array_keys($all) as $name) { + if (in_array($name, $modules)) { + $result[$name] = $isEnable; + } else { + $result[$name] = $this->list->has($name); + } + } + $segment = new ModuleList\DeploymentConfig($result); + $this->writer->update($segment); + $this->cleanup->clearCaches(); + $this->cleanup->clearCodeGeneratedFiles(); + } +} diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 723a4a5312b19..a9268a152f4c4 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -18,7 +18,7 @@ use Zend\Console\Request as ConsoleRequest; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Controller\AbstractActionController; - +use Magento\Setup\Model\ObjectManagerFactory; /** * Controller that handles all setup commands via command line interface. @@ -40,6 +40,8 @@ class ConsoleController extends AbstractActionController const CMD_UPDATE = 'update'; const CMD_UNINSTALL = 'uninstall'; const CMD_MAINTENANCE = 'maintenance'; + const CMD_MODULE_ENABLE = 'module-enable'; + const CMD_MODULE_DISABLE = 'module-disable'; /**#@- */ /** @@ -58,6 +60,8 @@ class ConsoleController extends AbstractActionController self::CMD_UPDATE => 'update', self::CMD_UNINSTALL => 'uninstall', self::CMD_MAINTENANCE => 'maintenance', + self::CMD_MODULE_ENABLE => 'module', + self::CMD_MODULE_DISABLE => 'module', ]; /** @@ -75,6 +79,8 @@ class ConsoleController extends AbstractActionController self::CMD_UPDATE, self::CMD_UNINSTALL, self::CMD_MAINTENANCE, + self::CMD_MODULE_ENABLE, + self::CMD_MODULE_DISABLE, UserConfig::KEY_LANGUAGE, UserConfig::KEY_CURRENCY, UserConfig::KEY_TIMEZONE, @@ -101,6 +107,20 @@ class ConsoleController extends AbstractActionController */ private $installer; + /** + * Object manager factory + * + * @var ObjectManagerFactory + */ + private $objectManagerFactory; + + /** + * Object manager + * + * @var \Magento\Framework\ObjectManagerInterface + */ + private $objectManager; + /** * Gets router configuration to be used in module definition * @@ -244,6 +264,18 @@ private static function getCliConfig() 'usage_short' => self::CMD_MAINTENANCE, 'usage_desc' => 'Set maintenance mode, optionally for specified addresses', ], + self::CMD_MODULE_ENABLE => [ + 'route' => self::CMD_MODULE_ENABLE . ' --modules= [--force]', + 'usage' => '--modules=Module_Foo,Module_Bar [--force]', + 'usage_short' => self::CMD_MODULE_ENABLE, + 'usage_desc' => 'Enable specified modules' + ], + self::CMD_MODULE_DISABLE => [ + 'route' => self::CMD_MODULE_DISABLE . ' --modules= [--force]', + 'usage' => '--modules=Module_Foo,Module_Bar [--force]', + 'usage_short' => self::CMD_MODULE_DISABLE, + 'usage_desc' => 'Disable specified modules' + ], self::CMD_HELP => [ 'route' => self::CMD_HELP . ' [' . implode('|', self::$helpOptions) . ']:type', 'usage' => '<' . implode('|', self::$helpOptions) . '>', @@ -260,17 +292,20 @@ private static function getCliConfig() * @param Lists $options * @param InstallerFactory $installerFactory * @param MaintenanceMode $maintenanceMode + * @param ObjectManagerFactory $objectManagerFactory */ public function __construct( ConsoleLogger $consoleLogger, Lists $options, InstallerFactory $installerFactory, - MaintenanceMode $maintenanceMode + MaintenanceMode $maintenanceMode, + ObjectManagerFactory $objectManagerFactory ) { $this->log = $consoleLogger; $this->options = $options; $this->installer = $installerFactory->create($consoleLogger); $this->maintenanceMode = $maintenanceMode; + $this->objectManagerFactory = $objectManagerFactory; } /** @@ -430,6 +465,44 @@ public function maintenanceAction() } } + /** + * Action for enabling or disabling modules + * + * @return void + * @throws \Magento\Setup\Exception + */ + public function moduleAction() + { + /** @var \Zend\Console\Request $request */ + $request = $this->getRequest(); + $isEnable = $request->getParam(0) == self::CMD_MODULE_ENABLE; + $modules = explode(',', $request->getParam('modules')); + /** @var \Magento\Framework\Module\Status $status */ + $status = $this->getObjectManager()->get('Magento\Framework\Module\Status'); + if (!$request->getParam('force')) { + if (!$status->isSetEnabledAllowed($isEnable, $modules)) { + $message = "Unable to change status of modules because of the following errors:\n" + . implode("\n", $status->getErrors()); + throw new \Magento\Setup\Exception($message); + } + } + $status->setEnabled($isEnable, $modules); + $this->log->log("Modules' status has been updated."); + } + + /** + * Getter for object manager + * + * @return \Magento\Framework\ObjectManagerInterface + */ + private function getObjectManager() + { + if (!$this->objectManager) { + $this->objectManager = $this->objectManagerFactory->create(); + } + return $this->objectManager; + } + /** * Shows necessary information for installing Magento * diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index bf910b5e1215d..8c40dcf997c0f 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -25,10 +25,7 @@ use Magento\Framework\Shell\CommandRenderer; use Magento\Setup\Module\ConnectionFactory; use Magento\Setup\Module\SetupFactory; -use Magento\Setup\Mvc\Bootstrap\InitParamListener; use Magento\Store\Model\Store; -use Zend\ServiceManager\ServiceLocatorInterface; -use Magento\Framework\App\ObjectManagerFactory; /** * Class Installer contains the logic to install Magento application. @@ -177,13 +174,6 @@ class Installer */ private $installInfo = []; - /** - * Initialization parameters for Magento application bootstrap - * - * @var string - */ - private $initParams; - /** * @var \Magento\Framework\ObjectManagerInterface */ @@ -220,7 +210,6 @@ class Installer * @param ConnectionFactory $connectionFactory * @param MaintenanceMode $maintenanceMode * @param Filesystem $filesystem - * @param ServiceLocatorInterface $serviceManager * @param SampleData $sampleData * @param ObjectManagerFactory $objectManagerFactory */ @@ -238,7 +227,6 @@ public function __construct( ConnectionFactory $connectionFactory, MaintenanceMode $maintenanceMode, Filesystem $filesystem, - ServiceLocatorInterface $serviceManager, SampleData $sampleData, ObjectManagerFactory $objectManagerFactory ) { @@ -255,7 +243,6 @@ public function __construct( $this->shellRenderer = new CommandRenderer; $this->maintenanceMode = $maintenanceMode; $this->filesystem = $filesystem; - $this->initParams = $serviceManager->get(InitParamListener::BOOTSTRAP_PARAM); $this->sampleData = $sampleData; $this->installInfo[self::INFO_MESSAGE] = array(); $this->deploymentConfig = $deploymentConfig; @@ -859,7 +846,7 @@ private function getObjectManager() { if (null === $this->objectManager) { $this->assertDeploymentConfigExists(); - $this->objectManager = $this->objectManagerFactory->create($this->initParams); + $this->objectManager = $this->objectManagerFactory->create(); } return $this->objectManager; } diff --git a/setup/src/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php index f0dc241c13716..3aea75e7a6925 100644 --- a/setup/src/Magento/Setup/Model/InstallerFactory.php +++ b/setup/src/Magento/Setup/Model/InstallerFactory.php @@ -7,8 +7,6 @@ namespace Magento\Setup\Model; use Zend\ServiceManager\ServiceLocatorInterface; -use Magento\Setup\Mvc\Bootstrap\InitParamListener; -use Magento\Framework\App\Bootstrap; class InstallerFactory { @@ -37,7 +35,6 @@ public function __construct(ServiceLocatorInterface $serviceLocator) */ public function create(LoggerInterface $log) { - $params = $this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM); return new Installer( $this->serviceLocator->get('Magento\Setup\Model\FilePermissions'), $this->serviceLocator->get('Magento\Framework\App\DeploymentConfig\Writer'), @@ -52,9 +49,8 @@ public function create(LoggerInterface $log) $this->serviceLocator->get('Magento\Setup\Module\ConnectionFactory'), $this->serviceLocator->get('Magento\Framework\App\MaintenanceMode'), $this->serviceLocator->get('Magento\Framework\Filesystem'), - $this->serviceLocator, $this->serviceLocator->get('Magento\Setup\Model\SampleData'), - Bootstrap::createObjectManagerFactory(BP, $params) + $this->serviceLocator->get('Magento\Setup\Model\ObjectManagerFactory') ); } } diff --git a/setup/src/Magento/Setup/Model/ObjectManagerFactory.php b/setup/src/Magento/Setup/Model/ObjectManagerFactory.php new file mode 100644 index 0000000000000..cc902a22e2e4c --- /dev/null +++ b/setup/src/Magento/Setup/Model/ObjectManagerFactory.php @@ -0,0 +1,43 @@ +serviceLocator = $serviceLocator; + } + + /** + * @return \Magento\Framework\ObjectManagerInterface + */ + public function create() + { + $initParams = $this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM); + $factory = Bootstrap::createObjectManagerFactory(BP, $initParams); + return $factory->create($initParams); + } +} From e158cf4e189d9f83cac372ae64b1520cd2e53f80 Mon Sep 17 00:00:00 2001 From: Anton Makarenko Date: Wed, 14 Jan 2015 10:17:59 -0600 Subject: [PATCH 33/89] MAGETWO-32606: Enable/Disable Modules for Existing Application - tweaked interface of module status model to return more verbose information - covered Setup ObjectManager Factory with a test --- .../Setup/Model/ObjectManagerFactoryTest.php | 20 +++++++++ .../Magento/Framework/Module/StatusTest.php | 9 ++-- .../Controller/ConsoleControllerTest.php | 7 +-- .../Magento/Framework/Module/Status.php | 44 +++++++------------ .../Setup/Controller/ConsoleController.php | 14 ++++-- 5 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Setup/Model/ObjectManagerFactoryTest.php diff --git a/dev/tests/integration/testsuite/Magento/Setup/Model/ObjectManagerFactoryTest.php b/dev/tests/integration/testsuite/Magento/Setup/Model/ObjectManagerFactoryTest.php new file mode 100644 index 0000000000000..5dfb4a1e272c4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Model/ObjectManagerFactoryTest.php @@ -0,0 +1,20 @@ +getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface'); + $locator->expects($this->once())->method('get')->with(InitParamListener::BOOTSTRAP_PARAM)->willReturn([]); + $factory = new ObjectManagerFactory($locator); + $this->assertInstanceOf('Magento\Framework\ObjectManagerInterface', $factory->create()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php index 6587cbf75c43d..688c2bdc22d66 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php @@ -46,16 +46,17 @@ public function testSetEnabled() { $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; $this->loader->expects($this->once())->method('load')->willReturn($modules); - $this->moduleList->expects($this->once())->method('has')->with('Module_Baz'); + $this->moduleList->expects($this->at(0))->method('has')->with('Module_Foo')->willReturn(true); + $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(true); $constraint = new \PHPUnit_Framework_Constraint_IsInstanceOf( 'Magento\Framework\Module\ModuleList\DeploymentConfig' ); $this->writer->expects($this->once())->method('update')->with($constraint); $this->cleanup->expects($this->once())->method('clearCaches'); $this->cleanup->expects($this->once())->method('clearCodeGeneratedFiles'); - $this->assertEquals([], $this->object->getErrors()); - $this->object->setEnabled(true, ['Module_Foo', 'Module_Bar']); - $this->assertEquals([], $this->object->getErrors()); + $result = $this->object->setEnabled(true, ['Module_Foo', 'Module_Bar']); + $this->assertEquals(['Module_Bar'], $result); } /** diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index f3307fc72ea54..ec13baa36e3f2 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -285,7 +285,7 @@ public function testModuleAction($command, $modules, $isForce, $expectedIsEnable { $status = $this->getModuleActionMocks($command, $modules, $isForce); if (!$isForce) { - $status->expects($this->once())->method('isSetEnabledAllowed')->willReturn(true); + $status->expects($this->once())->method('checkSetEnabledErrors')->willReturn([]); } $status->expects($this->once())->method('setEnabled')->with($expectedIsEnabled, $expectedModules); $this->consoleLogger->expects($this->once())->method('log'); @@ -333,8 +333,9 @@ private function getModuleActionMocks($command, $modules, $isForce) public function testModuleActionNotAllowed() { $status = $this->getModuleActionMocks(ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', false); - $status->expects($this->once())->method('isSetEnabledAllowed')->willReturn(false); - $status->expects($this->once())->method('getErrors')->willReturn(['Circular dependency of Foo and Bar']); + $status->expects($this->once()) + ->method('checkSetEnabledErrors') + ->willReturn(['Circular dependency of Foo and Bar']); $status->expects($this->never())->method('setEnabled'); $this->controller->moduleAction(); } diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index dab2e14a0fe5d..42fcb63732ac6 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -42,13 +42,6 @@ class Status */ private $cleanup; - /** - * Error messages collected during last command - * - * @var string[] - */ - private $errors = []; - /** * Constructor * @@ -72,37 +65,27 @@ public function __construct(ModuleList\Loader $loader, ModuleList $list, Writer * * @param bool $isEnable * @param string[] $modules - * @return bool - */ - public function isSetEnabledAllowed($isEnable, $modules) - { - $this->errors = []; - return true; - } - - /** - * Gets error messages that may have occurred during last command - * * @return string[] */ - public function getErrors() + public function checkSetEnabledErrors($isEnable, $modules) { - return $this->errors; + return []; } /** * Sets specified modules to enabled or disabled state * * Performs other necessary routines, such as cache cleanup + * Returns list of modules that have changed * * @param bool $isEnable * @param string[] $modules - * @return void + * @return string[] * @throws \LogicException */ public function setEnabled($isEnable, $modules) { - $this->errors = []; + $changed = []; $all = $this->loader->load(); foreach ($modules as $name) { if (!isset($all[$name])) { @@ -111,15 +94,22 @@ public function setEnabled($isEnable, $modules) } $result = []; foreach (array_keys($all) as $name) { + $currentStatus = $this->list->has($name); if (in_array($name, $modules)) { $result[$name] = $isEnable; + if ($isEnable != $currentStatus) { + $changed[] = $name; + } } else { - $result[$name] = $this->list->has($name); + $result[$name] = $currentStatus; } } - $segment = new ModuleList\DeploymentConfig($result); - $this->writer->update($segment); - $this->cleanup->clearCaches(); - $this->cleanup->clearCodeGeneratedFiles(); + if ($changed) { + $segment = new ModuleList\DeploymentConfig($result); + $this->writer->update($segment); + $this->cleanup->clearCaches(); + $this->cleanup->clearCodeGeneratedFiles(); + } + return $changed; } } diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index a9268a152f4c4..957d265c61c0a 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -480,14 +480,20 @@ public function moduleAction() /** @var \Magento\Framework\Module\Status $status */ $status = $this->getObjectManager()->get('Magento\Framework\Module\Status'); if (!$request->getParam('force')) { - if (!$status->isSetEnabledAllowed($isEnable, $modules)) { + $errors = $status->checkSetEnabledErrors($isEnable, $modules); + if ($errors) { $message = "Unable to change status of modules because of the following errors:\n" - . implode("\n", $status->getErrors()); + . implode("\n", $errors); throw new \Magento\Setup\Exception($message); } } - $status->setEnabled($isEnable, $modules); - $this->log->log("Modules' status has been updated."); + $changed = $status->setEnabled($isEnable, $modules); + if ($changed) { + $message = "The following modules' status has been updated: " . implode(', ', $changed); + } else { + $message = 'There have been no changes to any modules.'; + } + $this->log->log($message); } /** From 556a9d6299ace8bf08f87296052ad6fc9f72051a Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 14 Jan 2015 14:33:45 -0600 Subject: [PATCH 34/89] MAGETWO-32613: Add dependency restrictions - initial dependency restriction logic --- .../Framework/Module/ConflictChecker.php | 83 ++++++++++++ .../Framework/Module/DependencyChecker.php | 124 ++++++++++++++++++ .../Module/DependencyGraphFactory.php | 40 ++++++ .../Magento/Framework/Module/Status.php | 65 ++++++++- 4 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 lib/internal/Magento/Framework/Module/ConflictChecker.php create mode 100644 lib/internal/Magento/Framework/Module/DependencyChecker.php create mode 100644 lib/internal/Magento/Framework/Module/DependencyGraphFactory.php diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php new file mode 100644 index 0000000000000..55f53a9901a87 --- /dev/null +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -0,0 +1,83 @@ +modules = $modules; + $this->enabledModules = $enabledModules; + } + + /** + * @param $moduleName + * @return array + */ + public function checkConflictWhenEnableModule($moduleName) + { + $conflicts = []; + foreach (array_keys($this->getMagentoConflicts($moduleName)) as $module) { + if ($this->checkIfEnabled($this->getRealName($module))) { + $conflicts[] = $this->getRealName($module); + } + } + return $conflicts; + } + + /** + * @param $moduleName + * @return mixed + */ + public function getMagentoConflicts($moduleName) + { + $jsonDecoder = new \Magento\Framework\Json\Decoder(); + // workaround: convert Magento_X to X + $module = substr($moduleName, 8); + $data = $jsonDecoder->decode(file_get_contents(BP . '/app/code/Magento/' . $module . '/composer.json')); + return $data[self::KEY_CONFLICT]; + } + + /** + * Check if module is enabled + * + * @param string $moduleName + * @return bool + */ + private function checkIfEnabled($moduleName) + { + return array_search($moduleName, $this->enabledModules) !== false; + } + + /** + * Convert alias used in composer.json to Magento_X format + * + * @param $alias + * @return string + */ + private function getRealName($alias) + { + // workaround: convert composer.json alias to magento_x + $lowerCaseModuleName = 'magento_' . str_replace('-', '', substr($alias, strlen(DependencyGraphFactory::ALIAS_PREFIX))); + foreach ($this->modules as $module) { + if (strtolower($module) == $lowerCaseModuleName) { + return $module; + } + } + } +} \ No newline at end of file diff --git a/lib/internal/Magento/Framework/Module/DependencyChecker.php b/lib/internal/Magento/Framework/Module/DependencyChecker.php new file mode 100644 index 0000000000000..0b6e5b1c1e0fa --- /dev/null +++ b/lib/internal/Magento/Framework/Module/DependencyChecker.php @@ -0,0 +1,124 @@ +factory = $factory; + $this->modules = $modules; + $this->enabledModules = $enabledModules; + } + + /** + * Checks modules that are depending on the to-be-disabled module + * + * @param string $moduleName + * @return array + */ + public function checkDependencyWhenDisableModule($moduleName) + { + // workarounds: convert Magento_X to x + $moduleName = strtolower(substr($moduleName, 8)); + $dependenciesMissing = []; + $graph = $this->factory->create($this->modules); + foreach ($this->modules as $module) { + // workaround: convert Magento_X to x + if ($this->checkIfEnabled($module) && strtolower(substr($module, 8)) !== $moduleName) { + if (!empty($graph->dfs(strtolower(substr($module, 8)), $moduleName)) && + $this->checkIfEnabled($module) + ) { + $dependenciesMissing[] = $module; + } + } + } + return $dependenciesMissing; + } + + /** + * Checks modules the to-be-enabled module is depending on + * + * @param string $moduleName + * @return array + */ + public function checkDependencyWhenEnableModule($moduleName) + { + // workarounds: convert Magento_X to X + $moduleName = substr($moduleName, 8); + $dependenciesMissing = []; + foreach ($this->getMagentoDependencies($moduleName) as $module) { + if (!$this->checkIfEnabled($this->getRealName($module))) { + $dependenciesMissing[] = $this->getRealName($module); + } + } + return $dependenciesMissing; + } + + /** + * Get array of modules that a module depends on + * + * @param string $moduleName + * @return array + */ + private function getMagentoDependencies($moduleName) + { + $jsonDecoder = new \Magento\Framework\Json\Decoder(); + $data = $jsonDecoder->decode(file_get_contents(BP . '/app/code/Magento/' . $moduleName . '/composer.json')); + $dependencies = []; + // get rid of non Magento dependencies + foreach (array_keys($data[DependencyGraphFactory::KEY_REQUIRE]) as $depend) { + if (strpos($depend, DependencyGraphFactory::ALIAS_PREFIX) === 0) { + $dependencies[] = $depend; + } + } + return $dependencies; + } + + /** + * Check if module is enabled + * + * @param string $moduleName + * @return bool + */ + private function checkIfEnabled($moduleName) + { + return array_search($moduleName, $this->enabledModules) !== false; + } + + /** + * Convert alias used in composer.json to Magento_X format + * + * @param $alias + * @return string + */ + private function getRealName($alias) + { + // workaround: convert composer.json alias to magento_x + $lowerCaseModuleName = 'magento_' . str_replace('-', '', substr($alias, strlen(DependencyGraphFactory::ALIAS_PREFIX))); + foreach ($this->modules as $module) { + if (strtolower($module) == $lowerCaseModuleName) { + return $module; + } + } + } +} diff --git a/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php b/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php new file mode 100644 index 0000000000000..9c8d38c159fed --- /dev/null +++ b/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php @@ -0,0 +1,40 @@ +decode(file_get_contents(BP . '/app/code/Magento/' . $module . '/composer.json')); + $nodes[] = strtolower($module); + foreach (array_keys($data[self::KEY_REQUIRE]) as $depend) { + if (strpos($depend, self::ALIAS_PREFIX) === 0) { + // workaround: convert composer.json to alias x + $depend = substr($depend, strlen(self::ALIAS_PREFIX)); + $depend = str_replace('-', '', $depend); + $dependencies[] = [strtolower($module), $depend]; + } + } + } + $nodes = array_unique($nodes); + + return new \Magento\Framework\Data\Graph($nodes, $dependencies); + } +} diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index 42fcb63732ac6..add831be71883 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -8,6 +8,7 @@ use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\App\State\Cleanup; +use Magento\Framework\App\DeploymentConfig; /** * A service for controlling module status @@ -42,6 +43,11 @@ class Status */ private $cleanup; + /** + * @var DeploymentConfig + */ + private $deploymentConfig; + /** * Constructor * @@ -50,12 +56,13 @@ class Status * @param Writer $writer * @param Cleanup $cleanup */ - public function __construct(ModuleList\Loader $loader, ModuleList $list, Writer $writer, Cleanup $cleanup) + public function __construct(ModuleList\Loader $loader, ModuleList $list, Writer $writer, Cleanup $cleanup, DeploymentConfig $deploymentConfig) { $this->loader = $loader; $this->list = $list; $this->writer = $writer; $this->cleanup = $cleanup; + $this->deploymentConfig = $deploymentConfig; } /** @@ -69,7 +76,61 @@ public function __construct(ModuleList\Loader $loader, ModuleList $list, Writer */ public function checkSetEnabledErrors($isEnable, $modules) { - return []; + // TODO: deploymentConfig only works when application exists + $enabledModules = []; + $all = $this->deploymentConfig->getSegment(ModuleList\DeploymentConfig::CONFIG_KEY); + foreach ($all as $module => $enabled) { + if ($enabled) { + $enabledModules[] = $module; + } + } + + $errorMessages = []; + + if ($isEnable) { + $dependencyChecker = new DependencyChecker( + new DependencyGraphFactory(), + array_keys($all), + array_unique(array_merge($enabledModules, $modules)) // union, consider to-be-enable modules + ); + foreach ($modules as $moduleName) { + $errorModules = $dependencyChecker->checkDependencyWhenEnableModule($moduleName); + if (!empty($errorModules)) { + $errorMessages[] = "Cannot enable $moduleName, depending on inactive modules:"; + foreach ($errorModules as $errorModule) { + $errorMessages [] = "\t$errorModule"; + } + } + } + // TODO: consolidate to one for loop + $conflictChecker = new ConflictChecker(array_keys($all), array_unique(array_merge($enabledModules, $modules))); + foreach ($modules as $moduleName) { + $errorModules = $conflictChecker->checkConflictWhenEnableModule($moduleName); + if (!empty($errorModules)) { + $errorMessages[] = "Cannot enable $moduleName, conflicting active modules:"; + foreach ($errorModules as $errorModule) { + $errorMessages [] = "\t$errorModule"; + } + } + } + } else { + $dependencyChecker = new DependencyChecker( + new DependencyGraphFactory(), + array_keys($all), + $enabledModules + ); + foreach ($modules as $moduleName) { + $errorModules = $dependencyChecker->checkDependencyWhenDisableModule($moduleName); + if (!empty($errorModules)) { + $errorMessages[] = "Cannot disable $moduleName, active modules depending on it:"; + foreach ($errorModules as $errorModule) { + $errorMessages [] = "\t$errorModule"; + } + } + } + } + + return $errorMessages; } /** From 27f992d883ae7978a754604ecb2a39fa95e9e336 Mon Sep 17 00:00:00 2001 From: Anton Makarenko Date: Wed, 14 Jan 2015 17:18:26 -0600 Subject: [PATCH 35/89] MAGETWO-32606: Enable/Disable Modules for Existing Application - fixed various small issues from CR notes --- .../Magento/Framework/Module/StatusTest.php | 10 ++--- .../Controller/ConsoleControllerTest.php | 10 ++--- .../Magento/Setup/Model/InstallerTest.php | 3 +- .../Magento/Framework/Module/Status.php | 43 +++++++++++++------ .../Setup/Controller/ConsoleController.php | 17 +++++--- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php index 688c2bdc22d66..acc86089ee768 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php @@ -42,7 +42,7 @@ protected function setUp() $this->object = new Status($this->loader, $this->moduleList, $this->writer, $this->cleanup); } - public function testSetEnabled() + public function testSetIsEnabled() { $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; $this->loader->expects($this->once())->method('load')->willReturn($modules); @@ -55,18 +55,18 @@ public function testSetEnabled() $this->writer->expects($this->once())->method('update')->with($constraint); $this->cleanup->expects($this->once())->method('clearCaches'); $this->cleanup->expects($this->once())->method('clearCodeGeneratedFiles'); - $result = $this->object->setEnabled(true, ['Module_Foo', 'Module_Bar']); + $result = $this->object->setIsEnabled(true, ['Module_Foo', 'Module_Bar']); $this->assertEquals(['Module_Bar'], $result); } /** * @expectedException \LogicException - * @expectedExceptionMessage Unknown module: 'Module_Baz' + * @expectedExceptionMessage Unknown module(s): 'Module_Baz' */ - public function testSetEnabledUnknown() + public function testSetIsEnabledUnknown() { $modules = ['Module_Foo' => '', 'Module_Bar' => '']; $this->loader->expects($this->once())->method('load')->willReturn($modules); - $this->object->setEnabled(true, ['Module_Baz']); + $this->object->setIsEnabled(true, ['Module_Baz']); } } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index ec13baa36e3f2..b5ca1975c2e48 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -285,9 +285,9 @@ public function testModuleAction($command, $modules, $isForce, $expectedIsEnable { $status = $this->getModuleActionMocks($command, $modules, $isForce); if (!$isForce) { - $status->expects($this->once())->method('checkSetEnabledErrors')->willReturn([]); + $status->expects($this->once())->method('checkConstraints')->willReturn([]); } - $status->expects($this->once())->method('setEnabled')->with($expectedIsEnabled, $expectedModules); + $status->expects($this->once())->method('setIsEnabled')->with($expectedIsEnabled, $expectedModules); $this->consoleLogger->expects($this->once())->method('log'); $this->controller->moduleAction(); } @@ -328,15 +328,15 @@ private function getModuleActionMocks($command, $modules, $isForce) /** * @expectedException \Magento\Setup\Exception - * @expectedExceptionMessage Unable to change status of modules because of the following errors: + * @expectedExceptionMessage Unable to change status of modules because of the following constraints: */ public function testModuleActionNotAllowed() { $status = $this->getModuleActionMocks(ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', false); $status->expects($this->once()) - ->method('checkSetEnabledErrors') + ->method('checkConstraints') ->willReturn(['Circular dependency of Foo and Bar']); - $status->expects($this->never())->method('setEnabled'); + $status->expects($this->never())->method('setIsEnabled'); $this->controller->moduleAction(); } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php index df94492c0451d..c17f726144367 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php @@ -5,7 +5,6 @@ namespace Magento\Setup\Model; -use Magento\Setup\Mvc\Bootstrap\InitParamListener; use Magento\Framework\App\DeploymentConfig\DbConfig; use Magento\Framework\App\DeploymentConfig\EncryptConfig; use Magento\Framework\App\Filesystem\DirectoryList; @@ -331,7 +330,7 @@ public function testCheckDatabaseConnection() /** * @expectedException \Magento\Setup\Exception - * @expectedException Database connection failure. + * @expectedExceptionMessage Database connection failure. */ public function testCheckDatabaseConnectionFailed() { diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index 42fcb63732ac6..4a0cd8f24204d 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -67,7 +67,7 @@ public function __construct(ModuleList\Loader $loader, ModuleList $list, Writer * @param string[] $modules * @return string[] */ - public function checkSetEnabledErrors($isEnable, $modules) + public function checkConstraints($isEnable, $modules) { return []; } @@ -78,26 +78,19 @@ public function checkSetEnabledErrors($isEnable, $modules) * Performs other necessary routines, such as cache cleanup * Returns list of modules that have changed * - * @param bool $isEnable + * @param bool $isEnabled * @param string[] $modules * @return string[] - * @throws \LogicException */ - public function setEnabled($isEnable, $modules) + public function setIsEnabled($isEnabled, $modules) { - $changed = []; - $all = $this->loader->load(); - foreach ($modules as $name) { - if (!isset($all[$name])) { - throw new \LogicException("Unknown module: '{$name}'"); - } - } $result = []; - foreach (array_keys($all) as $name) { + $changed = []; + foreach ($this->getAllModules($modules) as $name) { $currentStatus = $this->list->has($name); if (in_array($name, $modules)) { - $result[$name] = $isEnable; - if ($isEnable != $currentStatus) { + $result[$name] = $isEnabled; + if ($isEnabled != $currentStatus) { $changed[] = $name; } } else { @@ -112,4 +105,26 @@ public function setEnabled($isEnable, $modules) } return $changed; } + + /** + * Gets all modules and filters against the specified list + * + * @param string[] $modules + * @return string[] + * @throws \LogicException + */ + private function getAllModules($modules) + { + $all = $this->loader->load(); + $unknown = []; + foreach ($modules as $name) { + if (!isset($all[$name])) { + $unknown[] = $name; + } + } + if ($unknown) { + throw new \LogicException("Unknown module(s): '" . implode("', '", $unknown) . "'"); + } + return array_keys($all); + } } diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 957d265c61c0a..07de1656d69de 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -480,16 +480,21 @@ public function moduleAction() /** @var \Magento\Framework\Module\Status $status */ $status = $this->getObjectManager()->get('Magento\Framework\Module\Status'); if (!$request->getParam('force')) { - $errors = $status->checkSetEnabledErrors($isEnable, $modules); - if ($errors) { - $message = "Unable to change status of modules because of the following errors:\n" - . implode("\n", $errors); + $constraints = $status->checkConstraints($isEnable, $modules); + if ($constraints) { + $message = "Unable to change status of modules because of the following constraints:\n" + . implode("\n", $constraints); throw new \Magento\Setup\Exception($message); } } - $changed = $status->setEnabled($isEnable, $modules); + $changed = $status->setIsEnabled($isEnable, $modules); if ($changed) { - $message = "The following modules' status has been updated: " . implode(', ', $changed); + if ($isEnable) { + $message = 'The following modules have been enabled:'; + } else { + $message = 'The following modules have been disabled:'; + } + $message .= ' ' . implode(', ', $changed); } else { $message = 'There have been no changes to any modules.'; } From 3aaca382a0a8ed50d59cb986b1571a6c711a5396 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 15 Jan 2015 11:13:20 -0600 Subject: [PATCH 36/89] MAGETWO-32613: Add dependency restrictions - improved dependency restrictions checking logic - integrate with CLI --- .../Magento/Framework/Module/Checker.php | 74 ++++++++++++ .../Framework/Module/ConflictChecker.php | 99 +++++++++-------- .../Framework/Module/DependencyChecker.php | 105 +++++------------- .../Framework/Module/DependencyGraph.php | 71 ++++++++++++ .../Module/DependencyGraphFactory.php | 64 ++++++++--- .../Magento/Framework/Module/Mapper.php | 73 ++++++++++++ .../Magento/Framework/Module/Status.php | 61 ++++++---- 7 files changed, 386 insertions(+), 161 deletions(-) create mode 100644 lib/internal/Magento/Framework/Module/Checker.php create mode 100644 lib/internal/Magento/Framework/Module/DependencyGraph.php create mode 100644 lib/internal/Magento/Framework/Module/Mapper.php diff --git a/lib/internal/Magento/Framework/Module/Checker.php b/lib/internal/Magento/Framework/Module/Checker.php new file mode 100644 index 0000000000000..364fc050dc135 --- /dev/null +++ b/lib/internal/Magento/Framework/Module/Checker.php @@ -0,0 +1,74 @@ +mapper = $mapper; + } + + /** + * Set list of all modules + * + * @param $modules + * @return void + */ + public function setModules($modules) + { + $this->modules = $modules; + $this->mapper->setModules($modules); + } + + /** + * Set list of enabled modules, assuming module enable/disable succeeds + * + * @param $enabledModules + * @return void + */ + public function setEnabledModules($enabledModules) + { + $this->enabledModules = $enabledModules; + } + + /** + * Check if module is enabled + * + * @param string $moduleName + * @return bool + */ + protected function checkIfEnabled($moduleName) + { + return array_search($moduleName, $this->enabledModules) !== false; + } +} diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index 55f53a9901a87..352220cdb0ff0 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -1,83 +1,90 @@ modules = $modules; - $this->enabledModules = $enabledModules; + parent::__construct($mapper); + $this->filesystem = $filesystem; } /** + * Check if enabling module will conflict any modules + * * @param $moduleName * @return array */ public function checkConflictWhenEnableModule($moduleName) { $conflicts = []; - foreach (array_keys($this->getMagentoConflicts($moduleName)) as $module) { - if ($this->checkIfEnabled($this->getRealName($module))) { - $conflicts[] = $this->getRealName($module); + foreach ($this->enabledModules as $enabledModule) { + if ($this->checkIfConflict($enabledModule, $moduleName)) { + $conflicts[] = $enabledModule; } } return $conflicts; } /** - * @param $moduleName - * @return mixed - */ - public function getMagentoConflicts($moduleName) - { - $jsonDecoder = new \Magento\Framework\Json\Decoder(); - // workaround: convert Magento_X to X - $module = substr($moduleName, 8); - $data = $jsonDecoder->decode(file_get_contents(BP . '/app/code/Magento/' . $module . '/composer.json')); - return $data[self::KEY_CONFLICT]; - } - - /** - * Check if module is enabled + * Check if module is conflicted * * @param string $moduleName * @return bool */ - private function checkIfEnabled($moduleName) + private function checkIfConflict($enabledModule, $moduleName) { - return array_search($moduleName, $this->enabledModules) !== false; - } + $jsonDecoder = new \Magento\Framework\Json\Decoder(); - /** - * Convert alias used in composer.json to Magento_X format - * - * @param $alias - * @return string - */ - private function getRealName($alias) - { - // workaround: convert composer.json alias to magento_x - $lowerCaseModuleName = 'magento_' . str_replace('-', '', substr($alias, strlen(DependencyGraphFactory::ALIAS_PREFIX))); - foreach ($this->modules as $module) { - if (strtolower($module) == $lowerCaseModuleName) { - return $module; + $vendorA = $this->mapper->moduleFullNameToVendorName($enabledModule); + $vendorB = $this->mapper->moduleFullNameToVendorName($moduleName); + $moduleA = $this->mapper->moduleFullNameToModuleName($enabledModule); + $moduleB = $this->mapper->moduleFullNameToModuleName($moduleName); + + $readAdapter = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MODULES); + + $data1 = $jsonDecoder->decode($readAdapter->readFile("$vendorA/$moduleA/composer.json")); + $data2 = $jsonDecoder->decode($readAdapter->readFile("$vendorB/$moduleB/composer.json")); + + if (isset($data1[self::KEY_CONFLICT])) { + foreach (array_keys($data1[self::KEY_CONFLICT]) as $packageName) { + $module = $this->mapper->packageNameToModuleFullName($packageName); + if ($module == $moduleName) { + return true; + } + } + } + + if (isset($data2[self::KEY_CONFLICT])) { + foreach (array_keys($data2[self::KEY_CONFLICT]) as $packageName) { + $module = $this->mapper->packageNameToModuleFullName($packageName); + if ($module == $enabledModule) { + return true; + } } } + return false; } -} \ No newline at end of file +} diff --git a/lib/internal/Magento/Framework/Module/DependencyChecker.php b/lib/internal/Magento/Framework/Module/DependencyChecker.php index 0b6e5b1c1e0fa..446fca1d2be59 100644 --- a/lib/internal/Magento/Framework/Module/DependencyChecker.php +++ b/lib/internal/Magento/Framework/Module/DependencyChecker.php @@ -1,33 +1,27 @@ factory = $factory; - $this->modules = $modules; - $this->enabledModules = $enabledModules; } /** @@ -38,18 +32,13 @@ public function __construct(DependencyGraphFactory $factory, array $modules, arr */ public function checkDependencyWhenDisableModule($moduleName) { - // workarounds: convert Magento_X to x - $moduleName = strtolower(substr($moduleName, 8)); $dependenciesMissing = []; $graph = $this->factory->create($this->modules); + $graph->traverseGraph($moduleName, DependencyGraph::INVERSE); foreach ($this->modules as $module) { - // workaround: convert Magento_X to x - if ($this->checkIfEnabled($module) && strtolower(substr($module, 8)) !== $moduleName) { - if (!empty($graph->dfs(strtolower(substr($module, 8)), $moduleName)) && - $this->checkIfEnabled($module) - ) { - $dependenciesMissing[] = $module; - } + $dependencyChain = $graph->getChain($module); + if (!empty($dependencyChain) && $this->checkIfEnabled($module)) { + $dependenciesMissing[$module] = array_reverse($dependencyChain); } } return $dependenciesMissing; @@ -63,62 +52,20 @@ public function checkDependencyWhenDisableModule($moduleName) */ public function checkDependencyWhenEnableModule($moduleName) { - // workarounds: convert Magento_X to X - $moduleName = substr($moduleName, 8); $dependenciesMissing = []; - foreach ($this->getMagentoDependencies($moduleName) as $module) { - if (!$this->checkIfEnabled($this->getRealName($module))) { - $dependenciesMissing[] = $this->getRealName($module); - } - } - return $dependenciesMissing; - } - - /** - * Get array of modules that a module depends on - * - * @param string $moduleName - * @return array - */ - private function getMagentoDependencies($moduleName) - { - $jsonDecoder = new \Magento\Framework\Json\Decoder(); - $data = $jsonDecoder->decode(file_get_contents(BP . '/app/code/Magento/' . $moduleName . '/composer.json')); - $dependencies = []; - // get rid of non Magento dependencies - foreach (array_keys($data[DependencyGraphFactory::KEY_REQUIRE]) as $depend) { - if (strpos($depend, DependencyGraphFactory::ALIAS_PREFIX) === 0) { - $dependencies[] = $depend; - } - } - return $dependencies; - } - - /** - * Check if module is enabled - * - * @param string $moduleName - * @return bool - */ - private function checkIfEnabled($moduleName) - { - return array_search($moduleName, $this->enabledModules) !== false; - } - - /** - * Convert alias used in composer.json to Magento_X format - * - * @param $alias - * @return string - */ - private function getRealName($alias) - { - // workaround: convert composer.json alias to magento_x - $lowerCaseModuleName = 'magento_' . str_replace('-', '', substr($alias, strlen(DependencyGraphFactory::ALIAS_PREFIX))); + $graph = $this->factory->create($this->modules); + $graph->traverseGraph($moduleName); foreach ($this->modules as $module) { - if (strtolower($module) == $lowerCaseModuleName) { - return $module; + $dependencyChain = $graph->getChain($module); + if (!empty($dependencyChain) && !$this->checkIfEnabled($module)) { + foreach ($dependencyChain as $key => $node) { + if (!$this->checkIfEnabled($node)) { + $dependencyChain[$key] = $dependencyChain[$key] . '(disabled)'; + } + } + $dependenciesMissing[$module] = $dependencyChain; } } + return $dependenciesMissing; } } diff --git a/lib/internal/Magento/Framework/Module/DependencyGraph.php b/lib/internal/Magento/Framework/Module/DependencyGraph.php new file mode 100644 index 0000000000000..e2ebba672817a --- /dev/null +++ b/lib/internal/Magento/Framework/Module/DependencyGraph.php @@ -0,0 +1,71 @@ +_assertNode($fromNode, true); + //$this->_traverseGraph($fromNode, $this->getRelations($mode), [$fromNode]); + $this->_traverseGraphBFS($fromNode, $this->getRelations($mode)); + } + + protected function _traverseGraph($fromNode, $graph, $path = [], &$visited = []) + { + $visited[$fromNode] = $fromNode; + if (isset($graph[$fromNode])) { + foreach ($graph[$fromNode] as $node) { + if (!isset($visited[$node])) { + $path[] = $node; + $this->paths[$node] = $path; + $this->_traverseGraph($node, $graph, $path, $visited); + } + } + } + } + + protected function _traverseGraphBFS($fromNode, $graph) + { + $queue = [$fromNode]; + $visited = []; + $this->paths[$fromNode] = [$fromNode]; + while (!empty($queue)) { + $node = array_shift($queue); + $visited[$node] = $node; + if (isset($graph[$node])) { + foreach ($graph[$node] as $child) { + if (!isset($visited[$child])) { + $this->paths[$child] = array_merge($this->paths[$node], [$child]); + $queue[] = $child; + } + } + } + } + } + + /** + * Get chain to node + * Note that this is not necessarily the only chain + * + * @param string $toNode + * @return array + */ + public function getChain($toNode) + { + return isset($this->paths[$toNode]) ? $this->paths[$toNode] : []; + } +} diff --git a/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php b/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php index 9c8d38c159fed..e88d4dcaab490 100644 --- a/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php +++ b/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php @@ -1,40 +1,72 @@ filesystem = $filesystem; + $this->mapper = $mapper; + } + + /** + * @param array $modules + * @return DependencyGraph */ - public function create(array $modules) + public function create($modules) { + $readAdapter = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MODULES); + + $this->modules = $modules; + $this->mapper->setModules($modules); + $nodes = []; $dependencies = []; // build the graph data - foreach ($modules as $module) { + foreach ($this->modules as $module) { $jsonDecoder = new \Magento\Framework\Json\Decoder(); - // workaround: convert Magento_X to X - $module = substr($module, 8); - $data = $jsonDecoder->decode(file_get_contents(BP . '/app/code/Magento/' . $module . '/composer.json')); - $nodes[] = strtolower($module); + $module_partial = $this->mapper->moduleFullNameToModuleName($module); + $vendor = $this->mapper->moduleFullNameToVendorName($module); + $data = $jsonDecoder->decode($readAdapter->readFile("$vendor/$module_partial/composer.json")); + $nodes[] = $module; foreach (array_keys($data[self::KEY_REQUIRE]) as $depend) { - if (strpos($depend, self::ALIAS_PREFIX) === 0) { - // workaround: convert composer.json to alias x - $depend = substr($depend, strlen(self::ALIAS_PREFIX)); - $depend = str_replace('-', '', $depend); - $dependencies[] = [strtolower($module), $depend]; + $depend = $this->mapper->packageNameToModuleFullName($depend); + if ($depend) { + $dependencies[] = [$module, $depend]; } } } $nodes = array_unique($nodes); - return new \Magento\Framework\Data\Graph($nodes, $dependencies); + return new DependencyGraph($nodes, $dependencies); } } diff --git a/lib/internal/Magento/Framework/Module/Mapper.php b/lib/internal/Magento/Framework/Module/Mapper.php new file mode 100644 index 0000000000000..6786365c01a9a --- /dev/null +++ b/lib/internal/Magento/Framework/Module/Mapper.php @@ -0,0 +1,73 @@ +filesystem = $filesystem; + } + + public function setModules($modules) + { + $this->modules = $modules; + $jsonDecoder = new \Magento\Framework\Json\Decoder(); + $readAdapter = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MODULES); + foreach ($this->modules as $module) { + $modulePartial = $this->moduleFullNameToModuleName($module); + $vendor = $this->moduleFullNameToVendorName($module); + $data = $jsonDecoder->decode($readAdapter->readFile("$vendor/$modulePartial/composer.json")); + $this->packageNameMap[$data['name']] = $module; + } + } + + /** + * Convert Magento_X to X + * + * @param string $moduleFullName + * @return string + */ + public function moduleFullNameToModuleName($moduleFullName) + { + return explode('_', $moduleFullName)[1]; + } + + /** + * Convert Magento_X to Magento + */ + public function moduleFullNameToVendorName($moduleFullName) + { + return explode('_', $moduleFullName)[0]; + } + + /** + * Convert magento/modules-x to Magento_X + * + * @param string $packageName + * @return string + */ + public function packageNameToModuleFullName($packageName) + { + return isset($this->packageNameMap[$packageName]) ? $this->packageNameMap[$packageName] : ''; + } +} diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index b4798b40b5c62..65c1f1a7edbc7 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -9,6 +9,7 @@ use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\App\State\Cleanup; use Magento\Framework\App\DeploymentConfig; +use Magento\Tools\Dependency\Report\Framework\Data\Dependency; /** * A service for controlling module status @@ -48,6 +49,16 @@ class Status */ private $deploymentConfig; + /** + * @var DependencyChecker + */ + private $dependencyChecker; + + /** + * @var ConflictChecker + */ + private $conflictChecker; + /** * Constructor * @@ -55,14 +66,26 @@ class Status * @param ModuleList $list * @param Writer $writer * @param Cleanup $cleanup + * @param ConflictChecker $conflictChecker + * @param DependencyChecker $dependencyChecker + * @param DeploymentConfig $deploymentConfig */ - public function __construct(ModuleList\Loader $loader, ModuleList $list, Writer $writer, Cleanup $cleanup, DeploymentConfig $deploymentConfig) - { + public function __construct( + ModuleList\Loader $loader, + ModuleList $list, + Writer $writer, + Cleanup $cleanup, + ConflictChecker $conflictChecker, + DependencyChecker $dependencyChecker, + DeploymentConfig $deploymentConfig + ) { $this->loader = $loader; $this->list = $list; $this->writer = $writer; $this->cleanup = $cleanup; $this->deploymentConfig = $deploymentConfig; + $this->conflictChecker = $conflictChecker; + $this->dependencyChecker = $dependencyChecker; } /** @@ -88,24 +111,24 @@ public function checkConstraints($isEnable, $modules) $errorMessages = []; if ($isEnable) { - $dependencyChecker = new DependencyChecker( - new DependencyGraphFactory(), - array_keys($all), - array_unique(array_merge($enabledModules, $modules)) // union, consider to-be-enable modules - ); + $this->dependencyChecker->setModules(array_keys($all)); + $this->dependencyChecker->setEnabledModules(array_unique(array_merge($enabledModules, $modules))); + foreach ($modules as $moduleName) { - $errorModules = $dependencyChecker->checkDependencyWhenEnableModule($moduleName); + $errorModules = $this->dependencyChecker->checkDependencyWhenEnableModule($moduleName); if (!empty($errorModules)) { $errorMessages[] = "Cannot enable $moduleName, depending on inactive modules:"; - foreach ($errorModules as $errorModule) { - $errorMessages [] = "\t$errorModule"; + foreach ($errorModules as $errorModule => $path) { + $errorMessages [] = "\t$errorModule: " . implode('->', $path); } } } // TODO: consolidate to one for loop - $conflictChecker = new ConflictChecker(array_keys($all), array_unique(array_merge($enabledModules, $modules))); + $this->conflictChecker->setModules($modules); + $this->conflictChecker->setEnabledModules(array_unique(array_merge($enabledModules, $modules))); + foreach ($modules as $moduleName) { - $errorModules = $conflictChecker->checkConflictWhenEnableModule($moduleName); + $errorModules = $this->conflictChecker->checkConflictWhenEnableModule($moduleName); if (!empty($errorModules)) { $errorMessages[] = "Cannot enable $moduleName, conflicting active modules:"; foreach ($errorModules as $errorModule) { @@ -114,17 +137,15 @@ public function checkConstraints($isEnable, $modules) } } } else { - $dependencyChecker = new DependencyChecker( - new DependencyGraphFactory(), - array_keys($all), - $enabledModules - ); + $this->dependencyChecker->setModules(array_keys($all)); + $this->dependencyChecker->setEnabledModules(array_diff($enabledModules, $modules)); + foreach ($modules as $moduleName) { - $errorModules = $dependencyChecker->checkDependencyWhenDisableModule($moduleName); + $errorModules = $this->dependencyChecker->checkDependencyWhenDisableModule($moduleName); if (!empty($errorModules)) { $errorMessages[] = "Cannot disable $moduleName, active modules depending on it:"; - foreach ($errorModules as $errorModule) { - $errorMessages [] = "\t$errorModule"; + foreach ($errorModules as $errorModule => $path) { + $errorMessages [] = "\t$errorModule: " . implode('->', $path); } } } From 78a857e07de5f152cf35c4ca6c048d1bb9b1a7b3 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 21 Jan 2015 11:19:09 -0600 Subject: [PATCH 37/89] MAGETWO-32613: Add dependency restrictions - refactored so that reusing logic to obtain modules JSON data - added unit tests --- .../Magento/Framework/Module/CheckerTest.php | 18 +++ .../Framework/Module/ConflictCheckerTest.php | 98 +++++++++++++++ .../Module/DependencyCheckerTest.php | 45 +++++++ .../Module/DependencyGraphFactoryTest.php | 42 +++++++ .../Framework/Module/DependencyGraphTest.php | 66 +++++++++++ .../Magento/Framework/Module/MapperTest.php | 26 ++++ .../Magento/Framework/Module/StatusTest.php | 112 +++++++++++++++++- .../Magento/Setup/Model/ModuleListTest.php | 60 ++++++++++ .../Magento/Framework/Module/Checker.php | 27 ++--- .../Framework/Module/ConflictChecker.php | 41 +++---- .../Framework/Module/DependencyChecker.php | 74 ++++++++---- .../Framework/Module/DependencyGraph.php | 30 ++--- .../Module/DependencyGraphFactory.php | 46 ++----- .../Magento/Framework/Module/Mapper.php | 59 +++------ .../Magento/Framework/Module/Status.php | 77 ++++++------ .../Setup/Controller/ConsoleController.php | 16 ++- setup/src/Magento/Setup/Model/ModuleList.php | 80 +++++++++++++ 17 files changed, 702 insertions(+), 215 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/CheckerTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphFactoryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/MapperTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/ModuleListTest.php create mode 100644 setup/src/Magento/Setup/Model/ModuleList.php diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/CheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/CheckerTest.php new file mode 100644 index 0000000000000..fe3441a83d86b --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/CheckerTest.php @@ -0,0 +1,18 @@ + '{name: vendor/a}']; + $mapperMock = $this->getMock('Magento\Framework\Module\Mapper', [], [], '', false); + $mapperMock->expects($this->once())->method('createMapping')->with($modulesData); + $checker = new Checker($mapperMock); + $checker->setModulesData($modulesData); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php new file mode 100644 index 0000000000000..888751476ba7a --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -0,0 +1,98 @@ +getMock('Magento\Framework\Module\Mapper', [], [], '', false); + $mapperMock->expects($this->any()) + ->method('packageNameToModuleFullName') + ->will($this->returnValueMap($mapperReturnMap)); + $conflictChecker = new ConflictChecker($mapperMock); + $conflictChecker->setModulesData($data); + $conflictChecker->setEnabledModules($enabledData); + $this->assertEquals($conflictingModules, $conflictChecker->checkConflictsWhenEnableModules($moduleName)); + } + + /** + * @return array + */ + public function checkConflictWhenEnableModuleDataProvider() + { + return [ + [ + [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], + ['Vendor_A' => '{"conflict":{"vendor/module-B":0.1}}', 'Vendor_B' => '{}'], + ['Vendor_A'], + ['Vendor_B'], + ['Vendor_B' => ['Vendor_A']] + ], + [ + [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], + ['Vendor_A' => '{"conflict":{"vendor/module-B":0.1}}', 'Vendor_B' => '{}'], + [], + ['Vendor_B'], + ['Vendor_B' => []] + ], + [ + [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], + ['Vendor_B' => '{"conflict":{"vendor/module-A":0.1}}', 'Vendor_A' => '{}'], + ['Vendor_A'], + ['Vendor_B'], + ['Vendor_B' => ['Vendor_A']] + ], + [ + [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], + ['Vendor_B' => '{"conflict":{"vendor/module-A":0.1}}', 'Vendor_A' => '{}'], + [], + ['Vendor_B'], + ['Vendor_B' => []] + ], + [ + [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], + ['Vendor_A' => '{}', 'Vendor_B' => '{}'], + ['Vendor_A'], + ['Vendor_B'], + ['Vendor_B' => []] + ], + [ + [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B'], ['vendor/module-C', 'Vendor_C']], + ['Vendor_A' => '{}', 'Vendor_B' => '{}', 'Vendor_C' => '{}'], + ['Vendor_A'], + ['Vendor_B', 'Vendor_C'], + ['Vendor_B' => [], 'Vendor_C' => []] + ], + [ + [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B'], ['vendor/module-C', 'Vendor_C']], + ['Vendor_A' => '{"conflict":{"vendor/module-C":0.1}}', 'Vendor_B' => '{}', 'Vendor_C' => '{}'], + ['Vendor_A'], + ['Vendor_B', 'Vendor_C'], + ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A']] + ], + [ + [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B'], ['vendor/module-C', 'Vendor_C']], + ['Vendor_A' => '{}', 'Vendor_B' => '{"conflict":{"vendor/module-C":0.1}}', 'Vendor_C' => '{}'], + ['Vendor_A'], + ['Vendor_B', 'Vendor_C'], + ['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']] + ], + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php new file mode 100644 index 0000000000000..82bbb2cc02820 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php @@ -0,0 +1,45 @@ +getMock('Magento\Framework\Module\Mapper'); + $factoryMock = $this->getMock('Magento\Framework\Module\DependencyGraphFactory', [], [], '', false); + $factoryMock->expects($this->once())->method('create')->will($this->returnValue($graph)); + $this->checker = new DependencyChecker($factoryMock, $mapperMock); + $this->checker->setModulesData(['A' => '{}', 'B' => '{}', 'C' => '{}', 'D' => '{}', 'E' => '{}']); + } + public function testCheckDependenciesWhenDisableModules() + { + $this->checker->setEnabledModules(['A', 'B', 'C', 'D', 'E']); + $actual = $this->checker->checkDependenciesWhenDisableModules(['B', 'D']); + $expected = ['B' => ['A' => ['A', 'B']], 'D' => ['A' => ['A', 'B', 'D']]]; + $this->assertEquals($expected, $actual); + } + + public function testCheckDependenciesWhenEnableModules() + { + $this->checker->setEnabledModules(['C']); + $actual = $this->checker->checkDependenciesWhenEnableModules(['B', 'D']); + $expected = [ + 'B' => ['A' => ['B', 'D', 'A(disabled)'], 'E' => ['B', 'E(disabled)']], + 'D' => ['A' => ['D', 'A(disabled)'], 'E' => ['D', 'A(disabled)', 'B', 'E(disabled)']], + ]; + $this->assertEquals($expected, $actual); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphFactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphFactoryTest.php new file mode 100644 index 0000000000000..72f9f09775ca2 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphFactoryTest.php @@ -0,0 +1,42 @@ +getMock('Magento\Framework\Module\Mapper', [], [], '', false); + $valueMap = [ + ['vendor/module-a', 'Vendor_A'], + ['vendor/module-b', 'Vendor_B'], + ['vendor/module-c', 'Vendor_C'], + ['vendor/module-d', 'Vendor_D'], + ['vendor/module-e', 'Vendor_E'], + ]; + $mapper->expects($this->any()) + ->method('packageNameToModuleFullName') + ->will($this->returnValueMap($valueMap)); + $modulesData = [ + 'Vendor_A' => '{"require": {"vendor/module-b":"0.1", "vendor/module-c":"0.1"}}', + 'Vendor_B' => '{"require": {"vendor/module-d":"0.1"}}', + 'Vendor_C' => '{"require": {"vendor/module-e":"0.1"}}', + 'Vendor_D' => '{"require": {"vendor/module-a":"0.1"}}', + 'Vendor_E' => '{"require": {"vendor/module-b":"0.1", "vendor/module-d":"0.1"}}', + ]; + $relations = [ + 'Vendor_A' => ['Vendor_B' => 'Vendor_B', 'Vendor_C' => 'Vendor_C'], + 'Vendor_B' => ['Vendor_D' => 'Vendor_D'], + 'Vendor_C' => ['Vendor_E' => 'Vendor_E'], + 'Vendor_D' => ['Vendor_A' => 'Vendor_A'], + 'Vendor_E' => ['Vendor_B' => 'Vendor_B', 'Vendor_D' => 'Vendor_D'], + ]; + $graph = $factory->create($mapper, $modulesData); + $this->assertInstanceOf('Magento\Framework\Module\DependencyGraph', $graph); + $this->assertEquals($relations, $graph->getRelations()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphTest.php new file mode 100644 index 0000000000000..027209450a86c --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphTest.php @@ -0,0 +1,66 @@ +traverseGraph($from, $mode); + $this->assertEquals($chain, $dependencyGraph->getChain($to)); + } + + /** + * @return array + */ + public function getChainDataProvider() + { + return [ + [ + ['A', 'B', 'C', 'D', 'E'], + [['A', 'B'], ['A', 'C'], ['B', 'D'], ['B', 'E'], ['D', 'E']], + 'A', + 'E', + DependencyGraph::DIRECTIONAL , + ['A', 'B', 'E'] + ], + [ + ['A', 'B', 'C', 'D', 'E'], + [['A', 'B'], ['A', 'C'], ['B', 'D'], ['B', 'E'], ['D', 'E']], + 'E', + 'A', + DependencyGraph::INVERSE , + ['E', 'B', 'A'] + ], + [ + ['A', 'B', 'C', 'D', 'E'], + [['A', 'C'], ['C', 'B'], ['C', 'E'], ['B', 'D'], ['D', 'E']], + 'A', + 'E', + DependencyGraph::DIRECTIONAL, + ['A', 'C', 'E'] + ], + [ + ['A', 'B', 'C', 'D', 'E'], + [['A', 'C'], ['C', 'B'], ['C', 'E'], ['B', 'D'], ['D', 'E']], + 'E', + 'A', + DependencyGraph::INVERSE, + ['E', 'C', 'A'] + ], + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/MapperTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/MapperTest.php new file mode 100644 index 0000000000000..ec991ad5be94d --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/MapperTest.php @@ -0,0 +1,26 @@ + '{"name":"vendor/module-a"}', + 'Vendor_B' => '{"name":"vendor/module-b"}', + 'Vendor_C' => '{"name":"vendor/module-c"}', + ]; + $mapper->createMapping($modulesData); + $this->assertEquals('Vendor_A', $mapper->packageNameToModuleFullName('vendor/module-a')); + $this->assertEquals('Vendor_B', $mapper->packageNameToModuleFullName('vendor/module-b')); + $this->assertEquals('Vendor_C', $mapper->packageNameToModuleFullName('vendor/module-c')); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php index acc86089ee768..6562030bd4399 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php @@ -18,6 +18,11 @@ class StatusTest extends \PHPUnit_Framework_TestCase */ private $moduleList; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $reader; + /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -28,6 +33,16 @@ class StatusTest extends \PHPUnit_Framework_TestCase */ private $cleanup; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $conflictChecker; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $dependencyChecker; + /** * @var Status */ @@ -37,9 +52,104 @@ protected function setUp() { $this->loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $this->reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); $this->writer = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); $this->cleanup = $this->getMock('Magento\Framework\App\State\Cleanup', [], [], '', false); - $this->object = new Status($this->loader, $this->moduleList, $this->writer, $this->cleanup); + $this->conflictChecker = $this->getMock('Magento\Framework\Module\ConflictChecker', [], [], '', false); + $this->dependencyChecker = $this->getMock('Magento\Framework\Module\DependencyChecker', [], [], '', false); + $this->object = new Status( + $this->loader, + $this->moduleList, + $this->reader, + $this->writer, + $this->cleanup, + $this->conflictChecker, + $this->dependencyChecker + ); + } + + public function setUpCheckConstraints() + { + $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; + $this->loader->expects($this->once())->method('load')->willReturn($modules); + $fileIteratorMock = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false); + $fileIteratorMock->expects($this->once()) + ->method('toArray') + ->will($this->returnValue(['{}', '{}', '{}'])); + $this->reader->expects($this->once()) + ->method('getComposerJsonFiles') + ->will($this->returnValue($fileIteratorMock)); + } + public function testCheckConstraintsEnableAllowed() + { + $this->setUpCheckConstraints(); + $this->conflictChecker->expects($this->once()) + ->method('checkConflictsWhenEnableModules') + ->will($this->returnValue(['Module_Foo' => [], 'Module_Bar' => []])); + $this->dependencyChecker->expects($this->once()) + ->method('checkDependenciesWhenEnableModules') + ->will($this->returnValue(['Module_Foo' => [], 'Module_Bar' => []])); + $result = $this->object->checkConstraints(true, ['Module_Foo' => '', 'Module_Bar' => '']); + $this->assertEquals([], $result); + } + + public function testCheckConstraintsEnableNotAllowed() + { + $this->setUpCheckConstraints(); + $this->conflictChecker->expects($this->once()) + ->method('checkConflictsWhenEnableModules') + ->will($this->returnValue(['Module_Foo' => ['Module_Bar'], 'Module_Bar' => ['Module_Foo']])); + $this->dependencyChecker->expects($this->once()) + ->method('checkDependenciesWhenEnableModules') + ->will($this->returnValue( + [ + 'Module_Foo' => ['Module_Baz' => ['Module_Foo', 'Module_Baz(disabled)']], + 'Module_Bar' => ['Module_Baz' => ['Module_Bar', 'Module_Baz(disabled)']], + ] + )); + $result = $this->object->checkConstraints(true, ['Module_Foo' => '', 'Module_Bar' => '']); + $expect = [ + 'Cannot enable Module_Foo, depending on inactive modules:', + "\tModule_Baz: Module_Foo->Module_Baz(disabled)", + 'Cannot enable Module_Bar, depending on inactive modules:', + "\tModule_Baz: Module_Bar->Module_Baz(disabled)", + 'Cannot enable Module_Foo, conflicting active modules:', + "\tModule_Bar", + 'Cannot enable Module_Bar, conflicting active modules:', + "\tModule_Foo", + ]; + $this->assertEquals($expect, $result); + } + + public function testCheckConstraintsDisableAllowed() + { + $this->setUpCheckConstraints(); + $this->dependencyChecker->expects($this->once()) + ->method('checkDependenciesWhenDisableModules') + ->will($this->returnValue(['Module_Foo' => [], 'Module_Bar' => []])); + $result = $this->object->checkConstraints(false, ['Module_Foo' => '', 'Module_Bar' => '']); + $this->assertEquals([], $result); + } + + public function testCheckConstraintsDisableNotAllowed() + { + $this->setUpCheckConstraints(); + $this->dependencyChecker->expects($this->once()) + ->method('checkDependenciesWhenDisableModules') + ->will($this->returnValue( + [ + 'Module_Foo' => ['Module_Baz' => ['Module_Baz', 'Module_Foo']], + 'Module_Bar' => ['Module_Baz' => ['Module_Baz', 'Module_Bar']], + ] + )); + $result = $this->object->checkConstraints(false, ['Module_Foo' => '', 'Module_Bar' => '']); + $expect = [ + 'Cannot disable Module_Foo, active modules depending on it:', + "\tModule_Baz: Module_Baz->Module_Foo", + 'Cannot disable Module_Bar, active modules depending on it:', + "\tModule_Baz: Module_Baz->Module_Bar", + ]; + $this->assertEquals($expect, $result); } public function testSetIsEnabled() diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ModuleListTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ModuleListTest.php new file mode 100644 index 0000000000000..d840eb6ed9cf3 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ModuleListTest.php @@ -0,0 +1,60 @@ +getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); + $modules = [ + 'Vendor_A' => ['data' => 'a'], + 'Vendor_B' => ['data' => 'b'], + 'Vendor_C' => ['data' => 'c'], + ]; + $loaderMock->expects($this->once())->method('load')->will($this->returnValue($modules)); + $this->moduleList = new ModuleList($loaderMock); + } + + public function testGetAll() + { + $expect = [ + 'Vendor_A' => ['data' => 'a'], + 'Vendor_B' => ['data' => 'b'], + 'Vendor_C' => ['data' => 'c'], + ]; + $this->assertEquals($expect, $this->moduleList->getAll()); + // call once more to make sure it's cached + $this->moduleList->getAll(); + } + + public function testGetOne() + { + $expect = ['data' => 'b']; + $this->assertEquals($expect, $this->moduleList->getOne('Vendor_B')); + } + + public function testGetNames() + { + $expect = ['Vendor_A', 'Vendor_B', 'Vendor_C']; + $this->assertEquals($expect, $this->moduleList->getNames()); + } + + public function testHasTrue() + { + $this->assertTrue($this->moduleList->has('Vendor_A')); + } + + public function testHasFalse() + { + $this->assertFalse($this->moduleList->has('No_Such_Module')); + } +} diff --git a/lib/internal/Magento/Framework/Module/Checker.php b/lib/internal/Magento/Framework/Module/Checker.php index 364fc050dc135..5596b9ec5b32a 100644 --- a/lib/internal/Magento/Framework/Module/Checker.php +++ b/lib/internal/Magento/Framework/Module/Checker.php @@ -10,14 +10,14 @@ class Checker { /** - * List of all modules + * All Modules composer.json data * * @var array */ - protected $modules; + protected $modulesData; /** - * List of all enabled modules assuming module enable/disable operation succeeds + * List of enabled modules * * @var array */ @@ -39,15 +39,15 @@ public function __construct(Mapper $mapper) } /** - * Set list of all modules + * Set modules data, this also provide the data to Mapper to create mappings of package name to module name * - * @param $modules + * @param string[] $modulesData * @return void */ - public function setModules($modules) + public function setModulesData($modulesData) { - $this->modules = $modules; - $this->mapper->setModules($modules); + $this->modulesData = $modulesData; + $this->mapper->createMapping($modulesData); } /** @@ -60,15 +60,4 @@ public function setEnabledModules($enabledModules) { $this->enabledModules = $enabledModules; } - - /** - * Check if module is enabled - * - * @param string $moduleName - * @return bool - */ - protected function checkIfEnabled($moduleName) - { - return array_search($moduleName, $this->enabledModules) !== false; - } } diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index 352220cdb0ff0..f41b37e8bda64 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -21,31 +21,27 @@ class ConflictChecker extends Checker */ protected $filesystem; - /** - * @param Filesystem $filesystem - * @param Mapper $mapper - */ - public function __construct(Filesystem $filesystem, Mapper $mapper) - { - parent::__construct($mapper); - $this->filesystem = $filesystem; - } - /** * Check if enabling module will conflict any modules * - * @param $moduleName + * @param string[] $moduleNames * @return array */ - public function checkConflictWhenEnableModule($moduleName) + public function checkConflictsWhenEnableModules($moduleNames) { - $conflicts = []; - foreach ($this->enabledModules as $enabledModule) { - if ($this->checkIfConflict($enabledModule, $moduleName)) { - $conflicts[] = $enabledModule; + // union of currently enabled modules and to-be-enabled modules + $this->enabledModules = array_unique(array_merge($this->enabledModules, $moduleNames)); + $conflictsAll = []; + foreach ($moduleNames as $moduleName) { + $conflicts = []; + foreach ($this->enabledModules as $enabledModule) { + if ($this->checkIfConflict($enabledModule, $moduleName)) { + $conflicts[] = $enabledModule; + } } + $conflictsAll[$moduleName] = $conflicts; } - return $conflicts; + return $conflictsAll; } /** @@ -58,15 +54,8 @@ private function checkIfConflict($enabledModule, $moduleName) { $jsonDecoder = new \Magento\Framework\Json\Decoder(); - $vendorA = $this->mapper->moduleFullNameToVendorName($enabledModule); - $vendorB = $this->mapper->moduleFullNameToVendorName($moduleName); - $moduleA = $this->mapper->moduleFullNameToModuleName($enabledModule); - $moduleB = $this->mapper->moduleFullNameToModuleName($moduleName); - - $readAdapter = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MODULES); - - $data1 = $jsonDecoder->decode($readAdapter->readFile("$vendorA/$moduleA/composer.json")); - $data2 = $jsonDecoder->decode($readAdapter->readFile("$vendorB/$moduleB/composer.json")); + $data1 = $jsonDecoder->decode($this->modulesData[$enabledModule]); + $data2 = $jsonDecoder->decode($this->modulesData[$moduleName]); if (isset($data1[self::KEY_CONFLICT])) { foreach (array_keys($data1[self::KEY_CONFLICT]) as $packageName) { diff --git a/lib/internal/Magento/Framework/Module/DependencyChecker.php b/lib/internal/Magento/Framework/Module/DependencyChecker.php index 446fca1d2be59..7c6280c50dc58 100644 --- a/lib/internal/Magento/Framework/Module/DependencyChecker.php +++ b/lib/internal/Magento/Framework/Module/DependencyChecker.php @@ -25,47 +25,71 @@ public function __construct(DependencyGraphFactory $factory, Mapper $mapper) } /** - * Checks modules that are depending on the to-be-disabled module + * Checks dependencies when disabling modules * - * @param string $moduleName + * @param string[] $moduleNames * @return array */ - public function checkDependencyWhenDisableModule($moduleName) + public function checkDependenciesWhenDisableModules($moduleNames) { - $dependenciesMissing = []; - $graph = $this->factory->create($this->modules); - $graph->traverseGraph($moduleName, DependencyGraph::INVERSE); - foreach ($this->modules as $module) { - $dependencyChain = $graph->getChain($module); - if (!empty($dependencyChain) && $this->checkIfEnabled($module)) { - $dependenciesMissing[$module] = array_reverse($dependencyChain); + // assume disable succeeds: currently enabled modules - to-be-disabled modules + $this->enabledModules = array_diff($this->enabledModules, $moduleNames); + $dependenciesMissingAll = []; + $graph = $this->factory->create($this->mapper, $this->modulesData); + foreach ($moduleNames as $moduleName) { + $dependenciesMissing = []; + $graph->traverseGraph($moduleName, DependencyGraph::INVERSE); + foreach (array_keys($this->modulesData) as $module) { + $dependencyChain = $graph->getChain($module); + if (!empty($dependencyChain) && $this->checkIfEnabled($module)) { + $dependenciesMissing[$module] = array_reverse($dependencyChain); + } } + $dependenciesMissingAll[$moduleName] = $dependenciesMissing; } - return $dependenciesMissing; + return $dependenciesMissingAll; } /** - * Checks modules the to-be-enabled module is depending on + * Checks dependencies when enabling modules * - * @param string $moduleName + * @param string[] $moduleNames * @return array */ - public function checkDependencyWhenEnableModule($moduleName) + public function checkDependenciesWhenEnableModules($moduleNames) { - $dependenciesMissing = []; - $graph = $this->factory->create($this->modules); - $graph->traverseGraph($moduleName); - foreach ($this->modules as $module) { - $dependencyChain = $graph->getChain($module); - if (!empty($dependencyChain) && !$this->checkIfEnabled($module)) { - foreach ($dependencyChain as $key => $node) { - if (!$this->checkIfEnabled($node)) { - $dependencyChain[$key] = $dependencyChain[$key] . '(disabled)'; + // assume enable succeeds: union of currently enabled modules and to-be-enabled modules + $this->enabledModules = array_unique(array_merge($this->enabledModules, $moduleNames)); + $dependenciesMissingAll = []; + $graph = $this->factory->create($this->mapper, $this->modulesData); + foreach ($moduleNames as $moduleName) { + $dependenciesMissing = []; + $graph->traverseGraph($moduleName); + foreach (array_keys($this->modulesData) as $module) { + $dependencyChain = $graph->getChain($module); + if (!empty($dependencyChain) && !$this->checkIfEnabled($module)) { + foreach ($dependencyChain as $key => $node) { + if (!$this->checkIfEnabled($node)) { + $dependencyChain[$key] = $dependencyChain[$key] . '(disabled)'; + } } + $dependenciesMissing[$module] = $dependencyChain; } - $dependenciesMissing[$module] = $dependencyChain; } + $dependenciesMissingAll[$moduleName] = $dependenciesMissing; } - return $dependenciesMissing; + return $dependenciesMissingAll; + } + + + /** + * Check if module is enabled + * + * @param string $moduleName + * @return bool + */ + protected function checkIfEnabled($moduleName) + { + return array_search($moduleName, $this->enabledModules) !== false; } } diff --git a/lib/internal/Magento/Framework/Module/DependencyGraph.php b/lib/internal/Magento/Framework/Module/DependencyGraph.php index e2ebba672817a..c3d1c8daa4fd7 100644 --- a/lib/internal/Magento/Framework/Module/DependencyGraph.php +++ b/lib/internal/Magento/Framework/Module/DependencyGraph.php @@ -13,31 +13,23 @@ class DependencyGraph extends \Magento\Framework\Data\Graph private $paths; /** - * Traverse the graph using depth-search traversal + * Traverse the graph using breadth-search traversal from a root * * @return void */ public function traverseGraph($fromNode, $mode = self::DIRECTIONAL) { $this->_assertNode($fromNode, true); - //$this->_traverseGraph($fromNode, $this->getRelations($mode), [$fromNode]); $this->_traverseGraphBFS($fromNode, $this->getRelations($mode)); } - protected function _traverseGraph($fromNode, $graph, $path = [], &$visited = []) - { - $visited[$fromNode] = $fromNode; - if (isset($graph[$fromNode])) { - foreach ($graph[$fromNode] as $node) { - if (!isset($visited[$node])) { - $path[] = $node; - $this->paths[$node] = $path; - $this->_traverseGraph($node, $graph, $path, $visited); - } - } - } - } - + /** + * Traverse helper method + * + * @param $fromNode + * @param $graph + * @return void + */ protected function _traverseGraphBFS($fromNode, $graph) { $queue = [$fromNode]; @@ -45,11 +37,11 @@ protected function _traverseGraphBFS($fromNode, $graph) $this->paths[$fromNode] = [$fromNode]; while (!empty($queue)) { $node = array_shift($queue); - $visited[$node] = $node; - if (isset($graph[$node])) { + if (!empty($graph[$node])) { foreach ($graph[$node] as $child) { if (!isset($visited[$child])) { $this->paths[$child] = array_merge($this->paths[$node], [$child]); + $visited[$child] = $child; $queue[] = $child; } } @@ -58,7 +50,7 @@ protected function _traverseGraphBFS($fromNode, $graph) } /** - * Get chain to node + * Get shortest chain to node * Note that this is not necessarily the only chain * * @param string $toNode diff --git a/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php b/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php index e88d4dcaab490..4894e6ebf8192 100644 --- a/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php +++ b/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php @@ -11,57 +11,25 @@ class DependencyGraphFactory { const KEY_REQUIRE = 'require'; - /** - * @var Mapper - */ - private $mapper; - - /** - * @var array - */ - private $modules; - - /** - * Filesystem - * - * @var Filesystem - */ - private $filesystem; - /** * @param Mapper $mapper - */ - public function __construct(Filesystem $filesystem, Mapper $mapper) - { - $this->filesystem = $filesystem; - $this->mapper = $mapper; - } - - /** - * @param array $modules + * @param array $modulesData * @return DependencyGraph */ - public function create($modules) + public function create(Mapper $mapper, $modulesData) { - $readAdapter = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MODULES); - - $this->modules = $modules; - $this->mapper->setModules($modules); - $nodes = []; $dependencies = []; // build the graph data - foreach ($this->modules as $module) { + foreach ($modulesData as $moduleName => $data) { $jsonDecoder = new \Magento\Framework\Json\Decoder(); - $module_partial = $this->mapper->moduleFullNameToModuleName($module); - $vendor = $this->mapper->moduleFullNameToVendorName($module); - $data = $jsonDecoder->decode($readAdapter->readFile("$vendor/$module_partial/composer.json")); - $nodes[] = $module; + $data = $jsonDecoder->decode($data); + $nodes[] = $moduleName; foreach (array_keys($data[self::KEY_REQUIRE]) as $depend) { - $depend = $this->mapper->packageNameToModuleFullName($depend); + $depend = $mapper->packageNameToModuleFullName($depend); if ($depend) { - $dependencies[] = [$module, $depend]; + $dependencies[] = [$moduleName, $depend]; } } } diff --git a/lib/internal/Magento/Framework/Module/Mapper.php b/lib/internal/Magento/Framework/Module/Mapper.php index 6786365c01a9a..d19cb5ef0b9f5 100644 --- a/lib/internal/Magento/Framework/Module/Mapper.php +++ b/lib/internal/Magento/Framework/Module/Mapper.php @@ -1,4 +1,8 @@ filesystem = $filesystem; - } - - public function setModules($modules) + public function createMapping($modulesData) { - $this->modules = $modules; $jsonDecoder = new \Magento\Framework\Json\Decoder(); - $readAdapter = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MODULES); - foreach ($this->modules as $module) { - $modulePartial = $this->moduleFullNameToModuleName($module); - $vendor = $this->moduleFullNameToVendorName($module); - $data = $jsonDecoder->decode($readAdapter->readFile("$vendor/$modulePartial/composer.json")); - $this->packageNameMap[$data['name']] = $module; + foreach ($modulesData as $path => $data) { + $data = $jsonDecoder->decode($data); + $this->packageNameMap[$data['name']] = $path; } } /** - * Convert Magento_X to X - * - * @param string $moduleFullName - * @return string - */ - public function moduleFullNameToModuleName($moduleFullName) - { - return explode('_', $moduleFullName)[1]; - } - - /** - * Convert Magento_X to Magento - */ - public function moduleFullNameToVendorName($moduleFullName) - { - return explode('_', $moduleFullName)[0]; - } - - /** - * Convert magento/modules-x to Magento_X + * Convert package name in composer.json to module name in module.xml * * @param string $packageName * @return string diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index 65c1f1a7edbc7..b38517005f3b5 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -45,20 +45,26 @@ class Status private $cleanup; /** - * @var DeploymentConfig - */ - private $deploymentConfig; - - /** + * Dependency Checker + * * @var DependencyChecker */ private $dependencyChecker; /** + * Conflict checker + * * @var ConflictChecker */ private $conflictChecker; + /** + * Module Directory Reader + * + * @var Dir\Reader + */ + private $reader; + /** * Constructor * @@ -68,22 +74,21 @@ class Status * @param Cleanup $cleanup * @param ConflictChecker $conflictChecker * @param DependencyChecker $dependencyChecker - * @param DeploymentConfig $deploymentConfig */ public function __construct( ModuleList\Loader $loader, ModuleList $list, + Dir\Reader $reader, Writer $writer, Cleanup $cleanup, ConflictChecker $conflictChecker, - DependencyChecker $dependencyChecker, - DeploymentConfig $deploymentConfig + DependencyChecker $dependencyChecker ) { $this->loader = $loader; $this->list = $list; + $this->reader = $reader; $this->writer = $writer; $this->cleanup = $cleanup; - $this->deploymentConfig = $deploymentConfig; $this->conflictChecker = $conflictChecker; $this->dependencyChecker = $dependencyChecker; } @@ -91,60 +96,50 @@ public function __construct( /** * Whether it is allowed to enable or disable specified modules * - * TODO: not implemented yet (MAGETWO-32613) - * * @param bool $isEnable * @param string[] $modules * @return string[] */ public function checkConstraints($isEnable, $modules) { - // TODO: deploymentConfig only works when application exists - $enabledModules = []; - $all = $this->deploymentConfig->getSegment(ModuleList\DeploymentConfig::CONFIG_KEY); - foreach ($all as $module => $enabled) { - if ($enabled) { - $enabledModules[] = $module; - } - } - + $enabledModules = $this->list->getNames(); + // array keys: module name in module.xml; array values: raw content from composer.json + // this raw data is used to create a dependency graph and also a package name-module name mapping + $rawData = array_combine(array_keys($this->loader->load()), $this->reader->getComposerJsonFiles()->toArray()); $errorMessages = []; + $this->dependencyChecker->setModulesData($rawData); + $this->dependencyChecker->setEnabledModules($enabledModules); if ($isEnable) { - $this->dependencyChecker->setModules(array_keys($all)); - $this->dependencyChecker->setEnabledModules(array_unique(array_merge($enabledModules, $modules))); + $this->conflictChecker->setModulesData($rawData); + $this->conflictChecker->setEnabledModules($enabledModules); + + $errorModulesDependency = $this->dependencyChecker->checkDependenciesWhenEnableModules($modules); + $errorModulesConflict = $this->conflictChecker->checkConflictsWhenEnableModules($modules); - foreach ($modules as $moduleName) { - $errorModules = $this->dependencyChecker->checkDependencyWhenEnableModule($moduleName); - if (!empty($errorModules)) { + foreach ($errorModulesDependency as $moduleName => $missingDependencies) { + if (!empty($missingDependencies)) { $errorMessages[] = "Cannot enable $moduleName, depending on inactive modules:"; - foreach ($errorModules as $errorModule => $path) { + foreach ($missingDependencies as $errorModule => $path) { $errorMessages [] = "\t$errorModule: " . implode('->', $path); } } } - // TODO: consolidate to one for loop - $this->conflictChecker->setModules($modules); - $this->conflictChecker->setEnabledModules(array_unique(array_merge($enabledModules, $modules))); - - foreach ($modules as $moduleName) { - $errorModules = $this->conflictChecker->checkConflictWhenEnableModule($moduleName); - if (!empty($errorModules)) { + foreach ($errorModulesConflict as $moduleName => $conflictingModules) { + if (!empty($conflictingModules)) { $errorMessages[] = "Cannot enable $moduleName, conflicting active modules:"; - foreach ($errorModules as $errorModule) { - $errorMessages [] = "\t$errorModule"; + foreach ($conflictingModules as $conflictingModule) { + $errorMessages [] = "\t$conflictingModule"; } } } } else { - $this->dependencyChecker->setModules(array_keys($all)); - $this->dependencyChecker->setEnabledModules(array_diff($enabledModules, $modules)); + $errorModulesDependency = $this->dependencyChecker->checkDependenciesWhenDisableModules($modules); - foreach ($modules as $moduleName) { - $errorModules = $this->dependencyChecker->checkDependencyWhenDisableModule($moduleName); - if (!empty($errorModules)) { + foreach ($errorModulesDependency as $moduleName => $missingDependencies) { + if (!empty($missingDependencies)) { $errorMessages[] = "Cannot disable $moduleName, active modules depending on it:"; - foreach ($errorModules as $errorModule => $path) { + foreach ($missingDependencies as $errorModule => $path) { $errorMessages [] = "\t$errorModule: " . implode('->', $path); } } diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 07de1656d69de..5ff8539858256 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -13,6 +13,7 @@ use Magento\Setup\Model\Installer; use Magento\Setup\Model\InstallerFactory; use Magento\Setup\Model\Lists; +use Magento\Setup\Model\ModuleList; use Magento\Setup\Model\UserConfigurationDataMapper as UserConfig; use Magento\Setup\Mvc\Bootstrap\InitParamListener; use Zend\Console\Request as ConsoleRequest; @@ -121,6 +122,13 @@ class ConsoleController extends AbstractActionController */ private $objectManager; + /** + * Module List + * + * @var ModuleList + */ + private $moduleList; + /** * Gets router configuration to be used in module definition * @@ -299,12 +307,14 @@ public function __construct( Lists $options, InstallerFactory $installerFactory, MaintenanceMode $maintenanceMode, + ModuleList $moduleList, ObjectManagerFactory $objectManagerFactory ) { $this->log = $consoleLogger; $this->options = $options; $this->installer = $installerFactory->create($consoleLogger); $this->maintenanceMode = $maintenanceMode; + $this->moduleList = $moduleList; $this->objectManagerFactory = $objectManagerFactory; } @@ -477,8 +487,12 @@ public function moduleAction() $request = $this->getRequest(); $isEnable = $request->getParam(0) == self::CMD_MODULE_ENABLE; $modules = explode(',', $request->getParam('modules')); + $reader = $this->getObjectManager()->create( + 'Magento\Framework\Module\Dir\Reader', + ['moduleList' => $this->moduleList] + ); /** @var \Magento\Framework\Module\Status $status */ - $status = $this->getObjectManager()->get('Magento\Framework\Module\Status'); + $status = $this->getObjectManager()->create('Magento\Framework\Module\Status', ['reader' => $reader]); if (!$request->getParam('force')) { $constraints = $status->checkConstraints($isEnable, $modules); if ($constraints) { diff --git a/setup/src/Magento/Setup/Model/ModuleList.php b/setup/src/Magento/Setup/Model/ModuleList.php new file mode 100644 index 0000000000000..27d5b9152811d --- /dev/null +++ b/setup/src/Magento/Setup/Model/ModuleList.php @@ -0,0 +1,80 @@ +loader = $loader; + } + + /** + * {@inheritdoc} + * @see getNames() + */ + public function getAll() + { + if (null === $this->data) { + $this->data = $this->loader->load(); + } + return $this->data; + } + + /** + * {@inheritdoc} + * @see has() + */ + public function getOne($name) + { + $data = $this->getAll(); + return isset($data[$name]) ? $data[$name] : null; + } + + /** + * {@inheritdoc} + */ + public function getNames() + { + $data = $this->getAll(); + $result = array_keys($data); + return $result; + } + + /** + * {@inheritdoc} + */ + public function has($name) + { + return array_search($name, $this->getNames()) !== false; + } +} \ No newline at end of file From cc73758f3f4aff148942543235ab19814f5414ac Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 21 Jan 2015 11:46:40 -0600 Subject: [PATCH 38/89] MAGETWO-32613: Add dependency restrictions - fixed unit test in ConsoleController --- .../Controller/ConsoleControllerTest.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index b5ca1975c2e48..c06457b95d1e4 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -49,6 +49,11 @@ class ConsoleControllerTest extends \PHPUnit_Framework_TestCase */ private $controller; + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ModuleList + */ + private $moduleList; + /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface */ @@ -72,6 +77,8 @@ public function setUp() $this->parameters= $this->getMock('\Zend\Stdlib\Parameters', [], [], '', false); $this->request->expects($this->any())->method('getParams')->willReturn($this->parameters); + $this->moduleList = $this->getMock('Magento\Setup\Model\ModuleList', [], [], '', false); + $this->mvcEvent = $this->getMock('\Zend\Mvc\MvcEvent', [], [], '', false); $this->mvcEvent->expects($this->once())->method('setRequest')->with($this->request)->willReturn( $this->mvcEvent @@ -90,6 +97,7 @@ public function setUp() $this->options, $installerFactory, $this->maintenanceMode, + $this->moduleList, $objectManagerFactory ); $this->controller->setEvent($this->mvcEvent); @@ -319,10 +327,13 @@ private function getModuleActionMocks($command, $modules, $isForce) $this->request->expects($this->at(1))->method('getParam')->with('modules')->willReturn($modules); $this->request->expects($this->at(2))->method('getParam')->with('force')->willReturn($isForce); $status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); - $this->objectManager->expects($this->once()) - ->method('get') - ->with('Magento\Framework\Module\Status') - ->willReturn($status); + $reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); + $this->objectManager->expects($this->exactly(2)) + ->method('create') + ->will($this->returnValueMap([ + ['Magento\Framework\Module\Status', ['reader' => $reader], $status], + ['Magento\Framework\Module\Dir\Reader', ['moduleList' => $this->moduleList], $reader], + ])); return $status; } From 91b6cda2e5c57268a106449086e1b508d8f2d8f0 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 21 Jan 2015 11:54:18 -0600 Subject: [PATCH 39/89] MAGETWO-32613: Add dependency restrictions - removed unused reference --- lib/internal/Magento/Framework/Module/Status.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index b38517005f3b5..3c7f89fd990ae 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -8,8 +8,6 @@ use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\App\State\Cleanup; -use Magento\Framework\App\DeploymentConfig; -use Magento\Tools\Dependency\Report\Framework\Data\Dependency; /** * A service for controlling module status From cad279debad524a7c6015049b40b0c4b99439d5e Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 22 Jan 2015 10:59:58 -0600 Subject: [PATCH 40/89] MAGETWO-32613: Add dependency restrictions - changed according to CR feedback --- .../Magento/Framework/Data/GraphTest.php | 20 +++ .../Magento/Framework/Module/CheckerTest.php | 18 --- .../Framework/Module/ConflictCheckerTest.php | 67 +++++---- .../Module/DependencyCheckerTest.php | 59 ++++++-- .../Module/DependencyGraphFactoryTest.php | 42 ------ .../Framework/Module/DependencyGraphTest.php | 66 --------- .../Magento/Framework/Module/MapperTest.php | 26 ---- .../Framework/Module/PackageInfoTest.php | 103 ++++++++++++++ .../Magento/Framework/Module/StatusTest.php | 51 ++----- .../Controller/ConsoleControllerTest.php | 17 +-- .../Magento/Setup/Model/StatusFactoryTest.php | 40 ++++++ lib/internal/Magento/Framework/Data/Graph.php | 33 +++++ .../Magento/Framework/Module/Checker.php | 63 -------- .../Framework/Module/ConflictChecker.php | 48 +++---- .../Framework/Module/DependencyChecker.php | 94 ++++++------ .../Framework/Module/DependencyGraph.php | 63 -------- .../Module/DependencyGraphFactory.php | 40 ------ .../Magento/Framework/Module/Mapper.php | 44 ------ .../Magento/Framework/Module/PackageInfo.php | 134 ++++++++++++++++++ .../Magento/Framework/Module/Status.php | 58 +++----- .../Setup/Controller/ConsoleController.php | 22 ++- setup/src/Magento/Setup/Model/ModuleList.php | 6 +- .../src/Magento/Setup/Model/StatusFactory.php | 57 ++++++++ 23 files changed, 591 insertions(+), 580 deletions(-) delete mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/CheckerTest.php delete mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphFactoryTest.php delete mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphTest.php delete mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/MapperTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/StatusFactoryTest.php delete mode 100644 lib/internal/Magento/Framework/Module/Checker.php delete mode 100644 lib/internal/Magento/Framework/Module/DependencyGraph.php delete mode 100644 lib/internal/Magento/Framework/Module/DependencyGraphFactory.php delete mode 100644 lib/internal/Magento/Framework/Module/Mapper.php create mode 100644 lib/internal/Magento/Framework/Module/PackageInfo.php create mode 100644 setup/src/Magento/Setup/Model/StatusFactory.php diff --git a/dev/tests/unit/testsuite/Magento/Framework/Data/GraphTest.php b/dev/tests/unit/testsuite/Magento/Framework/Data/GraphTest.php index 9522a0681b64f..22d754e6cefc4 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Data/GraphTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Data/GraphTest.php @@ -104,4 +104,24 @@ public function testDfs() $this->assertEquals([], $model->dfs(3, 1, \Magento\Framework\Data\Graph::INVERSE)); $this->assertEquals([1, 2, 3], $model->dfs(1, 3, \Magento\Framework\Data\Graph::NON_DIRECTIONAL)); } + + public function testFindPathsToReachableNodes() + { + $model = new \Magento\Framework\Data\Graph([1, 2, 3, 4, 5], [[1, 2], [1, 3], [1, 4], [4, 5]]); + + // directional + $paths = $model->findPathsToReachableNodes(1); + ksort($paths); + $this->assertEquals([1 => [1], 2 => [1, 2], 3 => [1, 3], 4 => [1, 4], 5 => [1, 4, 5]], $paths); + + // inverse + $paths = $model->findPathsToReachableNodes(5, \Magento\Framework\Data\Graph::INVERSE); + ksort($paths); + $this->assertEquals([1 => [5, 4, 1], 4 => [5, 4], 5 => [5]], $paths); + + // non-directional + $paths = $model->findPathsToReachableNodes(5, \Magento\Framework\Data\Graph::NON_DIRECTIONAL); + ksort($paths); + $this->assertEquals([1 => [5, 4, 1], 2 => [5, 4, 1, 2], 3 => [5, 4, 1, 3], 4 => [5, 4], 5 => [5]], $paths); + } } diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/CheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/CheckerTest.php deleted file mode 100644 index fe3441a83d86b..0000000000000 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/CheckerTest.php +++ /dev/null @@ -1,18 +0,0 @@ - '{name: vendor/a}']; - $mapperMock = $this->getMock('Magento\Framework\Module\Mapper', [], [], '', false); - $mapperMock->expects($this->once())->method('createMapping')->with($modulesData); - $checker = new Checker($mapperMock); - $checker->setModulesData($modulesData); - } -} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index 888751476ba7a..c286c9cd3cd24 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -9,26 +9,31 @@ class ConflictCheckerTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider checkConflictWhenEnableModuleDataProvider - * @param array $mapperReturnMap - * @param array $data - * @param array $enabledData + * @param array $nameReturnMap + * @param array $conflictReturnMap + * @param array $enabledModules * @param string $moduleName + * @param array $expected */ public function testCheckConflictsWhenEnableModules( - $mapperReturnMap, - $data, - $enabledData, + $nameReturnMap, + $conflictReturnMap, + $enabledModules, $moduleName, - $conflictingModules + $expected ) { - $mapperMock = $this->getMock('Magento\Framework\Module\Mapper', [], [], '', false); - $mapperMock->expects($this->any()) - ->method('packageNameToModuleFullName') - ->will($this->returnValueMap($mapperReturnMap)); - $conflictChecker = new ConflictChecker($mapperMock); - $conflictChecker->setModulesData($data); - $conflictChecker->setEnabledModules($enabledData); - $this->assertEquals($conflictingModules, $conflictChecker->checkConflictsWhenEnableModules($moduleName)); + $packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); + $packageInfoMock->expects($this->any()) + ->method('getPackageName') + ->will($this->returnValueMap($nameReturnMap)); + $packageInfoMock->expects($this->any()) + ->method('getEnabledModules') + ->will($this->returnValue($enabledModules)); + $packageInfoMock->expects($this->any()) + ->method('getConflict') + ->will($this->returnValueMap($conflictReturnMap)); + $conflictChecker = new ConflictChecker($packageInfoMock); + $this->assertEquals($expected, $conflictChecker->checkConflictsWhenEnableModules($moduleName)); } /** @@ -38,57 +43,57 @@ public function checkConflictWhenEnableModuleDataProvider() { return [ [ - [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], - ['Vendor_A' => '{"conflict":{"vendor/module-B":0.1}}', 'Vendor_B' => '{}'], + [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], + [['Vendor_A', ['vendor/module-B']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], - ['Vendor_A' => '{"conflict":{"vendor/module-B":0.1}}', 'Vendor_B' => '{}'], + [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], + [['Vendor_A', ['vendor/module-B']], ['Vendor_B', []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], - ['Vendor_B' => '{"conflict":{"vendor/module-A":0.1}}', 'Vendor_A' => '{}'], + [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], + [['Vendor_B', ['vendor/module-A']], ['Vendor_A', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], - ['Vendor_B' => '{"conflict":{"vendor/module-A":0.1}}', 'Vendor_A' => '{}'], + [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], + [['Vendor_B', ['vendor/module-A']], ['Vendor_A', []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B']], - ['Vendor_A' => '{}', 'Vendor_B' => '{}'], + [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], + [['Vendor_A', []], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B'], ['vendor/module-C', 'Vendor_C']], - ['Vendor_A' => '{}', 'Vendor_B' => '{}', 'Vendor_C' => '{}'], + [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B'], ['Vendor_C', 'vendor/module-C']], + [['Vendor_A', []], ['Vendor_B', []], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => []] ], [ - [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B'], ['vendor/module-C', 'Vendor_C']], - ['Vendor_A' => '{"conflict":{"vendor/module-C":0.1}}', 'Vendor_B' => '{}', 'Vendor_C' => '{}'], + [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B'], ['Vendor_C', 'vendor/module-C']], + [['Vendor_A', ['vendor/module-C']], ['Vendor_B', []], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A']] ], [ - [['vendor/module-A', 'Vendor_A'], ['vendor/module-B', 'Vendor_B'], ['vendor/module-C', 'Vendor_C']], - ['Vendor_A' => '{}', 'Vendor_B' => '{"conflict":{"vendor/module-C":0.1}}', 'Vendor_C' => '{}'], + [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B'], ['Vendor_C', 'vendor/module-C']], + [['Vendor_A', []], ['Vendor_B', ['vendor/module-C']], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']] diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php index 82bbb2cc02820..f2084f6256aa9 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php @@ -12,21 +12,51 @@ class DependencyCheckerTest extends \PHPUnit_Framework_TestCase */ private $checker; + /** + * @var \Magento\Framework\Module\PackageInfo|\PHPUnit_Framework_MockObject_MockObject + */ + private $packageInfoMock; + public function setUp() { - $graph = new DependencyGraph( - ['A', 'B', 'C', 'D', 'E'], - [['A', 'B'], ['B', 'D'], ['B', 'E'], ['C', 'E'], ['D', 'A']] - ); - $mapperMock = $this->getMock('Magento\Framework\Module\Mapper'); - $factoryMock = $this->getMock('Magento\Framework\Module\DependencyGraphFactory', [], [], '', false); - $factoryMock->expects($this->once())->method('create')->will($this->returnValue($graph)); - $this->checker = new DependencyChecker($factoryMock, $mapperMock); - $this->checker->setModulesData(['A' => '{}', 'B' => '{}', 'C' => '{}', 'D' => '{}', 'E' => '{}']); + $this->packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); + $this->packageInfoMock + ->expects($this->any()) + ->method('getAllModuleNames') + ->will($this->returnValue(['A', 'B', 'C', 'D', 'E'])); + $requireMap = [ + ['A', ['vendor/module-B']], + ['B', ['vendor/module-D', 'vendor/module-E']], + ['C', ['vendor/module-E']], + ['D', ['vendor/module-A']], + ['E', []], + ]; + $this->packageInfoMock + ->expects($this->any()) + ->method('getRequire') + ->will($this->returnValueMap($requireMap)); + + $moduleNameMap = [ + ['vendor/module-A', 'A'], + ['vendor/module-B', 'B'], + ['vendor/module-C', 'C'], + ['vendor/module-D', 'D'], + ['vendor/module-E', 'E'], + ]; + $this->packageInfoMock + ->expects($this->any()) + ->method('getModuleName') + ->will($this->returnValueMap($moduleNameMap)); + + $this->checker = new DependencyChecker($this->packageInfoMock); } public function testCheckDependenciesWhenDisableModules() { - $this->checker->setEnabledModules(['A', 'B', 'C', 'D', 'E']); + $this->packageInfoMock + ->expects($this->any()) + ->method('getEnabledModules') + ->will($this->returnValue(['A', 'B', 'C', 'D', 'E'])); + $actual = $this->checker->checkDependenciesWhenDisableModules(['B', 'D']); $expected = ['B' => ['A' => ['A', 'B']], 'D' => ['A' => ['A', 'B', 'D']]]; $this->assertEquals($expected, $actual); @@ -34,11 +64,14 @@ public function testCheckDependenciesWhenDisableModules() public function testCheckDependenciesWhenEnableModules() { - $this->checker->setEnabledModules(['C']); + $this->packageInfoMock + ->expects($this->any()) + ->method('getEnabledModules') + ->will($this->returnValue(['C'])); $actual = $this->checker->checkDependenciesWhenEnableModules(['B', 'D']); $expected = [ - 'B' => ['A' => ['B', 'D', 'A(disabled)'], 'E' => ['B', 'E(disabled)']], - 'D' => ['A' => ['D', 'A(disabled)'], 'E' => ['D', 'A(disabled)', 'B', 'E(disabled)']], + 'B' => ['A' => ['B', 'D', 'A'], 'E' => ['B', 'E']], + 'D' => ['A' => ['D', 'A'], 'E' => ['D', 'A', 'B', 'E']], ]; $this->assertEquals($expected, $actual); } diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphFactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphFactoryTest.php deleted file mode 100644 index 72f9f09775ca2..0000000000000 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphFactoryTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getMock('Magento\Framework\Module\Mapper', [], [], '', false); - $valueMap = [ - ['vendor/module-a', 'Vendor_A'], - ['vendor/module-b', 'Vendor_B'], - ['vendor/module-c', 'Vendor_C'], - ['vendor/module-d', 'Vendor_D'], - ['vendor/module-e', 'Vendor_E'], - ]; - $mapper->expects($this->any()) - ->method('packageNameToModuleFullName') - ->will($this->returnValueMap($valueMap)); - $modulesData = [ - 'Vendor_A' => '{"require": {"vendor/module-b":"0.1", "vendor/module-c":"0.1"}}', - 'Vendor_B' => '{"require": {"vendor/module-d":"0.1"}}', - 'Vendor_C' => '{"require": {"vendor/module-e":"0.1"}}', - 'Vendor_D' => '{"require": {"vendor/module-a":"0.1"}}', - 'Vendor_E' => '{"require": {"vendor/module-b":"0.1", "vendor/module-d":"0.1"}}', - ]; - $relations = [ - 'Vendor_A' => ['Vendor_B' => 'Vendor_B', 'Vendor_C' => 'Vendor_C'], - 'Vendor_B' => ['Vendor_D' => 'Vendor_D'], - 'Vendor_C' => ['Vendor_E' => 'Vendor_E'], - 'Vendor_D' => ['Vendor_A' => 'Vendor_A'], - 'Vendor_E' => ['Vendor_B' => 'Vendor_B', 'Vendor_D' => 'Vendor_D'], - ]; - $graph = $factory->create($mapper, $modulesData); - $this->assertInstanceOf('Magento\Framework\Module\DependencyGraph', $graph); - $this->assertEquals($relations, $graph->getRelations()); - } -} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphTest.php deleted file mode 100644 index 027209450a86c..0000000000000 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyGraphTest.php +++ /dev/null @@ -1,66 +0,0 @@ -traverseGraph($from, $mode); - $this->assertEquals($chain, $dependencyGraph->getChain($to)); - } - - /** - * @return array - */ - public function getChainDataProvider() - { - return [ - [ - ['A', 'B', 'C', 'D', 'E'], - [['A', 'B'], ['A', 'C'], ['B', 'D'], ['B', 'E'], ['D', 'E']], - 'A', - 'E', - DependencyGraph::DIRECTIONAL , - ['A', 'B', 'E'] - ], - [ - ['A', 'B', 'C', 'D', 'E'], - [['A', 'B'], ['A', 'C'], ['B', 'D'], ['B', 'E'], ['D', 'E']], - 'E', - 'A', - DependencyGraph::INVERSE , - ['E', 'B', 'A'] - ], - [ - ['A', 'B', 'C', 'D', 'E'], - [['A', 'C'], ['C', 'B'], ['C', 'E'], ['B', 'D'], ['D', 'E']], - 'A', - 'E', - DependencyGraph::DIRECTIONAL, - ['A', 'C', 'E'] - ], - [ - ['A', 'B', 'C', 'D', 'E'], - [['A', 'C'], ['C', 'B'], ['C', 'E'], ['B', 'D'], ['D', 'E']], - 'E', - 'A', - DependencyGraph::INVERSE, - ['E', 'C', 'A'] - ], - ]; - } -} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/MapperTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/MapperTest.php deleted file mode 100644 index ec991ad5be94d..0000000000000 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/MapperTest.php +++ /dev/null @@ -1,26 +0,0 @@ - '{"name":"vendor/module-a"}', - 'Vendor_B' => '{"name":"vendor/module-b"}', - 'Vendor_C' => '{"name":"vendor/module-c"}', - ]; - $mapper->createMapping($modulesData); - $this->assertEquals('Vendor_A', $mapper->packageNameToModuleFullName('vendor/module-a')); - $this->assertEquals('Vendor_B', $mapper->packageNameToModuleFullName('vendor/module-b')); - $this->assertEquals('Vendor_C', $mapper->packageNameToModuleFullName('vendor/module-c')); - } -} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php new file mode 100644 index 0000000000000..e7f3944d94cd7 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php @@ -0,0 +1,103 @@ +moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $this->loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); + $this->reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); + $this->moduleList->expects($this->any())->method('getNames')->will($this->returnValue(['A', 'B', 'C'])); + $this->loader->expects($this->any()) + ->method('load') + ->will($this->returnValue(['A' => [], 'B' => [], 'C' => [], 'D' => [], 'E' => []])); + + $composerData = [ + 'A' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}}', + 'B' => '{"name":"b", "require":{"d":"0.1"}}', + 'C' => '{"name":"c", "require":{"e":"0.1"}}', + 'D' => '{"name":"d", "conflict":{"c":"0.1"}}', + 'E' => '{"name":"e"}', + ]; + $fileIteratorMock = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false); + $fileIteratorMock->expects($this->any()) + ->method('toArray') + ->will($this->returnValue($composerData)); + $this->reader->expects($this->any()) + ->method('getComposerJsonFiles') + ->will($this->returnValue($fileIteratorMock)); + + $this->packageInfo = new PackageInfo($this->moduleList, $this->loader, $this->reader); + } + + public function testGetAllModuleNames() + { + $this->assertEquals(['A', 'B', 'C', 'D', 'E'], $this->packageInfo->getAllModuleNames()); + } + + public function testGetEnabledModules() + { + $this->assertEquals(['A', 'B', 'C'], $this->packageInfo->getEnabledModules()); + } + + public function testGetPackageName() + { + $this->assertEquals('a', $this->packageInfo->getPackageName('A')); + $this->assertEquals('b', $this->packageInfo->getPackageName('B')); + $this->assertEquals('c', $this->packageInfo->getPackageName('C')); + $this->assertEquals('d', $this->packageInfo->getPackageName('D')); + $this->assertEquals('e', $this->packageInfo->getPackageName('E')); + } + + public function testGetModuleName() + { + $this->assertEquals('A', $this->packageInfo->getModuleName('a')); + $this->assertEquals('B', $this->packageInfo->getModuleName('b')); + $this->assertEquals('C', $this->packageInfo->getModuleName('c')); + $this->assertEquals('D', $this->packageInfo->getModuleName('d')); + $this->assertEquals('E', $this->packageInfo->getModuleName('e')); + } + + public function testGetRequire() + { + $this->assertEquals(['b'], $this->packageInfo->getRequire('A')); + $this->assertEquals(['d'], $this->packageInfo->getRequire('B')); + $this->assertEquals(['e'], $this->packageInfo->getRequire('C')); + $this->assertEquals([], $this->packageInfo->getRequire('D')); + $this->assertEquals([], $this->packageInfo->getRequire('E')); + } + + public function testGetConflict() + { + $this->assertEquals(['c'], $this->packageInfo->getConflict('A')); + $this->assertEquals([], $this->packageInfo->getConflict('B')); + $this->assertEquals([], $this->packageInfo->getConflict('C')); + $this->assertEquals(['c'], $this->packageInfo->getConflict('D')); + $this->assertEquals([], $this->packageInfo->getConflict('E')); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php index 6562030bd4399..20f1d23e2b54a 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php @@ -18,11 +18,6 @@ class StatusTest extends \PHPUnit_Framework_TestCase */ private $moduleList; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $reader; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -52,7 +47,6 @@ protected function setUp() { $this->loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); - $this->reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); $this->writer = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); $this->cleanup = $this->getMock('Magento\Framework\App\State\Cleanup', [], [], '', false); $this->conflictChecker = $this->getMock('Magento\Framework\Module\ConflictChecker', [], [], '', false); @@ -60,7 +54,6 @@ protected function setUp() $this->object = new Status( $this->loader, $this->moduleList, - $this->reader, $this->writer, $this->cleanup, $this->conflictChecker, @@ -68,21 +61,8 @@ protected function setUp() ); } - public function setUpCheckConstraints() - { - $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; - $this->loader->expects($this->once())->method('load')->willReturn($modules); - $fileIteratorMock = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false); - $fileIteratorMock->expects($this->once()) - ->method('toArray') - ->will($this->returnValue(['{}', '{}', '{}'])); - $this->reader->expects($this->once()) - ->method('getComposerJsonFiles') - ->will($this->returnValue($fileIteratorMock)); - } public function testCheckConstraintsEnableAllowed() { - $this->setUpCheckConstraints(); $this->conflictChecker->expects($this->once()) ->method('checkConflictsWhenEnableModules') ->will($this->returnValue(['Module_Foo' => [], 'Module_Bar' => []])); @@ -95,7 +75,6 @@ public function testCheckConstraintsEnableAllowed() public function testCheckConstraintsEnableNotAllowed() { - $this->setUpCheckConstraints(); $this->conflictChecker->expects($this->once()) ->method('checkConflictsWhenEnableModules') ->will($this->returnValue(['Module_Foo' => ['Module_Bar'], 'Module_Bar' => ['Module_Foo']])); @@ -103,27 +82,26 @@ public function testCheckConstraintsEnableNotAllowed() ->method('checkDependenciesWhenEnableModules') ->will($this->returnValue( [ - 'Module_Foo' => ['Module_Baz' => ['Module_Foo', 'Module_Baz(disabled)']], - 'Module_Bar' => ['Module_Baz' => ['Module_Bar', 'Module_Baz(disabled)']], + 'Module_Foo' => ['Module_Baz' => ['Module_Foo', 'Module_Baz']], + 'Module_Bar' => ['Module_Baz' => ['Module_Bar', 'Module_Baz']], ] )); $result = $this->object->checkConstraints(true, ['Module_Foo' => '', 'Module_Bar' => '']); $expect = [ - 'Cannot enable Module_Foo, depending on inactive modules:', - "\tModule_Baz: Module_Foo->Module_Baz(disabled)", - 'Cannot enable Module_Bar, depending on inactive modules:', - "\tModule_Baz: Module_Bar->Module_Baz(disabled)", - 'Cannot enable Module_Foo, conflicting active modules:', - "\tModule_Bar", - 'Cannot enable Module_Bar, conflicting active modules:', - "\tModule_Foo", + 'Cannot enable Module_Foo, depending on disabled modules:', + "Module_Baz: Module_Foo->Module_Baz", + 'Cannot enable Module_Bar, depending on disabled modules:', + "Module_Baz: Module_Bar->Module_Baz", + 'Cannot enable Module_Foo, conflicting modules:', + "Module_Bar", + 'Cannot enable Module_Bar, conflicting modules:', + "Module_Foo", ]; $this->assertEquals($expect, $result); } public function testCheckConstraintsDisableAllowed() { - $this->setUpCheckConstraints(); $this->dependencyChecker->expects($this->once()) ->method('checkDependenciesWhenDisableModules') ->will($this->returnValue(['Module_Foo' => [], 'Module_Bar' => []])); @@ -133,7 +111,6 @@ public function testCheckConstraintsDisableAllowed() public function testCheckConstraintsDisableNotAllowed() { - $this->setUpCheckConstraints(); $this->dependencyChecker->expects($this->once()) ->method('checkDependenciesWhenDisableModules') ->will($this->returnValue( @@ -144,10 +121,10 @@ public function testCheckConstraintsDisableNotAllowed() )); $result = $this->object->checkConstraints(false, ['Module_Foo' => '', 'Module_Bar' => '']); $expect = [ - 'Cannot disable Module_Foo, active modules depending on it:', - "\tModule_Baz: Module_Baz->Module_Foo", - 'Cannot disable Module_Bar, active modules depending on it:', - "\tModule_Baz: Module_Baz->Module_Bar", + 'Cannot disable Module_Foo, modules depending on it:', + "Module_Baz: Module_Baz->Module_Foo", + 'Cannot disable Module_Bar, modules depending on it:', + "Module_Baz: Module_Baz->Module_Bar", ]; $this->assertEquals($expect, $result); } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index c06457b95d1e4..c9bc69cdbd8e9 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -50,9 +50,9 @@ class ConsoleControllerTest extends \PHPUnit_Framework_TestCase private $controller; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ModuleList + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\StatusFactory */ - private $moduleList; + private $statusFactory; /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface @@ -77,7 +77,7 @@ public function setUp() $this->parameters= $this->getMock('\Zend\Stdlib\Parameters', [], [], '', false); $this->request->expects($this->any())->method('getParams')->willReturn($this->parameters); - $this->moduleList = $this->getMock('Magento\Setup\Model\ModuleList', [], [], '', false); + $this->statusFactory = $this->getMock('Magento\Setup\Model\StatusFactory', [], [], '', false); $this->mvcEvent = $this->getMock('\Zend\Mvc\MvcEvent', [], [], '', false); $this->mvcEvent->expects($this->once())->method('setRequest')->with($this->request)->willReturn( @@ -97,8 +97,8 @@ public function setUp() $this->options, $installerFactory, $this->maintenanceMode, - $this->moduleList, - $objectManagerFactory + $objectManagerFactory, + $this->statusFactory ); $this->controller->setEvent($this->mvcEvent); $this->controller->dispatch($this->request, $response); @@ -328,12 +328,9 @@ private function getModuleActionMocks($command, $modules, $isForce) $this->request->expects($this->at(2))->method('getParam')->with('force')->willReturn($isForce); $status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); $reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); - $this->objectManager->expects($this->exactly(2)) + $this->statusFactory->expects($this->once()) ->method('create') - ->will($this->returnValueMap([ - ['Magento\Framework\Module\Status', ['reader' => $reader], $status], - ['Magento\Framework\Module\Dir\Reader', ['moduleList' => $this->moduleList], $reader], - ])); + ->will($this->returnValue($status)); return $status; } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/StatusFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/StatusFactoryTest.php new file mode 100644 index 0000000000000..6b760ca895753 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/StatusFactoryTest.php @@ -0,0 +1,40 @@ +getMock('Magento\Setup\Model\ModuleList', [], [], '', false); + $objectManagerMock = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $readerMock = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); + $packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); + $conflictCheckerMock = $this->getMock('Magento\Framework\Module\ConflictChecker', [], [], '', false); + $dependencyCheckerMock = $this->getMock('Magento\Framework\Module\DependencyChecker', [], [], '', false); + $statusMock = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); + $returnValueMap = [ + ['Magento\Framework\Module\Dir\Reader', ['moduleList' => $moduleListMock], $readerMock], + ['Magento\Framework\Module\PackageInfo', ['reader' => $readerMock], $packageInfoMock], + ['Magento\Framework\Module\ConflictChecker', ['packageInfo' => $packageInfoMock], $conflictCheckerMock], + ['Magento\Framework\Module\DependencyChecker', ['packageInfo' => $packageInfoMock], $dependencyCheckerMock], + [ + 'Magento\Framework\Module\Status', + ['conflictChecker' => $conflictCheckerMock, 'dependencyChecker' => $dependencyCheckerMock], + $statusMock, + ] + ]; + $objectManagerMock->expects($this->any())->method('create')->will($this->returnValueMap($returnValueMap)); + $objectManagerFactoryMock = $this->getMock('Magento\Setup\Model\ObjectManagerFactory', [], [], '', false); + $objectManagerFactoryMock + ->expects($this->once()) + ->method('create') + ->will($this->returnValue($objectManagerMock)); + + $statusFactory = new StatusFactory($moduleListMock, $objectManagerFactoryMock); + $this->assertSame($statusMock, $statusFactory->create()); + } +} diff --git a/lib/internal/Magento/Framework/Data/Graph.php b/lib/internal/Magento/Framework/Data/Graph.php index 83d07efc9093a..c9a3cbb3e7d72 100644 --- a/lib/internal/Magento/Framework/Data/Graph.php +++ b/lib/internal/Magento/Framework/Data/Graph.php @@ -134,6 +134,39 @@ public function findCycle($node = null, $firstOnly = true) return $results; } + /** + * Find paths to reachable nodes from root node + * + * Returns array of paths, key is destination node and value is path (an array) from rootNode to destination node + * Eg. dest => [root, A, dest] means root -> A -> dest + * + * @param string|int $rootNode + * @param int $mode + * @return array + */ + public function findPathsToReachableNodes($rootNode, $mode = self::DIRECTIONAL) + { + $graph = $this->getRelations($mode); + $paths = []; + $queue = [$rootNode]; + $visited = [$rootNode => $rootNode]; + $paths[$rootNode] = [$rootNode]; + while (!empty($queue)) { + $node = array_shift($queue); + if (!empty($graph[$node])) { + foreach ($graph[$node] as $child) { + if (!isset($visited[$child])) { + $paths[$child] = $paths[$node]; + $paths[$child][] = $child; + $visited[$child] = $child; + $queue[] = $child; + } + } + } + } + return $paths; + } + /** * "Depth-first search" of a path between nodes * diff --git a/lib/internal/Magento/Framework/Module/Checker.php b/lib/internal/Magento/Framework/Module/Checker.php deleted file mode 100644 index 5596b9ec5b32a..0000000000000 --- a/lib/internal/Magento/Framework/Module/Checker.php +++ /dev/null @@ -1,63 +0,0 @@ -mapper = $mapper; - } - - /** - * Set modules data, this also provide the data to Mapper to create mappings of package name to module name - * - * @param string[] $modulesData - * @return void - */ - public function setModulesData($modulesData) - { - $this->modulesData = $modulesData; - $this->mapper->createMapping($modulesData); - } - - /** - * Set list of enabled modules, assuming module enable/disable succeeds - * - * @param $enabledModules - * @return void - */ - public function setEnabledModules($enabledModules) - { - $this->enabledModules = $enabledModules; - } -} diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index f41b37e8bda64..a5fc962d1c7f3 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -7,19 +7,22 @@ use Magento\Framework\Filesystem; -class ConflictChecker extends Checker +class ConflictChecker { /** - * Key to conflicting packages array in composer.json files + * Composer package info + * + * @var PackageInfo */ - const KEY_CONFLICT = 'conflict'; + private $packageInfo; /** - * Filesystem - * - * @var Filesystem + * @param PackageInfo $packageInfo */ - protected $filesystem; + public function __construct(PackageInfo $packageInfo) + { + $this->packageInfo = $packageInfo; + } /** * Check if enabling module will conflict any modules @@ -30,11 +33,11 @@ class ConflictChecker extends Checker public function checkConflictsWhenEnableModules($moduleNames) { // union of currently enabled modules and to-be-enabled modules - $this->enabledModules = array_unique(array_merge($this->enabledModules, $moduleNames)); + $enabledModules = array_unique(array_merge($this->packageInfo->getEnabledModules(), $moduleNames)); $conflictsAll = []; foreach ($moduleNames as $moduleName) { $conflicts = []; - foreach ($this->enabledModules as $enabledModule) { + foreach ($enabledModules as $enabledModule) { if ($this->checkIfConflict($enabledModule, $moduleName)) { $conflicts[] = $enabledModule; } @@ -52,28 +55,15 @@ public function checkConflictsWhenEnableModules($moduleNames) */ private function checkIfConflict($enabledModule, $moduleName) { - $jsonDecoder = new \Magento\Framework\Json\Decoder(); - - $data1 = $jsonDecoder->decode($this->modulesData[$enabledModule]); - $data2 = $jsonDecoder->decode($this->modulesData[$moduleName]); - - if (isset($data1[self::KEY_CONFLICT])) { - foreach (array_keys($data1[self::KEY_CONFLICT]) as $packageName) { - $module = $this->mapper->packageNameToModuleFullName($packageName); - if ($module == $moduleName) { - return true; - } - } + if (array_search($this->packageInfo->getPackageName($enabledModule), + $this->packageInfo->getConflict($moduleName)) !== false) { + return true; } - - if (isset($data2[self::KEY_CONFLICT])) { - foreach (array_keys($data2[self::KEY_CONFLICT]) as $packageName) { - $module = $this->mapper->packageNameToModuleFullName($packageName); - if ($module == $enabledModule) { - return true; - } - } + if (array_search($this->packageInfo->getPackageName($moduleName), + $this->packageInfo->getConflict($enabledModule)) !== false) { + return true; } + return false; } } diff --git a/lib/internal/Magento/Framework/Module/DependencyChecker.php b/lib/internal/Magento/Framework/Module/DependencyChecker.php index 7c6280c50dc58..dd94a5ede346a 100644 --- a/lib/internal/Magento/Framework/Module/DependencyChecker.php +++ b/lib/internal/Magento/Framework/Module/DependencyChecker.php @@ -5,23 +5,24 @@ */ namespace Magento\Framework\Module; +use Magento\Framework\Data\Graph; use Magento\Framework\Filesystem; -class DependencyChecker extends Checker +class DependencyChecker { /** - * @var DependencyGraphFactory + * Composer package info + * + * @var PackageInfo */ - protected $factory; + private $packageInfo; /** - * @param DependencyGraphFactory $factory - * @param Mapper $mapper + * @param PackageInfo $packageInfo */ - public function __construct(DependencyGraphFactory $factory, Mapper $mapper) + public function __construct(PackageInfo $packageInfo) { - parent::__construct($mapper); - $this->factory = $factory; + $this->packageInfo = $packageInfo; } /** @@ -33,21 +34,8 @@ public function __construct(DependencyGraphFactory $factory, Mapper $mapper) public function checkDependenciesWhenDisableModules($moduleNames) { // assume disable succeeds: currently enabled modules - to-be-disabled modules - $this->enabledModules = array_diff($this->enabledModules, $moduleNames); - $dependenciesMissingAll = []; - $graph = $this->factory->create($this->mapper, $this->modulesData); - foreach ($moduleNames as $moduleName) { - $dependenciesMissing = []; - $graph->traverseGraph($moduleName, DependencyGraph::INVERSE); - foreach (array_keys($this->modulesData) as $module) { - $dependencyChain = $graph->getChain($module); - if (!empty($dependencyChain) && $this->checkIfEnabled($module)) { - $dependenciesMissing[$module] = array_reverse($dependencyChain); - } - } - $dependenciesMissingAll[$moduleName] = $dependenciesMissing; - } - return $dependenciesMissingAll; + $enabledModules = array_diff($this->packageInfo->getEnabledModules(), $moduleNames); + return $this->checkDependencyGraph(false, $moduleNames, $enabledModules); } /** @@ -59,21 +47,33 @@ public function checkDependenciesWhenDisableModules($moduleNames) public function checkDependenciesWhenEnableModules($moduleNames) { // assume enable succeeds: union of currently enabled modules and to-be-enabled modules - $this->enabledModules = array_unique(array_merge($this->enabledModules, $moduleNames)); + $enabledModules = array_unique(array_merge($this->packageInfo->getEnabledModules(), $moduleNames)); + return $this->checkDependencyGraph(true, $moduleNames, $enabledModules); + } + + /** + * Check the dependency graph + * + * @param bool $isEnable + * @param string[] $moduleNames list of modules to be enabled/disabled + * @param string[] $enabledModules list of enabled modules assuming enable/disable succeeds + * @return array + */ + private function checkDependencyGraph($isEnable, $moduleNames, $enabledModules) + { $dependenciesMissingAll = []; - $graph = $this->factory->create($this->mapper, $this->modulesData); + $graph = $this->createGraph($this->packageInfo); + $graphMode = $isEnable ? Graph::DIRECTIONAL : Graph::INVERSE; foreach ($moduleNames as $moduleName) { $dependenciesMissing = []; - $graph->traverseGraph($moduleName); - foreach (array_keys($this->modulesData) as $module) { - $dependencyChain = $graph->getChain($module); - if (!empty($dependencyChain) && !$this->checkIfEnabled($module)) { - foreach ($dependencyChain as $key => $node) { - if (!$this->checkIfEnabled($node)) { - $dependencyChain[$key] = $dependencyChain[$key] . '(disabled)'; - } + $paths = $graph->findPathsToReachableNodes($moduleName, $graphMode); + foreach ($this->packageInfo->getAllModuleNames() as $module) { + if (isset($paths[$module])) { + if ($isEnable && !in_array($module, $enabledModules)) { + $dependenciesMissing[$module] = $paths[$module]; + } else if (!$isEnable && in_array($module, $enabledModules)) { + $dependenciesMissing[$module] = array_reverse($paths[$module]); } - $dependenciesMissing[$module] = $dependencyChain; } } $dependenciesMissingAll[$moduleName] = $dependenciesMissing; @@ -81,15 +81,29 @@ public function checkDependenciesWhenEnableModules($moduleNames) return $dependenciesMissingAll; } - /** - * Check if module is enabled + * Create the dependency graph * - * @param string $moduleName - * @return bool + * @param PackageInfo $packageInfo + * @return Graph */ - protected function checkIfEnabled($moduleName) + private function createGraph(PackageInfo $packageInfo) { - return array_search($moduleName, $this->enabledModules) !== false; + $nodes = []; + $dependencies = []; + + // build the graph data + foreach ($packageInfo->getAllModuleNames() as $moduleName) { + $nodes[] = $moduleName; + foreach ($packageInfo->getRequire($moduleName) as $dependPackageName) { + $depend = $packageInfo->getModuleName($dependPackageName); + if ($depend) { + $dependencies[] = [$moduleName, $depend]; + } + } + } + $nodes = array_unique($nodes); + + return new Graph($nodes, $dependencies); } } diff --git a/lib/internal/Magento/Framework/Module/DependencyGraph.php b/lib/internal/Magento/Framework/Module/DependencyGraph.php deleted file mode 100644 index c3d1c8daa4fd7..0000000000000 --- a/lib/internal/Magento/Framework/Module/DependencyGraph.php +++ /dev/null @@ -1,63 +0,0 @@ -_assertNode($fromNode, true); - $this->_traverseGraphBFS($fromNode, $this->getRelations($mode)); - } - - /** - * Traverse helper method - * - * @param $fromNode - * @param $graph - * @return void - */ - protected function _traverseGraphBFS($fromNode, $graph) - { - $queue = [$fromNode]; - $visited = []; - $this->paths[$fromNode] = [$fromNode]; - while (!empty($queue)) { - $node = array_shift($queue); - if (!empty($graph[$node])) { - foreach ($graph[$node] as $child) { - if (!isset($visited[$child])) { - $this->paths[$child] = array_merge($this->paths[$node], [$child]); - $visited[$child] = $child; - $queue[] = $child; - } - } - } - } - } - - /** - * Get shortest chain to node - * Note that this is not necessarily the only chain - * - * @param string $toNode - * @return array - */ - public function getChain($toNode) - { - return isset($this->paths[$toNode]) ? $this->paths[$toNode] : []; - } -} diff --git a/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php b/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php deleted file mode 100644 index 4894e6ebf8192..0000000000000 --- a/lib/internal/Magento/Framework/Module/DependencyGraphFactory.php +++ /dev/null @@ -1,40 +0,0 @@ - $data) { - $jsonDecoder = new \Magento\Framework\Json\Decoder(); - $data = $jsonDecoder->decode($data); - $nodes[] = $moduleName; - foreach (array_keys($data[self::KEY_REQUIRE]) as $depend) { - $depend = $mapper->packageNameToModuleFullName($depend); - if ($depend) { - $dependencies[] = [$moduleName, $depend]; - } - } - } - $nodes = array_unique($nodes); - - return new DependencyGraph($nodes, $dependencies); - } -} diff --git a/lib/internal/Magento/Framework/Module/Mapper.php b/lib/internal/Magento/Framework/Module/Mapper.php deleted file mode 100644 index d19cb5ef0b9f5..0000000000000 --- a/lib/internal/Magento/Framework/Module/Mapper.php +++ /dev/null @@ -1,44 +0,0 @@ - $data) { - $data = $jsonDecoder->decode($data); - $this->packageNameMap[$data['name']] = $path; - } - } - - /** - * Convert package name in composer.json to module name in module.xml - * - * @param string $packageName - * @return string - */ - public function packageNameToModuleFullName($packageName) - { - return isset($this->packageNameMap[$packageName]) ? $this->packageNameMap[$packageName] : ''; - } -} diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php new file mode 100644 index 0000000000000..1a86cd656c812 --- /dev/null +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -0,0 +1,134 @@ +enabledModules = $list->getNames(); + /** + * array keys: module name in module.xml; array values: raw content from composer.json + * this raw data is used to create a dependency graph and also a package name-module name mapping + */ + $rawData = array_combine(array_keys($loader->load()), $reader->getComposerJsonFiles()->toArray()); + foreach ($rawData as $moduleName => $jsonData) { + $jsonData = \Zend_Json::decode($jsonData); + $this->packageNameMap[$moduleName] = $jsonData['name']; + $this->moduleNameMap[$jsonData['name']] = $moduleName; + if (!empty($jsonData['require'])) { + $this->requireMap[$moduleName] = array_keys($jsonData['require']); + } + if (!empty($jsonData['conflict'])) { + $this->conflictMap[$moduleName] = array_keys($jsonData['conflict']); + } + } + } + + /** + * Get all modules names + * + * @return array + */ + public function getAllModuleNames() + { + return array_values($this->moduleNameMap); + } + + /** + * Get only enabled modules + * + * @return string[] + */ + public function getEnabledModules() + { + return $this->enabledModules; + } + + /** + * Get package name of a module + * + * @param string $moduleName + * @return string + */ + public function getPackageName($moduleName) + { + return isset($this->packageNameMap[$moduleName]) ? $this->packageNameMap[$moduleName] : ''; + } + + /** + * Get module name of a package + * + * @param string $packageName + * @return string + */ + public function getModuleName($packageName) + { + return isset($this->moduleNameMap[$packageName]) ? $this->moduleNameMap[$packageName] : ''; + } + + /** + * Get all package names a module requires + * + * @param string $moduleName + * @return array + */ + public function getRequire($moduleName) + { + return isset($this->requireMap[$moduleName]) ? $this->requireMap[$moduleName] : []; + } + + /** + * Get all package names a module conflicts + * + * @param string $moduleName + * @return array + */ + public function getConflict($moduleName) + { + return isset($this->conflictMap[$moduleName]) ? $this->conflictMap[$moduleName] : []; + } +} diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index 3c7f89fd990ae..aade9c3da37f6 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -56,13 +56,6 @@ class Status */ private $conflictChecker; - /** - * Module Directory Reader - * - * @var Dir\Reader - */ - private $reader; - /** * Constructor * @@ -76,7 +69,6 @@ class Status public function __construct( ModuleList\Loader $loader, ModuleList $list, - Dir\Reader $reader, Writer $writer, Cleanup $cleanup, ConflictChecker $conflictChecker, @@ -84,7 +76,6 @@ public function __construct( ) { $this->loader = $loader; $this->list = $list; - $this->reader = $reader; $this->writer = $writer; $this->cleanup = $cleanup; $this->conflictChecker = $conflictChecker; @@ -100,50 +91,33 @@ public function __construct( */ public function checkConstraints($isEnable, $modules) { - $enabledModules = $this->list->getNames(); - // array keys: module name in module.xml; array values: raw content from composer.json - // this raw data is used to create a dependency graph and also a package name-module name mapping - $rawData = array_combine(array_keys($this->loader->load()), $this->reader->getComposerJsonFiles()->toArray()); $errorMessages = []; - - $this->dependencyChecker->setModulesData($rawData); - $this->dependencyChecker->setEnabledModules($enabledModules); if ($isEnable) { - $this->conflictChecker->setModulesData($rawData); - $this->conflictChecker->setEnabledModules($enabledModules); - $errorModulesDependency = $this->dependencyChecker->checkDependenciesWhenEnableModules($modules); $errorModulesConflict = $this->conflictChecker->checkConflictsWhenEnableModules($modules); - - foreach ($errorModulesDependency as $moduleName => $missingDependencies) { - if (!empty($missingDependencies)) { - $errorMessages[] = "Cannot enable $moduleName, depending on inactive modules:"; - foreach ($missingDependencies as $errorModule => $path) { - $errorMessages [] = "\t$errorModule: " . implode('->', $path); - } - } - } - foreach ($errorModulesConflict as $moduleName => $conflictingModules) { - if (!empty($conflictingModules)) { - $errorMessages[] = "Cannot enable $moduleName, conflicting active modules:"; - foreach ($conflictingModules as $conflictingModule) { - $errorMessages [] = "\t$conflictingModule"; - } - } - } } else { $errorModulesDependency = $this->dependencyChecker->checkDependenciesWhenDisableModules($modules); + $errorModulesConflict = []; + } - foreach ($errorModulesDependency as $moduleName => $missingDependencies) { - if (!empty($missingDependencies)) { - $errorMessages[] = "Cannot disable $moduleName, active modules depending on it:"; - foreach ($missingDependencies as $errorModule => $path) { - $errorMessages [] = "\t$errorModule: " . implode('->', $path); - } + foreach ($errorModulesDependency as $moduleName => $missingDependencies) { + if (!empty($missingDependencies)) { + $errorMessages[] = $isEnable ? + "Cannot enable $moduleName, depending on disabled modules:" : + "Cannot disable $moduleName, modules depending on it:"; + foreach ($missingDependencies as $errorModule => $path) { + $errorMessages [] = "$errorModule: " . implode('->', $path); } } } + foreach ($errorModulesConflict as $moduleName => $conflictingModules) { + if (!empty($conflictingModules)) { + $errorMessages[] = "Cannot enable $moduleName, conflicting modules:"; + $errorMessages[] = implode(',', $conflictingModules); + } + } + return $errorMessages; } diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 5ff8539858256..76bc6cc3215ae 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -13,7 +13,7 @@ use Magento\Setup\Model\Installer; use Magento\Setup\Model\InstallerFactory; use Magento\Setup\Model\Lists; -use Magento\Setup\Model\ModuleList; +use Magento\Setup\Model\StatusFactory; use Magento\Setup\Model\UserConfigurationDataMapper as UserConfig; use Magento\Setup\Mvc\Bootstrap\InitParamListener; use Zend\Console\Request as ConsoleRequest; @@ -123,11 +123,11 @@ class ConsoleController extends AbstractActionController private $objectManager; /** - * Module List + * Status factory * - * @var ModuleList + * @var StatusFactory */ - private $moduleList; + private $statusFactory; /** * Gets router configuration to be used in module definition @@ -301,21 +301,22 @@ private static function getCliConfig() * @param InstallerFactory $installerFactory * @param MaintenanceMode $maintenanceMode * @param ObjectManagerFactory $objectManagerFactory + * @param StatusFactory $statusFactory */ public function __construct( ConsoleLogger $consoleLogger, Lists $options, InstallerFactory $installerFactory, MaintenanceMode $maintenanceMode, - ModuleList $moduleList, - ObjectManagerFactory $objectManagerFactory + ObjectManagerFactory $objectManagerFactory, + StatusFactory $statusFactory ) { $this->log = $consoleLogger; $this->options = $options; $this->installer = $installerFactory->create($consoleLogger); $this->maintenanceMode = $maintenanceMode; - $this->moduleList = $moduleList; $this->objectManagerFactory = $objectManagerFactory; + $this->statusFactory = $statusFactory; } /** @@ -487,12 +488,7 @@ public function moduleAction() $request = $this->getRequest(); $isEnable = $request->getParam(0) == self::CMD_MODULE_ENABLE; $modules = explode(',', $request->getParam('modules')); - $reader = $this->getObjectManager()->create( - 'Magento\Framework\Module\Dir\Reader', - ['moduleList' => $this->moduleList] - ); - /** @var \Magento\Framework\Module\Status $status */ - $status = $this->getObjectManager()->create('Magento\Framework\Module\Status', ['reader' => $reader]); + $status = $this->statusFactory->create(); if (!$request->getParam('force')) { $constraints = $status->checkConstraints($isEnable, $modules); if ($constraints) { diff --git a/setup/src/Magento/Setup/Model/ModuleList.php b/setup/src/Magento/Setup/Model/ModuleList.php index 27d5b9152811d..eddfd5b17129a 100644 --- a/setup/src/Magento/Setup/Model/ModuleList.php +++ b/setup/src/Magento/Setup/Model/ModuleList.php @@ -66,8 +66,7 @@ public function getOne($name) public function getNames() { $data = $this->getAll(); - $result = array_keys($data); - return $result; + return array_keys($data); } /** @@ -75,6 +74,7 @@ public function getNames() */ public function has($name) { - return array_search($name, $this->getNames()) !== false; + $this->getAll(); + return isset($this->data[$name]); } } \ No newline at end of file diff --git a/setup/src/Magento/Setup/Model/StatusFactory.php b/setup/src/Magento/Setup/Model/StatusFactory.php new file mode 100644 index 0000000000000..c31f2508415f5 --- /dev/null +++ b/setup/src/Magento/Setup/Model/StatusFactory.php @@ -0,0 +1,57 @@ +moduleList = $moduleList; + $this->objectManagerFactory = $objectManagerFactory; + } + + /** + * Create Status object + * + * @return \Magento\Framework\Module\Status + */ + public function create() + { + $objectManager = $this->objectManagerFactory->create(); + $reader = $objectManager->create('Magento\Framework\Module\Dir\Reader', ['moduleList' => $this->moduleList]); + $packageInfo = $objectManager->create('Magento\Framework\Module\PackageInfo', ['reader' => $reader]); + $conflictChecker = $objectManager->create( + 'Magento\Framework\Module\ConflictChecker', + ['packageInfo' => $packageInfo] + ); + $dependencyChecker = $objectManager->create( + 'Magento\Framework\Module\DependencyChecker', + ['packageInfo' => $packageInfo] + ); + return $objectManager->create( + 'Magento\Framework\Module\Status', + ['conflictChecker' => $conflictChecker, 'dependencyChecker' => $dependencyChecker] + ); + } +} From 03dfe9c31107514e2b49bb2573e1e73eaaa0d05e Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 22 Jan 2015 19:19:09 -0600 Subject: [PATCH 41/89] MAGETWO-32613: Add dependency restrictions - changed according to CR feedback --- .../Framework/Module/ConflictCheckerTest.php | 36 ++--- .../Module/DependencyCheckerTest.php | 59 ++++---- .../Module/PackageInfoFactoryTest.php | 28 ++++ .../Framework/Module/PackageInfoTest.php | 66 ++++----- .../Controller/ConsoleControllerTest.php | 11 +- .../Magento/Setup/Model/StatusFactoryTest.php | 40 ------ .../Framework/Module/ConflictChecker.php | 31 +++-- .../Framework/Module/DependencyChecker.php | 45 ++++-- .../Magento/Framework/Module/PackageInfo.php | 130 ++++++++++-------- .../Framework/Module/PackageInfoFactory.php | 41 ++++++ .../Magento/Framework/Module/Status.php | 10 +- .../Setup/Controller/ConsoleController.php | 15 +- .../src/Magento/Setup/Model/StatusFactory.php | 57 -------- 13 files changed, 285 insertions(+), 284 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoFactoryTest.php delete mode 100644 dev/tests/unit/testsuite/Magento/Setup/Model/StatusFactoryTest.php create mode 100644 lib/internal/Magento/Framework/Module/PackageInfoFactory.php delete mode 100644 setup/src/Magento/Setup/Model/StatusFactory.php diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index c286c9cd3cd24..e356df4c3f971 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -9,30 +9,30 @@ class ConflictCheckerTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider checkConflictWhenEnableModuleDataProvider - * @param array $nameReturnMap * @param array $conflictReturnMap * @param array $enabledModules * @param string $moduleName * @param array $expected */ public function testCheckConflictsWhenEnableModules( - $nameReturnMap, $conflictReturnMap, $enabledModules, $moduleName, $expected ) { + $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); $packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); - $packageInfoMock->expects($this->any()) - ->method('getPackageName') - ->will($this->returnValueMap($nameReturnMap)); - $packageInfoMock->expects($this->any()) - ->method('getEnabledModules') + $moduleListMock->expects($this->any()) + ->method('getNames') ->will($this->returnValue($enabledModules)); $packageInfoMock->expects($this->any()) ->method('getConflict') ->will($this->returnValueMap($conflictReturnMap)); - $conflictChecker = new ConflictChecker($packageInfoMock); + $packageInfoFactoryMock = $this->getMock('Magento\Framework\Module\PackageInfoFactory', [], [], '', false); + $packageInfoFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($packageInfoMock)); + $conflictChecker = new ConflictChecker($moduleListMock, $packageInfoFactoryMock); $this->assertEquals($expected, $conflictChecker->checkConflictsWhenEnableModules($moduleName)); } @@ -43,57 +43,49 @@ public function checkConflictWhenEnableModuleDataProvider() { return [ [ - [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], - [['Vendor_A', ['vendor/module-B']], ['Vendor_B', []]], + [['Vendor_A', ['Vendor_B']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], - [['Vendor_A', ['vendor/module-B']], ['Vendor_B', []]], + [['Vendor_A', ['Vendor_B']], ['Vendor_B', []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], - [['Vendor_B', ['vendor/module-A']], ['Vendor_A', []]], + [['Vendor_B', ['Vendor_A']], ['Vendor_A', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], - [['Vendor_B', ['vendor/module-A']], ['Vendor_A', []]], + [['Vendor_B', ['Vendor_A']], ['Vendor_A', []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B']], [['Vendor_A', []], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B'], ['Vendor_C', 'vendor/module-C']], [['Vendor_A', []], ['Vendor_B', []], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => []] ], [ - [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B'], ['Vendor_C', 'vendor/module-C']], - [['Vendor_A', ['vendor/module-C']], ['Vendor_B', []], ['Vendor_C', []]], + [['Vendor_A', ['Vendor_C']], ['Vendor_B', []], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A']] ], [ - [['Vendor_A', 'vendor/module-A'], ['Vendor_B', 'vendor/module-B'], ['Vendor_C', 'vendor/module-C']], - [['Vendor_A', []], ['Vendor_B', ['vendor/module-C']], ['Vendor_C', []]], + [['Vendor_A', []], ['Vendor_B', ['Vendor_C']], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']] diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php index f2084f6256aa9..a91857c5362ea 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php @@ -17,18 +17,29 @@ class DependencyCheckerTest extends \PHPUnit_Framework_TestCase */ private $packageInfoMock; + /** + * @var \Magento\Framework\Module\PackageInfoFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $packageInfoFactoryMock; + + /** + * @var \Magento\Framework\Module\ModuleList|\PHPUnit_Framework_MockObject_MockObject + */ + private $listMock; + + /** + * @var \Magento\Framework\Module\ModuleList\Loader|\PHPUnit_Framework_MockObject_MockObject + */ + private $loaderMock; + public function setUp() { $this->packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); - $this->packageInfoMock - ->expects($this->any()) - ->method('getAllModuleNames') - ->will($this->returnValue(['A', 'B', 'C', 'D', 'E'])); $requireMap = [ - ['A', ['vendor/module-B']], - ['B', ['vendor/module-D', 'vendor/module-E']], - ['C', ['vendor/module-E']], - ['D', ['vendor/module-A']], + ['A', ['B']], + ['B', ['D', 'E']], + ['C', ['E']], + ['D', ['A']], ['E', []], ]; $this->packageInfoMock @@ -36,26 +47,25 @@ public function setUp() ->method('getRequire') ->will($this->returnValueMap($requireMap)); - $moduleNameMap = [ - ['vendor/module-A', 'A'], - ['vendor/module-B', 'B'], - ['vendor/module-C', 'C'], - ['vendor/module-D', 'D'], - ['vendor/module-E', 'E'], - ]; - $this->packageInfoMock - ->expects($this->any()) - ->method('getModuleName') - ->will($this->returnValueMap($moduleNameMap)); + $this->packageInfoFactoryMock = $this->getMock('Magento\Framework\Module\PackageInfoFactory', [], [], '', false); + $this->packageInfoFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($this->packageInfoMock)); - $this->checker = new DependencyChecker($this->packageInfoMock); + $this->listMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $this->loaderMock = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); + $this->loaderMock + ->expects($this->any()) + ->method('load') + ->will($this->returnValue(['A' => [], 'B' => [], 'C' => [], 'D' => [], 'E' => []])); } public function testCheckDependenciesWhenDisableModules() { - $this->packageInfoMock + $this->listMock ->expects($this->any()) - ->method('getEnabledModules') + ->method('getNames') ->will($this->returnValue(['A', 'B', 'C', 'D', 'E'])); + $this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoFactoryMock); $actual = $this->checker->checkDependenciesWhenDisableModules(['B', 'D']); $expected = ['B' => ['A' => ['A', 'B']], 'D' => ['A' => ['A', 'B', 'D']]]; @@ -64,10 +74,11 @@ public function testCheckDependenciesWhenDisableModules() public function testCheckDependenciesWhenEnableModules() { - $this->packageInfoMock + $this->listMock ->expects($this->any()) - ->method('getEnabledModules') + ->method('getNames') ->will($this->returnValue(['C'])); + $this->checker = new DependencyChecker($this->listMock, $this->loaderMock, $this->packageInfoFactoryMock); $actual = $this->checker->checkDependenciesWhenEnableModules(['B', 'D']); $expected = [ 'B' => ['A' => ['B', 'D', 'A'], 'E' => ['B', 'E']], diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoFactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoFactoryTest.php new file mode 100644 index 0000000000000..28b60cef85c12 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoFactoryTest.php @@ -0,0 +1,28 @@ +getMock('Magento\Setup\Model\ModuleList', [], [], '', false); + $reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); + $packageInfo = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); + $returnValueMap = [ + ['Magento\Setup\Model\ModuleList', [], $moduleList], + ['Magento\Framework\Module\Dir\Reader', ['moduleList' => $moduleList], $reader], + ['Magento\Framework\Module\PackageInfo', ['reader' => $reader], $packageInfo], + ]; + $objectManagerMock = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $objectManagerMock->expects($this->any()) + ->method('create') + ->will($this->returnValueMap($returnValueMap)); + $factory = new PackageInfoFactory($objectManagerMock); + + $this->assertSame($packageInfo, $factory->create()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php index e7f3944d94cd7..37076de9f9290 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php @@ -7,11 +7,6 @@ class PackageInfoTest extends \PHPUnit_Framework_TestCase { - /** - * @var \Magento\Framework\Module\ModuleList|\PHPUnit_Framework_MockObject_MockObject - */ - private $moduleList; - /** * @var \Magento\Framework\Module\ModuleList\Loader|\PHPUnit_Framework_MockObject_MockObject */ @@ -29,11 +24,9 @@ class PackageInfoTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); $this->loader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); $this->reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); - $this->moduleList->expects($this->any())->method('getNames')->will($this->returnValue(['A', 'B', 'C'])); - $this->loader->expects($this->any()) + $this->loader->expects($this->once()) ->method('load') ->will($this->returnValue(['A' => [], 'B' => [], 'C' => [], 'D' => [], 'E' => []])); @@ -45,33 +38,14 @@ public function setUp() 'E' => '{"name":"e"}', ]; $fileIteratorMock = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false); - $fileIteratorMock->expects($this->any()) + $fileIteratorMock->expects($this->once()) ->method('toArray') ->will($this->returnValue($composerData)); - $this->reader->expects($this->any()) + $this->reader->expects($this->once()) ->method('getComposerJsonFiles') ->will($this->returnValue($fileIteratorMock)); - $this->packageInfo = new PackageInfo($this->moduleList, $this->loader, $this->reader); - } - - public function testGetAllModuleNames() - { - $this->assertEquals(['A', 'B', 'C', 'D', 'E'], $this->packageInfo->getAllModuleNames()); - } - - public function testGetEnabledModules() - { - $this->assertEquals(['A', 'B', 'C'], $this->packageInfo->getEnabledModules()); - } - - public function testGetPackageName() - { - $this->assertEquals('a', $this->packageInfo->getPackageName('A')); - $this->assertEquals('b', $this->packageInfo->getPackageName('B')); - $this->assertEquals('c', $this->packageInfo->getPackageName('C')); - $this->assertEquals('d', $this->packageInfo->getPackageName('D')); - $this->assertEquals('e', $this->packageInfo->getPackageName('E')); + $this->packageInfo = new PackageInfo($this->loader, $this->reader); } public function testGetModuleName() @@ -83,21 +57,39 @@ public function testGetModuleName() $this->assertEquals('E', $this->packageInfo->getModuleName('e')); } - public function testGetRequire() + public function testGetRequireReturnModuleName() { - $this->assertEquals(['b'], $this->packageInfo->getRequire('A')); - $this->assertEquals(['d'], $this->packageInfo->getRequire('B')); - $this->assertEquals(['e'], $this->packageInfo->getRequire('C')); + $this->assertEquals(['B'], $this->packageInfo->getRequire('A')); + $this->assertEquals(['D'], $this->packageInfo->getRequire('B')); + $this->assertEquals(['E'], $this->packageInfo->getRequire('C')); $this->assertEquals([], $this->packageInfo->getRequire('D')); $this->assertEquals([], $this->packageInfo->getRequire('E')); } - public function testGetConflict() + public function testGetConflictReturnModuleName() { - $this->assertEquals(['c'], $this->packageInfo->getConflict('A')); + $this->assertEquals(['C'], $this->packageInfo->getConflict('A')); $this->assertEquals([], $this->packageInfo->getConflict('B')); $this->assertEquals([], $this->packageInfo->getConflict('C')); - $this->assertEquals(['c'], $this->packageInfo->getConflict('D')); + $this->assertEquals(['C'], $this->packageInfo->getConflict('D')); $this->assertEquals([], $this->packageInfo->getConflict('E')); } + + public function testGetRequireReturnPackageName() + { + $this->assertEquals(['b'], $this->packageInfo->getRequire('A', false)); + $this->assertEquals(['d'], $this->packageInfo->getRequire('B', false)); + $this->assertEquals(['e'], $this->packageInfo->getRequire('C', false)); + $this->assertEquals([], $this->packageInfo->getRequire('D', false)); + $this->assertEquals([], $this->packageInfo->getRequire('E', false)); + } + + public function testGetConflictReturnPackageName() + { + $this->assertEquals(['c'], $this->packageInfo->getConflict('A', false)); + $this->assertEquals([], $this->packageInfo->getConflict('B', false)); + $this->assertEquals([], $this->packageInfo->getConflict('C', false)); + $this->assertEquals(['c'], $this->packageInfo->getConflict('D', false)); + $this->assertEquals([], $this->packageInfo->getConflict('E', false)); + } } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index c9bc69cdbd8e9..b5c4a062fe611 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -49,11 +49,6 @@ class ConsoleControllerTest extends \PHPUnit_Framework_TestCase */ private $controller; - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\StatusFactory - */ - private $statusFactory; - /** * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface */ @@ -77,8 +72,6 @@ public function setUp() $this->parameters= $this->getMock('\Zend\Stdlib\Parameters', [], [], '', false); $this->request->expects($this->any())->method('getParams')->willReturn($this->parameters); - $this->statusFactory = $this->getMock('Magento\Setup\Model\StatusFactory', [], [], '', false); - $this->mvcEvent = $this->getMock('\Zend\Mvc\MvcEvent', [], [], '', false); $this->mvcEvent->expects($this->once())->method('setRequest')->with($this->request)->willReturn( $this->mvcEvent @@ -98,7 +91,7 @@ public function setUp() $installerFactory, $this->maintenanceMode, $objectManagerFactory, - $this->statusFactory + $objectManagerFactory ); $this->controller->setEvent($this->mvcEvent); $this->controller->dispatch($this->request, $response); @@ -328,7 +321,7 @@ private function getModuleActionMocks($command, $modules, $isForce) $this->request->expects($this->at(2))->method('getParam')->with('force')->willReturn($isForce); $status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); $reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); - $this->statusFactory->expects($this->once()) + $this->objectManager->expects($this->once()) ->method('create') ->will($this->returnValue($status)); return $status; diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/StatusFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/StatusFactoryTest.php deleted file mode 100644 index 6b760ca895753..0000000000000 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/StatusFactoryTest.php +++ /dev/null @@ -1,40 +0,0 @@ -getMock('Magento\Setup\Model\ModuleList', [], [], '', false); - $objectManagerMock = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); - $readerMock = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); - $packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); - $conflictCheckerMock = $this->getMock('Magento\Framework\Module\ConflictChecker', [], [], '', false); - $dependencyCheckerMock = $this->getMock('Magento\Framework\Module\DependencyChecker', [], [], '', false); - $statusMock = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); - $returnValueMap = [ - ['Magento\Framework\Module\Dir\Reader', ['moduleList' => $moduleListMock], $readerMock], - ['Magento\Framework\Module\PackageInfo', ['reader' => $readerMock], $packageInfoMock], - ['Magento\Framework\Module\ConflictChecker', ['packageInfo' => $packageInfoMock], $conflictCheckerMock], - ['Magento\Framework\Module\DependencyChecker', ['packageInfo' => $packageInfoMock], $dependencyCheckerMock], - [ - 'Magento\Framework\Module\Status', - ['conflictChecker' => $conflictCheckerMock, 'dependencyChecker' => $dependencyCheckerMock], - $statusMock, - ] - ]; - $objectManagerMock->expects($this->any())->method('create')->will($this->returnValueMap($returnValueMap)); - $objectManagerFactoryMock = $this->getMock('Magento\Setup\Model\ObjectManagerFactory', [], [], '', false); - $objectManagerFactoryMock - ->expects($this->once()) - ->method('create') - ->will($this->returnValue($objectManagerMock)); - - $statusFactory = new StatusFactory($moduleListMock, $objectManagerFactoryMock); - $this->assertSame($statusMock, $statusFactory->create()); - } -} diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index a5fc962d1c7f3..bfc78a091160f 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -5,10 +5,18 @@ */ namespace Magento\Framework\Module; -use Magento\Framework\Filesystem; - +/** + * Checks for conflicts between modules + */ class ConflictChecker { + /** + * Enabled module list + * + * @var ModuleList + */ + private $list; + /** * Composer package info * @@ -17,11 +25,15 @@ class ConflictChecker private $packageInfo; /** - * @param PackageInfo $packageInfo + * Constructor + * + * @param ModuleList $list + * @param PackageInfoFactory $packageInfoFactory */ - public function __construct(PackageInfo $packageInfo) + public function __construct(ModuleList $list, PackageInfoFactory $packageInfoFactory) { - $this->packageInfo = $packageInfo; + $this->list = $list; + $this->packageInfo = $packageInfoFactory->create(); } /** @@ -33,7 +45,7 @@ public function __construct(PackageInfo $packageInfo) public function checkConflictsWhenEnableModules($moduleNames) { // union of currently enabled modules and to-be-enabled modules - $enabledModules = array_unique(array_merge($this->packageInfo->getEnabledModules(), $moduleNames)); + $enabledModules = array_unique(array_merge($this->list->getNames(), $moduleNames)); $conflictsAll = []; foreach ($moduleNames as $moduleName) { $conflicts = []; @@ -50,17 +62,16 @@ public function checkConflictsWhenEnableModules($moduleNames) /** * Check if module is conflicted * + * @param string $enabledModule * @param string $moduleName * @return bool */ private function checkIfConflict($enabledModule, $moduleName) { - if (array_search($this->packageInfo->getPackageName($enabledModule), - $this->packageInfo->getConflict($moduleName)) !== false) { + if (array_search($enabledModule, $this->packageInfo->getConflict($moduleName)) !== false) { return true; } - if (array_search($this->packageInfo->getPackageName($moduleName), - $this->packageInfo->getConflict($enabledModule)) !== false) { + if (array_search($moduleName, $this->packageInfo->getConflict($enabledModule)) !== false) { return true; } diff --git a/lib/internal/Magento/Framework/Module/DependencyChecker.php b/lib/internal/Magento/Framework/Module/DependencyChecker.php index dd94a5ede346a..b50d7566549ec 100644 --- a/lib/internal/Magento/Framework/Module/DependencyChecker.php +++ b/lib/internal/Magento/Framework/Module/DependencyChecker.php @@ -6,10 +6,26 @@ namespace Magento\Framework\Module; use Magento\Framework\Data\Graph; -use Magento\Framework\Filesystem; +/** + * Checks for dependencies between modules + */ class DependencyChecker { + /** + * Enabled module list + * + * @var ModuleList + */ + private $list; + + /** + * All module loader + * + * @var ModuleList\Loader + */ + private $loader; + /** * Composer package info * @@ -18,11 +34,17 @@ class DependencyChecker private $packageInfo; /** - * @param PackageInfo $packageInfo + * Constructor + * + * @param ModuleList $list + * @param ModuleList\Loader $loader + * @param PackageInfoFactory $packageInfoFactory */ - public function __construct(PackageInfo $packageInfo) + public function __construct(ModuleList $list, ModuleList\Loader $loader, PackageInfoFactory $packageInfoFactory) { - $this->packageInfo = $packageInfo; + $this->list = $list; + $this->loader = $loader; + $this->packageInfo = $packageInfoFactory->create(); } /** @@ -34,7 +56,7 @@ public function __construct(PackageInfo $packageInfo) public function checkDependenciesWhenDisableModules($moduleNames) { // assume disable succeeds: currently enabled modules - to-be-disabled modules - $enabledModules = array_diff($this->packageInfo->getEnabledModules(), $moduleNames); + $enabledModules = array_diff($this->list->getNames(), $moduleNames); return $this->checkDependencyGraph(false, $moduleNames, $enabledModules); } @@ -47,7 +69,7 @@ public function checkDependenciesWhenDisableModules($moduleNames) public function checkDependenciesWhenEnableModules($moduleNames) { // assume enable succeeds: union of currently enabled modules and to-be-enabled modules - $enabledModules = array_unique(array_merge($this->packageInfo->getEnabledModules(), $moduleNames)); + $enabledModules = array_unique(array_merge($this->list->getNames(), $moduleNames)); return $this->checkDependencyGraph(true, $moduleNames, $enabledModules); } @@ -67,7 +89,7 @@ private function checkDependencyGraph($isEnable, $moduleNames, $enabledModules) foreach ($moduleNames as $moduleName) { $dependenciesMissing = []; $paths = $graph->findPathsToReachableNodes($moduleName, $graphMode); - foreach ($this->packageInfo->getAllModuleNames() as $module) { + foreach (array_keys($this->loader->load()) as $module) { if (isset($paths[$module])) { if ($isEnable && !in_array($module, $enabledModules)) { $dependenciesMissing[$module] = $paths[$module]; @@ -93,12 +115,11 @@ private function createGraph(PackageInfo $packageInfo) $dependencies = []; // build the graph data - foreach ($packageInfo->getAllModuleNames() as $moduleName) { + foreach (array_keys($this->loader->load()) as $moduleName) { $nodes[] = $moduleName; - foreach ($packageInfo->getRequire($moduleName) as $dependPackageName) { - $depend = $packageInfo->getModuleName($dependPackageName); - if ($depend) { - $dependencies[] = [$moduleName, $depend]; + foreach ($packageInfo->getRequire($moduleName) as $dependModuleName) { + if ($dependModuleName) { + $dependencies[] = [$moduleName, $dependModuleName]; } } } diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index 1a86cd656c812..28924bb82c133 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Module; +/** + * Provide information of dependencies and conflicts in composer.json files and mapping of package name to module name + */ class PackageInfo { /** @@ -12,14 +15,7 @@ class PackageInfo * * @var string[] */ - private $packageNameMap; - - /** - * Module name to package name map - * - * @var string[] - */ - private $moduleNameMap; + private $packageModuleMap; /** * "require" field of each module @@ -36,99 +32,123 @@ class PackageInfo private $conflictMap; /** - * List of enabled modules + * All modules loader * - * @var string[] + * @var ModuleList\Loader */ - private $enabledModules; + private $loader; /** - * @param ModuleList $list - * @param ModuleList\Loader $loader - * @param Dir\Reader $reader + * Reader of composer.json files + * + * @var Dir\Reader */ - public function __construct(ModuleList $list, ModuleList\Loader $loader, Dir\Reader $reader) - { - $this->enabledModules = $list->getNames(); - /** - * array keys: module name in module.xml; array values: raw content from composer.json - * this raw data is used to create a dependency graph and also a package name-module name mapping - */ - $rawData = array_combine(array_keys($loader->load()), $reader->getComposerJsonFiles()->toArray()); - foreach ($rawData as $moduleName => $jsonData) { - $jsonData = \Zend_Json::decode($jsonData); - $this->packageNameMap[$moduleName] = $jsonData['name']; - $this->moduleNameMap[$jsonData['name']] = $moduleName; - if (!empty($jsonData['require'])) { - $this->requireMap[$moduleName] = array_keys($jsonData['require']); - } - if (!empty($jsonData['conflict'])) { - $this->conflictMap[$moduleName] = array_keys($jsonData['conflict']); - } - } - } + private $reader; /** - * Get all modules names + * Constructor * - * @return array + * @param ModuleList\Loader $loader + * @param Dir\Reader $reader */ - public function getAllModuleNames() + public function __construct(ModuleList\Loader $loader, Dir\Reader $reader) { - return array_values($this->moduleNameMap); + $this->loader = $loader; + $this->reader = $reader; } /** - * Get only enabled modules + * Load the packages information * - * @return string[] + * @return void */ - public function getEnabledModules() + private function load() { - return $this->enabledModules; + if ($this->packageModuleMap === null) { + /** + * array keys: module name in module.xml; array values: raw content from composer.json + * this raw data is used to create a dependency graph and also a package name-module name mapping + */ + $rawData = array_combine(array_keys($this->loader->load()), $this->reader->getComposerJsonFiles()->toArray()); + foreach ($rawData as $moduleName => $jsonData) { + $jsonData = \Zend_Json::decode($jsonData); + $this->packageModuleMap[$jsonData['name']] = $moduleName; + if (!empty($jsonData['require'])) { + $this->requireMap[$moduleName] = array_keys($jsonData['require']); + } + if (!empty($jsonData['conflict'])) { + $this->conflictMap[$moduleName] = array_keys($jsonData['conflict']); + } + } + } } /** - * Get package name of a module + * Get module name of a package * - * @param string $moduleName + * @param string $packageName * @return string */ - public function getPackageName($moduleName) + public function getModuleName($packageName) { - return isset($this->packageNameMap[$moduleName]) ? $this->packageNameMap[$moduleName] : ''; + $this->load(); + return isset($this->packageModuleMap[$packageName]) ? $this->packageModuleMap[$packageName] : ''; } /** - * Get module name of a package + * Convert an array of package names to module names * - * @param string $packageName - * @return string + * @param string[] $packageNames + * @return string[] */ - public function getModuleName($packageName) + private function convertToModuleNames($packageNames) { - return isset($this->moduleNameMap[$packageName]) ? $this->moduleNameMap[$packageName] : ''; + $moduleNames = []; + foreach ($packageNames as $package) { + $moduleNames[] = $this->getModuleName($package); + } + return $moduleNames; } /** * Get all package names a module requires * * @param string $moduleName + * @param bool $returnModuleName * @return array */ - public function getRequire($moduleName) + public function getRequire($moduleName, $returnModuleName = true) { - return isset($this->requireMap[$moduleName]) ? $this->requireMap[$moduleName] : []; + $this->load(); + $require = []; + if (isset($this->requireMap[$moduleName])) { + if ($returnModuleName) { + $require = $this->convertToModuleNames($this->requireMap[$moduleName]); + } else { + $require = $this->requireMap[$moduleName]; + } + } + return $require; } /** * Get all package names a module conflicts * * @param string $moduleName + * @param bool $returnModuleName * @return array */ - public function getConflict($moduleName) + public function getConflict($moduleName, $returnModuleName = true) { - return isset($this->conflictMap[$moduleName]) ? $this->conflictMap[$moduleName] : []; + $this->load(); + $conflict = []; + if (isset($this->conflictMap[$moduleName])) { + if ($returnModuleName) { + $conflict = $this->convertToModuleNames($this->conflictMap[$moduleName]); + } else { + $conflict = $this->conflictMap[$moduleName]; + } + } + return $conflict; } } diff --git a/lib/internal/Magento/Framework/Module/PackageInfoFactory.php b/lib/internal/Magento/Framework/Module/PackageInfoFactory.php new file mode 100644 index 0000000000000..cb40899a51dfa --- /dev/null +++ b/lib/internal/Magento/Framework/Module/PackageInfoFactory.php @@ -0,0 +1,41 @@ +objectManager = $objectManager; + } + + /** + * Create class instance with specified parameters + * + * @return \Magento\Framework\Module\PackageInfo + */ + public function create() + { + $moduleList = $this->objectManager->create('Magento\Setup\Model\ModuleList'); + $reader = $this->objectManager->create('Magento\Framework\Module\Dir\Reader', ['moduleList' => $moduleList]); + return $this->objectManager->create('Magento\Framework\Module\PackageInfo', ['reader' => $reader]); + } +} \ No newline at end of file diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index aade9c3da37f6..336c7e2d97815 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -85,14 +85,14 @@ public function __construct( /** * Whether it is allowed to enable or disable specified modules * - * @param bool $isEnable + * @param bool $isEnabled * @param string[] $modules * @return string[] */ - public function checkConstraints($isEnable, $modules) + public function checkConstraints($isEnabled, $modules) { $errorMessages = []; - if ($isEnable) { + if ($isEnabled) { $errorModulesDependency = $this->dependencyChecker->checkDependenciesWhenEnableModules($modules); $errorModulesConflict = $this->conflictChecker->checkConflictsWhenEnableModules($modules); } else { @@ -102,7 +102,7 @@ public function checkConstraints($isEnable, $modules) foreach ($errorModulesDependency as $moduleName => $missingDependencies) { if (!empty($missingDependencies)) { - $errorMessages[] = $isEnable ? + $errorMessages[] = $isEnabled ? "Cannot enable $moduleName, depending on disabled modules:" : "Cannot disable $moduleName, modules depending on it:"; foreach ($missingDependencies as $errorModule => $path) { @@ -114,7 +114,7 @@ public function checkConstraints($isEnable, $modules) foreach ($errorModulesConflict as $moduleName => $conflictingModules) { if (!empty($conflictingModules)) { $errorMessages[] = "Cannot enable $moduleName, conflicting modules:"; - $errorMessages[] = implode(',', $conflictingModules); + $errorMessages[] = implode(', ', $conflictingModules); } } diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 76bc6cc3215ae..4a130c4a0f45b 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -13,7 +13,6 @@ use Magento\Setup\Model\Installer; use Magento\Setup\Model\InstallerFactory; use Magento\Setup\Model\Lists; -use Magento\Setup\Model\StatusFactory; use Magento\Setup\Model\UserConfigurationDataMapper as UserConfig; use Magento\Setup\Mvc\Bootstrap\InitParamListener; use Zend\Console\Request as ConsoleRequest; @@ -122,13 +121,6 @@ class ConsoleController extends AbstractActionController */ private $objectManager; - /** - * Status factory - * - * @var StatusFactory - */ - private $statusFactory; - /** * Gets router configuration to be used in module definition * @@ -301,22 +293,19 @@ private static function getCliConfig() * @param InstallerFactory $installerFactory * @param MaintenanceMode $maintenanceMode * @param ObjectManagerFactory $objectManagerFactory - * @param StatusFactory $statusFactory */ public function __construct( ConsoleLogger $consoleLogger, Lists $options, InstallerFactory $installerFactory, MaintenanceMode $maintenanceMode, - ObjectManagerFactory $objectManagerFactory, - StatusFactory $statusFactory + ObjectManagerFactory $objectManagerFactory ) { $this->log = $consoleLogger; $this->options = $options; $this->installer = $installerFactory->create($consoleLogger); $this->maintenanceMode = $maintenanceMode; $this->objectManagerFactory = $objectManagerFactory; - $this->statusFactory = $statusFactory; } /** @@ -488,7 +477,7 @@ public function moduleAction() $request = $this->getRequest(); $isEnable = $request->getParam(0) == self::CMD_MODULE_ENABLE; $modules = explode(',', $request->getParam('modules')); - $status = $this->statusFactory->create(); + $status = $this->getObjectManager()->create('Magento\Framework\Module\Status'); if (!$request->getParam('force')) { $constraints = $status->checkConstraints($isEnable, $modules); if ($constraints) { diff --git a/setup/src/Magento/Setup/Model/StatusFactory.php b/setup/src/Magento/Setup/Model/StatusFactory.php deleted file mode 100644 index c31f2508415f5..0000000000000 --- a/setup/src/Magento/Setup/Model/StatusFactory.php +++ /dev/null @@ -1,57 +0,0 @@ -moduleList = $moduleList; - $this->objectManagerFactory = $objectManagerFactory; - } - - /** - * Create Status object - * - * @return \Magento\Framework\Module\Status - */ - public function create() - { - $objectManager = $this->objectManagerFactory->create(); - $reader = $objectManager->create('Magento\Framework\Module\Dir\Reader', ['moduleList' => $this->moduleList]); - $packageInfo = $objectManager->create('Magento\Framework\Module\PackageInfo', ['reader' => $reader]); - $conflictChecker = $objectManager->create( - 'Magento\Framework\Module\ConflictChecker', - ['packageInfo' => $packageInfo] - ); - $dependencyChecker = $objectManager->create( - 'Magento\Framework\Module\DependencyChecker', - ['packageInfo' => $packageInfo] - ); - return $objectManager->create( - 'Magento\Framework\Module\Status', - ['conflictChecker' => $conflictChecker, 'dependencyChecker' => $dependencyChecker] - ); - } -} From ebb9a1efb7e03f7b9356d7f8b8244d0318a2bf0a Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 23 Jan 2015 10:46:53 -0600 Subject: [PATCH 42/89] MAGETWO-32613: Add dependency restrictions - fixed unit tests --- .../Framework/Module/ConflictCheckerTest.php | 16 ++++++++-------- .../Framework/Module/DependencyCheckerTest.php | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index e356df4c3f971..fe8c9fdaa8b3f 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -43,49 +43,49 @@ public function checkConflictWhenEnableModuleDataProvider() { return [ [ - [['Vendor_A', ['Vendor_B']], ['Vendor_B', []]], + [['Vendor_A', true, ['Vendor_B']], ['Vendor_B', true, []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['Vendor_A', ['Vendor_B']], ['Vendor_B', []]], + [['Vendor_A', true, ['Vendor_B']], ['Vendor_B', true, []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_B', ['Vendor_A']], ['Vendor_A', []]], + [['Vendor_B', true, ['Vendor_A']], ['Vendor_A', true, []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['Vendor_B', ['Vendor_A']], ['Vendor_A', []]], + [['Vendor_B', true, ['Vendor_A']], ['Vendor_A', true, []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_A', []], ['Vendor_B', []]], + [['Vendor_A', true, []], ['Vendor_B', true, []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_A', []], ['Vendor_B', []], ['Vendor_C', []]], + [['Vendor_A', true, []], ['Vendor_B', true, []], ['Vendor_C', true, []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => []] ], [ - [['Vendor_A', ['Vendor_C']], ['Vendor_B', []], ['Vendor_C', []]], + [['Vendor_A', true, ['Vendor_C']], ['Vendor_B', true, []], ['Vendor_C', true, []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A']] ], [ - [['Vendor_A', []], ['Vendor_B', ['Vendor_C']], ['Vendor_C', []]], + [['Vendor_A', true, []], ['Vendor_B', true, ['Vendor_C']], ['Vendor_C', true, []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']] diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php index a91857c5362ea..d02b3d8af500a 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php @@ -36,11 +36,11 @@ public function setUp() { $this->packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); $requireMap = [ - ['A', ['B']], - ['B', ['D', 'E']], - ['C', ['E']], - ['D', ['A']], - ['E', []], + ['A', true, ['B']], + ['B', true, ['D', 'E']], + ['C', true, ['E']], + ['D', true, ['A']], + ['E', true, []], ]; $this->packageInfoMock ->expects($this->any()) From 441ed355839932c9283cdb1a5a14a6015ff9efc2 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 23 Jan 2015 11:25:12 -0600 Subject: [PATCH 43/89] MAGETWO-32613: Add dependency restrictions - moved ModuleList in setup to framework --- .../Module/FullModuleListTest.php} | 6 +++--- .../Framework/Module/PackageInfoFactoryTest.php | 6 +++--- .../Magento/Framework/Module/FullModuleList.php | 12 +++++------- .../Magento/Framework/Module/PackageInfo.php | 5 ++++- .../Magento/Framework/Module/PackageInfoFactory.php | 7 +++++-- 5 files changed, 20 insertions(+), 16 deletions(-) rename dev/tests/unit/testsuite/Magento/{Setup/Model/ModuleListTest.php => Framework/Module/FullModuleListTest.php} (90%) rename setup/src/Magento/Setup/Model/ModuleList.php => lib/internal/Magento/Framework/Module/FullModuleList.php (83%) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ModuleListTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/FullModuleListTest.php similarity index 90% rename from dev/tests/unit/testsuite/Magento/Setup/Model/ModuleListTest.php rename to dev/tests/unit/testsuite/Magento/Framework/Module/FullModuleListTest.php index d840eb6ed9cf3..68f09f5aa6ead 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ModuleListTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/FullModuleListTest.php @@ -3,9 +3,9 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup\Model; +namespace Magento\Framework\Module; -class ModuleListTest extends \PHPUnit_Framework_TestCase +class FullModuleListTest extends \PHPUnit_Framework_TestCase { /** * @var ModuleList @@ -21,7 +21,7 @@ public function setUp() 'Vendor_C' => ['data' => 'c'], ]; $loaderMock->expects($this->once())->method('load')->will($this->returnValue($modules)); - $this->moduleList = new ModuleList($loaderMock); + $this->moduleList = new FullModuleList($loaderMock); } public function testGetAll() diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoFactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoFactoryTest.php index 28b60cef85c12..c95b95749a867 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoFactoryTest.php @@ -9,12 +9,12 @@ class PackageInfoFactoryTest extends \PHPUnit_Framework_TestCase { public function testCreate() { - $moduleList = $this->getMock('Magento\Setup\Model\ModuleList', [], [], '', false); + $fullModuleList = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); $reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); $packageInfo = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); $returnValueMap = [ - ['Magento\Setup\Model\ModuleList', [], $moduleList], - ['Magento\Framework\Module\Dir\Reader', ['moduleList' => $moduleList], $reader], + ['Magento\Framework\Module\FullModuleList', [], $fullModuleList], + ['Magento\Framework\Module\Dir\Reader', ['moduleList' => $fullModuleList], $reader], ['Magento\Framework\Module\PackageInfo', ['reader' => $reader], $packageInfo], ]; $objectManagerMock = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); diff --git a/setup/src/Magento/Setup/Model/ModuleList.php b/lib/internal/Magento/Framework/Module/FullModuleList.php similarity index 83% rename from setup/src/Magento/Setup/Model/ModuleList.php rename to lib/internal/Magento/Framework/Module/FullModuleList.php index eddfd5b17129a..65a918e43b788 100644 --- a/setup/src/Magento/Setup/Model/ModuleList.php +++ b/lib/internal/Magento/Framework/Module/FullModuleList.php @@ -3,21 +3,19 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Setup\Model; - -use Magento\Framework\Module\ModuleList\Loader; +namespace Magento\Framework\Module; /** * A list of modules in the Magento application * * Represents all modules, regardless of enabled or not */ -class ModuleList implements \Magento\Framework\Module\ModuleListInterface +class FullModuleList implements ModuleListInterface { /** * Loader of module information from source code * - * @var Loader + * @var ModuleList\Loader */ private $loader; @@ -31,9 +29,9 @@ class ModuleList implements \Magento\Framework\Module\ModuleListInterface /** * Constructor * - * @param Loader $loader + * @param ModuleList\Loader $loader */ - public function __construct(Loader $loader) + public function __construct(ModuleList\Loader $loader) { $this->loader = $loader; } diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index 28924bb82c133..a7c830e522513 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -69,7 +69,10 @@ private function load() * array keys: module name in module.xml; array values: raw content from composer.json * this raw data is used to create a dependency graph and also a package name-module name mapping */ - $rawData = array_combine(array_keys($this->loader->load()), $this->reader->getComposerJsonFiles()->toArray()); + $rawData = array_combine( + array_keys($this->loader->load()), + $this->reader->getComposerJsonFiles()->toArray() + ); foreach ($rawData as $moduleName => $jsonData) { $jsonData = \Zend_Json::decode($jsonData); $this->packageModuleMap[$jsonData['name']] = $moduleName; diff --git a/lib/internal/Magento/Framework/Module/PackageInfoFactory.php b/lib/internal/Magento/Framework/Module/PackageInfoFactory.php index cb40899a51dfa..5f4a2565642ff 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfoFactory.php +++ b/lib/internal/Magento/Framework/Module/PackageInfoFactory.php @@ -34,8 +34,11 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan */ public function create() { - $moduleList = $this->objectManager->create('Magento\Setup\Model\ModuleList'); - $reader = $this->objectManager->create('Magento\Framework\Module\Dir\Reader', ['moduleList' => $moduleList]); + $fullModuleList = $this->objectManager->create('Magento\Framework\Module\FullModuleList'); + $reader = $this->objectManager->create( + 'Magento\Framework\Module\Dir\Reader', + ['moduleList' => $fullModuleList] + ); return $this->objectManager->create('Magento\Framework\Module\PackageInfo', ['reader' => $reader]); } } \ No newline at end of file From 58009cfa529138679720bf67396ee1a630426168 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 23 Jan 2015 11:35:44 -0600 Subject: [PATCH 44/89] MAGETWO-32613: Add dependency restrictions - corrected code style --- lib/internal/Magento/Framework/Module/FullModuleList.php | 2 +- lib/internal/Magento/Framework/Module/PackageInfoFactory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/FullModuleList.php b/lib/internal/Magento/Framework/Module/FullModuleList.php index 65a918e43b788..91f2386ba9231 100644 --- a/lib/internal/Magento/Framework/Module/FullModuleList.php +++ b/lib/internal/Magento/Framework/Module/FullModuleList.php @@ -75,4 +75,4 @@ public function has($name) $this->getAll(); return isset($this->data[$name]); } -} \ No newline at end of file +} diff --git a/lib/internal/Magento/Framework/Module/PackageInfoFactory.php b/lib/internal/Magento/Framework/Module/PackageInfoFactory.php index 5f4a2565642ff..de7c0d3a63914 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfoFactory.php +++ b/lib/internal/Magento/Framework/Module/PackageInfoFactory.php @@ -41,4 +41,4 @@ public function create() ); return $this->objectManager->create('Magento\Framework\Module\PackageInfo', ['reader' => $reader]); } -} \ No newline at end of file +} From ad4eb49bf04fa7fa6bc1aca41d95b68e974f05f1 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Mon, 26 Jan 2015 16:30:50 -0600 Subject: [PATCH 45/89] MAGETWO-33156: Technical restraint is still checked in enable/disable module CLI tool even if no changes will be made - changed controller logic so that unchanged modules will be checked first --- .../Magento/Framework/Module/StatusTest.php | 18 ++- .../Controller/ConsoleControllerTest.php | 114 +++++++++++++++++- .../Magento/Framework/Module/Status.php | 37 ++++-- .../Setup/Controller/ConsoleController.php | 27 +++-- 4 files changed, 164 insertions(+), 32 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php index 20f1d23e2b54a..762f5b09721a1 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php @@ -133,17 +133,16 @@ public function testSetIsEnabled() { $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; $this->loader->expects($this->once())->method('load')->willReturn($modules); - $this->moduleList->expects($this->at(0))->method('has')->with('Module_Foo')->willReturn(true); + $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(true); + $this->moduleList->expects($this->at(2))->method('has')->with('Module_Baz')->willReturn(false); $constraint = new \PHPUnit_Framework_Constraint_IsInstanceOf( 'Magento\Framework\Module\ModuleList\DeploymentConfig' ); $this->writer->expects($this->once())->method('update')->with($constraint); $this->cleanup->expects($this->once())->method('clearCaches'); $this->cleanup->expects($this->once())->method('clearCodeGeneratedFiles'); - $result = $this->object->setIsEnabled(true, ['Module_Foo', 'Module_Bar']); - $this->assertEquals(['Module_Bar'], $result); + $this->object->setIsEnabled(true, ['Module_Foo', 'Module_Bar']); } /** @@ -156,4 +155,15 @@ public function testSetIsEnabledUnknown() $this->loader->expects($this->once())->method('load')->willReturn($modules); $this->object->setIsEnabled(true, ['Module_Baz']); } + + public function testGetUnchangedModules() + { + $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; + $this->loader->expects($this->once())->method('load')->willReturn($modules); + $this->moduleList->expects($this->at(0))->method('has')->with('Module_Foo')->willReturn(true); + $this->moduleList->expects($this->at(1))->method('has')->with('Module_Bar')->willReturn(true); + $this->moduleList->expects($this->at(2))->method('has')->with('Module_Baz')->willReturn(true); + $result = $this->object->getUnchangedModules(true, ['Module_Foo', 'Module_Bar', 'Module_Baz']); + $this->assertEquals(array_keys($modules), $result); + } } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index b5c4a062fe611..d5955521c74de 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -284,11 +284,14 @@ public function testHelpActionNoType() */ public function testModuleAction($command, $modules, $isForce, $expectedIsEnabled, $expectedModules) { - $status = $this->getModuleActionMocks($command, $modules, $isForce); + $status = $this->getModuleActionMocks($command, $modules, $isForce, false); + $status->expects($this->once())->method('getUnchangedModules')->willReturn([]); if (!$isForce) { $status->expects($this->once())->method('checkConstraints')->willReturn([]); } - $status->expects($this->once())->method('setIsEnabled')->with($expectedIsEnabled, $expectedModules); + $status->expects($this->once()) + ->method('setIsEnabled') + ->with($expectedIsEnabled, $expectedModules); $this->consoleLogger->expects($this->once())->method('log'); $this->controller->moduleAction(); } @@ -306,21 +309,114 @@ public function moduleActionDataProvider() ]; } + /** + * @param string $command + * @param string $modules + * @param bool $isForce + * @param bool $expectedIsEnabled + * @param string[] $expectedModules + * @dataProvider moduleActionDataProvider + */ + public function testModuleActionNoChanges($command, $modules, $isForce, $expectedIsEnabled, $expectedModules) + { + $status = $this->getModuleActionMocks($command, $modules, $isForce, true); + $status->expects($this->once()) + ->method('getUnchangedModules') + ->with($expectedIsEnabled, $expectedModules) + ->willReturn($expectedModules); + $status->expects($this->never())->method('checkConstraints'); + $status->expects($this->never())->method('setIsEnabled'); + $this->consoleLogger->expects($this->once())->method('log'); + $this->controller->moduleAction(); + } + + /** + * @param string $command + * @param string $modules + * @param bool $isForce + * @param bool $expectedIsEnabled + * @param string[] $expectedModules + * @param string[] $unchangedModules + * @dataProvider moduleActionPartialNoChangesDataProvider + */ + public function testModuleActionPartialNoChanges( + $command, + $modules, + $isForce, + $expectedIsEnabled, + $expectedModules, + $unchangedModules + ) { + $status = $this->getModuleActionMocks($command, $modules, $isForce, false); + $status->expects($this->once())->method('getUnchangedModules')->willReturn($unchangedModules); + if (!$isForce) { + $status->expects($this->once())->method('checkConstraints')->willReturn([]); + } + $status->expects($this->once()) + ->method('setIsEnabled') + ->with($expectedIsEnabled, array_diff($expectedModules, $unchangedModules)); + $this->consoleLogger->expects($this->once())->method('log'); + $this->controller->moduleAction(); + } + + /** + * @return array + */ + public function moduleActionPartialNoChangesDataProvider() + { + return [ + [ + ConsoleController::CMD_MODULE_ENABLE, + 'Module_Foo,Module_Bar', + false, + true, + ['Module_Foo', 'Module_Bar'], + ['Module_Foo'], + ], + [ + ConsoleController::CMD_MODULE_ENABLE, + 'Module_Foo,Module_Bar', + true, + true, + ['Module_Foo', 'Module_Bar'], + ['Module_Foo'], + ], + [ + ConsoleController::CMD_MODULE_DISABLE, + 'Module_Foo,Module_Bar', + false, + false, + ['Module_Foo', 'Module_Bar'], + ['Module_Foo'], + ], + [ + ConsoleController::CMD_MODULE_DISABLE, + 'Module_Foo,Module_Bar', + true, + false, + ['Module_Foo', 'Module_Bar'], + ['Module_Foo'], + ], + ]; + } + /** * Prepares a set of mocks for testing module action * * @param string $command * @param string $modules * @param bool $isForce + * @param bool $isUnchanged * @return \PHPUnit_Framework_MockObject_MockObject */ - private function getModuleActionMocks($command, $modules, $isForce) + private function getModuleActionMocks($command, $modules, $isForce, $isUnchanged) { $this->request->expects($this->at(0))->method('getParam')->with(0)->willReturn($command); $this->request->expects($this->at(1))->method('getParam')->with('modules')->willReturn($modules); - $this->request->expects($this->at(2))->method('getParam')->with('force')->willReturn($isForce); + if (!$isUnchanged) { + $this->request->expects($this->at(2))->method('getParam')->with('force')->willReturn($isForce); + } $status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); - $reader = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false); $this->objectManager->expects($this->once()) ->method('create') ->will($this->returnValue($status)); @@ -333,7 +429,13 @@ private function getModuleActionMocks($command, $modules, $isForce) */ public function testModuleActionNotAllowed() { - $status = $this->getModuleActionMocks(ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', false); + $status = $this->getModuleActionMocks( + ConsoleController::CMD_MODULE_ENABLE, + 'Module_Foo,Module_Bar', + false, + false + ); + $status->expects($this->once())->method('getUnchangedModules')->willReturn([]); $status->expects($this->once()) ->method('checkConstraints') ->willReturn(['Circular dependency of Foo and Bar']); diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index 336c7e2d97815..5e4640cf77039 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -125,34 +125,47 @@ public function checkConstraints($isEnabled, $modules) * Sets specified modules to enabled or disabled state * * Performs other necessary routines, such as cache cleanup - * Returns list of modules that have changed * * @param bool $isEnabled * @param string[] $modules - * @return string[] + * @return void */ public function setIsEnabled($isEnabled, $modules) { $result = []; - $changed = []; foreach ($this->getAllModules($modules) as $name) { $currentStatus = $this->list->has($name); if (in_array($name, $modules)) { $result[$name] = $isEnabled; - if ($isEnabled != $currentStatus) { - $changed[] = $name; - } } else { $result[$name] = $currentStatus; } } - if ($changed) { - $segment = new ModuleList\DeploymentConfig($result); - $this->writer->update($segment); - $this->cleanup->clearCaches(); - $this->cleanup->clearCodeGeneratedFiles(); + $segment = new ModuleList\DeploymentConfig($result); + $this->writer->update($segment); + $this->cleanup->clearCaches(); + $this->cleanup->clearCodeGeneratedFiles(); + } + + /** + * Get a list of modules that will not be changed + * + * @param bool $isEnabled + * @param string[] $modules + * @return string[] + */ + public function getUnchangedModules($isEnabled, $modules) + { + $unchanged = []; + foreach ($this->getAllModules($modules) as $name) { + $currentStatus = $this->list->has($name); + if (in_array($name, $modules)) { + if ($isEnabled == $currentStatus) { + $unchanged[] = $name; + } + } } - return $changed; + return $unchanged; } /** diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 4a130c4a0f45b..0f09d6dbdac58 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -477,23 +477,30 @@ public function moduleAction() $request = $this->getRequest(); $isEnable = $request->getParam(0) == self::CMD_MODULE_ENABLE; $modules = explode(',', $request->getParam('modules')); + /** @var \Magento\Framework\Module\Status $status */ $status = $this->getObjectManager()->create('Magento\Framework\Module\Status'); - if (!$request->getParam('force')) { - $constraints = $status->checkConstraints($isEnable, $modules); - if ($constraints) { - $message = "Unable to change status of modules because of the following constraints:\n" - . implode("\n", $constraints); - throw new \Magento\Setup\Exception($message); + + $unchangedModules = $status->getUnchangedModules($isEnable, $modules); + $modules = array_diff($modules, $unchangedModules); + if (!empty($modules)) { + if (!$request->getParam('force')) { + $constraints = $status->checkConstraints($isEnable, $modules); + if ($constraints) { + $message = "Unable to change status of modules because of the following constraints:\n" + . implode("\n", $constraints); + throw new \Magento\Setup\Exception($message); + } } - } - $changed = $status->setIsEnabled($isEnable, $modules); - if ($changed) { + $status->setIsEnabled($isEnable, $modules); if ($isEnable) { $message = 'The following modules have been enabled:'; } else { $message = 'The following modules have been disabled:'; } - $message .= ' ' . implode(', ', $changed); + $message .= ' ' . implode(', ', $modules); + if (!empty($unchangedModules)) { + $message .= "\nThe following modules have no changes: " . implode(', ', $unchangedModules); + } } else { $message = 'There have been no changes to any modules.'; } From ffad2fc0ab1df60dde4a5974124e43c55035f438 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Mon, 26 Jan 2015 17:17:30 -0600 Subject: [PATCH 46/89] MAGETWO-33156: Technical restraint is still checked in enable/disable module CLI tool even if no changes will be made - fixed unit tests --- .../testsuite/Magento/Framework/App/State/CleanupTest.php | 5 +++-- .../unit/testsuite/Magento/Setup/Model/InstallerTest.php | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php index 7aa89f89b3e18..ea507c41f818f 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php @@ -7,6 +7,7 @@ namespace Magento\Framework\App\State; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\DriverPool; use Magento\Framework\View\Asset\Source; class CleanupTest extends \PHPUnit_Framework_TestCase @@ -78,8 +79,8 @@ public function testClearMaterializedViewFiles() $static = $this->getDirectoryCleanMock(); $var = $this->getDirectoryCleanMock(Source::TMP_MATERIALIZATION_DIR); $this->filesystem->expects($this->exactly(2))->method('getDirectoryWrite')->will($this->returnValueMap([ - [DirectoryList::STATIC_VIEW, $static], - [DirectoryList::VAR_DIR, $var], + [DirectoryList::STATIC_VIEW, DriverPool::FILE, $static], + [DirectoryList::VAR_DIR, DriverPool::FILE, $var], ])); $this->object->clearMaterializedViewFiles(); } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php index c17f726144367..4a546a53069e1 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php @@ -8,6 +8,7 @@ use Magento\Framework\App\DeploymentConfig\DbConfig; use Magento\Framework\App\DeploymentConfig\EncryptConfig; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\DriverPool; class InstallerTest extends \PHPUnit_Framework_TestCase { @@ -277,9 +278,9 @@ public function testUninstall() ->expects($this->any()) ->method('getDirectoryWrite') ->will($this->returnValueMap([ - [DirectoryList::VAR_DIR, $varDir], - [DirectoryList::STATIC_VIEW, $staticDir], - [DirectoryList::CONFIG, $configDir], + [DirectoryList::VAR_DIR, DriverPool::FILE, $varDir], + [DirectoryList::STATIC_VIEW, DriverPool::FILE, $staticDir], + [DirectoryList::CONFIG, DriverPool::FILE, $configDir], ])); $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); $this->logger From 4ba835892cc81e0d22a393e2e509be183f6c06b2 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Mon, 26 Jan 2015 17:35:23 -0600 Subject: [PATCH 47/89] MAGETWO-33205: Help command in Setup CLI for list of modules - Added the improved feature. --- .../Setup/Controller/ConsoleController.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 0f09d6dbdac58..18e441d1a6f75 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -44,6 +44,12 @@ class ConsoleController extends AbstractActionController const CMD_MODULE_DISABLE = 'module-disable'; /**#@- */ + /**#@+ + * Help option for retrieving list of modules + */ + const HELP_LIST_OF_MODULES = 'module-list'; + /**#@- */ + /** * Map of controller actions exposed in CLI * @@ -84,6 +90,7 @@ class ConsoleController extends AbstractActionController UserConfig::KEY_LANGUAGE, UserConfig::KEY_CURRENCY, UserConfig::KEY_TIMEZONE, + self::HELP_LIST_OF_MODULES, ]; /** @@ -543,6 +550,8 @@ public function helpAction() return $this->arrayToString($this->options->getCurrencyList()); case UserConfig::KEY_TIMEZONE: return $this->arrayToString($this->options->getTimezoneList()); + case self::HELP_LIST_OF_MODULES: + return $this->getModuleList(); default: if (isset($usages[$type])) { if ($usages[$type]) { @@ -622,4 +631,34 @@ private function arrayToString($input) } return $result; } + + /** + * Get lists of modules - enabled and disabled + * + * @return string + */ + private function getModuleList() + { + $moduleList = $this->getObjectManager()->create('Magento\Framework\Module\ModuleList'); + $result = "\nList of enabled modules:\n"; + $enabledModuleList = $moduleList->getNames(); + foreach ($enabledModuleList as $moduleName) { + $result .= "$moduleName\n"; + } + if (count($enabledModuleList) === 0) { + $result .= "None\n"; + } + + $fullModuleList = $this->getObjectManager()->create('Magento\Framework\Module\FullModuleList'); + $result .= "\nList of disabled modules:\n"; + $disabledModuleList = array_diff($fullModuleList->getNames(), $enabledModuleList); + foreach ($disabledModuleList as $moduleName) { + $result .= "$moduleName\n"; + } + if (count($disabledModuleList) === 0) { + $result .= "None\n"; + } + + return $result; + } } From e12fd16b76c10c8c1456675fc6c52ee4ca777761 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 13 Jan 2015 13:58:40 -0600 Subject: [PATCH 48/89] MAGETWO-32089: Setup Models Unit Test Coverage - corrected typo --- dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php | 2 +- .../unit/testsuite/Magento/Setup/Model/PhpInformationTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php index 0e702a0cc572e..a96983ffbf9d2 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php @@ -1,6 +1,6 @@ Date: Tue, 13 Jan 2015 17:27:34 -0600 Subject: [PATCH 49/89] MAGETWO-32091: Setup "Module" Models Unit Test Coverage - Completing the task by covering all classes for unit tests. --- .../Setup/Module/ConnectionFactoryTest.php | 3 +- .../Setup/Module/ResourceFactoryTest.php | 3 +- .../Setup/Module/Setup/FileResolverTest.php | 7 +- .../Setup/Module/Setup/ResourceConfigTest.php | 3 +- .../Magento/Setup/Module/SetupFactoryTest.php | 3 +- .../Magento/Setup/Module/SetupModuleTest.php | 122 ++++++++++++++++++ .../Magento/Setup/Module/SetupTest.php | 3 +- .../Magento/Setup/Module/_files/recurring.php | 1 + 8 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/_files/recurring.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/ConnectionFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/ConnectionFactoryTest.php index b35329d6e77ac..c3419e531af4b 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Module/ConnectionFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/ConnectionFactoryTest.php @@ -1,6 +1,7 @@ loggerMock = $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface'); + $this->moduleListMock = $this->getMockForAbstractClass('Magento\Framework\Module\ModuleListInterface'); + $this->moduleName = 'SampleModule'; + $this->moduleListMock + ->expects($this->any()) + ->method('getOne') + ->with($this->moduleName) + ->will($this->returnValue(['name' => 'SampleModule', 'schema_version' => '2.0.0'])); + $this->resourceModelMock = $this->getMock('Magento\Framework\App\Resource', [], [], '', false); + } + + public function testApplyRecurringUpdatesWithValidFile() + { + $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); + $fileResolver + ->expects($this->any()) + ->method('getSqlSetupFiles') + ->with($this->moduleName, 'recurring.php') + ->will($this->returnValue([__DIR__ . '/_files/recurring.php'])); + $setupModule = new SetupModule( + $this->loggerMock, + $this->moduleListMock, + $fileResolver, + $this->moduleName, + $this->resourceModelMock + ); + $setupModule = $setupModule->applyRecurringUpdates(); + $this->assertInstanceOf('Magento\Setup\Module\SetupModule', $setupModule); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessageRegExp #Error in file: *# + */ + public function testApplyRecurringUpdatesWithInvalidFile() + { + $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); + $fileResolver + ->expects($this->any()) + ->method('getSqlSetupFiles') + ->with($this->moduleName, 'recurring.php') + ->will($this->returnValue([__DIR__ . '/_files/recurring1.php'])); + $setupModule = new SetupModule( + $this->loggerMock, + $this->moduleListMock, + $fileResolver, + $this->moduleName, + $this->resourceModelMock + ); + $setupModule->applyRecurringUpdates(); + } + + public function testApplyUpdatesWithNullResource() + { + $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); + $fileResolver + ->expects($this->any()) + ->method('getResourceCode') + ->will($this->returnValue(null)); + $setupModule = new SetupModule( + $this->loggerMock, + $this->moduleListMock, + $fileResolver, + $this->moduleName, + $this->resourceModelMock + ); + $setupModule = $setupModule->applyUpdates(); + $this->assertInstanceOf('Magento\Setup\Module\SetupModule', $setupModule); + } + + public function testApplyUpdatesWithNoVersions() + { + $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); + $this->resourceModelMock + ->expects($this->any()) + ->method('getDbVersion') + ->will($this->returnValue(false)); + $setupModule = new SetupModule( + $this->loggerMock, + $this->moduleListMock, + $fileResolver, + $this->moduleName, + $this->resourceModelMock + ); + $setupModule = $setupModule->applyUpdates(); + $this->assertInstanceOf('Magento\Setup\Module\SetupModule', $setupModule); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupTest.php index ea9ead5c29519..936013f3c2320 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupTest.php @@ -1,6 +1,7 @@ Date: Mon, 12 Jan 2015 14:30:52 -0600 Subject: [PATCH 50/89] MAGETWO-32086: Setup "Console" Controller Unit Test Coverage - Changes based on CR --- .../Controller/ConsoleControllerTest.php | 115 +++++++++++++----- .../Setup/Controller/ConsoleController.php | 2 +- 2 files changed, 87 insertions(+), 30 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index fa2b4c959c291..9f3e49af059b1 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -73,7 +73,7 @@ public function setUp() ); $this->mvcEvent->expects($this->once())->method('getRequest')->willReturn($this->request); $this->mvcEvent->expects($this->once())->method('setResponse')->with($response)->willReturn($this->mvcEvent); - $routeMatch->expects($this->any())->method('getParam')->willReturn('install'); + $routeMatch->expects($this->any())->method('getParam')->willReturn('not-found'); $this->mvcEvent->expects($this->any())->method('getRouteMatch')->willReturn($routeMatch); $this->controller = new ConsoleController( @@ -83,15 +83,33 @@ public function setUp() $this->controller->dispatch($this->request, $response); } + public function testGetRouterConfig() + { + $controller = $this->controller; + $actualRoute = $controller::getRouterConfig(); + $this->assertArrayHasKey($controller::CMD_HELP, $actualRoute); + $this->assertArrayHasKey($controller::CMD_INSTALL, $actualRoute); + $this->assertArrayHasKey($controller::CMD_INSTALL_CONFIG, $actualRoute); + $this->assertArrayHasKey($controller::CMD_INSTALL_SCHEMA, $actualRoute); + $this->assertArrayHasKey($controller::CMD_INSTALL_DATA, $actualRoute); + $this->assertArrayHasKey($controller::CMD_INSTALL_USER_CONFIG, $actualRoute); + $this->assertArrayHasKey($controller::CMD_INSTALL_ADMIN_USER, $actualRoute); + $this->assertArrayHasKey($controller::CMD_UPDATE, $actualRoute); + $this->assertArrayHasKey($controller::CMD_UNINSTALL, $actualRoute); + $this->assertArrayHasKey($controller::CMD_UPDATE, $actualRoute); + $this->assertArrayHasKey($controller::CMD_MAINTENANCE, $actualRoute); + } + public function testSetEventManager() { - $controllerMock = $this->controller; - $closureMock = function () use ($controllerMock){ + $controller = $this->controller; + $closureMock = function () use ($controller) { }; + $eventManager = $this->getMock('\Zend\EventManager\EventManagerInterface'); - $eventManager->expects($this->any())->method('attach')->will($this->returnCallback($closureMock)); + $eventManager->expects($this->atLeastOnce())->method('attach')->will($this->returnCallback($closureMock)); $returnValue = $this->controller->setEventManager($eventManager); - $this->assertEquals($returnValue, $this->controller); + $this->assertSame($returnValue, $this->controller); } /** @@ -109,19 +127,18 @@ public function testSetEventManagerWithError() public function testOnDispatch() { - $this->controller->onDispatch($this->mvcEvent); + $returnValue = $this->controller->onDispatch($this->mvcEvent); + $this->assertInstanceOf('\Zend\View\Model\ConsoleModel', $returnValue); } - /** - * @expectedException \Zend\Mvc\Exception\DomainException - * @expectedExceptionMessage Missing route matches; unsure how to retrieve action - */ - public function testOnDispatchWithException () + public function testOnDispatchWithException() { - $e = new \Zend\Mvc\Exception\DomainException('Missing route matches; unsure how to retrieve action'); + $errorMessage = 'Missing route matches; unsure how to retrieve action'; $event = $this->getMock('\Zend\Mvc\MvcEvent'); + $exception = $this->getMock('\Magento\Setup\Exception', [], [$errorMessage]); + $event->expects($this->once())->method('getRouteMatch')->willThrowException($exception); + $this->consoleLogger->expects($this->once())->method('log')->with($errorMessage); $this->controller->onDispatch($event); - $this->consoleLogger->expects($this->once())->method('log')->with($e->getMessage()); } public function testInstallAction() @@ -176,24 +193,22 @@ public function testUninstallAction() /** * @param int $maintenanceMode - * @param array $addresses * @param int $setCount * @param int $logCount * * @dataProvider maintenanceActionDataProvider */ - public function testMaintenanceAction($maintenanceMode, $addresses, $setCount, $logCount) + public function testMaintenanceAction($maintenanceMode, $setCount, $logCount) { $mapGetParam = [ ['set', null, $maintenanceMode], - ['addresses', null, $addresses], + ['addresses', null, null], ]; $this->request->expects($this->exactly(2))->method('getParam')->will($this->returnValueMap($mapGetParam)); $this->maintenanceMode->expects($this->exactly($setCount))->method('set'); - $expected = $addresses !== null ? 1 : 0; - $this->maintenanceMode->expects($this->exactly($expected))->method('setAddresses'); + $this->maintenanceMode->expects($this->exactly(0))->method('setAddresses'); $this->maintenanceMode->expects($this->once())->method('isOn')->willReturn($maintenanceMode); - $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($addresses); + $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn([]); $this->consoleLogger->expects($this->exactly($logCount))->method('log'); $this->controller->maintenanceAction(); } @@ -204,26 +219,67 @@ public function testMaintenanceAction($maintenanceMode, $addresses, $setCount, $ public function maintenanceActionDataProvider() { return [ - [1, ['address1', 'address2'], 1, 3], - [0, [], 1, 2], - [null, ['address1'], 0, 2], - [1, null, 1, 2], - [0, null, 1, 2], + [1, 1, 2], + [0, 1, 2], + [null, 0, 1], + ]; + } + + /** + * @param array $addresses + * @param int $logCount + * @param int $setAddressesCount + * + * @dataProvider maintenanceActionWithAddressDataProvider + */ + public function testMaintenanceActionWithAddress($addresses, $logCount, $setAddressesCount) + { + $mapGetParam = [ + ['set', null, true], + ['addresses', null, $addresses], + ]; + $this->request->expects($this->exactly(2))->method('getParam')->will($this->returnValueMap($mapGetParam)); + $this->maintenanceMode->expects($this->exactly(1))->method('set'); + $this->maintenanceMode->expects($this->exactly($setAddressesCount))->method('setAddresses'); + $this->maintenanceMode->expects($this->once())->method('isOn')->willReturn(true); + $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($addresses); + $this->consoleLogger->expects($this->exactly($logCount))->method('log'); + $this->controller->maintenanceAction(); + } + + /** + * @return array + */ + public function maintenanceActionWithAddressDataProvider() + { + return [ + [['address1', 'address2'], 3, 1], + [[], 2, 1], + [null, 2, 0], ]; } /** * @param string $type * @param string $method - * @param array $value + * @param array $expectedValue * * @dataProvider helpActionForLanguageCurrencyTimezoneDataProvider */ - public function testHelpActionForLanguageCurrencyTimezone($type, $method, $value) + public function testHelpActionForLanguageCurrencyTimezone($type, $method, $expectedValue) { $this->request->expects($this->once())->method('getParam')->willReturn($type); - $this->options->expects($this->once())->method($method)->willReturn($value); - $this->controller->helpAction(); + $this->options->expects($this->once())->method($method)->willReturn($expectedValue); + $returnValue = $this->controller->helpAction(); + + //Need to convert from String to Associated Array. + $result = explode(PHP_EOL, trim($returnValue)); + foreach ($result as $value) { + $tempArray = explode(' => ' , $value); + $actual[$tempArray[0]] = $tempArray[1]; + } + + $this->assertSame($expectedValue, $actual); } /** @@ -269,8 +325,9 @@ public function testHelpActionNoType() public function testHelpAction($option, $noParameters) { $this->request->expects($this->once())->method('getParam')->willReturn($option); + $usage = $this->controller->getCommandUsage(); - $expectedValue = explode(' ', (strlen($usage[$option])>0 ? $usage[$option] : $noParameters)); + $expectedValue = explode(' ', (strlen($usage[$option]) > 0 ? $usage[$option] : $noParameters)); $returnValue = explode( ' ', trim(str_replace([PHP_EOL, 'Available parameters:'], '', $this->controller->helpAction())) ); diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 723a4a5312b19..f0c1a01e2fcab 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -424,7 +424,7 @@ public function maintenanceAction() $this->log->log('Status: maintenance mode is ' . ($this->maintenanceMode->isOn() ? 'active' : 'not active')); $addressInfo = $this->maintenanceMode->getAddressInfo(); - if(isset($addressInfo) && !empty($addressInfo)) { + if (!empty($addressInfo)) { $addresses = implode(', ', $addressInfo); $this->log->log('List of exempt IP-addresses: ' . ($addresses ? $addresses : 'none')); } From d20d38ee4f494227a9f87e8eec98e7d38eb2046c Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Tue, 13 Jan 2015 15:55:23 -0600 Subject: [PATCH 51/89] MAGETWO-32321: Cleanup setup directory structure - adding setup/src/ to account for failing test in build. --- lib/internal/Magento/Framework/Test/Utility/Files.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Test/Utility/Files.php b/lib/internal/Magento/Framework/Test/Utility/Files.php index 30ad68f115fb8..afa55182b00fe 100644 --- a/lib/internal/Magento/Framework/Test/Utility/Files.php +++ b/lib/internal/Magento/Framework/Test/Utility/Files.php @@ -919,7 +919,8 @@ public function classFileExists($class, &$path = '') '/dev/tests/static/testsuite/', '/dev/tests/functional/tests/app/', '/dev/tests/unit/framework/', - '/dev/tests/unit/testsuite/' + '/dev/tests/unit/testsuite/', + '/setup/src/' ]; foreach ($directories as $dir) { From e96fa6bfba28605d129163d222977c10f9448f65 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Tue, 13 Jan 2015 18:27:57 -0600 Subject: [PATCH 52/89] MAGETWO-32091: Setup "Module" Models Unit Test Coverage - Added copyright info. --- .../unit/testsuite/Magento/Setup/Module/_files/recurring.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/_files/recurring.php b/dev/tests/unit/testsuite/Magento/Setup/Module/_files/recurring.php index 8b137891791fe..128485e2d144e 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Module/_files/recurring.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/_files/recurring.php @@ -1 +1,4 @@ - +/** +* Copyright © 2015 Magento. All rights reserved. +* See COPYING.txt for license details. +*/ From 72e49946eff9b7055dcc5c7ab601a3f808dde206 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Wed, 14 Jan 2015 08:29:32 -0600 Subject: [PATCH 53/89] MAGETWO-32086: Setup "Console" Controller Unit Test Coverage - fixing phpcs error --- .../Magento/Setup/Controller/ConsoleControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 9f3e49af059b1..4f402e2effef1 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -275,7 +275,7 @@ public function testHelpActionForLanguageCurrencyTimezone($type, $method, $expec //Need to convert from String to Associated Array. $result = explode(PHP_EOL, trim($returnValue)); foreach ($result as $value) { - $tempArray = explode(' => ' , $value); + $tempArray = explode(' => ', $value); $actual[$tempArray[0]] = $tempArray[1]; } From 9cff2a227575471c4e4c0fb7a2653de64a8773d8 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 14 Jan 2015 10:04:49 -0600 Subject: [PATCH 54/89] MAGETWO-32089: Setup Models Unit Test Coverage - corrected code style error --- .../Magento/Setup/Model/AdminAccountTest.php | 26 +++++++++++++++---- .../Setup/Model/Installer/ProgressTest.php | 2 +- .../Magento/Setup/Model/ListsTest.php | 5 +++- .../Magento/Setup/Model/WebLoggerTest.php | 4 +-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php index 164a18cd9ef3d..0234493701db5 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/AdminAccountTest.php @@ -41,7 +41,11 @@ public function setUp() $this->setUpMock ->expects($this->any()) ->method('getTable') - ->will($this->returnCallback(function ($table) {return $table;})); + ->will($this->returnCallback( + function ($table) { + return $table; + } + )); $this->randomMock = $this->getMock('Magento\Framework\Math\Random'); $this->randomMock->expects($this->any())->method('getRandomString')->will($this->returnValue('salt')); @@ -91,7 +95,10 @@ public function testSaveUserExistsAdminRoleExists() $existingAdminRoleData, ], ]; - $this->dbAdapterMock->expects($this->exactly(2))->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock + ->expects($this->exactly(2)) + ->method('fetchRow') + ->will($this->returnValueMap($returnValueMap)); $this->dbAdapterMock->expects($this->once())->method('quoteInto')->will($this->returnValue('')); $this->dbAdapterMock->expects($this->once())->method('update')->will($this->returnValue(1)); @@ -151,7 +158,10 @@ public function testSaveUserExistsNewAdminRole() ], ]; - $this->dbAdapterMock->expects($this->exactly(3))->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock + ->expects($this->exactly(3)) + ->method('fetchRow') + ->will($this->returnValueMap($returnValueMap)); $this->dbAdapterMock->expects($this->once())->method('quoteInto')->will($this->returnValue('')); $this->dbAdapterMock->expects($this->once())->method('update')->will($this->returnValue(1)); @@ -189,7 +199,10 @@ public function testSaveNewUserAdminRoleExists() ], ]; - $this->dbAdapterMock->expects($this->exactly(2))->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock + ->expects($this->exactly(2)) + ->method('fetchRow') + ->will($this->returnValueMap($returnValueMap)); // insert only once (new user) $this->dbAdapterMock->expects($this->once())->method('insert'); // after inserting new user @@ -242,7 +255,10 @@ public function testSaveNewUserNewAdminRole() ]; - $this->dbAdapterMock->expects($this->exactly(3))->method('fetchRow')->will($this->returnValueMap($returnValueMap)); + $this->dbAdapterMock + ->expects($this->exactly(3)) + ->method('fetchRow') + ->will($this->returnValueMap($returnValueMap)); // after inserting new user $this->dbAdapterMock->expects($this->once())->method('lastInsertId')->will($this->returnValue(1)); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php index 3b61cbef767c7..ed2678af00165 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/Installer/ProgressTest.php @@ -33,7 +33,7 @@ public function constructorExceptionInvalidTotalDataProvider() */ public function testConstructorExceptionCurrentExceedsTotal() { - new Progress(1,2); + new Progress(1, 2); } public function testSetNext() diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php index a96983ffbf9d2..7adc82b9c1070 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php @@ -17,7 +17,10 @@ class ListsTest extends \PHPUnit_Framework_TestCase public function setUp() { $objectManager = new ObjectManager($this); - $this->lists = new Lists($objectManager->getObject('Zend_Locale'), $objectManager->getObject('Magento\Framework\Locale\Config')); + $this->lists = new Lists( + $objectManager->getObject('Zend_Locale'), + $objectManager->getObject('Magento\Framework\Locale\Config') + ); } public function testGetTimezoneList() diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php index ee65c974e0536..40037aaf7229a 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php @@ -83,8 +83,8 @@ public function testLogSuccess() $this->webLogger->logSuccess('Success2'); $this->assertEquals( '[SUCCESS] ' . 'Success1' . '
    ' . - '[SUCCESS] ' . 'Success2' . '
    ' - , self::$log); + '[SUCCESS] ' . 'Success2' . '
    ', + self::$log); } public function testLogError() From f9008888201edce15bc87fbb0696e2d23c5d4cc7 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 14 Jan 2015 16:44:52 -0600 Subject: [PATCH 55/89] MAGETWO-32089: Setup Models Unit Test Coverage - fixed testGet in WebLoggerTest failing in Windows --- dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php index 40037aaf7229a..5486d89749fa1 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php @@ -142,7 +142,7 @@ public function testLogMeta() public function testGet() { - $this->webLogger->log("Message1\n"); + $this->webLogger->log('Message1' . PHP_EOL); $this->webLogger->log('Message2'); $expected = [ From 8080080d87204ef02e6d22c93bbbe6de3f5ed27b Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Fri, 16 Jan 2015 14:57:11 -0600 Subject: [PATCH 56/89] MAGETWO-32091: Setup "Module" Models Unit Test Coverage - Changes based on CR feedback. --- composer.lock | 2 +- .../Setup/Module/Setup/FileResolverTest.php | 42 +++++++++---------- .../Magento/Setup/Module/SetupFactoryTest.php | 4 +- .../Magento/Setup/Module/SetupModuleTest.php | 18 ++++---- .../data/module1_setup/data-install.php | 5 +++ .../Module1/sql/module1_setup/install.php | 5 +++ .../Module2/sql/module2_setup/install.php | 5 +++ .../data/module3_setup/data-install.php | 5 +++ .../Magento/Setup/Module/_files/recurring.php | 7 ++-- 9 files changed, 57 insertions(+), 36 deletions(-) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/_files/Magento/Module1/data/module1_setup/data-install.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/_files/Magento/Module1/sql/module1_setup/install.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/_files/Magento/Module2/sql/module2_setup/install.php create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Module/_files/Magento/Module3/data/module3_setup/data-install.php diff --git a/composer.lock b/composer.lock index 842f9cd5fc65a..c1a9565d04737 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": "d60f0d0004f9184c2f206d1114fdeb28", + "hash": "5a0c3f24fb829631190971035d208974", "packages": [ { "name": "composer/composer", diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php index 120f902f1d1cf..d5601f1f8a524 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php @@ -6,8 +6,6 @@ namespace Magento\Setup\Module\Setup; -use Magento\Framework\App\Filesystem\DirectoryList; - class FileResolverTest extends \PHPUnit_Framework_TestCase { /** @@ -22,56 +20,56 @@ class FileResolverTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->directoryListMock = $this->getMockBuilder('Magento\Framework\App\Filesystem\DirectoryList') - ->disableOriginalConstructor() - ->setMethods(['getPath']) - ->getMock(); - + $this->directoryListMock = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); $this->fileResolver = new FileResolver($this->directoryListMock); } public function testGetSqlSetupFiles() { $this->directoryListMock - ->expects($this->any()) + ->expects($this->exactly(4)) ->method('getPath') - ->with(DirectoryList::MODULES) - ->will($this->returnValue(BP . '/app/code')); + ->will($this->returnValue(__DIR__ . '/../_files')); // All valid data - $this->assertGreaterThan(0, count($this->fileResolver->getSqlSetupFiles('Magento_Core', '*.php'))); + $this->assertGreaterThan(0, count($this->fileResolver->getSqlSetupFiles('Magento_Module1', '*.php'))); // Valid module name with default filename pattern - $this->assertGreaterThan(0, count($this->fileResolver->getSqlSetupFiles('Magento_Core'))); + $this->assertGreaterThan(0, count($this->fileResolver->getSqlSetupFiles('Magento_Module1'))); // Invalid module name - $this->assertCount(0, $this->fileResolver->getSqlSetupFiles('Magento_NonCore', '*.php')); + $this->assertCount(0, $this->fileResolver->getSqlSetupFiles('Magento_Module5', '*.php')); // Invalid filename pattern for SQL files - $this->assertCount(0, $this->fileResolver->getSqlSetupFiles('Magento_NonCore', '*.text')); + $this->assertCount(0, $this->fileResolver->getSqlSetupFiles('Magento_Module1', '*.text')); } public function testGetResourceCode() { $this->directoryListMock - ->expects($this->any()) + ->expects($this->exactly(10)) ->method('getPath') - ->with(DirectoryList::MODULES) - ->will($this->returnValue(BP . '/app/code')); + ->will($this->returnValue(__DIR__ . '/../_files')); // Valid module name with both 'data' and 'sql' directories - $this->assertSame('core_setup', $this->fileResolver->getResourceCode('Magento_Core')); + $this->assertSame('module1_setup', $this->fileResolver->getResourceCode('Magento_Module1')); // Valid module name with only 'sql' directories (no 'data') - $this->assertSame('adminnotification_setup', $this->fileResolver->getResourceCode('Magento_AdminNotification')); + $this->assertSame('module2_setup', $this->fileResolver->getResourceCode('Magento_Module2')); // Valid module name with only 'data' directories (no 'sql') - $this->assertSame('checkout_setup', $this->fileResolver->getResourceCode('Magento_Checkout')); + $this->assertSame('module3_setup', $this->fileResolver->getResourceCode('Magento_Module3')); // Valid module name with no 'data' and 'sql' directories - $this->assertNull($this->fileResolver->getResourceCode('Magento_Backend')); + $this->assertNull($this->fileResolver->getResourceCode('Magento_Module4')); // Invalid module name - $this->assertNull($this->fileResolver->getResourceCode('Magento_SomeModule')); + $this->assertNull($this->fileResolver->getResourceCode('Magento_Module5')); } + + + + + + } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupFactoryTest.php index a0b3a9e84599d..4c5ca898699ad 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupFactoryTest.php @@ -51,10 +51,10 @@ public function testCreateSetup() public function testCreateSetupModule() { - $setup = $this->setupFactory->createSetupModule( + $setupModule = $this->setupFactory->createSetupModule( $this->getMockForAbstractClass('Magento\Setup\Model\LoggerInterface'), 'sampleModuleName' ); - $this->assertInstanceOf('Magento\Setup\Module\Setup', $setup); + $this->assertInstanceOf('Magento\Setup\Module\SetupModule', $setupModule); } } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php index 093f7045644eb..3af7e0b951af0 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php @@ -36,7 +36,7 @@ protected function setUp() $this->moduleListMock = $this->getMockForAbstractClass('Magento\Framework\Module\ModuleListInterface'); $this->moduleName = 'SampleModule'; $this->moduleListMock - ->expects($this->any()) + ->expects($this->once()) ->method('getOne') ->with($this->moduleName) ->will($this->returnValue(['name' => 'SampleModule', 'schema_version' => '2.0.0'])); @@ -47,10 +47,13 @@ public function testApplyRecurringUpdatesWithValidFile() { $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); $fileResolver - ->expects($this->any()) + ->expects($this->once()) ->method('getSqlSetupFiles') ->with($this->moduleName, 'recurring.php') ->will($this->returnValue([__DIR__ . '/_files/recurring.php'])); + $this->loggerMock + ->expects($this->once()) + ->method('log'); $setupModule = new SetupModule( $this->loggerMock, $this->moduleListMock, @@ -70,10 +73,13 @@ public function testApplyRecurringUpdatesWithInvalidFile() { $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); $fileResolver - ->expects($this->any()) + ->expects($this->once()) ->method('getSqlSetupFiles') ->with($this->moduleName, 'recurring.php') ->will($this->returnValue([__DIR__ . '/_files/recurring1.php'])); + $this->loggerMock + ->expects($this->once()) + ->method('log'); $setupModule = new SetupModule( $this->loggerMock, $this->moduleListMock, @@ -88,7 +94,7 @@ public function testApplyUpdatesWithNullResource() { $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); $fileResolver - ->expects($this->any()) + ->expects($this->once()) ->method('getResourceCode') ->will($this->returnValue(null)); $setupModule = new SetupModule( @@ -105,10 +111,6 @@ public function testApplyUpdatesWithNullResource() public function testApplyUpdatesWithNoVersions() { $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); - $this->resourceModelMock - ->expects($this->any()) - ->method('getDbVersion') - ->will($this->returnValue(false)); $setupModule = new SetupModule( $this->loggerMock, $this->moduleListMock, diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/_files/Magento/Module1/data/module1_setup/data-install.php b/dev/tests/unit/testsuite/Magento/Setup/Module/_files/Magento/Module1/data/module1_setup/data-install.php new file mode 100644 index 0000000000000..25f63440e1a2d --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/_files/Magento/Module1/data/module1_setup/data-install.php @@ -0,0 +1,5 @@ + Date: Fri, 16 Jan 2015 10:51:04 -0600 Subject: [PATCH 57/89] MAGETWO-32086: Setup "Console" Controller Unit Test Coverage - Changes based on CR. --- .../Controller/ConsoleControllerTest.php | 79 ++++++++----------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 4f402e2effef1..e73bc315653c1 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -5,7 +5,7 @@ namespace Magento\Setup\Controller; -use \Magento\Setup\Model\UserConfigurationDataMapper as UserConfig; +use Magento\Setup\Model\UserConfigurationDataMapper as UserConfig; class ConsoleControllerTest extends \PHPUnit_Framework_TestCase { @@ -51,23 +51,23 @@ class ConsoleControllerTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->consoleLogger = $this->getMock('\Magento\Setup\Model\ConsoleLogger', [], [], '', false); - $installerFactory = $this->getMock('\Magento\Setup\Model\InstallerFactory', [], [], '', false); - $this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false); + $this->consoleLogger = $this->getMock('Magento\Setup\Model\ConsoleLogger', [], [], '', false); + $installerFactory = $this->getMock('Magento\Setup\Model\InstallerFactory', [], [], '', false); + $this->installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false); $installerFactory->expects($this->once())->method('create')->with($this->consoleLogger)->willReturn( $this->installer ); - $this->options = $this->getMock('\Magento\Setup\Model\Lists', [], [], '', false); - $this->maintenanceMode = $this->getMock('\Magento\Framework\App\MaintenanceMode', [], [], '', false); + $this->options = $this->getMock('Magento\Setup\Model\Lists', [], [], '', false); + $this->maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false); - $this->request = $this->getMock('\Zend\Console\Request', [], [], '', false); - $response = $this->getMock('\Zend\Console\Response', [], [], '', false); - $routeMatch = $this->getMock('\Zend\Mvc\Router\RouteMatch', [], [], '', false); + $this->request = $this->getMock('Zend\Console\Request', [], [], '', false); + $response = $this->getMock('Zend\Console\Response', [], [], '', false); + $routeMatch = $this->getMock('Zend\Mvc\Router\RouteMatch', [], [], '', false); - $this->parameters= $this->getMock('\Zend\Stdlib\Parameters', [], [], '', false); + $this->parameters= $this->getMock('Zend\Stdlib\Parameters', [], [], '', false); $this->request->expects($this->any())->method('getParams')->willReturn($this->parameters); - $this->mvcEvent = $this->getMock('\Zend\Mvc\MvcEvent', [], [], '', false); + $this->mvcEvent = $this->getMock('Zend\Mvc\MvcEvent', [], [], '', false); $this->mvcEvent->expects($this->once())->method('setRequest')->with($this->request)->willReturn( $this->mvcEvent ); @@ -87,17 +87,14 @@ public function testGetRouterConfig() { $controller = $this->controller; $actualRoute = $controller::getRouterConfig(); - $this->assertArrayHasKey($controller::CMD_HELP, $actualRoute); - $this->assertArrayHasKey($controller::CMD_INSTALL, $actualRoute); - $this->assertArrayHasKey($controller::CMD_INSTALL_CONFIG, $actualRoute); - $this->assertArrayHasKey($controller::CMD_INSTALL_SCHEMA, $actualRoute); - $this->assertArrayHasKey($controller::CMD_INSTALL_DATA, $actualRoute); - $this->assertArrayHasKey($controller::CMD_INSTALL_USER_CONFIG, $actualRoute); - $this->assertArrayHasKey($controller::CMD_INSTALL_ADMIN_USER, $actualRoute); - $this->assertArrayHasKey($controller::CMD_UPDATE, $actualRoute); - $this->assertArrayHasKey($controller::CMD_UNINSTALL, $actualRoute); - $this->assertArrayHasKey($controller::CMD_UPDATE, $actualRoute); - $this->assertArrayHasKey($controller::CMD_MAINTENANCE, $actualRoute); + foreach ($actualRoute as $route) { + $options = $route['options']; + $this->assertArrayHasKey('route', $options); + $this->assertArrayHasKey('defaults', $options); + $defaults = $options['defaults']; + $this->assertArrayHasKey('controller', $defaults); + $this->assertArrayHasKey('action', $defaults); + } } public function testSetEventManager() @@ -106,36 +103,23 @@ public function testSetEventManager() $closureMock = function () use ($controller) { }; - $eventManager = $this->getMock('\Zend\EventManager\EventManagerInterface'); + $eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); $eventManager->expects($this->atLeastOnce())->method('attach')->will($this->returnCallback($closureMock)); $returnValue = $this->controller->setEventManager($eventManager); $this->assertSame($returnValue, $this->controller); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage Some Message - */ - public function testSetEventManagerWithError() - { - $e = 'Some Message'; - $eventManager = $this->getMock('\Zend\EventManager\EventManagerInterface'); - $eventManager->expects($this->once())->method('attach')->willThrowException(new \RuntimeException($e)); - $returnValue = $this->controller->setEventManager($eventManager); - $this->assertEquals($returnValue, $this->controller); - } - public function testOnDispatch() { $returnValue = $this->controller->onDispatch($this->mvcEvent); - $this->assertInstanceOf('\Zend\View\Model\ConsoleModel', $returnValue); + $this->assertInstanceOf('Zend\View\Model\ConsoleModel', $returnValue); } public function testOnDispatchWithException() { $errorMessage = 'Missing route matches; unsure how to retrieve action'; - $event = $this->getMock('\Zend\Mvc\MvcEvent'); - $exception = $this->getMock('\Magento\Setup\Exception', [], [$errorMessage]); + $event = $this->getMock('Zend\Mvc\MvcEvent'); + $exception = $this->getMock('Magento\Setup\Exception', [], [$errorMessage]); $event->expects($this->once())->method('getRouteMatch')->willThrowException($exception); $this->consoleLogger->expects($this->once())->method('log')->with($errorMessage); $this->controller->onDispatch($event); @@ -272,8 +256,9 @@ public function testHelpActionForLanguageCurrencyTimezone($type, $method, $expec $this->options->expects($this->once())->method($method)->willReturn($expectedValue); $returnValue = $this->controller->helpAction(); - //Need to convert from String to Associated Array. - $result = explode(PHP_EOL, trim($returnValue)); + //Need to convert from String to associative array. + $result = explode("\n", trim($returnValue)); + $actual = []; foreach ($result as $value) { $tempArray = explode(' => ', $value); $actual[$tempArray[0]] = $tempArray[1]; @@ -289,18 +274,18 @@ public function helpActionForLanguageCurrencyTimezoneDataProvider() { return [ [UserConfig::KEY_LANGUAGE, 'getLocaleList', [ - 'en_GB' => 'English (United Kingdom)', - 'en_US' => 'English (United States)' + 'someCode1' => 'some country', + 'someCode2' => 'some country2', ] ], [UserConfig::KEY_CURRENCY, 'getCurrencyList', [ - 'USD' => 'US Dollar (USD)', - 'EUR' => 'Euro (EUR)' + 'currencyCode1' => 'some currency1', + 'currencyCode2' => 'some currency2', ] ], [UserConfig::KEY_TIMEZONE, 'getTimezoneList', [ - 'America/Chicago' => 'Central Standard Time (America/Chicago)', - 'America/Mexico_City' => 'Central Standard Time (Mexico) (America/Mexico_City)' + 'timezone1' => 'some specific timezone1', + 'timezone2' => 'some specific timezone2', ] ], ]; From 4feb1d032a56c040157fa831628fc0d0b38fcb40 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Tue, 20 Jan 2015 09:16:57 -0600 Subject: [PATCH 58/89] MAGETWO-32090: Setup "Mvc" Models Unit Test Coverage - add unit tests for Magento\Setup\Mvc\Console\RouteListener --- .../Setup/Mvc/Console/RouteListenerTest.php | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php new file mode 100644 index 0000000000000..70e2b37e0312b --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php @@ -0,0 +1,149 @@ +getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); + $httpRequest = $this->getMockBuilder('Zend\Http\Request')->getMock(); + $mvcEvent->expects($this->any())->method('getRequest')->willReturn($httpRequest); + + // Sending an HttpRequest to console RouteListener should return null + $this->assertNull($routeListener->onRoute($mvcEvent)); + } + + public function testOnRouteMatch() + { + $routeListener = new RouteListener(); + /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ + $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); + $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); + $mvcEvent->expects($this->any())->method('getRequest')->willReturn($request); + + $router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); + $match = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch')->disableOriginalConstructor()->getMock(); + $router->expects($this->any())->method('match')->willReturn($match); + $mvcEvent->expects($this->any())->method('getRouter')->willReturn($router); + + // There is a RouteMatch, so RouteListener will return null to trigger default listeners + $this->assertNull($routeListener->onRoute($mvcEvent)); + } + + public function testOnRouteError() + { + $routeListener = new RouteListener(); + /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ + $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); + $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); + $mvcEvent->expects($this->any())->method('getRequest')->willReturn($request); + + $router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); + $router->expects($this->any())->method('match')->willReturn(null); + $mvcEvent->expects($this->any())->method('getRouter')->willReturn($router); + + $request->expects($this->any())->method('getContent')->willReturn([]); + + $application = $this->getMockBuilder('Zend\Mvc\ApplicationInterface')->getMock(); + $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); + $console = $this->getMockBuilder('Zend\Console\Adapter\AdapterInterface')->getMock(); + + $configArray = ['console'=>['router'=>['routes'=>['testAction'=>'test']]]]; + $serviceManager->method('get')->will($this->returnValueMap([['Config', $configArray], ['console', $console]])); + + $application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); + $mvcEvent->expects($this->any())->method('getApplication')->willReturn($application); + + // Verify the error is set + $mvcEvent->expects($this->once())->method('setError'); + + // Should always return null + $this->assertNull($routeListener->onRoute($mvcEvent)); + } + + public function testOnRouteNoError() + { + $routeListener = new RouteListener(); + /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ + $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); + $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); + $mvcEvent->expects($this->any())->method('getRequest')->willReturn($request); + + $router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); + $routeMatch = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch')->disableOriginalConstructor()->getMock(); + $router->expects($this->any())->method('match')->willReturn($routeMatch); + $mvcEvent->expects($this->any())->method('getRouter')->willReturn($router); + + // Verify the error is not set + $mvcEvent->expects($this->never())->method('setError'); + + // Should always return null + $this->assertNull($routeListener->onRoute($mvcEvent)); + } + + + public function testOnRouteValidationMessage() + { + $routeListener = new RouteListener(); + /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ + $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); + $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); + $mvcEvent->expects($this->any())->method('getRequest')->willReturn($request); + + $router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); + //$routeMatch = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch')->disableOriginalConstructor()->getMock(); + $router->expects($this->any())->method('match')->willReturn(null); + $mvcEvent->expects($this->any())->method('getRouter')->willReturn($router); + + $request->expects($this->any())->method('getContent')->willReturn(['install']); + + $application = $this->getMockBuilder('Zend\Mvc\ApplicationInterface')->getMock(); + $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); + $console = $this->getMockBuilder('Zend\Console\Adapter\AdapterInterface')->getMock(); + + // $configArray = ['console'=>['router'=>['routes'=>['testAction'=>['test']]]]]; + $configArray = ['console'=>['router'=>['routes'=>['install'=>['options' => ['route' => 'testRoute']]]]]]; + $serviceManager->method('get')->will($this->returnValueMap([['Config', $configArray], ['console', $console]])); + + $application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); + $mvcEvent->expects($this->any())->method('getApplication')->willReturn($application); + + // Verify the error is set + $mvcEvent->expects($this->once())->method('setError'); + $mvcEvent->expects($this->once()) + ->method('setResult') + ->with($this->isInstanceOf('Zend\View\Model\ConsoleModel')); + + // Should always return null + $this->assertNull($routeListener->onRoute($mvcEvent)); + } + + + public function testAttach() + { + $routeListener = new RouteListener(); + /** @var 'Zend\EventManager\EventManagerInterface|PHPUnit_Framework_MockObject_MockObject $eventManager */ + $eventManager = $this->getMockBuilder('Zend\EventManager\EventManagerInterface')->getMock(); + $eventManager->expects($this->once()) + ->method('attach') + ->with( + $this->equalTo(MvcEvent::EVENT_ROUTE), + $this->contains($routeListener), + 10 + ); + $routeListener->attach($eventManager); + } +} From e78e798cb3408b101dcc8b588a650ae8dfc4eb44 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 22 Jan 2015 16:07:03 -0600 Subject: [PATCH 59/89] MAGETWO-32088: Setup "Installer" Model Unit Test Coverage - Fixing broken test after merging with mainline --- .../unit/testsuite/Magento/Setup/Model/InstallerTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php index a1814152dd102..4ca0769b19cae 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php @@ -9,6 +9,7 @@ use Magento\Framework\App\DeploymentConfig\DbConfig; use Magento\Framework\App\DeploymentConfig\EncryptConfig; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\DriverPool; class InstallerTest extends \PHPUnit_Framework_TestCase { @@ -287,9 +288,9 @@ public function testUninstall() ->expects($this->any()) ->method('getDirectoryWrite') ->will($this->returnValueMap([ - [DirectoryList::VAR_DIR, $varDir], - [DirectoryList::STATIC_VIEW, $staticDir], - [DirectoryList::CONFIG, $configDir], + [DirectoryList::VAR_DIR, DriverPool::FILE, $varDir, ], + [DirectoryList::STATIC_VIEW, DriverPool::FILE, $staticDir], + [DirectoryList::CONFIG, DriverPool::FILE, $configDir], ])); $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); $this->logger From 4375051333a4aa6a17a28254efdb3fb271f1d14a Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Thu, 22 Jan 2015 16:28:10 -0600 Subject: [PATCH 60/89] MAGETWO-32090: Setup "Mvc" Models Unit Test Coverage - Refactor InitParamListenerTest and RoutListenerTest to create reusable functions - Other formatting changes --- .../Mvc/Bootstrap/InitParamListenerTest.php | 158 +++++++++++------- .../Setup/Mvc/Console/RouteListenerTest.php | 140 +++++++++------- 2 files changed, 171 insertions(+), 127 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php index 0d01fc9cd3ef9..2705da3729bb8 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php @@ -14,6 +14,18 @@ */ class InitParamListenerTest extends \PHPUnit_Framework_TestCase { + + /** @var InitParamListener */ + private $listener; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + private $callbackHandler; + + public function setUp() + { + $this->listener = new InitParamListener(); + } + public function testAttachToConsoleRoutesEmpty() { $inputConfig = []; @@ -27,7 +39,7 @@ public function testAttachToConsoleRoutesEmpty() public function testAttachToConsoleRoutesOneRoute() { $inputConfig = [ - 'console' => ['router' => ['routes' => [['options' => ['route' =>'one_route']]]]] + 'console' => ['router' => ['routes' => [['options' => ['route' => 'one_route']]]]] ]; $expectedConfig = [ 'console' => ['router' => ['routes' => [['options' => ['route' => 'one_route [--magento_init_params=]']]]]] @@ -43,20 +55,20 @@ public function testAttachToConsoleRoutesManyRoute() { $inputConfig = [ 'console' => ['router' => ['routes' => [ - ['options' => ['route' =>'one_route']], - ['options' => ['route' =>'two_route']], - ['options' => ['route' =>'three_route']], - ['options' => ['route' =>'four_route']], - ['options' => ['route' =>'five_route']], + ['options' => ['route' => 'one_route']], + ['options' => ['route' => 'two_route']], + ['options' => ['route' => 'three_route']], + ['options' => ['route' => 'four_route']], + ['options' => ['route' => 'five_route']], ]]] ]; $expectedConfig = [ 'console' => ['router' => ['routes' => [ ['options' => ['route' => 'one_route [--magento_init_params=]']], - ['options' => ['route' =>'two_route [--magento_init_params=]']], - ['options' => ['route' =>'three_route [--magento_init_params=]']], - ['options' => ['route' =>'four_route [--magento_init_params=]']], - ['options' => ['route' =>'five_route [--magento_init_params=]']], + ['options' => ['route' => 'two_route [--magento_init_params=]']], + ['options' => ['route' => 'three_route [--magento_init_params=]']], + ['options' => ['route' => 'four_route [--magento_init_params=]']], + ['options' => ['route' => 'five_route [--magento_init_params=]']], ]]] ]; @@ -69,56 +81,38 @@ public function testAttachToConsoleRoutesManyRoute() public function testGetConsoleUsage() { $usage = InitParamListener::getConsoleUsage(); - // First element should be blank line + + // usage statement should have a blank line followed by a line containing the parameter + $this->assertGreaterThanOrEqual(2, count($usage)); + + // First element should be a blank line $this->assertEquals('', $usage[0]); - // Only one parameter definition is added to usage statement - $this->assertContains(escapeshellarg('[--magento_init_params=\'\']'), escapeshellarg($usage[1][0])); + + // Parameter definition is added to the usage statement + $this->assertContains(InitParamListener::BOOTSTRAP_PARAM, implode($usage[1])); } public function testAttach() { - $listener = new InitParamListener(); - /** @var \Zend\EventManager\EventManagerInterface | \PHPUnit_Framework_MockObject_MockObject $events */ - $events = $this->getMockBuilder('Zend\EventManager\EventManagerInterface')->getMock(); - $sharedManager = $this->getMockBuilder('Zend\EventManager\SharedEventManager')->getMock(); - $sharedManager->expects($this->once())->method('attach')->with( - 'Zend\Mvc\Application', - MvcEvent::EVENT_BOOTSTRAP, - [$listener, 'onBootstrap'] - ); - $events->expects($this->once())->method('getSharedManager')->willReturn($sharedManager); - - $listener->attach($events); + $events = $this->prepareEventManager(); + $this->listener->attach($events); } public function testDetach() { - $callbackHandler = $this->getMockBuilder('Zend\Stdlib\CallbackHandler')->disableOriginalConstructor() - ->getMock(); - - $listener = new InitParamListener(); - /** @var \Zend\EventManager\EventManagerInterface | \PHPUnit_Framework_MockObject_MockObject $events */ - $events = $this->getMockBuilder('Zend\EventManager\EventManagerInterface')->getMock(); - $sharedManager = $this->getMockBuilder('Zend\EventManager\SharedEventManager')->getMock(); - $sharedManager->expects($this->once())->method('attach') - ->with('Zend\Mvc\Application', MvcEvent::EVENT_BOOTSTRAP, [$listener, 'onBootstrap']) - ->willReturn($callbackHandler); - $events->expects($this->once())->method('getSharedManager')->willReturn($sharedManager); - $events->expects($this->once())->method('detach')->with($callbackHandler)->willReturn(true); - $listener->attach($events); - $listener->detach($events); + $events = $this->prepareEventManager(); + $this->listener->attach($events); + $events->expects($this->once())->method('detach')->with($this->callbackHandler)->willReturn(true); + $this->listener->detach($events); } public function testOnBootstrap() { - $listener = new InitParamListener(); - /** @var \Zend\Mvc\MvcEvent | \PHPUnit_Framework_MockObject_MockObject $mvcEvent */ - $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->getMock(); - /** @var \Zend\Mvc\Application | \PHPUnit_Framework_MockObject_MockObject $mvcApplication */ + /** @var \Zend\Mvc\MvcEvent|\PHPUnit_Framework_MockObject_MockObject $mvcEvent */ + $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent'); $mvcApplication = $this->getMockBuilder('Zend\Mvc\Application')->disableOriginalConstructor()->getMock(); $mvcEvent->expects($this->once())->method('getApplication')->willReturn($mvcApplication); - /** @var \Zend\ServiceManager\ServiceManager | \PHPUnit_Framework_MockObject_MockObject $mvcApplication */ - $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceManager')->getMock(); + $serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager'); $initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS][DirectoryList::ROOT] = ['path' => '/test']; $serviceManager->expects($this->once())->method('get') ->willReturn($initParams); @@ -130,38 +124,39 @@ public function testOnBootstrap() ); $mvcApplication->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); - $listener->onBootstrap($mvcEvent); + $this->listener->onBootstrap($mvcEvent); + } + + public function testCreateDirectoryList() + { + $initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = + [DirectoryList::ROOT => [DirectoryList::PATH => '/test/root']]; + + $directoryList = $this->listener->createDirectoryList($initParams); + $this->assertEquals('/test/root/app', $directoryList->getPath(DirectoryList::APP)); } /** * @expectedException LogicException * @expectedExceptionMessage Magento root directory is not specified. */ - public function testOnBootstrapException() + public function testCreateDirectoryListException() { - $listener = new InitParamListener(); - /** @var \Zend\Mvc\MvcEvent | \PHPUnit_Framework_MockObject_MockObject $mvcEvent */ - $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->getMock(); - $mvcApplication = $this->getMockBuilder('Zend\Mvc\Application')->disableOriginalConstructor()->getMock(); - $mvcEvent->expects($this->once())->method('getApplication')->willReturn($mvcApplication); - $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceManager')->getMock(); - $mvcApplication->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); - $listener->onBootstrap($mvcEvent); + $this->listener->createDirectoryList([]); } public function testCreateServiceNotConsole() { - $listener = new InitParamListener(); /** - * @var \Zend\ServiceManager\ServiceLocatorInterface | \PHPUnit_Framework_MockObject_MockObject $serviceLocator + * @var \Zend\ServiceManager\ServiceLocatorInterface|\PHPUnit_Framework_MockObject_MockObject $serviceLocator */ - $serviceLocator = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); + $serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); $mvcApplication = $this->getMockBuilder('Zend\Mvc\Application')->disableOriginalConstructor()->getMock(); - $request = $this->getMockBuilder('Zend\Stdlib\RequestInterface')->getMock(); + $request = $this->getMock('Zend\Stdlib\RequestInterface'); $mvcApplication->expects($this->any())->method('getRequest')->willReturn($request); $serviceLocator->expects($this->once())->method('get')->with('Application') ->willReturn($mvcApplication); - $listener->createService($serviceLocator); + $this->listener->createService($serviceLocator); } /** @@ -179,9 +174,9 @@ public function testCreateService($zfAppConfig, $env, $cliParam, $expectedArray) } $listener = new InitParamListener(); /** - * @var \Zend\ServiceManager\ServiceLocatorInterface | \PHPUnit_Framework_MockObject_MockObject $serviceLocator + * @var \Zend\ServiceManager\ServiceLocatorInterface|\PHPUnit_Framework_MockObject_MockObject $serviceLocator */ - $serviceLocator = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); + $serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); $mvcApplication = $this->getMockBuilder('Zend\Mvc\Application')->disableOriginalConstructor()->getMock(); $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); $request->expects($this->any()) @@ -244,4 +239,43 @@ public function createServiceDataProvider() ['MAGE_DIRS' => ['base' => ['path' => '/var/www/magento2/CLI']], 'MAGE_MODE' => 'production']], ]; } + + public function testCreateFilesystem() + { + $testPath = 'test/path/'; + + /** @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject $directoryList */ + $directoryList = $this->getMockBuilder('Magento\Framework\App\Filesystem\DirectoryList') + ->disableOriginalConstructor()->getMock(); + $directoryList->expects($this->any())->method('getPath')->willReturn($testPath); + $filesystem = $this->listener->createFilesystem($directoryList); + + // Verifies the filesystem was created with the directory list passed in + $this->assertEquals($testPath, $filesystem->getDirectoryRead('app')->getAbsolutePath()); + } + + /** + * Prepare the event manager with a SharedEventManager, it will expect attach() to be called once. + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function prepareEventManager() + { + $this->callbackHandler = $this->getMockBuilder('Zend\Stdlib\CallbackHandler')->disableOriginalConstructor() + ->getMock(); + + /** @var \Zend\EventManager\EventManagerInterface|\PHPUnit_Framework_MockObject_MockObject $events */ + $eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); + + $sharedManager = $this->getMock('Zend\EventManager\SharedEventManager'); + $sharedManager->expects($this->once())->method('attach')->with( + 'Zend\Mvc\Application', + MvcEvent::EVENT_BOOTSTRAP, + [$this->listener, 'onBootstrap'] + )->willReturn($this->callbackHandler); + $eventManager->expects($this->once())->method('getSharedManager')->willReturn($sharedManager); + return $eventManager; + } + + } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php index 70e2b37e0312b..527a7494812ac 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php @@ -14,112 +14,91 @@ class RouteListenerTest extends \PHPUnit_Framework_TestCase { + /** @var RouteListener */ + private $routeListener; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + private $request; + + /** @var PHPUnit_Framework_MockObject_MockObject */ + private $router; + + public function setUp() + { + $this->routeListener = new RouteListener(); + $this->request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); + $this->router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); + } + public function testOnRouteHttpRequest() { - $routeListener = new RouteListener(); /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); $httpRequest = $this->getMockBuilder('Zend\Http\Request')->getMock(); $mvcEvent->expects($this->any())->method('getRequest')->willReturn($httpRequest); // Sending an HttpRequest to console RouteListener should return null - $this->assertNull($routeListener->onRoute($mvcEvent)); + $this->assertNull($this->routeListener->onRoute($mvcEvent)); } public function testOnRouteMatch() { - $routeListener = new RouteListener(); - /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ - $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); - $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); - $mvcEvent->expects($this->any())->method('getRequest')->willReturn($request); + $mvcEvent = $this->prepareEvent(); - $router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); $match = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch')->disableOriginalConstructor()->getMock(); - $router->expects($this->any())->method('match')->willReturn($match); - $mvcEvent->expects($this->any())->method('getRouter')->willReturn($router); + $this->router->expects($this->any())->method('match')->willReturn($match); + $mvcEvent->expects($this->any())->method('getRouter')->willReturn($this->router); // There is a RouteMatch, so RouteListener will return null to trigger default listeners - $this->assertNull($routeListener->onRoute($mvcEvent)); + $this->assertNull($this->routeListener->onRoute($mvcEvent)); } public function testOnRouteError() { - $routeListener = new RouteListener(); - /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ - $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); - $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); - $mvcEvent->expects($this->any())->method('getRequest')->willReturn($request); - - $router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); - $router->expects($this->any())->method('match')->willReturn(null); - $mvcEvent->expects($this->any())->method('getRouter')->willReturn($router); - - $request->expects($this->any())->method('getContent')->willReturn([]); + $mvcEvent = $this->prepareEvent(); - $application = $this->getMockBuilder('Zend\Mvc\ApplicationInterface')->getMock(); - $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); - $console = $this->getMockBuilder('Zend\Console\Adapter\AdapterInterface')->getMock(); + $this->router->expects($this->any())->method('match')->willReturn(null); + $mvcEvent->expects($this->any())->method('getRouter')->willReturn($this->router); - $configArray = ['console'=>['router'=>['routes'=>['testAction'=>'test']]]]; - $serviceManager->method('get')->will($this->returnValueMap([['Config', $configArray], ['console', $console]])); - - $application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); - $mvcEvent->expects($this->any())->method('getApplication')->willReturn($application); + $this->request->expects($this->any())->method('getContent')->willReturn([]); + $this->prepareOnRoute($mvcEvent, ['console'=>['router'=>['routes'=>['testAction'=>'test']]]]); // Verify the error is set $mvcEvent->expects($this->once())->method('setError'); // Should always return null - $this->assertNull($routeListener->onRoute($mvcEvent)); + $this->assertNull($this->routeListener->onRoute($mvcEvent)); } public function testOnRouteNoError() { - $routeListener = new RouteListener(); - /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ - $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); - $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); - $mvcEvent->expects($this->any())->method('getRequest')->willReturn($request); + $mvcEvent = $this->prepareEvent(); - $router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); $routeMatch = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch')->disableOriginalConstructor()->getMock(); - $router->expects($this->any())->method('match')->willReturn($routeMatch); - $mvcEvent->expects($this->any())->method('getRouter')->willReturn($router); + $this->router->expects($this->any())->method('match')->willReturn($routeMatch); + $mvcEvent->expects($this->any())->method('getRouter')->willReturn($this->router); // Verify the error is not set $mvcEvent->expects($this->never())->method('setError'); // Should always return null - $this->assertNull($routeListener->onRoute($mvcEvent)); + $this->assertNull($this->routeListener->onRoute($mvcEvent)); } public function testOnRouteValidationMessage() { - $routeListener = new RouteListener(); - /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ - $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); - $request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); - $mvcEvent->expects($this->any())->method('getRequest')->willReturn($request); + $mvcEvent = $this->prepareEvent(); - $router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); - //$routeMatch = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch')->disableOriginalConstructor()->getMock(); - $router->expects($this->any())->method('match')->willReturn(null); - $mvcEvent->expects($this->any())->method('getRouter')->willReturn($router); + $this->router->expects($this->any())->method('match')->willReturn(null); + $mvcEvent->expects($this->any())->method('getRouter')->willReturn($this->router); - $request->expects($this->any())->method('getContent')->willReturn(['install']); + $this->request->expects($this->any())->method('getContent')->willReturn(['install']); - $application = $this->getMockBuilder('Zend\Mvc\ApplicationInterface')->getMock(); - $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); - $console = $this->getMockBuilder('Zend\Console\Adapter\AdapterInterface')->getMock(); - - // $configArray = ['console'=>['router'=>['routes'=>['testAction'=>['test']]]]]; - $configArray = ['console'=>['router'=>['routes'=>['install'=>['options' => ['route' => 'testRoute']]]]]]; - $serviceManager->method('get')->will($this->returnValueMap([['Config', $configArray], ['console', $console]])); - - $application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); - $mvcEvent->expects($this->any())->method('getApplication')->willReturn($application); + $this->prepareOnRoute( + $mvcEvent, + ['console'=>['router'=>['routes'=>['install'=>['options' => ['route' => 'testRoute']]]]]] + ); // Verify the error is set $mvcEvent->expects($this->once())->method('setError'); @@ -128,22 +107,53 @@ public function testOnRouteValidationMessage() ->with($this->isInstanceOf('Zend\View\Model\ConsoleModel')); // Should always return null - $this->assertNull($routeListener->onRoute($mvcEvent)); + $this->assertNull($this->routeListener->onRoute($mvcEvent)); } public function testAttach() { - $routeListener = new RouteListener(); - /** @var 'Zend\EventManager\EventManagerInterface|PHPUnit_Framework_MockObject_MockObject $eventManager */ + /** @var \Zend\EventManager\EventManagerInterface|PHPUnit_Framework_MockObject_MockObject $eventManager */ $eventManager = $this->getMockBuilder('Zend\EventManager\EventManagerInterface')->getMock(); $eventManager->expects($this->once()) ->method('attach') ->with( $this->equalTo(MvcEvent::EVENT_ROUTE), - $this->contains($routeListener), + $this->contains($this->routeListener), 10 ); - $routeListener->attach($eventManager); + $this->routeListener->attach($eventManager); + } + + /** + * Create a mock MVC event with a console mock console request. + * + * @return PHPUnit_Framework_MockObject_MockObject|MvcEvent + */ + private function prepareEvent() + { + $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); + $this->request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); + $mvcEvent->expects($this->any())->method('getRequest')->willReturn($this->request); + return $mvcEvent; + } + + /** + * Add a mock application, service manager and console adapter. + * + * @param PHPUnit_Framework_MockObject_MockObject $mvcEvent + * @param $configArray + */ + private function prepareOnRoute($mvcEvent, $configArray) + { + $application = $this->getMockBuilder('Zend\Mvc\ApplicationInterface')->getMock(); + $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); + $console = $this->getMockBuilder('Zend\Console\Adapter\AdapterInterface')->getMock(); + + $serviceManager->method('get')->will($this->returnValueMap([['Config', $configArray], ['console', $console]])); + + $application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); + $mvcEvent->expects($this->any())->method('getApplication')->willReturn($application); + } } From 0f2654018504c37202c005c2df44fd6e924fa95a Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Thu, 22 Jan 2015 16:39:47 -0600 Subject: [PATCH 61/89] MAGETWO-32090: Setup "Mvc" Models Unit Test Coverage - Corrected formatting around '=>' in RoutListenerTest --- .../testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php index 527a7494812ac..d3dba765db7b6 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php @@ -61,7 +61,7 @@ public function testOnRouteError() $mvcEvent->expects($this->any())->method('getRouter')->willReturn($this->router); $this->request->expects($this->any())->method('getContent')->willReturn([]); - $this->prepareOnRoute($mvcEvent, ['console'=>['router'=>['routes'=>['testAction'=>'test']]]]); + $this->prepareOnRoute($mvcEvent, ['console' => ['router' => ['routes' => ['testAction' => 'test']]]]); // Verify the error is set $mvcEvent->expects($this->once())->method('setError'); @@ -97,7 +97,7 @@ public function testOnRouteValidationMessage() $this->prepareOnRoute( $mvcEvent, - ['console'=>['router'=>['routes'=>['install'=>['options' => ['route' => 'testRoute']]]]]] + ['console' => ['router' => ['routes' => ['install' => ['options' => ['route' => 'testRoute']]]]]] ); // Verify the error is set From d0a28ea44f0030b6fda2a15bbf339ae852f1523f Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Thu, 22 Jan 2015 16:35:47 -0600 Subject: [PATCH 62/89] MAGETWO-32088: Setup "Installer" Model Unit Test Coverage - removing excessive comma --- dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php index 4ca0769b19cae..d8446956e9423 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php @@ -288,7 +288,7 @@ public function testUninstall() ->expects($this->any()) ->method('getDirectoryWrite') ->will($this->returnValueMap([ - [DirectoryList::VAR_DIR, DriverPool::FILE, $varDir, ], + [DirectoryList::VAR_DIR, DriverPool::FILE, $varDir], [DirectoryList::STATIC_VIEW, DriverPool::FILE, $staticDir], [DirectoryList::CONFIG, DriverPool::FILE, $configDir], ])); From 4d4cbdbad8858ae36c3f3a55d59bb42b725acfd2 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Fri, 23 Jan 2015 09:11:52 -0600 Subject: [PATCH 63/89] MAGETWO-32090: Setup "Mvc" Models Unit Test Coverage - Added new assertions to test array - Set setup to protected access --- .../Setup/Mvc/Bootstrap/InitParamListenerTest.php | 9 ++++----- .../Magento/Setup/Mvc/Console/RouteListenerTest.php | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php index 2705da3729bb8..22d79fc2c32a4 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php @@ -21,7 +21,7 @@ class InitParamListenerTest extends \PHPUnit_Framework_TestCase /** @var PHPUnit_Framework_MockObject_MockObject */ private $callbackHandler; - public function setUp() + protected function setUp() { $this->listener = new InitParamListener(); } @@ -82,7 +82,8 @@ public function testGetConsoleUsage() { $usage = InitParamListener::getConsoleUsage(); - // usage statement should have a blank line followed by a line containing the parameter + // usage statement should be an array and have a blank line followed by a line containing the parameter + $this->assertTrue(is_array($usage), 'usage should be an array'); $this->assertGreaterThanOrEqual(2, count($usage)); // First element should be a blank line @@ -156,7 +157,7 @@ public function testCreateServiceNotConsole() $mvcApplication->expects($this->any())->method('getRequest')->willReturn($request); $serviceLocator->expects($this->once())->method('get')->with('Application') ->willReturn($mvcApplication); - $this->listener->createService($serviceLocator); + $this->assertEquals([], $this->listener->createService($serviceLocator)); } /** @@ -276,6 +277,4 @@ private function prepareEventManager() $eventManager->expects($this->once())->method('getSharedManager')->willReturn($sharedManager); return $eventManager; } - - } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php index d3dba765db7b6..fe7db0e4e0e0e 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php @@ -23,7 +23,7 @@ class RouteListenerTest extends \PHPUnit_Framework_TestCase /** @var PHPUnit_Framework_MockObject_MockObject */ private $router; - public function setUp() + protected function setUp() { $this->routeListener = new RouteListener(); $this->request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); @@ -154,6 +154,5 @@ private function prepareOnRoute($mvcEvent, $configArray) $application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); $mvcEvent->expects($this->any())->method('getApplication')->willReturn($application); - } } From d85512d405f21bbfd344d6440a7b3fc96ebaa034 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Fri, 23 Jan 2015 10:23:43 -0600 Subject: [PATCH 64/89] MAGETWO-32090: Setup "Mvc" Models Unit Test Coverage - Correct assertion to test if variable is array --- .../Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php index 22d79fc2c32a4..f226b226b58d7 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php @@ -83,7 +83,7 @@ public function testGetConsoleUsage() $usage = InitParamListener::getConsoleUsage(); // usage statement should be an array and have a blank line followed by a line containing the parameter - $this->assertTrue(is_array($usage), 'usage should be an array'); + $this->assertArrayHasKey(0, $usage); $this->assertGreaterThanOrEqual(2, count($usage)); // First element should be a blank line From 56b1c95a51d5d7d776adeae3b46cd137535edb51 Mon Sep 17 00:00:00 2001 From: Paul Lewis Date: Fri, 23 Jan 2015 11:04:14 -0600 Subject: [PATCH 65/89] MAGETWO-32090: Setup "Mvc" Models Unit Test Coverage - fix formatting errors, lines too long and missing leading \ in @var --- .../Mvc/Bootstrap/InitParamListenerTest.php | 9 ++++++--- .../Setup/Mvc/Console/RouteListenerTest.php | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php index f226b226b58d7..1ec56e1e93e2d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php @@ -18,7 +18,7 @@ class InitParamListenerTest extends \PHPUnit_Framework_TestCase /** @var InitParamListener */ private $listener; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject */ private $callbackHandler; protected function setUp() @@ -138,7 +138,7 @@ public function testCreateDirectoryList() } /** - * @expectedException LogicException + * @expectedException \LogicException * @expectedExceptionMessage Magento root directory is not specified. */ public function testCreateDirectoryListException() @@ -245,7 +245,10 @@ public function testCreateFilesystem() { $testPath = 'test/path/'; - /** @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject $directoryList */ + /** + * @var \Magento\Framework\App\Filesystem\DirectoryList| + * \PHPUnit_Framework_MockObject_MockObject $directoryList + */ $directoryList = $this->getMockBuilder('Magento\Framework\App\Filesystem\DirectoryList') ->disableOriginalConstructor()->getMock(); $directoryList->expects($this->any())->method('getPath')->willReturn($testPath); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php index fe7db0e4e0e0e..5e4525027850f 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Mvc/Console/RouteListenerTest.php @@ -17,22 +17,23 @@ class RouteListenerTest extends \PHPUnit_Framework_TestCase /** @var RouteListener */ private $routeListener; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject */ private $request; - /** @var PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit_Framework_MockObject_MockObject */ private $router; protected function setUp() { $this->routeListener = new RouteListener(); $this->request = $this->getMockBuilder('Zend\Console\Request')->disableOriginalConstructor()->getMock(); - $this->router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface')->disableOriginalConstructor()->getMock(); + $this->router = $this->getMockBuilder('Zend\Mvc\Router\RouteInterface') + ->disableOriginalConstructor()->getMock(); } public function testOnRouteHttpRequest() { - /** @var \Zend\Mvc\MvcEvent|PHPUnit_Framework_MockObject_MockObject $mvcEvent */ + /** @var \Zend\Mvc\MvcEvent|\PHPUnit_Framework_MockObject_MockObject $mvcEvent */ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->disableOriginalConstructor()->getMock(); $httpRequest = $this->getMockBuilder('Zend\Http\Request')->getMock(); $mvcEvent->expects($this->any())->method('getRequest')->willReturn($httpRequest); @@ -113,7 +114,7 @@ public function testOnRouteValidationMessage() public function testAttach() { - /** @var \Zend\EventManager\EventManagerInterface|PHPUnit_Framework_MockObject_MockObject $eventManager */ + /** @var \Zend\EventManager\EventManagerInterface|\PHPUnit_Framework_MockObject_MockObject $eventManager */ $eventManager = $this->getMockBuilder('Zend\EventManager\EventManagerInterface')->getMock(); $eventManager->expects($this->once()) ->method('attach') @@ -128,7 +129,7 @@ public function testAttach() /** * Create a mock MVC event with a console mock console request. * - * @return PHPUnit_Framework_MockObject_MockObject|MvcEvent + * @return \PHPUnit_Framework_MockObject_MockObject|MvcEvent */ private function prepareEvent() { @@ -141,7 +142,7 @@ private function prepareEvent() /** * Add a mock application, service manager and console adapter. * - * @param PHPUnit_Framework_MockObject_MockObject $mvcEvent + * @param \PHPUnit_Framework_MockObject_MockObject $mvcEvent * @param $configArray */ private function prepareOnRoute($mvcEvent, $configArray) @@ -150,7 +151,9 @@ private function prepareOnRoute($mvcEvent, $configArray) $serviceManager = $this->getMockBuilder('Zend\ServiceManager\ServiceLocatorInterface')->getMock(); $console = $this->getMockBuilder('Zend\Console\Adapter\AdapterInterface')->getMock(); - $serviceManager->method('get')->will($this->returnValueMap([['Config', $configArray], ['console', $console]])); + $serviceManager + ->expects($this->any()) + ->method('get')->will($this->returnValueMap([['Config', $configArray], ['console', $console]])); $application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager); $mvcEvent->expects($this->any())->method('getApplication')->willReturn($application); From 291828f924f87594cd01e063a515a0e301db832e Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Tue, 27 Jan 2015 16:47:08 -0600 Subject: [PATCH 66/89] MAGETWO-32948: Contribution to Mainline of Sprint 22 Work - fixed code style and missing dependency --- .../Magento/Framework/App/State/CleanupTest.php | 2 +- .../Magento/Framework/Module/DependencyCheckerTest.php | 9 ++++++++- .../Magento/Setup/Controller/ConsoleControllerTest.php | 9 +++------ .../Magento/Setup/Model/InstallerFactoryTest.php | 2 +- .../unit/testsuite/Magento/Setup/Model/InstallerTest.php | 4 ++++ .../Setup/Model/UserConfigurationDataMapperTest.php | 2 ++ .../unit/testsuite/Magento/Setup/Model/WebLoggerTest.php | 6 +++++- .../Magento/Setup/Module/Setup/FileResolverTest.php | 6 ------ .../testsuite/Magento/Setup/Module/SetupModuleTest.php | 4 ++-- 9 files changed, 26 insertions(+), 18 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php index ea507c41f818f..81e161dc8b406 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/State/CleanupTest.php @@ -80,7 +80,7 @@ public function testClearMaterializedViewFiles() $var = $this->getDirectoryCleanMock(Source::TMP_MATERIALIZATION_DIR); $this->filesystem->expects($this->exactly(2))->method('getDirectoryWrite')->will($this->returnValueMap([ [DirectoryList::STATIC_VIEW, DriverPool::FILE, $static], - [DirectoryList::VAR_DIR, DriverPool::FILE, $var], + [DirectoryList::VAR_DIR, DriverPool::FILE, $var], ])); $this->object->clearMaterializedViewFiles(); } diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php index d02b3d8af500a..24db2adc2e794 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php @@ -47,7 +47,14 @@ public function setUp() ->method('getRequire') ->will($this->returnValueMap($requireMap)); - $this->packageInfoFactoryMock = $this->getMock('Magento\Framework\Module\PackageInfoFactory', [], [], '', false); + $this->packageInfoFactoryMock = $this->getMock( + 'Magento\Framework\Module\PackageInfoFactory' + , + [], + [], + '', + false + ); $this->packageInfoFactoryMock->expects($this->once()) ->method('create') ->will($this->returnValue($this->packageInfoMock)); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 7fef729912252..7d4ad1e326e32 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -113,12 +113,8 @@ public function testGetRouterConfig() public function testSetEventManager() { - $controller = $this->controller; - $closureMock = function () use ($controller) { - }; - $eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); - $eventManager->expects($this->atLeastOnce())->method('attach')->will($this->returnCallback($closureMock)); + $eventManager->expects($this->atLeastOnce())->method('attach'); $returnValue = $this->controller->setEventManager($eventManager); $this->assertSame($returnValue, $this->controller); } @@ -497,7 +493,8 @@ public function testHelpAction($option, $noParameters) $usage = $this->controller->getCommandUsage(); $expectedValue = explode(' ', (strlen($usage[$option]) > 0 ? $usage[$option] : $noParameters)); $returnValue = explode( - ' ', trim(str_replace([PHP_EOL, 'Available parameters:'], '', $this->controller->helpAction())) + ' ', + trim(str_replace([PHP_EOL, 'Available parameters:'], '', $this->controller->helpAction())) ); $expectedValue = asort($expectedValue); $returnValue = asort($returnValue); diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php index d53163931e904..1e6a164a6a10b 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerFactoryTest.php @@ -5,7 +5,7 @@ namespace Magento\Setup\Model; -class InstallerFactoryTest Extends \PHPUnit_Framework_TestCase +class InstallerFactoryTest extends \PHPUnit_Framework_TestCase { public function testCreate() { diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php index 4a546a53069e1..462f14bc89dc1 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php @@ -10,6 +10,10 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; +/** + * @SuppressWarnings(PHPMD.TooManyFields) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class InstallerTest extends \PHPUnit_Framework_TestCase { /** diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php index 83dd1773cb7cf..241d2ffd8ac68 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/UserConfigurationDataMapperTest.php @@ -26,6 +26,8 @@ public function testGetConfigData(array $data, array $expected) /** * return array + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getConfigDataDataProvider() { diff --git a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php index 5486d89749fa1..5b6f2e4441dee 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php @@ -84,7 +84,8 @@ public function testLogSuccess() $this->assertEquals( '[SUCCESS] ' . 'Success1' . '
    ' . '[SUCCESS] ' . 'Success2' . '
    ', - self::$log); + self::$log + ); } public function testLogError() @@ -181,6 +182,9 @@ public static function readLog() return self::$log; } + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ public static function writeToLog($logFile, $message) { self::$log .= $message; diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php index d5601f1f8a524..89a7ad5db818f 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/Setup/FileResolverTest.php @@ -66,10 +66,4 @@ public function testGetResourceCode() // Invalid module name $this->assertNull($this->fileResolver->getResourceCode('Magento_Module5')); } - - - - - - } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php index 3af7e0b951af0..75fabe08645a2 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Module/SetupModuleTest.php @@ -90,7 +90,7 @@ public function testApplyRecurringUpdatesWithInvalidFile() $setupModule->applyRecurringUpdates(); } - public function testApplyUpdatesWithNullResource() + public function testApplyUpdatesWithNullResource() { $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); $fileResolver @@ -108,7 +108,7 @@ public function testApplyUpdatesWithNullResource() $this->assertInstanceOf('Magento\Setup\Module\SetupModule', $setupModule); } - public function testApplyUpdatesWithNoVersions() + public function testApplyUpdatesWithNoVersions() { $fileResolver = $this->getMock('Magento\Setup\Module\Setup\FileResolver', [], [], '', false); $setupModule = new SetupModule( From 5f7f6d053c8f41c06a14d72dfa64653e9559d691 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Tue, 27 Jan 2015 17:51:39 -0600 Subject: [PATCH 67/89] MAGETWO-32948: Contribution to Mainline of Sprint 22 Work - fixed code style --- .../Magento/Framework/Module/DependencyCheckerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php index 24db2adc2e794..4b41c4f452bac 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php @@ -48,8 +48,7 @@ public function setUp() ->will($this->returnValueMap($requireMap)); $this->packageInfoFactoryMock = $this->getMock( - 'Magento\Framework\Module\PackageInfoFactory' - , + 'Magento\Framework\Module\PackageInfoFactory', [], [], '', From d9d4ae04563a350cf908225e0c3f1d34c78a39d4 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Tue, 27 Jan 2015 13:31:40 -0600 Subject: [PATCH 68/89] MAGETWO-33205: Help command in Setup CLI for list of modules - Added testcase for the change. --- .../Controller/ConsoleControllerTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index d5955521c74de..861ad5593094f 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -264,6 +264,37 @@ public function helpActionForLanguageCurrencyTimezoneDataProvider() ]; } + public function testHelpActionForModuleList() + { + $this->request->expects($this->once())->method('getParam')->willReturn(ConsoleController::HELP_LIST_OF_MODULES); + $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $moduleListMock + ->expects($this->once()) + ->method('getNames') + ->will($this->returnValue(['Magento_Core', 'Magento_Store'])); + $fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); + $fullModuleListMock + ->expects($this->once()) + ->method('getNames') + ->will($this->returnValue(['Magento_Core', 'Magento_Store', 'Magento_Directory'])); + $returnValueMap = [ + [ + 'Magento\Framework\Module\ModuleList', + [], + $moduleListMock, + ], + [ + 'Magento\Framework\Module\FullModuleList', + [], + $fullModuleListMock, + ], + ]; + $this->objectManager->expects($this->exactly(2)) + ->method('create') + ->will($this->returnValueMap($returnValueMap)); + $this->controller->helpAction(); + } + public function testHelpActionNoType() { $beginHelpString = "\n==-------------------==\n" From 31f505d61407ecee2e78f047afa2b8e23055ccd2 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 27 Jan 2015 14:20:50 -0600 Subject: [PATCH 69/89] MAGETWO-33156: Technical constraint is still checked in enable/disable module CLI tool even if no changes will be made - simplified algorithm --- .../Magento/Framework/Module/StatusTest.php | 38 ++++++++++++++++--- .../Controller/ConsoleControllerTest.php | 24 ++++++------ .../Magento/Framework/Module/Status.php | 12 +++--- .../Setup/Controller/ConsoleController.php | 14 +++---- 4 files changed, 55 insertions(+), 33 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php index 762f5b09721a1..76aa8d02d9fcc 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php @@ -156,14 +156,40 @@ public function testSetIsEnabledUnknown() $this->object->setIsEnabled(true, ['Module_Baz']); } - public function testGetUnchangedModules() + /** + * @dataProvider getModulesToChangeDataProvider + * @param bool $firstEnabled + * @param bool $secondEnabled + * @param bool $thirdEnabled + * @param bool $isEnabled + * @param string[] $expected + */ + public function testGetModulesToChange($firstEnabled, $secondEnabled, $thirdEnabled, $isEnabled, $expected) { $modules = ['Module_Foo' => '', 'Module_Bar' => '', 'Module_Baz' => '']; $this->loader->expects($this->once())->method('load')->willReturn($modules); - $this->moduleList->expects($this->at(0))->method('has')->with('Module_Foo')->willReturn(true); - $this->moduleList->expects($this->at(1))->method('has')->with('Module_Bar')->willReturn(true); - $this->moduleList->expects($this->at(2))->method('has')->with('Module_Baz')->willReturn(true); - $result = $this->object->getUnchangedModules(true, ['Module_Foo', 'Module_Bar', 'Module_Baz']); - $this->assertEquals(array_keys($modules), $result); + $this->moduleList->expects($this->at(0))->method('has')->with('Module_Foo')->willReturn($firstEnabled); + $this->moduleList->expects($this->at(1))->method('has')->with('Module_Bar')->willReturn($secondEnabled); + $this->moduleList->expects($this->at(2))->method('has')->with('Module_Baz')->willReturn($thirdEnabled); + $result = $this->object->getModulesToChange($isEnabled, ['Module_Foo', 'Module_Bar', 'Module_Baz']); + $this->assertEquals($expected, $result); + } + + /** + * @return array + */ + public function getModulesToChangeDataProvider() + { + return [ + [true, true, true, true, []], + [true, true, false, true, ['Module_Baz']], + [true, false, true, true, ['Module_Bar']], + [true, false, false, true, ['Module_Bar', 'Module_Baz']], + [false, false, false, true, ['Module_Foo', 'Module_Bar', 'Module_Baz']], + [true, false, false, false, ['Module_Foo']], + [false, true, false, false, ['Module_Bar']], + [false, true, true, false, ['Module_Bar', 'Module_Baz']], + [true, true, true, false, ['Module_Foo', 'Module_Bar', 'Module_Baz']], + ]; } } diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 861ad5593094f..7ac78f588b10f 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -316,7 +316,7 @@ public function testHelpActionNoType() public function testModuleAction($command, $modules, $isForce, $expectedIsEnabled, $expectedModules) { $status = $this->getModuleActionMocks($command, $modules, $isForce, false); - $status->expects($this->once())->method('getUnchangedModules')->willReturn([]); + $status->expects($this->once())->method('getModulesToChange')->willReturn($expectedModules); if (!$isForce) { $status->expects($this->once())->method('checkConstraints')->willReturn([]); } @@ -352,9 +352,9 @@ public function testModuleActionNoChanges($command, $modules, $isForce, $expecte { $status = $this->getModuleActionMocks($command, $modules, $isForce, true); $status->expects($this->once()) - ->method('getUnchangedModules') + ->method('getModulesToChange') ->with($expectedIsEnabled, $expectedModules) - ->willReturn($expectedModules); + ->willReturn([]); $status->expects($this->never())->method('checkConstraints'); $status->expects($this->never())->method('setIsEnabled'); $this->consoleLogger->expects($this->once())->method('log'); @@ -367,7 +367,7 @@ public function testModuleActionNoChanges($command, $modules, $isForce, $expecte * @param bool $isForce * @param bool $expectedIsEnabled * @param string[] $expectedModules - * @param string[] $unchangedModules + * @param string[] $modulesToChange * @dataProvider moduleActionPartialNoChangesDataProvider */ public function testModuleActionPartialNoChanges( @@ -376,16 +376,16 @@ public function testModuleActionPartialNoChanges( $isForce, $expectedIsEnabled, $expectedModules, - $unchangedModules + $modulesToChange ) { $status = $this->getModuleActionMocks($command, $modules, $isForce, false); - $status->expects($this->once())->method('getUnchangedModules')->willReturn($unchangedModules); + $status->expects($this->once())->method('getModulesToChange')->willReturn($modulesToChange); if (!$isForce) { $status->expects($this->once())->method('checkConstraints')->willReturn([]); } $status->expects($this->once()) ->method('setIsEnabled') - ->with($expectedIsEnabled, array_diff($expectedModules, $unchangedModules)); + ->with($expectedIsEnabled, $modulesToChange); $this->consoleLogger->expects($this->once())->method('log'); $this->controller->moduleAction(); } @@ -402,7 +402,7 @@ public function moduleActionPartialNoChangesDataProvider() false, true, ['Module_Foo', 'Module_Bar'], - ['Module_Foo'], + ['Module_Bar'], ], [ ConsoleController::CMD_MODULE_ENABLE, @@ -410,7 +410,7 @@ public function moduleActionPartialNoChangesDataProvider() true, true, ['Module_Foo', 'Module_Bar'], - ['Module_Foo'], + ['Module_Bar'], ], [ ConsoleController::CMD_MODULE_DISABLE, @@ -418,7 +418,7 @@ public function moduleActionPartialNoChangesDataProvider() false, false, ['Module_Foo', 'Module_Bar'], - ['Module_Foo'], + ['Module_Bar'], ], [ ConsoleController::CMD_MODULE_DISABLE, @@ -426,7 +426,7 @@ public function moduleActionPartialNoChangesDataProvider() true, false, ['Module_Foo', 'Module_Bar'], - ['Module_Foo'], + ['Module_Bar'], ], ]; } @@ -466,7 +466,7 @@ public function testModuleActionNotAllowed() false, false ); - $status->expects($this->once())->method('getUnchangedModules')->willReturn([]); + $status->expects($this->once())->method('getModulesToChange')->willReturn(['Module_Foo', 'Module_Bar']); $status->expects($this->once()) ->method('checkConstraints') ->willReturn(['Circular dependency of Foo and Bar']); diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index 5e4640cf77039..4cd0de7ec21e7 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -148,24 +148,24 @@ public function setIsEnabled($isEnabled, $modules) } /** - * Get a list of modules that will not be changed + * Get a list of modules that will be changed * * @param bool $isEnabled * @param string[] $modules * @return string[] */ - public function getUnchangedModules($isEnabled, $modules) + public function getModulesToChange($isEnabled, $modules) { - $unchanged = []; + $changed = []; foreach ($this->getAllModules($modules) as $name) { $currentStatus = $this->list->has($name); if (in_array($name, $modules)) { - if ($isEnabled == $currentStatus) { - $unchanged[] = $name; + if ($isEnabled != $currentStatus) { + $changed[] = $name; } } } - return $unchanged; + return $changed; } /** diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 18e441d1a6f75..ee0b4e673fbd7 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -487,27 +487,23 @@ public function moduleAction() /** @var \Magento\Framework\Module\Status $status */ $status = $this->getObjectManager()->create('Magento\Framework\Module\Status'); - $unchangedModules = $status->getUnchangedModules($isEnable, $modules); - $modules = array_diff($modules, $unchangedModules); - if (!empty($modules)) { + $modulesToChange = $status->getModulesToChange($isEnable, $modules); + if (!empty($modulesToChange)) { if (!$request->getParam('force')) { - $constraints = $status->checkConstraints($isEnable, $modules); + $constraints = $status->checkConstraints($isEnable, $modulesToChange); if ($constraints) { $message = "Unable to change status of modules because of the following constraints:\n" . implode("\n", $constraints); throw new \Magento\Setup\Exception($message); } } - $status->setIsEnabled($isEnable, $modules); + $status->setIsEnabled($isEnable, $modulesToChange); if ($isEnable) { $message = 'The following modules have been enabled:'; } else { $message = 'The following modules have been disabled:'; } - $message .= ' ' . implode(', ', $modules); - if (!empty($unchangedModules)) { - $message .= "\nThe following modules have no changes: " . implode(', ', $unchangedModules); - } + $message .= ' ' . implode(', ', $modulesToChange); } else { $message = 'There have been no changes to any modules.'; } From a92dba6b692816680fb6c772405277c394b4263d Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Tue, 27 Jan 2015 16:12:46 -0600 Subject: [PATCH 70/89] MAGETWO-33205: Help command in Setup CLI for list of modules - Changes based on code review feedback. --- setup/src/Magento/Setup/Controller/ConsoleController.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index ee0b4e673fbd7..2a6137c220945 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -44,11 +44,10 @@ class ConsoleController extends AbstractActionController const CMD_MODULE_DISABLE = 'module-disable'; /**#@- */ - /**#@+ + /** * Help option for retrieving list of modules */ const HELP_LIST_OF_MODULES = 'module-list'; - /**#@- */ /** * Map of controller actions exposed in CLI @@ -547,7 +546,7 @@ public function helpAction() case UserConfig::KEY_TIMEZONE: return $this->arrayToString($this->options->getTimezoneList()); case self::HELP_LIST_OF_MODULES: - return $this->getModuleList(); + return $this->getModuleListMsg(); default: if (isset($usages[$type])) { if ($usages[$type]) { @@ -633,7 +632,7 @@ private function arrayToString($input) * * @return string */ - private function getModuleList() + private function getModuleListMsg() { $moduleList = $this->getObjectManager()->create('Magento\Framework\Module\ModuleList'); $result = "\nList of enabled modules:\n"; @@ -648,7 +647,7 @@ private function getModuleList() $fullModuleList = $this->getObjectManager()->create('Magento\Framework\Module\FullModuleList'); $result .= "\nList of disabled modules:\n"; $disabledModuleList = array_diff($fullModuleList->getNames(), $enabledModuleList); - foreach ($disabledModuleList as $moduleName) { + foreach ($disabledModuleList as $moduleName) { $result .= "$moduleName\n"; } if (count($disabledModuleList) === 0) { From cd9b1afd67e8b4d939370333935c2f7a9f43a4a6 Mon Sep 17 00:00:00 2001 From: Safwan Khan Date: Tue, 27 Jan 2015 16:33:04 -0600 Subject: [PATCH 71/89] MAGETWO-33205: Help command in Setup CLI for list of modules - One tiny docblock change. --- setup/src/Magento/Setup/Controller/ConsoleController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 2a6137c220945..8c90cd8f36a1b 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -628,7 +628,7 @@ private function arrayToString($input) } /** - * Get lists of modules - enabled and disabled + * Get formatted message containing list of enabled and disabled modules * * @return string */ From d2a38ec707a65ec26f0a42ac631bd6b53c0d1738 Mon Sep 17 00:00:00 2001 From: "Gavryshko, Ivan(igavryshko)" Date: Wed, 28 Jan 2015 09:01:43 -0600 Subject: [PATCH 72/89] MAGETWO-33204: Add Suggestion to Run Update Tool After a Module(s) is Enabled - fixed issues according to CR. --- .../Controller/ConsoleControllerTest.php | 36 +++++++++++++++++++ .../Setup/Controller/ConsoleController.php | 4 ++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 7ac78f588b10f..9260e11f14389 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -340,6 +340,42 @@ public function moduleActionDataProvider() ]; } + /** + * @param string $command + * @param string $modules + * @param bool $isForce + * @param bool $expectedIsEnabled + * @param string[] $expectedModules + * @dataProvider moduleActionEnabledSuggestionMessageDataProvider + */ + public function testModuleActionEnabledSuggestionMessage($command, $modules, $isForce, $expectedIsEnabled, $expectedModules) + { + $status = $this->getModuleActionMocks($command, $modules, $isForce, false); + $status->expects($this->once())->method('getModulesToChange')->willReturn($expectedModules); + if (!$isForce) { + $status->expects($this->once())->method('checkConstraints')->willReturn([]); + } + $status->expects($this->once()) + ->method('setIsEnabled') + ->with($expectedIsEnabled, $expectedModules); + $this->consoleLogger->expects($this->once()) + ->method('log') + ->with($this->stringContains("To make sure that the enabled modules are properly registered, run 'update' command.")); + $this->controller->moduleAction(); + } + + /** + * @return array + */ + public function moduleActionEnabledSuggestionMessageDataProvider() + { + return [ + [ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', false, true, ['Module_Foo', 'Module_Bar']], + [ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', true, true, ['Module_Foo', 'Module_Bar']], + [ConsoleController::CMD_MODULE_ENABLE, 'Module_Foo,Module_Bar', false, true, ['Module_Foo']], + ]; + } + /** * @param string $command * @param string $modules diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index 8c90cd8f36a1b..d9bac34c6e938 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -497,12 +497,14 @@ public function moduleAction() } } $status->setIsEnabled($isEnable, $modulesToChange); + $updateAfterEnableMessage = ''; if ($isEnable) { $message = 'The following modules have been enabled:'; + $updateAfterEnableMessage = "\nTo make sure that the enabled modules are properly registered, run 'update' command."; } else { $message = 'The following modules have been disabled:'; } - $message .= ' ' . implode(', ', $modulesToChange); + $message .= ' ' . implode(', ', $modulesToChange) . $updateAfterEnableMessage; } else { $message = 'There have been no changes to any modules.'; } From 99dc7b4ceafe852e0cd56dcbe81cdebd51e50381 Mon Sep 17 00:00:00 2001 From: "Gavryshko, Ivan(igavryshko)" Date: Wed, 28 Jan 2015 17:02:07 -0600 Subject: [PATCH 73/89] MAGETWO-33204: Add Suggestion to Run Update Tool After a Module(s) is Enabled - fixed issues according to CR. --- .../Magento/Setup/Controller/ConsoleControllerTest.php | 4 +++- setup/src/Magento/Setup/Controller/ConsoleController.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 9260e11f14389..d2ebde4d5921d 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -360,7 +360,9 @@ public function testModuleActionEnabledSuggestionMessage($command, $modules, $is ->with($expectedIsEnabled, $expectedModules); $this->consoleLogger->expects($this->once()) ->method('log') - ->with($this->stringContains("To make sure that the enabled modules are properly registered, run 'update' command.")); + ->with($this->stringContains( + "To make sure that the enabled modules are properly registered, run 'update' command." + )); $this->controller->moduleAction(); } diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php index d9bac34c6e938..429280b217af2 100644 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ b/setup/src/Magento/Setup/Controller/ConsoleController.php @@ -500,7 +500,8 @@ public function moduleAction() $updateAfterEnableMessage = ''; if ($isEnable) { $message = 'The following modules have been enabled:'; - $updateAfterEnableMessage = "\nTo make sure that the enabled modules are properly registered, run 'update' command."; + $updateAfterEnableMessage = "\nTo make sure that the enabled modules are properly registered," + . " run 'update' command."; } else { $message = 'The following modules have been disabled:'; } From f42716bb9994732371b13c73b24322684e08b44f Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 28 Jan 2015 14:32:52 -0600 Subject: [PATCH 74/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - added package version check into ConflictChecker --- .../Framework/Module/ConflictCheckerTest.php | 43 ++++++++++++++++--- .../Framework/Module/PackageInfoTest.php | 18 ++++---- .../Framework/Module/ConflictChecker.php | 14 +++--- .../Magento/Framework/Module/PackageInfo.php | 29 +++++++++++-- 4 files changed, 80 insertions(+), 24 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index fe8c9fdaa8b3f..c3389c3787575 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -28,6 +28,9 @@ public function testCheckConflictsWhenEnableModules( $packageInfoMock->expects($this->any()) ->method('getConflict') ->will($this->returnValueMap($conflictReturnMap)); + $packageInfoMock->expects($this->any()) + ->method('getVersion') + ->will($this->returnValue('0.1')); $packageInfoFactoryMock = $this->getMock('Magento\Framework\Module\PackageInfoFactory', [], [], '', false); $packageInfoFactoryMock->expects($this->once()) ->method('create') @@ -43,25 +46,25 @@ public function checkConflictWhenEnableModuleDataProvider() { return [ [ - [['Vendor_A', true, ['Vendor_B']], ['Vendor_B', true, []]], + [['Vendor_A', true, ['Vendor_B' => '0.1']], ['Vendor_B', true, []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['Vendor_A', true, ['Vendor_B']], ['Vendor_B', true, []]], + [['Vendor_A', true, ['Vendor_B' => '0.1']], ['Vendor_B', true, []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_B', true, ['Vendor_A']], ['Vendor_A', true, []]], + [['Vendor_B', true, ['Vendor_A' => '0.1']], ['Vendor_A', true, []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['Vendor_B', true, ['Vendor_A']], ['Vendor_A', true, []]], + [['Vendor_B', true, ['Vendor_A' => '0.1']], ['Vendor_A', true, []]], [], ['Vendor_B'], ['Vendor_B' => []] @@ -79,17 +82,45 @@ public function checkConflictWhenEnableModuleDataProvider() ['Vendor_B' => [], 'Vendor_C' => []] ], [ - [['Vendor_A', true, ['Vendor_C']], ['Vendor_B', true, []], ['Vendor_C', true, []]], + [['Vendor_A', true, ['Vendor_C' => '0.1']], ['Vendor_B', true, []], ['Vendor_C', true, []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A']] ], [ - [['Vendor_A', true, []], ['Vendor_B', true, ['Vendor_C']], ['Vendor_C', true, []]], + [['Vendor_A', true, []], ['Vendor_B', true, ['Vendor_C' => '0.1']], ['Vendor_C', true, []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']] ], ]; } + + public function testCheckConflictWhenEnableModuleDifferentVersion() + { + $moduleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); + $moduleListMock->expects($this->any()) + ->method('getNames') + ->will($this->returnValue(['Vendor_A', 'Vendor_B'])); + $packageInfoMock->expects($this->any()) + ->method('getConflict') + ->will($this->returnValueMap([ + ['Vendor_A', true, []], + ['Vendor_B', true, []], + ['Vendor_C', true, ['Vendor_A' => '0.2', 'Vendor_B' => '0.3']] + ])); + $packageInfoMock->expects($this->any()) + ->method('getVersion') + ->will($this->returnValueMap([['Vendor_A', '0.2'], ['Vendor_B', '0.4']])); + $packageInfoFactoryMock = $this->getMock('Magento\Framework\Module\PackageInfoFactory', [], [], '', false); + $packageInfoFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($packageInfoMock)); + $conflictChecker = new ConflictChecker($moduleListMock, $packageInfoFactoryMock); + $this->assertEquals( + ['Vendor_C' => ['Vendor_A']], + $conflictChecker->checkConflictsWhenEnableModules(['Vendor_C']) + ); + } } diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php index 37076de9f9290..936f3944019c6 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php @@ -31,11 +31,11 @@ public function setUp() ->will($this->returnValue(['A' => [], 'B' => [], 'C' => [], 'D' => [], 'E' => []])); $composerData = [ - 'A' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}}', - 'B' => '{"name":"b", "require":{"d":"0.1"}}', - 'C' => '{"name":"c", "require":{"e":"0.1"}}', - 'D' => '{"name":"d", "conflict":{"c":"0.1"}}', - 'E' => '{"name":"e"}', + 'A' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}, "version":"0.1"}', + 'B' => '{"name":"b", "require":{"d":"0.1"}, "version":"0.1"}', + 'C' => '{"name":"c", "require":{"e":"0.1"}, "version":"0.1"}', + 'D' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.1"}', + 'E' => '{"name":"e", "version":"0.1"}', ]; $fileIteratorMock = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false); $fileIteratorMock->expects($this->once()) @@ -68,10 +68,10 @@ public function testGetRequireReturnModuleName() public function testGetConflictReturnModuleName() { - $this->assertEquals(['C'], $this->packageInfo->getConflict('A')); + $this->assertEquals(['C' => '0.1'], $this->packageInfo->getConflict('A')); $this->assertEquals([], $this->packageInfo->getConflict('B')); $this->assertEquals([], $this->packageInfo->getConflict('C')); - $this->assertEquals(['C'], $this->packageInfo->getConflict('D')); + $this->assertEquals(['C' => '0.1'], $this->packageInfo->getConflict('D')); $this->assertEquals([], $this->packageInfo->getConflict('E')); } @@ -86,10 +86,10 @@ public function testGetRequireReturnPackageName() public function testGetConflictReturnPackageName() { - $this->assertEquals(['c'], $this->packageInfo->getConflict('A', false)); + $this->assertEquals(['c' => '0.1'], $this->packageInfo->getConflict('A', false)); $this->assertEquals([], $this->packageInfo->getConflict('B', false)); $this->assertEquals([], $this->packageInfo->getConflict('C', false)); - $this->assertEquals(['c'], $this->packageInfo->getConflict('D', false)); + $this->assertEquals(['c' => '0.1'], $this->packageInfo->getConflict('D', false)); $this->assertEquals([], $this->packageInfo->getConflict('E', false)); } } diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index bfc78a091160f..b76ed95a5ecce 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -60,18 +60,20 @@ public function checkConflictsWhenEnableModules($moduleNames) } /** - * Check if module is conflicted + * Check if two modules are conflicted * - * @param string $enabledModule - * @param string $moduleName + * @param string $moduleA + * @param string $moduleB * @return bool */ - private function checkIfConflict($enabledModule, $moduleName) + private function checkIfConflict($moduleA, $moduleB) { - if (array_search($enabledModule, $this->packageInfo->getConflict($moduleName)) !== false) { + if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && + $this->packageInfo->getConflict($moduleB)[$moduleA] === $this->packageInfo->getVersion($moduleA)) { return true; } - if (array_search($moduleName, $this->packageInfo->getConflict($enabledModule)) !== false) { + if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && + $this->packageInfo->getConflict($moduleA)[$moduleB] === $this->packageInfo->getVersion($moduleB)) { return true; } diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index a7c830e522513..7f5bfd2671d23 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -17,6 +17,13 @@ class PackageInfo */ private $packageModuleMap; + /** + * Map of modules to package current version, contains depending module's name + * + * @var string[] + */ + private $modulePackageVersionMap; + /** * "require" field of each module * @@ -25,7 +32,7 @@ class PackageInfo private $requireMap; /** - * "conflict" field of each module + * "conflict" field of each module, contains conflicting module's name and version * * @var array[] */ @@ -76,11 +83,12 @@ private function load() foreach ($rawData as $moduleName => $jsonData) { $jsonData = \Zend_Json::decode($jsonData); $this->packageModuleMap[$jsonData['name']] = $moduleName; + $this->modulePackageVersionMap[$moduleName] = $jsonData['version']; if (!empty($jsonData['require'])) { $this->requireMap[$moduleName] = array_keys($jsonData['require']); } if (!empty($jsonData['conflict'])) { - $this->conflictMap[$moduleName] = array_keys($jsonData['conflict']); + $this->conflictMap[$moduleName] = $jsonData['conflict']; } } } @@ -147,11 +155,26 @@ public function getConflict($moduleName, $returnModuleName = true) $conflict = []; if (isset($this->conflictMap[$moduleName])) { if ($returnModuleName) { - $conflict = $this->convertToModuleNames($this->conflictMap[$moduleName]); + $conflict = array_combine( + $this->convertToModuleNames(array_keys($this->conflictMap[$moduleName])), + $this->conflictMap[$moduleName] + ); } else { $conflict = $this->conflictMap[$moduleName]; } } return $conflict; } + + /** + * Get package version of a module + * + * @param string $moduleName + * @return string + */ + public function getVersion($moduleName) + { + $this->load(); + return $this->modulePackageVersionMap[$moduleName]; + } } From 0a37095a4a4b3d4f4c34386cc88b11ef58f07862 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 28 Jan 2015 15:35:12 -0600 Subject: [PATCH 75/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - added unit test --- .../Magento/Framework/Module/PackageInfoTest.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php index 936f3944019c6..9967a7168ac3b 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php @@ -32,10 +32,10 @@ public function setUp() $composerData = [ 'A' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}, "version":"0.1"}', - 'B' => '{"name":"b", "require":{"d":"0.1"}, "version":"0.1"}', + 'B' => '{"name":"b", "require":{"d":"0.3"}, "version":"0.2"}', 'C' => '{"name":"c", "require":{"e":"0.1"}, "version":"0.1"}', - 'D' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.1"}', - 'E' => '{"name":"e", "version":"0.1"}', + 'D' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.3"}', + 'E' => '{"name":"e", "version":"0.4"}', ]; $fileIteratorMock = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false); $fileIteratorMock->expects($this->once()) @@ -92,4 +92,13 @@ public function testGetConflictReturnPackageName() $this->assertEquals(['c' => '0.1'], $this->packageInfo->getConflict('D', false)); $this->assertEquals([], $this->packageInfo->getConflict('E', false)); } + + public function testGetVersion() + { + $this->assertEquals('0.1', $this->packageInfo->getVersion('A')); + $this->assertEquals('0.2', $this->packageInfo->getVersion('B')); + $this->assertEquals('0.1', $this->packageInfo->getVersion('C')); + $this->assertEquals('0.3', $this->packageInfo->getVersion('D')); + $this->assertEquals('0.4', $this->packageInfo->getVersion('E')); + } } From ac7edad865d46303aa55da795753f5a2465d6b21 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Wed, 28 Jan 2015 16:07:10 -0600 Subject: [PATCH 76/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - corrected doc block --- lib/internal/Magento/Framework/Module/PackageInfo.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index 7f5bfd2671d23..2fb79167644fc 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -6,7 +6,8 @@ namespace Magento\Framework\Module; /** - * Provide information of dependencies and conflicts in composer.json files and mapping of package name to module name + * Provide information of dependencies and conflicts in composer.json files, mapping of package name to module name, + * and mapping of module name to package version */ class PackageInfo { @@ -18,21 +19,21 @@ class PackageInfo private $packageModuleMap; /** - * Map of modules to package current version, contains depending module's name + * Map of module name to package version * * @var string[] */ private $modulePackageVersionMap; /** - * "require" field of each module + * "require" field of each module, contains depending modules' name * * @var array[] */ private $requireMap; /** - * "conflict" field of each module, contains conflicting module's name and version + * "conflict" field of each module, contains conflicting modules' name and version * * @var array[] */ From 2dc82e65f9a388cb2693c196018b20f16d08644c Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 29 Jan 2015 10:18:12 -0600 Subject: [PATCH 77/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - updated according to CR feedback --- .../Framework/Module/ConflictCheckerTest.php | 22 ++++++------ .../Module/DependencyCheckerTest.php | 10 +++--- .../Framework/Module/PackageInfoTest.php | 19 +---------- .../Magento/Framework/Module/PackageInfo.php | 34 +++++++------------ 4 files changed, 30 insertions(+), 55 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index c3389c3787575..64e0ef134d7ba 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -46,49 +46,49 @@ public function checkConflictWhenEnableModuleDataProvider() { return [ [ - [['Vendor_A', true, ['Vendor_B' => '0.1']], ['Vendor_B', true, []]], + [['Vendor_A', ['Vendor_B' => '0.1']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['Vendor_A', true, ['Vendor_B' => '0.1']], ['Vendor_B', true, []]], + [['Vendor_A', ['Vendor_B' => '0.1']], ['Vendor_B', []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_B', true, ['Vendor_A' => '0.1']], ['Vendor_A', true, []]], + [['Vendor_B', ['Vendor_A' => '0.1']], ['Vendor_A', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => ['Vendor_A']] ], [ - [['Vendor_B', true, ['Vendor_A' => '0.1']], ['Vendor_A', true, []]], + [['Vendor_B', ['Vendor_A' => '0.1']], ['Vendor_A', []]], [], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_A', true, []], ['Vendor_B', true, []]], + [['Vendor_A', []], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], ['Vendor_B' => []] ], [ - [['Vendor_A', true, []], ['Vendor_B', true, []], ['Vendor_C', true, []]], + [['Vendor_A', []], ['Vendor_B', []], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => []] ], [ - [['Vendor_A', true, ['Vendor_C' => '0.1']], ['Vendor_B', true, []], ['Vendor_C', true, []]], + [['Vendor_A', ['Vendor_C' => '0.1']], ['Vendor_B', []], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A']] ], [ - [['Vendor_A', true, []], ['Vendor_B', true, ['Vendor_C' => '0.1']], ['Vendor_C', true, []]], + [['Vendor_A', []], ['Vendor_B', ['Vendor_C' => '0.1']], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], ['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']] @@ -106,9 +106,9 @@ public function testCheckConflictWhenEnableModuleDifferentVersion() $packageInfoMock->expects($this->any()) ->method('getConflict') ->will($this->returnValueMap([ - ['Vendor_A', true, []], - ['Vendor_B', true, []], - ['Vendor_C', true, ['Vendor_A' => '0.2', 'Vendor_B' => '0.3']] + ['Vendor_A', []], + ['Vendor_B', []], + ['Vendor_C', ['Vendor_A' => '0.2', 'Vendor_B' => '0.3']] ])); $packageInfoMock->expects($this->any()) ->method('getVersion') diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php index d02b3d8af500a..a91857c5362ea 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/DependencyCheckerTest.php @@ -36,11 +36,11 @@ public function setUp() { $this->packageInfoMock = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false); $requireMap = [ - ['A', true, ['B']], - ['B', true, ['D', 'E']], - ['C', true, ['E']], - ['D', true, ['A']], - ['E', true, []], + ['A', ['B']], + ['B', ['D', 'E']], + ['C', ['E']], + ['D', ['A']], + ['E', []], ]; $this->packageInfoMock ->expects($this->any()) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php index 9967a7168ac3b..bf9b824f8e42d 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php @@ -75,24 +75,6 @@ public function testGetConflictReturnModuleName() $this->assertEquals([], $this->packageInfo->getConflict('E')); } - public function testGetRequireReturnPackageName() - { - $this->assertEquals(['b'], $this->packageInfo->getRequire('A', false)); - $this->assertEquals(['d'], $this->packageInfo->getRequire('B', false)); - $this->assertEquals(['e'], $this->packageInfo->getRequire('C', false)); - $this->assertEquals([], $this->packageInfo->getRequire('D', false)); - $this->assertEquals([], $this->packageInfo->getRequire('E', false)); - } - - public function testGetConflictReturnPackageName() - { - $this->assertEquals(['c' => '0.1'], $this->packageInfo->getConflict('A', false)); - $this->assertEquals([], $this->packageInfo->getConflict('B', false)); - $this->assertEquals([], $this->packageInfo->getConflict('C', false)); - $this->assertEquals(['c' => '0.1'], $this->packageInfo->getConflict('D', false)); - $this->assertEquals([], $this->packageInfo->getConflict('E', false)); - } - public function testGetVersion() { $this->assertEquals('0.1', $this->packageInfo->getVersion('A')); @@ -100,5 +82,6 @@ public function testGetVersion() $this->assertEquals('0.1', $this->packageInfo->getVersion('C')); $this->assertEquals('0.3', $this->packageInfo->getVersion('D')); $this->assertEquals('0.4', $this->packageInfo->getVersion('E')); + $this->assertEquals('', $this->packageInfo->getVersion('F')); } } diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index 2fb79167644fc..544e2d88483f6 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -84,7 +84,9 @@ private function load() foreach ($rawData as $moduleName => $jsonData) { $jsonData = \Zend_Json::decode($jsonData); $this->packageModuleMap[$jsonData['name']] = $moduleName; - $this->modulePackageVersionMap[$moduleName] = $jsonData['version']; + if (isset($jsonData['version'])) { + $this->modulePackageVersionMap[$moduleName] = $jsonData['version']; + } if (!empty($jsonData['require'])) { $this->requireMap[$moduleName] = array_keys($jsonData['require']); } @@ -123,46 +125,36 @@ private function convertToModuleNames($packageNames) } /** - * Get all package names a module requires + * Get all module names a module requires * * @param string $moduleName - * @param bool $returnModuleName * @return array */ - public function getRequire($moduleName, $returnModuleName = true) + public function getRequire($moduleName) { $this->load(); $require = []; if (isset($this->requireMap[$moduleName])) { - if ($returnModuleName) { - $require = $this->convertToModuleNames($this->requireMap[$moduleName]); - } else { - $require = $this->requireMap[$moduleName]; - } + $require = $this->convertToModuleNames($this->requireMap[$moduleName]); } return $require; } /** - * Get all package names a module conflicts + * Get all module names a module conflicts * * @param string $moduleName - * @param bool $returnModuleName * @return array */ - public function getConflict($moduleName, $returnModuleName = true) + public function getConflict($moduleName) { $this->load(); $conflict = []; if (isset($this->conflictMap[$moduleName])) { - if ($returnModuleName) { - $conflict = array_combine( - $this->convertToModuleNames(array_keys($this->conflictMap[$moduleName])), - $this->conflictMap[$moduleName] - ); - } else { - $conflict = $this->conflictMap[$moduleName]; - } + $conflict = array_combine( + $this->convertToModuleNames(array_keys($this->conflictMap[$moduleName])), + $this->conflictMap[$moduleName] + ); } return $conflict; } @@ -176,6 +168,6 @@ public function getConflict($moduleName, $returnModuleName = true) public function getVersion($moduleName) { $this->load(); - return $this->modulePackageVersionMap[$moduleName]; + return isset($this->modulePackageVersionMap[$moduleName]) ? $this->modulePackageVersionMap[$moduleName] : ''; } } From 5c41f70b939398f0bb5ad36c528e884b92dce89d Mon Sep 17 00:00:00 2001 From: "Gavryshko, Ivan(igavryshko)" Date: Thu, 29 Jan 2015 15:32:01 -0600 Subject: [PATCH 78/89] MAGETWO-32948: Contribution to Mainline of Sprint 22 Work fixed code style defect. --- .../Magento/Setup/Controller/ConsoleControllerTest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 8cfa6da689cdf..4d76ea3f90c75 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -385,8 +385,13 @@ public function moduleActionDataProvider() * @param string[] $expectedModules * @dataProvider moduleActionEnabledSuggestionMessageDataProvider */ - public function testModuleActionEnabledSuggestionMessage($command, $modules, $isForce, $expectedIsEnabled, $expectedModules) - { + public function testModuleActionEnabledSuggestionMessage( + $command, + $modules, + $isForce, + $expectedIsEnabled, + $expectedModules + ) { $status = $this->getModuleActionMocks($command, $modules, $isForce, false); $status->expects($this->once())->method('getModulesToChange')->willReturn($expectedModules); if (!$isForce) { From 89ca3246810c9a93c1138f12ab2f6788fc1801e3 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 29 Jan 2015 15:55:11 -0600 Subject: [PATCH 79/89] MAGETWO-32948: Contribution to Mainline of Sprint 22 Work - removed unused variable --- .../Magento/Setup/Controller/ConsoleControllerTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php index 4d76ea3f90c75..0656c24b58c06 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/ConsoleControllerTest.php @@ -446,7 +446,6 @@ public function testModuleActionNoChanges($command, $modules, $isForce, $expecte * @param string $modules * @param bool $isForce * @param bool $expectedIsEnabled - * @param string[] $expectedModules * @param string[] $modulesToChange * @dataProvider moduleActionPartialNoChangesDataProvider */ @@ -455,7 +454,6 @@ public function testModuleActionPartialNoChanges( $modules, $isForce, $expectedIsEnabled, - $expectedModules, $modulesToChange ) { $status = $this->getModuleActionMocks($command, $modules, $isForce, false); @@ -481,7 +479,6 @@ public function moduleActionPartialNoChangesDataProvider() 'Module_Foo,Module_Bar', false, true, - ['Module_Foo', 'Module_Bar'], ['Module_Bar'], ], [ @@ -489,7 +486,6 @@ public function moduleActionPartialNoChangesDataProvider() 'Module_Foo,Module_Bar', true, true, - ['Module_Foo', 'Module_Bar'], ['Module_Bar'], ], [ @@ -497,7 +493,6 @@ public function moduleActionPartialNoChangesDataProvider() 'Module_Foo,Module_Bar', false, false, - ['Module_Foo', 'Module_Bar'], ['Module_Bar'], ], [ @@ -505,7 +500,6 @@ public function moduleActionPartialNoChangesDataProvider() 'Module_Foo,Module_Bar', true, false, - ['Module_Foo', 'Module_Bar'], ['Module_Bar'], ], ]; From 37291ab499f9cfd2c07124d3e198b73b3127924f Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Thu, 29 Jan 2015 16:03:58 -0600 Subject: [PATCH 80/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - fixed version constraint check --- .../Framework/Module/ConflictCheckerTest.php | 14 ++++++++++- .../Framework/Module/ConflictChecker.php | 23 +++++++++++++------ .../Magento/Framework/Module/PackageInfo.php | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index 64e0ef134d7ba..f31388808f893 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -93,6 +93,18 @@ public function checkConflictWhenEnableModuleDataProvider() ['Vendor_B', 'Vendor_C'], ['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']] ], + [ + [['Vendor_A', ['Vendor_B' => '>=0.1']], ['Vendor_B', []]], + ['Vendor_A'], + ['Vendor_B'], + ['Vendor_B' => ['Vendor_A']] + ], + [ + [['Vendor_A', ['Vendor_B' => '~0.1']], ['Vendor_B', []]], + ['Vendor_A'], + ['Vendor_B'], + ['Vendor_B' => ['Vendor_A']] + ], ]; } @@ -108,7 +120,7 @@ public function testCheckConflictWhenEnableModuleDifferentVersion() ->will($this->returnValueMap([ ['Vendor_A', []], ['Vendor_B', []], - ['Vendor_C', ['Vendor_A' => '0.2', 'Vendor_B' => '0.3']] + ['Vendor_C', ['Vendor_A' => '>=0.2,<0.3', 'Vendor_B' => '<0.4']] ])); $packageInfoMock->expects($this->any()) ->method('getVersion') diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index b76ed95a5ecce..7e4b5979ccb28 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Module; +use Composer\Package\LinkConstraint\VersionConstraint; +use Composer\Package\Version\VersionParser; + /** * Checks for conflicts between modules */ @@ -68,15 +71,21 @@ public function checkConflictsWhenEnableModules($moduleNames) */ private function checkIfConflict($moduleA, $moduleB) { - if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && - $this->packageInfo->getConflict($moduleB)[$moduleA] === $this->packageInfo->getVersion($moduleA)) { - return true; + $versionParser = new VersionParser(); + if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && $this->packageInfo->getVersion($moduleA)) { + $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleB)[$moduleA]); + $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleA)); + if ($constraintA->matches($constraintB)) { + return true; + } } - if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && - $this->packageInfo->getConflict($moduleA)[$moduleB] === $this->packageInfo->getVersion($moduleB)) { - return true; + if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && $this->packageInfo->getVersion($moduleB)) { + $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleA)[$moduleB]); + $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleB)); + if ($constraintA->matches($constraintB)) { + return true; + } } - return false; } } diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index 544e2d88483f6..b7f69730fbd97 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -33,7 +33,7 @@ class PackageInfo private $requireMap; /** - * "conflict" field of each module, contains conflicting modules' name and version + * "conflict" field of each module, contains conflicting modules' name and version constraint * * @var array[] */ From 803d6e33cc7d42eebf7dd669669f0c8fb9ca4893 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 30 Jan 2015 09:45:45 -0600 Subject: [PATCH 81/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - fixed PackageInfo loading fails when composer.json doesn't exist --- .../Framework/Module/PackageInfoTest.php | 12 ++++---- .../Framework/Module/ConflictChecker.php | 1 - .../Magento/Framework/Module/PackageInfo.php | 30 +++++++++++++++---- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php index bf9b824f8e42d..b44f8107102ad 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/PackageInfoTest.php @@ -31,11 +31,11 @@ public function setUp() ->will($this->returnValue(['A' => [], 'B' => [], 'C' => [], 'D' => [], 'E' => []])); $composerData = [ - 'A' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}, "version":"0.1"}', - 'B' => '{"name":"b", "require":{"d":"0.3"}, "version":"0.2"}', - 'C' => '{"name":"c", "require":{"e":"0.1"}, "version":"0.1"}', - 'D' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.3"}', - 'E' => '{"name":"e", "version":"0.4"}', + 'A/composer.json' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}, "version":"0.1"}', + 'B/composer.json' => '{"name":"b", "require":{"d":"0.3"}, "version":"0.2"}', + 'C/composer.json' => '{"name":"c", "require":{"e":"0.1"}, "version":"0.1"}', + 'D/composer.json' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.3"}', + 'E/composer.json' => '{"name":"e", "version":"0.4"}', ]; $fileIteratorMock = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false); $fileIteratorMock->expects($this->once()) @@ -45,7 +45,7 @@ public function setUp() ->method('getComposerJsonFiles') ->will($this->returnValue($fileIteratorMock)); - $this->packageInfo = new PackageInfo($this->loader, $this->reader); + $this->packageInfo = new PackageInfo($this->loader, $this->reader, new \Magento\Framework\Stdlib\String()); } public function testGetModuleName() diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index 7e4b5979ccb28..0390f430590df 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -5,7 +5,6 @@ */ namespace Magento\Framework\Module; -use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Package\Version\VersionParser; /** diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index b7f69730fbd97..5bb9d78559dd0 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\Module; +use Magento\Framework\Stdlib\String; + /** * Provide information of dependencies and conflicts in composer.json files, mapping of package name to module name, * and mapping of module name to package version @@ -53,16 +55,24 @@ class PackageInfo */ private $reader; + /** + * String utilities + * + * @var String + */ + private $string; + /** * Constructor * * @param ModuleList\Loader $loader * @param Dir\Reader $reader */ - public function __construct(ModuleList\Loader $loader, Dir\Reader $reader) + public function __construct(ModuleList\Loader $loader, Dir\Reader $reader, String $string) { $this->loader = $loader; $this->reader = $reader; + $this->string = $string; } /** @@ -77,13 +87,21 @@ private function load() * array keys: module name in module.xml; array values: raw content from composer.json * this raw data is used to create a dependency graph and also a package name-module name mapping */ - $rawData = array_combine( - array_keys($this->loader->load()), - $this->reader->getComposerJsonFiles()->toArray() - ); + $rawData = []; + $jsonData = $this->reader->getComposerJsonFiles()->toArray(); + foreach (array_keys($this->loader->load()) as $moduleName) { + $key = $this->string->upperCaseWords($moduleName, '_', '/') . '/composer.json'; + if (isset($jsonData[$key])) { + $rawData[$moduleName] = $jsonData[$key]; + } else { + $rawData[$moduleName] = '{}'; + } + } foreach ($rawData as $moduleName => $jsonData) { $jsonData = \Zend_Json::decode($jsonData); - $this->packageModuleMap[$jsonData['name']] = $moduleName; + if (isset($jsonData['name'])) { + $this->packageModuleMap[$jsonData['name']] = $moduleName; + } if (isset($jsonData['version'])) { $this->modulePackageVersionMap[$moduleName] = $jsonData['version']; } From 234470f56a070b021ad5e9c21dfc6c603f44732a Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 30 Jan 2015 10:58:24 -0600 Subject: [PATCH 82/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - consolidated logic in PackageInfo load --- .../Magento/Framework/Module/PackageInfo.php | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index 5bb9d78559dd0..e797c2f764de3 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -83,33 +83,23 @@ public function __construct(ModuleList\Loader $loader, Dir\Reader $reader, Strin private function load() { if ($this->packageModuleMap === null) { - /** - * array keys: module name in module.xml; array values: raw content from composer.json - * this raw data is used to create a dependency graph and also a package name-module name mapping - */ - $rawData = []; $jsonData = $this->reader->getComposerJsonFiles()->toArray(); foreach (array_keys($this->loader->load()) as $moduleName) { $key = $this->string->upperCaseWords($moduleName, '_', '/') . '/composer.json'; if (isset($jsonData[$key])) { - $rawData[$moduleName] = $jsonData[$key]; - } else { - $rawData[$moduleName] = '{}'; - } - } - foreach ($rawData as $moduleName => $jsonData) { - $jsonData = \Zend_Json::decode($jsonData); - if (isset($jsonData['name'])) { - $this->packageModuleMap[$jsonData['name']] = $moduleName; - } - if (isset($jsonData['version'])) { - $this->modulePackageVersionMap[$moduleName] = $jsonData['version']; - } - if (!empty($jsonData['require'])) { - $this->requireMap[$moduleName] = array_keys($jsonData['require']); - } - if (!empty($jsonData['conflict'])) { - $this->conflictMap[$moduleName] = $jsonData['conflict']; + $packageData = \Zend_Json::decode($jsonData[$key]); + if (isset($packageData['name'])) { + $this->packageModuleMap[$packageData['name']] = $moduleName; + } + if (isset($packageData['version'])) { + $this->modulePackageVersionMap[$moduleName] = $packageData['version']; + } + if (!empty($packageData['require'])) { + $this->requireMap[$moduleName] = array_keys($packageData['require']); + } + if (!empty($packageData['conflict'])) { + $this->conflictMap[$moduleName] = $packageData['conflict']; + } } } } From 23538b583e359339326c70fcdb3e0d580071b858 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Fri, 30 Jan 2015 11:27:17 -0600 Subject: [PATCH 83/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - corrected doc block --- lib/internal/Magento/Framework/Module/PackageInfo.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index e797c2f764de3..ad74b5d0cb19b 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -67,6 +67,7 @@ class PackageInfo * * @param ModuleList\Loader $loader * @param Dir\Reader $reader + * @param \Magento\Framework\Stdlib\String $string */ public function __construct(ModuleList\Loader $loader, Dir\Reader $reader, String $string) { From 3ccbd2feadcfba7c33f1e944ceb8d1f36c823177 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Mon, 2 Feb 2015 11:55:25 -0600 Subject: [PATCH 84/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - added checkign for empty version --- .../Magento/Framework/Module/ConflictChecker.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index 0390f430590df..2d7facfa7fa3b 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -71,14 +71,20 @@ public function checkConflictsWhenEnableModules($moduleNames) private function checkIfConflict($moduleA, $moduleB) { $versionParser = new VersionParser(); - if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && $this->packageInfo->getVersion($moduleA)) { + if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && + $this->packageInfo->getConflict($moduleB)[$moduleA] && + $this->packageInfo->getVersion($moduleA) + ) { $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleB)[$moduleA]); $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleA)); if ($constraintA->matches($constraintB)) { return true; } } - if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && $this->packageInfo->getVersion($moduleB)) { + if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && + $this->packageInfo->getConflict($moduleA)[$moduleB] && + $this->packageInfo->getVersion($moduleB) + ) { $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleA)[$moduleB]); $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleB)); if ($constraintA->matches($constraintB)) { From 514992ea8b51504b34bc72ba3a95f5e7d27f38b4 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Mon, 2 Feb 2015 15:13:48 -0600 Subject: [PATCH 85/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - added more verbose message when checking conflicts --- .../Framework/Module/ConflictCheckerTest.php | 14 ++++++------ .../Magento/Framework/Module/StatusTest.php | 4 ++-- .../Framework/Module/ConflictChecker.php | 22 ++++++++++++------- .../Magento/Framework/Module/Status.php | 4 ++-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index f31388808f893..f2ed4dba0426b 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -49,7 +49,7 @@ public function checkConflictWhenEnableModuleDataProvider() [['Vendor_A', ['Vendor_B' => '0.1']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_A']] + ['Vendor_B' => ['Vendor_A conflicts with Vendor_B version 0.1 (current 0.1)']] ], [ [['Vendor_A', ['Vendor_B' => '0.1']], ['Vendor_B', []]], @@ -61,7 +61,7 @@ public function checkConflictWhenEnableModuleDataProvider() [['Vendor_B', ['Vendor_A' => '0.1']], ['Vendor_A', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_A']] + ['Vendor_B' => ['Vendor_B conflicts with Vendor_A version 0.1 (current 0.1)']] ], [ [['Vendor_B', ['Vendor_A' => '0.1']], ['Vendor_A', []]], @@ -85,25 +85,25 @@ public function checkConflictWhenEnableModuleDataProvider() [['Vendor_A', ['Vendor_C' => '0.1']], ['Vendor_B', []], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], - ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A']] + ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A conflicts with Vendor_C version 0.1 (current 0.1)']] ], [ [['Vendor_A', []], ['Vendor_B', ['Vendor_C' => '0.1']], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], - ['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']] + ['Vendor_B' => ['Vendor_B conflicts with Vendor_C version 0.1 (current 0.1)'], 'Vendor_C' => ['Vendor_B conflicts with Vendor_C version 0.1 (current 0.1)']] ], [ [['Vendor_A', ['Vendor_B' => '>=0.1']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_A']] + ['Vendor_B' => ['Vendor_A conflicts with Vendor_B version >=0.1 (current 0.1)']] ], [ [['Vendor_A', ['Vendor_B' => '~0.1']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_A']] + ['Vendor_B' => ['Vendor_A conflicts with Vendor_B version ~0.1 (current 0.1)']] ], ]; } @@ -131,7 +131,7 @@ public function testCheckConflictWhenEnableModuleDifferentVersion() ->will($this->returnValue($packageInfoMock)); $conflictChecker = new ConflictChecker($moduleListMock, $packageInfoFactoryMock); $this->assertEquals( - ['Vendor_C' => ['Vendor_A']], + ['Vendor_C' => ['Vendor_C conflicts with Vendor_A version >=0.2,<0.3 (current 0.2)']], $conflictChecker->checkConflictsWhenEnableModules(['Vendor_C']) ); } diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php index 76aa8d02d9fcc..6c02d6161f1c5 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/StatusTest.php @@ -92,9 +92,9 @@ public function testCheckConstraintsEnableNotAllowed() "Module_Baz: Module_Foo->Module_Baz", 'Cannot enable Module_Bar, depending on disabled modules:', "Module_Baz: Module_Bar->Module_Baz", - 'Cannot enable Module_Foo, conflicting modules:', + 'Cannot enable Module_Foo, conflicting with other modules:', "Module_Bar", - 'Cannot enable Module_Bar, conflicting modules:', + 'Cannot enable Module_Bar, conflicting with other modules:', "Module_Foo", ]; $this->assertEquals($expect, $result); diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index 2d7facfa7fa3b..09eff7b771de6 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -52,8 +52,9 @@ public function checkConflictsWhenEnableModules($moduleNames) foreach ($moduleNames as $moduleName) { $conflicts = []; foreach ($enabledModules as $enabledModule) { - if ($this->checkIfConflict($enabledModule, $moduleName)) { - $conflicts[] = $enabledModule; + $messages = $this->getConflictMessages($enabledModule, $moduleName); + if (!empty($messages)) { + $conflicts[] = implode("\n", $messages); } } $conflictsAll[$moduleName] = $conflicts; @@ -62,14 +63,15 @@ public function checkConflictsWhenEnableModules($moduleNames) } /** - * Check if two modules are conflicted + * Check if two modules are conflicted and get the message for display * * @param string $moduleA * @param string $moduleB - * @return bool + * @return string[] */ - private function checkIfConflict($moduleA, $moduleB) + private function getConflictMessages($moduleA, $moduleB) { + $messages = []; $versionParser = new VersionParser(); if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && $this->packageInfo->getConflict($moduleB)[$moduleA] && @@ -78,7 +80,9 @@ private function checkIfConflict($moduleA, $moduleB) $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleB)[$moduleA]); $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleA)); if ($constraintA->matches($constraintB)) { - return true; + $messages[] = "$moduleB conflicts with $moduleA version " . + $this->packageInfo->getConflict($moduleB)[$moduleA] . + ' (current ' . $this->packageInfo->getVersion($moduleA) . ')'; } } if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && @@ -88,9 +92,11 @@ private function checkIfConflict($moduleA, $moduleB) $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleA)[$moduleB]); $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleB)); if ($constraintA->matches($constraintB)) { - return true; + $messages[] = "$moduleA conflicts with $moduleB version " . + $this->packageInfo->getConflict($moduleA)[$moduleB] . + ' (current ' . $this->packageInfo->getVersion($moduleA) . ')';; } } - return false; + return $messages; } } diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index 4cd0de7ec21e7..64fb61aa797e4 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -113,8 +113,8 @@ public function checkConstraints($isEnabled, $modules) foreach ($errorModulesConflict as $moduleName => $conflictingModules) { if (!empty($conflictingModules)) { - $errorMessages[] = "Cannot enable $moduleName, conflicting modules:"; - $errorMessages[] = implode(', ', $conflictingModules); + $errorMessages[] = "Cannot enable $moduleName, conflicting with other modules:"; + $errorMessages[] = implode("\n", $conflictingModules); } } From 3a7c067432b027cdf539893f683c8afbbda24567 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Mon, 2 Feb 2015 15:20:24 -0600 Subject: [PATCH 86/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - corrected code style --- .../Magento/Framework/Module/ConflictCheckerTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index f2ed4dba0426b..39ecfa206929e 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -91,7 +91,10 @@ public function checkConflictWhenEnableModuleDataProvider() [['Vendor_A', []], ['Vendor_B', ['Vendor_C' => '0.1']], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], - ['Vendor_B' => ['Vendor_B conflicts with Vendor_C version 0.1 (current 0.1)'], 'Vendor_C' => ['Vendor_B conflicts with Vendor_C version 0.1 (current 0.1)']] + [ + 'Vendor_B' => ['Vendor_B conflicts with Vendor_C version 0.1 (current 0.1)'], + 'Vendor_C' => ['Vendor_B conflicts with Vendor_C version 0.1 (current 0.1)'] + ] ], [ [['Vendor_A', ['Vendor_B' => '>=0.1']], ['Vendor_B', []]], @@ -103,7 +106,7 @@ public function checkConflictWhenEnableModuleDataProvider() [['Vendor_A', ['Vendor_B' => '~0.1']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_A conflicts with Vendor_B version ~0.1 (current 0.1)']] + ['Vendor_B' => ['Vendor_A conflicts with Vendor_B version ~0.1 (current 0.1)']] ], ]; } From eb34df1b8e507c6d8dcae2bcc8a548b4598d7b84 Mon Sep 17 00:00:00 2001 From: Eddie Lau Date: Tue, 3 Feb 2015 13:55:11 -0600 Subject: [PATCH 87/89] MAGETWO-33157: Conflict restriction checking is missing version checking in enable/disable module CLI - rephrased error message --- .../Framework/Module/ConflictCheckerTest.php | 19 +++++++++++-------- .../Framework/Module/ConflictChecker.php | 12 ++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php index 39ecfa206929e..3f32a4c300b1c 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php @@ -49,7 +49,7 @@ public function checkConflictWhenEnableModuleDataProvider() [['Vendor_A', ['Vendor_B' => '0.1']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_A conflicts with Vendor_B version 0.1 (current 0.1)']] + ['Vendor_B' => ['Vendor_A conflicts with current Vendor_B version 0.1 (version should not be 0.1)']] ], [ [['Vendor_A', ['Vendor_B' => '0.1']], ['Vendor_B', []]], @@ -61,7 +61,7 @@ public function checkConflictWhenEnableModuleDataProvider() [['Vendor_B', ['Vendor_A' => '0.1']], ['Vendor_A', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_B conflicts with Vendor_A version 0.1 (current 0.1)']] + ['Vendor_B' => ['Vendor_B conflicts with current Vendor_A version 0.1 (version should not be 0.1)']] ], [ [['Vendor_B', ['Vendor_A' => '0.1']], ['Vendor_A', []]], @@ -85,28 +85,31 @@ public function checkConflictWhenEnableModuleDataProvider() [['Vendor_A', ['Vendor_C' => '0.1']], ['Vendor_B', []], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], - ['Vendor_B' => [], 'Vendor_C' => ['Vendor_A conflicts with Vendor_C version 0.1 (current 0.1)']] + [ + 'Vendor_B' => [], + 'Vendor_C' => ['Vendor_A conflicts with current Vendor_C version 0.1 (version should not be 0.1)'] + ] ], [ [['Vendor_A', []], ['Vendor_B', ['Vendor_C' => '0.1']], ['Vendor_C', []]], ['Vendor_A'], ['Vendor_B', 'Vendor_C'], [ - 'Vendor_B' => ['Vendor_B conflicts with Vendor_C version 0.1 (current 0.1)'], - 'Vendor_C' => ['Vendor_B conflicts with Vendor_C version 0.1 (current 0.1)'] + 'Vendor_B' => ['Vendor_B conflicts with current Vendor_C version 0.1 (version should not be 0.1)'], + 'Vendor_C' => ['Vendor_B conflicts with current Vendor_C version 0.1 (version should not be 0.1)'] ] ], [ [['Vendor_A', ['Vendor_B' => '>=0.1']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_A conflicts with Vendor_B version >=0.1 (current 0.1)']] + ['Vendor_B' => ['Vendor_A conflicts with current Vendor_B version 0.1 (version should not be >=0.1)']] ], [ [['Vendor_A', ['Vendor_B' => '~0.1']], ['Vendor_B', []]], ['Vendor_A'], ['Vendor_B'], - ['Vendor_B' => ['Vendor_A conflicts with Vendor_B version ~0.1 (current 0.1)']] + ['Vendor_B' => ['Vendor_A conflicts with current Vendor_B version 0.1 (version should not be ~0.1)']] ], ]; } @@ -134,7 +137,7 @@ public function testCheckConflictWhenEnableModuleDifferentVersion() ->will($this->returnValue($packageInfoMock)); $conflictChecker = new ConflictChecker($moduleListMock, $packageInfoFactoryMock); $this->assertEquals( - ['Vendor_C' => ['Vendor_C conflicts with Vendor_A version >=0.2,<0.3 (current 0.2)']], + ['Vendor_C' => ['Vendor_C conflicts with current Vendor_A version 0.2 (version should not be >=0.2,<0.3)']], $conflictChecker->checkConflictsWhenEnableModules(['Vendor_C']) ); } diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index 09eff7b771de6..27c83e1330487 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -80,9 +80,9 @@ private function getConflictMessages($moduleA, $moduleB) $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleB)[$moduleA]); $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleA)); if ($constraintA->matches($constraintB)) { - $messages[] = "$moduleB conflicts with $moduleA version " . - $this->packageInfo->getConflict($moduleB)[$moduleA] . - ' (current ' . $this->packageInfo->getVersion($moduleA) . ')'; + $messages[] = "$moduleB conflicts with current $moduleA version " . + $this->packageInfo->getVersion($moduleA) . + ' (version should not be ' . $this->packageInfo->getConflict($moduleB)[$moduleA] . ')'; } } if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && @@ -92,9 +92,9 @@ private function getConflictMessages($moduleA, $moduleB) $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleA)[$moduleB]); $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleB)); if ($constraintA->matches($constraintB)) { - $messages[] = "$moduleA conflicts with $moduleB version " . - $this->packageInfo->getConflict($moduleA)[$moduleB] . - ' (current ' . $this->packageInfo->getVersion($moduleA) . ')';; + $messages[] = "$moduleA conflicts with current $moduleB version " . + $this->packageInfo->getVersion($moduleA) . + ' (version should not be ' . $this->packageInfo->getConflict($moduleA)[$moduleB] . ')';; } } return $messages; From c515de9833f1f23c1872663493d49907efa00bcd Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Tue, 3 Feb 2015 14:10:52 -0600 Subject: [PATCH 88/89] MAGETWO-32948: Contribution to Mainline of Sprint 22 Work - fixed code style --- lib/internal/Magento/Framework/Module/ConflictChecker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Module/ConflictChecker.php b/lib/internal/Magento/Framework/Module/ConflictChecker.php index 27c83e1330487..a7e1e89ac383c 100644 --- a/lib/internal/Magento/Framework/Module/ConflictChecker.php +++ b/lib/internal/Magento/Framework/Module/ConflictChecker.php @@ -94,7 +94,7 @@ private function getConflictMessages($moduleA, $moduleB) if ($constraintA->matches($constraintB)) { $messages[] = "$moduleA conflicts with current $moduleB version " . $this->packageInfo->getVersion($moduleA) . - ' (version should not be ' . $this->packageInfo->getConflict($moduleA)[$moduleB] . ')';; + ' (version should not be ' . $this->packageInfo->getConflict($moduleA)[$moduleB] . ')'; } } return $messages; From a172ece089b7c39c95c7ed9b0936e293c7c6f5e8 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Thu, 5 Feb 2015 01:08:44 -0600 Subject: [PATCH 89/89] MAGETWO-32948: Contribution to Mainline of Sprint 22 Work - fixed unit test - fixed copyright --- .../testsuite/Magento/Setup/Controller/AddDatabaseTest.php | 3 ++- .../Magento/Setup/Controller/ConsoleControllerTest.php | 3 ++- .../Magento/Setup/Controller/CreateAdminAccountTest.php | 3 ++- .../Magento/Setup/Controller/CustomizeYourStoreTest.php | 3 ++- .../testsuite/Magento/Setup/Controller/DatabaseCheckTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Controller/IndexTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Controller/InstallTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Controller/LicenseTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Controller/NavigationTest.php | 3 ++- .../testsuite/Magento/Setup/Controller/ReadinessCheckTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Controller/SuccessTest.php | 3 ++- .../Magento/Setup/Controller/WebConfigurationTest.php | 3 ++- .../testsuite/Magento/Setup/Model/AdminAccountFactoryTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Model/AdminAccountTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Model/FilePermissionsTest.php | 3 ++- .../Magento/Setup/Model/Installer/ProgressFactoryTest.php | 3 ++- .../testsuite/Magento/Setup/Model/Installer/ProgressTest.php | 3 ++- .../testsuite/Magento/Setup/Model/InstallerFactoryTest.php | 3 ++- dev/tests/unit/testsuite/Magento/Setup/Model/InstallerTest.php | 3 ++- dev/tests/unit/testsuite/Magento/Setup/Model/LicenseTest.php | 3 ++- dev/tests/unit/testsuite/Magento/Setup/Model/ListsTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Model/NavigationTest.php | 3 ++- .../unit/testsuite/Magento/Setup/Model/PhpInformationTest.php | 3 ++- .../Magento/Setup/Model/UserConfigurationDataMapperTest.php | 3 ++- dev/tests/unit/testsuite/Magento/Setup/Model/WebLoggerTest.php | 3 ++- .../Magento/Setup/Mvc/Bootstrap/InitParamListenerTest.php | 3 ++- setup/src/Magento/Setup/Model/WebLogger.php | 2 +- 27 files changed, 53 insertions(+), 27 deletions(-) diff --git a/dev/tests/unit/testsuite/Magento/Setup/Controller/AddDatabaseTest.php b/dev/tests/unit/testsuite/Magento/Setup/Controller/AddDatabaseTest.php index 78db6435df5ac..cd8edf9c50f4b 100644 --- a/dev/tests/unit/testsuite/Magento/Setup/Controller/AddDatabaseTest.php +++ b/dev/tests/unit/testsuite/Magento/Setup/Controller/AddDatabaseTest.php @@ -1,6 +1,7 @@ directory->readFile($this->logFile)); + $fileContents = explode(PHP_EOL, $this->directory->readFile($this->logFile)); return $fileContents; }