diff --git a/app/code/Magento/CacheInvalidate/Model/Observer.php b/app/code/Magento/CacheInvalidate/Model/Observer.php new file mode 100644 index 0000000000000000000000000000000000000000..6deb4f50aac511b57fc7bf5cf920a6f172bad351 --- /dev/null +++ b/app/code/Magento/CacheInvalidate/Model/Observer.php @@ -0,0 +1,99 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CacheInvalidate\Model; + +/** + * Class Observer + */ +class Observer +{ + /** + * Application config object + * + * @var \Magento\Framework\App\Config\ScopeConfigInterface + */ + protected $_config; + + /** + * @var \Magento\PageCache\Helper\Data + */ + protected $_helper; + + /** + * @var \Magento\Framework\HTTP\Adapter\Curl + */ + protected $_curlAdapter; + + /** + * Constructor + * + * @param \Magento\PageCache\Model\Config $config + * @param \Magento\PageCache\Helper\Data $helper + * @param \Magento\Framework\HTTP\Adapter\Curl $curlAdapter + */ + public function __construct( + \Magento\PageCache\Model\Config $config, + \Magento\PageCache\Helper\Data $helper, + \Magento\Framework\HTTP\Adapter\Curl $curlAdapter + ) { + $this->_config = $config; + $this->_helper = $helper; + $this->_curlAdapter = $curlAdapter; + } + + /** + * If Varnish caching is enabled it collects array of tags + * of incoming object and asks to clean cache. + * + * @param \Magento\Framework\Event\Observer $observer + * @return void + */ + public function invalidateVarnish(\Magento\Framework\Event\Observer $observer) + { + if ($this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->_config->isEnabled()) { + $object = $observer->getEvent()->getObject(); + if ($object instanceof \Magento\Framework\Object\IdentityInterface) { + $tags = []; + $pattern = "((^|,)%s(,|$))"; + foreach ($object->getIdentities() as $tag) { + $tags[] = sprintf($pattern, preg_replace("~_\\d+$~", '', $tag)); + $tags[] = sprintf($pattern, $tag); + } + $this->sendPurgeRequest(implode('|', array_unique($tags))); + } + } + } + + /** + * Flash Varnish cache + * + * @param \Magento\Framework\Event\Observer $observer + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function flushAllCache(\Magento\Framework\Event\Observer $observer) + { + if ($this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->_config->isEnabled()) { + $this->sendPurgeRequest('.*'); + } + } + + /** + * Send curl purge request + * to invalidate cache by tags pattern + * + * @param string $tagsPattern + * @return void + */ + protected function sendPurgeRequest($tagsPattern) + { + $headers = ["X-Magento-Tags-Pattern: {$tagsPattern}"]; + $this->_curlAdapter->setOptions([CURLOPT_CUSTOMREQUEST => 'PURGE']); + $this->_curlAdapter->write('', $this->_helper->getUrl('*'), '1.1', $headers); + $this->_curlAdapter->read(); + $this->_curlAdapter->close(); + } +} diff --git a/app/code/Magento/CacheInvalidate/README.md b/app/code/Magento/CacheInvalidate/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6cca6ffec03e45b5b7c09ba7d6e8a6543e14eb00 --- /dev/null +++ b/app/code/Magento/CacheInvalidate/README.md @@ -0,0 +1,2 @@ +The CacheInvalidate module is used to invalidate the Varnish cache if it is configured. +It listens for events that request the cache to be flushed or cause the cache to be invalid, then sends Varnish a purge request using cURL. \ No newline at end of file diff --git a/app/code/Magento/CacheInvalidate/Test/Unit/Model/ObserverTest.php b/app/code/Magento/CacheInvalidate/Test/Unit/Model/ObserverTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1abf5d45605acb48f111f7126ab58dcae9c9e540 --- /dev/null +++ b/app/code/Magento/CacheInvalidate/Test/Unit/Model/ObserverTest.php @@ -0,0 +1,138 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CacheInvalidate\Test\Unit\Model; + +class ObserverTest extends \PHPUnit_Framework_TestCase +{ + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Model\Observer */ + protected $_model; + + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Event\Observer */ + protected $_observerMock; + + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\HTTP\Adapter\Curl */ + protected $_curlMock; + + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\PageCache\Model\Config */ + protected $_configMock; + + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\PageCache\Helper\Data */ + protected $_helperMock; + + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Object\ */ + protected $_observerObject; + + /** + * Set up all mocks and data for test + */ + public function setUp() + { + $this->_configMock = $this->getMock( + 'Magento\PageCache\Model\Config', + ['getType', 'isEnabled'], + [], + '', + false + ); + $this->_helperMock = $this->getMock('Magento\PageCache\Helper\Data', ['getUrl'], [], '', false); + $this->_curlMock = $this->getMock( + '\Magento\Framework\HTTP\Adapter\Curl', + ['setOptions', 'write', 'read', 'close'], + [], + '', + false + ); + $this->_model = new \Magento\CacheInvalidate\Model\Observer( + $this->_configMock, + $this->_helperMock, + $this->_curlMock + ); + $this->_observerMock = $this->getMock( + 'Magento\Framework\Event\Observer', + ['getEvent'], + [], + '', + false + ); + $this->_observerObject = $this->getMock('\Magento\Store\Model\Store', [], [], '', false); + } + + /** + * Test case for cache invalidation + */ + public function testInvalidateVarnish() + { + $tags = ['cache_1', 'cache_group']; + $pattern = '((^|,)cache(,|$))|((^|,)cache_1(,|$))|((^|,)cache_group(,|$))'; + + $this->_configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); + $this->_configMock->expects( + $this->once() + )->method( + 'getType' + )->will( + $this->returnValue(\Magento\PageCache\Model\Config::VARNISH) + ); + $eventMock = $this->getMock('Magento\Framework\Event', ['getObject'], [], '', false); + $eventMock->expects($this->once())->method('getObject')->will($this->returnValue($this->_observerObject)); + $this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock)); + $this->_observerObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags)); + $this->sendPurgeRequest($pattern); + + $this->_model->invalidateVarnish($this->_observerMock); + } + + /** + * Test case for flushing all the cache + */ + public function testFlushAllCache() + { + $this->_configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); + $this->_configMock->expects( + $this->once() + )->method( + 'getType' + )->will( + $this->returnValue(\Magento\PageCache\Model\Config::VARNISH) + ); + + $this->sendPurgeRequest('.*'); + $this->_model->flushAllCache($this->_observerMock); + } + + /** + * @param string $tags + */ + protected function sendPurgeRequest($tags) + { + $url = 'http://mangento.index.php'; + $httpVersion = '1.1'; + $headers = ["X-Magento-Tags-Pattern: {$tags}"]; + $this->_helperMock->expects( + $this->any() + )->method( + 'getUrl' + )->with( + $this->equalTo('*'), + [] + )->will( + $this->returnValue($url) + ); + $this->_curlMock->expects($this->once())->method('setOptions')->with([CURLOPT_CUSTOMREQUEST => 'PURGE']); + $this->_curlMock->expects( + $this->once() + )->method( + 'write' + )->with( + $this->equalTo(''), + $this->equalTo($url), + $httpVersion, + $this->equalTo($headers) + ); + $this->_curlMock->expects($this->once())->method('read'); + $this->_curlMock->expects($this->once())->method('close'); + } +} diff --git a/app/code/Magento/CacheInvalidate/composer.json b/app/code/Magento/CacheInvalidate/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..3fe142a52e825fe6bae3ab6d56e798302d3ba3c3 --- /dev/null +++ b/app/code/Magento/CacheInvalidate/composer.json @@ -0,0 +1,24 @@ +{ + "name": "magento/module-cache-invalidate", + "description": "N/A", + "require": { + "php": "~5.5.0|~5.6.0", + "magento/module-page-cache": "0.74.0-beta4", + "magento/framework": "0.74.0-beta4", + "magento/magento-composer-installer": "*" + }, + "type": "magento2-module", + "version": "0.74.0-beta4", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "extra": { + "map": [ + [ + "*", + "Magento/CacheInvalidate" + ] + ] + } +} diff --git a/app/code/Magento/CacheInvalidate/etc/events.xml b/app/code/Magento/CacheInvalidate/etc/events.xml new file mode 100644 index 0000000000000000000000000000000000000000..d4ba3665ee66fb4e1e1eee75045302c199bf2985 --- /dev/null +++ b/app/code/Magento/CacheInvalidate/etc/events.xml @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd"> + <event name="clean_cache_by_tags"> + <observer name="invalidate_varnish" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" /> + </event> + <event name="adminhtml_cache_flush_system"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" /> + </event> + <event name="clean_media_cache_after"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" /> + </event> + <event name="clean_catalog_images_cache_after"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" /> + </event> + <event name="assigned_theme_changed"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" /> + </event> + <event name="catalogrule_after_apply"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" /> + </event> + <event name="adminhtml_cache_refresh_type"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" /> + </event> + <event name="adminhtml_cache_flush_all"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" /> + </event> + <event name="assign_theme_to_stores_after"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" /> + </event> + <event name="controller_action_postdispatch_adminhtml_system_currency_saveRates"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" /> + </event> + <event name="controller_action_postdispatch_adminhtml_system_config_save"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" /> + </event> + <event name="controller_action_postdispatch_adminhtml_catalog_product_action_attribute_save"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" /> + </event> + <event name="controller_action_postdispatch_adminhtml_catalog_product_massStatus"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" /> + </event> + <event name="controller_action_postdispatch_adminhtml_system_currencysymbol_save"> + <observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" /> + </event> +</config> diff --git a/app/code/Magento/CacheInvalidate/etc/module.xml b/app/code/Magento/CacheInvalidate/etc/module.xml new file mode 100644 index 0000000000000000000000000000000000000000..ca87df877a43a93eb2be450fa10b0013d099eff9 --- /dev/null +++ b/app/code/Magento/CacheInvalidate/etc/module.xml @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> + <module name="Magento_CacheInvalidate" setup_version="2.0.0"> + <sequence> + <module name="Magento_Store"/> + </sequence> + </module> +</config> diff --git a/app/code/Magento/Checkout/Block/Cart/Shipping.php b/app/code/Magento/Checkout/Block/Cart/Shipping.php index 27f72fb347f391cd41e74da27eb83713e46abd1a..8cf93dd33eaa66b2e65598029299152b508dc991 100644 --- a/app/code/Magento/Checkout/Block/Cart/Shipping.php +++ b/app/code/Magento/Checkout/Block/Cart/Shipping.php @@ -34,7 +34,7 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart protected $_directoryBlock; /** - * @var \Magento\Quote\Model\Quote\Address\CarrierFactoryInterface + * @var \Magento\Shipping\Model\CarrierFactoryInterface */ protected $_carrierFactory; @@ -48,7 +48,7 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Directory\Block\Data $directoryBlock - * @param \Magento\Quote\Model\Quote\Address\CarrierFactoryInterface $carrierFactory + * @param \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory * @param PriceCurrencyInterface $priceCurrency * @param array $data */ @@ -57,7 +57,7 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Directory\Block\Data $directoryBlock, - \Magento\Quote\Model\Quote\Address\CarrierFactoryInterface $carrierFactory, + \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory, PriceCurrencyInterface $priceCurrency, array $data = [] ) { diff --git a/app/code/Magento/Checkout/composer.json b/app/code/Magento/Checkout/composer.json index 50db79346bdbb9c2e5c0f05a300135a83e6d7161..2877afcf85ed8820a084c34cd72c03874baf4996 100644 --- a/app/code/Magento/Checkout/composer.json +++ b/app/code/Magento/Checkout/composer.json @@ -10,6 +10,7 @@ "magento/module-customer": "0.74.0-beta4", "magento/module-catalog": "0.74.0-beta4", "magento/module-payment": "0.74.0-beta4", + "magento/module-shipping": "0.74.0-beta4", "magento/module-tax": "0.74.0-beta4", "magento/module-directory": "0.74.0-beta4", "magento/module-eav": "0.74.0-beta4", diff --git a/app/code/Magento/Dhl/Model/Carrier.php b/app/code/Magento/Dhl/Model/Carrier.php index 6d5c1720a2ce7b03dd418fb59139810ca3592116..dc2388e4e0c5606d3fbc3ff45c0a36d97d128da4 100644 --- a/app/code/Magento/Dhl/Model/Carrier.php +++ b/app/code/Magento/Dhl/Model/Carrier.php @@ -295,10 +295,10 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin /** * Collect and get rates * - * @param RateRequest $request + * @param \Magento\Framework\Object $request * @return bool|Result|null */ - public function collectRates(RateRequest $request) + public function collectRates(\Magento\Framework\Object $request) { if (!$this->getConfigFlag($this->_activeFlag)) { return false; @@ -1255,10 +1255,10 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin /** * Processing additional validation to check is carrier applicable. * - * @param RateRequest $request - * @return $this|Error|boolean + * @param \Magento\Framework\Object $request + * @return $this|\Magento\Framework\Object|boolean */ - public function proccessAdditionalValidation(RateRequest $request) + public function proccessAdditionalValidation(\Magento\Framework\Object $request) { //Skip by item validation if there is no items in request if (!count($this->getAllItems($request))) { diff --git a/app/code/Magento/Fedex/Model/Carrier.php b/app/code/Magento/Fedex/Model/Carrier.php index 51ac852ac050d79893f68a4dc7a1d4fc47da9ad8..66f266dd1a8450611cba7a72e55e406a135e6caa 100644 --- a/app/code/Magento/Fedex/Model/Carrier.php +++ b/app/code/Magento/Fedex/Model/Carrier.php @@ -236,10 +236,10 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C /** * Collect and get rates * - * @param RateRequest $request + * @param \Magento\Framework\Object $request * @return Result|bool|null */ - public function collectRates(RateRequest $request) + public function collectRates(\Magento\Framework\Object $request) { if (!$this->getConfigFlag($this->_activeFlag)) { return false; diff --git a/app/code/Magento/Log/Test/Unit/Model/VisitorTest.php b/app/code/Magento/Log/Test/Unit/Model/VisitorTest.php index 79e8d2bee271fd48e1e5b4854aa768cfae68c73a..9e970f2c88c77e27dc2b866065d4ec62b617b610 100644 --- a/app/code/Magento/Log/Test/Unit/Model/VisitorTest.php +++ b/app/code/Magento/Log/Test/Unit/Model/VisitorTest.php @@ -122,13 +122,23 @@ class VisitorTest extends \PHPUnit_Framework_TestCase public function testGetFirstVisitAt() { $time = time(); - $this->assertEquals($time, $this->visitor->getFirstVisitAt()); + $this->assertEquals( + $time, + $this->visitor->getFirstVisitAt(), + 'VisitorTest failed to assert the time for the first visit within 5 seconds.', + 5 + ); } public function testGetLastVisitAt() { $time = time(); - $this->assertEquals($time, $this->visitor->getLastVisitAt()); + $this->assertEquals( + $time, + $this->visitor->getLastVisitAt(), + 'VisitorTest failed to assert the time for the last visit within 5 seconds.', + 5 + ); } public function testLogNewVisitor() diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Flatrate.php b/app/code/Magento/OfflineShipping/Model/Carrier/Flatrate.php index ff96421b77034d67dc4cf1cb6ab6c4d83077d3ad..d85a0d771d2fb3a8602b779c84ca27c9204efccf 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Flatrate.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Flatrate.php @@ -55,12 +55,12 @@ class Flatrate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implement } /** - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return Result|bool * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request) + public function collectRates(\Magento\Framework\Object $request) { if (!$this->getConfigFlag('active')) { return false; diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Freeshipping.php b/app/code/Magento/OfflineShipping/Model/Carrier/Freeshipping.php index 0586b180b8832ae34b16ca6267c77dab93df82e4..fdbc3c264671dfe4714d0f003a48d54efcba85dc 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Freeshipping.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Freeshipping.php @@ -58,10 +58,10 @@ class Freeshipping extends \Magento\Shipping\Model\Carrier\AbstractCarrier imple /** * FreeShipping Rates Collector * - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return \Magento\Shipping\Model\Rate\Result|bool */ - public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request) + public function collectRates(\Magento\Framework\Object $request) { if (!$this->getConfigFlag('active')) { return false; diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Pickup.php b/app/code/Magento/OfflineShipping/Model/Carrier/Pickup.php index e1411217d1d5d1b96dae3cfd82ee4ba78047b4b1..40df2042c043dbb3782b0d3e6b8f3d6a1d304734 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Pickup.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Pickup.php @@ -50,11 +50,11 @@ class Pickup extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements } /** - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return \Magento\Shipping\Model\Rate\Result * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ - public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request) + public function collectRates(\Magento\Framework\Object $request) { if (!$this->getConfigFlag('active')) { return false; diff --git a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php index f5a7a8cd8a6264967eb99d1265963b52e043eab7..b89948409ebd294999cae7f1d7224bf3a19972b7 100644 --- a/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php +++ b/app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php @@ -74,13 +74,13 @@ class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implemen } /** - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return \Magento\Shipping\Model\Rate\Result * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request) + public function collectRates(\Magento\Framework\Object $request) { if (!$this->getConfigFlag('active')) { return false; diff --git a/app/code/Magento/Payment/Model/Cart.php b/app/code/Magento/Payment/Model/Cart.php index 85962afa760aac013aa161f98e21225336030a10..436bdc899a48d198278823bd4ec1c381384d6447 100644 --- a/app/code/Magento/Payment/Model/Cart.php +++ b/app/code/Magento/Payment/Model/Cart.php @@ -75,7 +75,7 @@ class Cart /** * @param \Magento\Payment\Model\Cart\SalesModel\Factory $salesModelFactory * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Sales\Model\Order|\Magento\Quote\Model\Quote $salesModel + * @param \Magento\Quote\Api\Data\CartInterface $salesModel */ public function __construct( \Magento\Payment\Model\Cart\SalesModel\Factory $salesModelFactory, @@ -91,6 +91,7 @@ class Cart * Return payment cart sales model * * @return \Magento\Payment\Model\Cart\SalesModel\SalesModelInterface + * @api */ public function getSalesModel() { @@ -102,6 +103,7 @@ class Cart * * @param float $taxAmount * @return void + * @api */ public function addTax($taxAmount) { @@ -113,6 +115,7 @@ class Cart * * @param float $taxAmount * @return void + * @api */ public function setTax($taxAmount) { @@ -123,6 +126,7 @@ class Cart * Get tax amount * * @return float + * @api */ public function getTax() { @@ -134,6 +138,7 @@ class Cart * * @param float $discountAmount * @return void + * @api */ public function addDiscount($discountAmount) { @@ -145,6 +150,7 @@ class Cart * * @param float $discountAmount * @return void + * @api */ public function setDiscount($discountAmount) { @@ -155,6 +161,7 @@ class Cart * Get discount amount * * @return float + * @api */ public function getDiscount() { @@ -166,6 +173,7 @@ class Cart * * @param float $shippingAmount * @return void + * @api */ public function addShipping($shippingAmount) { @@ -177,6 +185,7 @@ class Cart * * @param float $shippingAmount * @return void + * @api */ public function setShipping($shippingAmount) { @@ -187,6 +196,7 @@ class Cart * Get shipping amount * * @return float + * @api */ public function getShipping() { @@ -198,6 +208,7 @@ class Cart * * @param float $subtotalAmount * @return void + * @api */ public function addSubtotal($subtotalAmount) { @@ -208,6 +219,7 @@ class Cart * Get subtotal amount * * @return float + * @api */ public function getSubtotal() { @@ -222,6 +234,7 @@ class Cart * @param float $amount * @param string|null $identifier * @return void + * @api */ public function addCustomItem($name, $qty, $amount, $identifier = null) { @@ -232,6 +245,7 @@ class Cart * Get all cart items * * @return array + * @api */ public function getAllItems() { @@ -243,6 +257,7 @@ class Cart * Get shipping, tax, subtotal and discount amounts all together * * @return array + * @api */ public function getAmounts() { @@ -255,6 +270,7 @@ class Cart * Specify that shipping should be transferred as cart item * * @return void + * @api */ public function setTransferShippingAsItem() { @@ -265,6 +281,7 @@ class Cart * Specify that discount should be transferred as cart item * * @return void + * @api */ public function setTransferDiscountAsItem() { diff --git a/app/code/Magento/Payment/Model/Cart/SalesModel/Factory.php b/app/code/Magento/Payment/Model/Cart/SalesModel/Factory.php index 186a6fc45f5c8dc0ffe77e8f31aa54476da796ba..f077e1a72f1870943e626cbcc0dc41c1062c9ac6 100644 --- a/app/code/Magento/Payment/Model/Cart/SalesModel/Factory.php +++ b/app/code/Magento/Payment/Model/Cart/SalesModel/Factory.php @@ -26,7 +26,7 @@ class Factory /** * Wrap sales model with Magento\Payment\Model\Cart\SalesModel\SalesModelInterface * - * @param \Magento\Sales\Model\Order|\Magento\Quote\Model\Quote $salesModel + * @param \Magento\Quote\Api\Data\CartInterface $salesModel * @return \Magento\Payment\Model\Cart\SalesModel\SalesModelInterface * @throws \InvalidArgumentException */ diff --git a/app/code/Magento/Payment/Model/Cart/SalesModel/SalesModelInterface.php b/app/code/Magento/Payment/Model/Cart/SalesModel/SalesModelInterface.php index 117eb8b1d48e2ba5fd61cf5c504e67f6730c7003..a210f55bb3a2b3f7cb6a7d75d92377bac6070b17 100644 --- a/app/code/Magento/Payment/Model/Cart/SalesModel/SalesModelInterface.php +++ b/app/code/Magento/Payment/Model/Cart/SalesModel/SalesModelInterface.php @@ -14,26 +14,31 @@ interface SalesModelInterface * Get all items from shopping sales model * * @return array + * @api */ public function getAllItems(); /** * @return float|null + * @api */ public function getBaseSubtotal(); /** * @return float|null + * @api */ public function getBaseTaxAmount(); /** * @return float|null + * @api */ public function getBaseShippingAmount(); /** * @return float|null + * @api */ public function getBaseDiscountAmount(); @@ -43,13 +48,15 @@ interface SalesModelInterface * @param string $key * @param mixed $args * @return mixed + * @api */ public function getDataUsingMethod($key, $args = null); /** * Return object that contains tax related fields * - * @return \Magento\Sales\Model\Order|\Magento\Quote\Model\Quote\Address + * @return \Magento\Sales\Api\Data\OrderInterface|\Magento\Quote\Api\Data\AddressInterface + * @api */ public function getTaxContainer(); } diff --git a/app/code/Magento/Payment/Model/Checks/PaymentMethodChecksInterface.php b/app/code/Magento/Payment/Model/Checks/PaymentMethodChecksInterface.php index d2bb13d0eda1823369883e738efa3888c7507b65..9d2ad43801e5ebda0834b4c4adff7019e4631b65 100644 --- a/app/code/Magento/Payment/Model/Checks/PaymentMethodChecksInterface.php +++ b/app/code/Magento/Payment/Model/Checks/PaymentMethodChecksInterface.php @@ -14,6 +14,7 @@ interface PaymentMethodChecksInterface * Retrieve payment method code * * @return string + * @api */ public function getCode(); @@ -22,6 +23,7 @@ interface PaymentMethodChecksInterface * Can be used in admin * * @return bool + * @api */ public function canUseInternal(); @@ -29,6 +31,7 @@ interface PaymentMethodChecksInterface * Can be used in regular checkout * * @return bool + * @api */ public function canUseCheckout(); @@ -37,6 +40,7 @@ interface PaymentMethodChecksInterface * * @param string $country * @return bool + * @api */ public function canUseForCountry($country); @@ -45,6 +49,7 @@ interface PaymentMethodChecksInterface * * @param string $currencyCode * @return bool + * @api */ public function canUseForCurrency($currencyCode); @@ -55,6 +60,7 @@ interface PaymentMethodChecksInterface * @param int|string|null|\Magento\Store\Model\Store $storeId * * @return mixed + * @api */ public function getConfigData($field, $storeId = null); } diff --git a/app/code/Magento/Payment/Model/Config.php b/app/code/Magento/Payment/Model/Config.php index 62a196bfce79f0b267fea1af1edc2cbf5dd35097..9d782ce97998d70e2a78f63ecd92a51fa7a1a2ed 100644 --- a/app/code/Magento/Payment/Model/Config.php +++ b/app/code/Magento/Payment/Model/Config.php @@ -86,6 +86,7 @@ class Config * Retrieve active system payments * * @return array + * @api */ public function getActiveMethods() { @@ -107,6 +108,7 @@ class Config * Get list of credit card types * * @return array + * @api */ public function getCcTypes() { @@ -117,6 +119,7 @@ class Config * Retrieve array of payment methods information * * @return array + * @api */ public function getMethodsInfo() { @@ -127,6 +130,7 @@ class Config * Get payment groups * * @return array + * @api */ public function getGroups() { @@ -137,6 +141,7 @@ class Config * Retrieve list of months translation * * @return array + * @api */ public function getMonths() { @@ -155,6 +160,7 @@ class Config * Retrieve array of available years * * @return array + * @api */ public function getYears() { diff --git a/app/code/Magento/Payment/Model/InfoInterface.php b/app/code/Magento/Payment/Model/InfoInterface.php index 270ee9c16fe89c98208ec2f8ac1cde356adae12b..b39670441cf23d5fd320c6faf98f421ee39b5321 100644 --- a/app/code/Magento/Payment/Model/InfoInterface.php +++ b/app/code/Magento/Payment/Model/InfoInterface.php @@ -16,6 +16,7 @@ interface InfoInterface * * @param string $data * @return string + * @api */ public function encrypt($data); @@ -24,6 +25,7 @@ interface InfoInterface * * @param string $data * @return string + * @api */ public function decrypt($data); @@ -33,6 +35,7 @@ interface InfoInterface * @param string $key * @param string|null $value * @return mixed + * @api */ public function setAdditionalInformation($key, $value = null); @@ -41,6 +44,7 @@ interface InfoInterface * * @param mixed|null $key * @return bool + * @api */ public function hasAdditionalInformation($key = null); @@ -49,6 +53,7 @@ interface InfoInterface * * @param string|null $key * @return $this + * @api */ public function unsAdditionalInformation($key = null); @@ -57,6 +62,7 @@ interface InfoInterface * * @param string|null $key * @return mixed + * @api */ public function getAdditionalInformation($key = null); @@ -65,6 +71,7 @@ interface InfoInterface * * @return \Magento\Payment\Model\MethodInterface * @throws \Magento\Framework\Exception\LocalizedException + * @api */ public function getMethodInstance(); } diff --git a/app/code/Magento/Payment/Model/Method/AbstractMethod.php b/app/code/Magento/Payment/Model/Method/AbstractMethod.php index 74e26082b6c0b7525c47b07c57f5c6cf08bc263d..e316982a1be7081f470bc8cb2493d19ea0debfea 100644 --- a/app/code/Magento/Payment/Model/Method/AbstractMethod.php +++ b/app/code/Magento/Payment/Model/Method/AbstractMethod.php @@ -260,6 +260,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Check order availability * * @return bool + * @api */ public function canOrder() { @@ -270,6 +271,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Check authorize availability * * @return bool + * @api */ public function canAuthorize() { @@ -280,6 +282,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Check capture availability * * @return bool + * @api */ public function canCapture() { @@ -290,6 +293,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Check partial capture availability * * @return bool + * @api */ public function canCapturePartial() { @@ -300,6 +304,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Check whether capture can be performed once and no further capture possible * * @return bool + * @api */ public function canCaptureOnce() { @@ -310,6 +315,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Check refund availability * * @return bool + * @api */ public function canRefund() { @@ -320,6 +326,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Check partial refund availability for invoice * * @return bool + * @api */ public function canRefundPartialPerInvoice() { @@ -332,6 +339,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param \Magento\Framework\Object $payment * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function canVoid(\Magento\Framework\Object $payment) { @@ -363,6 +371,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Can be edit order (renew order) * * @return bool + * @api */ public function canEdit() { @@ -373,6 +382,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Check fetch transaction info availability * * @return bool + * @api */ public function canFetchTransactionInfo() { @@ -386,6 +396,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param string $transactionId * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payment, $transactionId) { @@ -396,6 +407,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Retrieve payment system relation flag * * @return bool + * @api */ public function isGateway() { @@ -406,6 +418,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Retrieve payment method online/offline flag * * @return bool + * @api */ public function isOffline() { @@ -416,6 +429,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Flag if we need to run payment initialize while order place * * @return bool + * @api */ public function isInitializeNeeded() { @@ -482,6 +496,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Retrieve block type for display method information * * @return string + * @api */ public function getInfoBlockType() { @@ -491,8 +506,9 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl /** * Retrieve payment information model object * - * @return \Magento\Payment\Model\Info + * @return \Magento\Payment\Model\InfoInterface * @throws \Magento\Framework\Exception\LocalizedException + * @api */ public function getInfoInstance() { @@ -508,6 +524,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * * @return $this * @throws \Magento\Framework\Exception\LocalizedException + * @api */ public function validate() { @@ -537,6 +554,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function order(\Magento\Framework\Object $payment, $amount) { @@ -555,6 +573,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function authorize(\Magento\Framework\Object $payment, $amount) { @@ -573,6 +592,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function capture(\Magento\Framework\Object $payment, $amount) { @@ -591,6 +611,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param Invoice $invoice * @param Payment $payment * @return $this + * @api */ public function processInvoice($invoice, $payment) { @@ -606,6 +627,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param Invoice $invoice * @param Payment $payment * @return $this + * @api */ public function processBeforeRefund($invoice, $payment) { @@ -621,6 +643,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function refund(\Magento\Framework\Object $payment, $amount) { @@ -635,6 +658,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param \Magento\Sales\Model\Order\Creditmemo $creditmemo * @param Payment $payment * @return $this + * @api */ public function processCreditmemo($creditmemo, $payment) { @@ -649,6 +673,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function cancel(\Magento\Framework\Object $payment) { @@ -661,6 +686,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param \Magento\Framework\Object $payment * @return $this * @throws \Magento\Framework\Exception\LocalizedException + * @api */ public function void(\Magento\Framework\Object $payment) { @@ -676,6 +702,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param \Magento\Payment\Model\InfoInterface $payment * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function canReviewPayment(\Magento\Payment\Model\InfoInterface $payment) { @@ -688,6 +715,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param \Magento\Payment\Model\InfoInterface $payment * @return false * @throws \Magento\Framework\Exception\LocalizedException + * @api */ public function acceptPayment(\Magento\Payment\Model\InfoInterface $payment) { @@ -703,6 +731,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * @param \Magento\Payment\Model\InfoInterface $payment * @return false * @throws \Magento\Framework\Exception\LocalizedException + * @api */ public function denyPayment(\Magento\Payment\Model\InfoInterface $payment) { @@ -744,6 +773,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * * @param array|\Magento\Framework\Object $data * @return $this + * @api */ public function assignData($data) { @@ -759,6 +789,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Prepare info instance for save * * @return $this + * @api */ public function prepareSave() { @@ -768,9 +799,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl /** * Check whether payment method can be used * - * TODO: payment method instance is not supposed to know about quote - * - * @param \Magento\Quote\Model\Quote|null $quote + * @param \Magento\Quote\Api\Data\CartInterface|null $quote * @return bool */ public function isAvailable($quote = null) @@ -797,6 +826,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function initialize($paymentAction, $stateObject) { @@ -808,6 +838,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * Used to universalize payment actions when processing payment place * * @return string + * @api */ public function getConfigPaymentAction() { @@ -832,6 +863,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * @api */ public function getDebugFlag() { @@ -843,6 +875,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl * * @param mixed $debugData * @return void + * @api */ public function debugData($debugData) { diff --git a/app/code/Magento/Payment/Model/Method/Cc.php b/app/code/Magento/Payment/Model/Method/Cc.php index 167f88c7e9fca09662aaad2148ed7c3599c210f9..978e75c5840aaeae528aad5111f93b3c77fc75c5 100644 --- a/app/code/Magento/Payment/Model/Method/Cc.php +++ b/app/code/Magento/Payment/Model/Method/Cc.php @@ -250,6 +250,7 @@ class Cc extends \Magento\Payment\Model\Method\AbstractMethod /** * @return bool + * @api */ public function hasVerification() { @@ -262,6 +263,7 @@ class Cc extends \Magento\Payment\Model\Method\AbstractMethod /** * @return array + * @api */ public function getVerificationRegEx() { @@ -298,6 +300,7 @@ class Cc extends \Magento\Payment\Model\Method\AbstractMethod /** * @param string $type * @return bool + * @api */ public function otherCcType($type) { @@ -309,6 +312,7 @@ class Cc extends \Magento\Payment\Model\Method\AbstractMethod * * @param string $ccNumber * @return bool + * @api */ public function validateCcNum($ccNumber) { @@ -348,6 +352,7 @@ class Cc extends \Magento\Payment\Model\Method\AbstractMethod * * @param string $ccNumber * @return bool + * @api */ public function validateCcNumOther($ccNumber) { @@ -357,7 +362,7 @@ class Cc extends \Magento\Payment\Model\Method\AbstractMethod /** * Check whether there are CC types set in configuration * - * @param \Magento\Quote\Model\Quote|null $quote + * @param \Magento\Quote\Api\Data\CartInterface|null $quote * @return bool */ public function isAvailable($quote = null) diff --git a/app/code/Magento/Payment/Model/MethodInterface.php b/app/code/Magento/Payment/Model/MethodInterface.php index 0e6c1da86887622a33d98efeb2df06b65e14741b..f800703d73e3cf04cbbd8294c70262e5fb60ae0a 100644 --- a/app/code/Magento/Payment/Model/MethodInterface.php +++ b/app/code/Magento/Payment/Model/MethodInterface.php @@ -15,6 +15,7 @@ interface MethodInterface * Retrieve payment method code * * @return string + * @api */ public function getCode(); @@ -22,6 +23,7 @@ interface MethodInterface * Retrieve block type for method form generation * * @return string + * @api */ public function getFormBlockType(); @@ -29,6 +31,7 @@ interface MethodInterface * Retrieve payment method title * * @return string + * @api */ public function getTitle(); } diff --git a/app/code/Magento/Payment/Model/MethodList.php b/app/code/Magento/Payment/Model/MethodList.php index 8ba8a76d77acc33da2bb8e9c2f1423776ed76313..5d486411b9f7a8d63139579ff76d55d13e26ccb8 100644 --- a/app/code/Magento/Payment/Model/MethodList.php +++ b/app/code/Magento/Payment/Model/MethodList.php @@ -33,10 +33,11 @@ class MethodList } /** - * @param \Magento\Quote\Model\Quote $quote + * @param \Magento\Quote\Api\Data\CartInterface $quote * @return \Magento\Payment\Model\MethodInterface[] + * @api */ - public function getAvailableMethods(\Magento\Quote\Model\Quote $quote = null) + public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null) { $store = $quote ? $quote->getStoreId() : null; $methods = []; @@ -54,10 +55,10 @@ class MethodList * Check payment method model * * @param \Magento\Payment\Model\MethodInterface $method - * @param \Magento\Quote\Model\Quote $quote + * @param \Magento\Quote\Api\Data\CartInterface $quote * @return bool */ - protected function _canUseMethod($method, \Magento\Quote\Model\Quote $quote) + protected function _canUseMethod($method, \Magento\Quote\Api\Data\CartInterface $quote) { return $this->methodSpecificationFactory->create( [ diff --git a/app/code/Magento/Quote/Model/Quote.php b/app/code/Magento/Quote/Model/Quote.php index 1d663cfd5d942c84d88a63f9161cdc9773f2c4aa..88010642002f69ba6d36ff56c882fd2f96076ccd 100644 --- a/app/code/Magento/Quote/Model/Quote.php +++ b/app/code/Magento/Quote/Model/Quote.php @@ -2253,12 +2253,6 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C { if (!$this->getReservedOrderId()) { $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this)); - } else { - //checking if reserved order id was already used for some order - //if yes reserving new one if not using old one - if ($this->_getResource()->isOrderIncrementIdUsed($this->getReservedOrderId())) { - $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this)); - } } return $this; } diff --git a/app/code/Magento/Quote/Model/Quote/Address.php b/app/code/Magento/Quote/Model/Quote/Address.php index c57a8d0d5e8163661cdb1e240d60924801c3e5bb..4cddfa347659b75a2930348d1fb19cf54bf3226c 100644 --- a/app/code/Magento/Quote/Model/Quote/Address.php +++ b/app/code/Magento/Quote/Model/Quote/Address.php @@ -248,7 +248,7 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements * @param \Magento\Quote\Model\Quote\Address\Total\CollectorFactory $totalCollectorFactory * @param Address\TotalFactory $addressTotalFactory * @param \Magento\Framework\Object\Copy $objectCopyService - * @param Address\CarrierFactoryInterface $carrierFactory + * @param \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory * @param Address\Validator $validator * @param \Magento\Customer\Model\Address\Mapper $addressMapper * @param \Magento\Framework\Model\Resource\AbstractResource $resource @@ -280,7 +280,7 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements \Magento\Quote\Model\Quote\Address\Total\CollectorFactory $totalCollectorFactory, \Magento\Quote\Model\Quote\Address\TotalFactory $addressTotalFactory, \Magento\Framework\Object\Copy $objectCopyService, - \Magento\Quote\Model\Quote\Address\CarrierFactoryInterface $carrierFactory, + \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory, Address\Validator $validator, \Magento\Customer\Model\Address\Mapper $addressMapper, \Magento\Framework\Model\Resource\AbstractResource $resource = null, diff --git a/app/code/Magento/Quote/Model/Quote/Address/ToOrder.php b/app/code/Magento/Quote/Model/Quote/Address/ToOrder.php index 6f58b342a667a7b0a56dee8e649007f5710ddfba..3b4649c44736fce125edcde2e664247dd5a22411 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/ToOrder.php +++ b/app/code/Magento/Quote/Model/Quote/Address/ToOrder.php @@ -75,7 +75,8 @@ class ToOrder '\Magento\Sales\Api\Data\OrderInterface' ); $order->setStoreId($object->getQuote()->getStoreId()) - ->setQuoteId($object->getQuote()->getId()); + ->setQuoteId($object->getQuote()->getId()) + ->setIncrementId($object->getQuote()->getReservedOrderId()); $this->objectCopyService->copyFieldsetToTarget('sales_convert_quote', 'to_order', $object->getQuote(), $order); $this->eventManager->dispatch( diff --git a/app/code/Magento/Quote/Model/Resource/Quote.php b/app/code/Magento/Quote/Model/Resource/Quote.php index 4483f59150e89ab68d768e1971b2507ce8461194..990902300124466ee9cdc4a3437425e9f5841156 100644 --- a/app/code/Magento/Quote/Model/Resource/Quote.php +++ b/app/code/Magento/Quote/Model/Resource/Quote.php @@ -16,22 +16,22 @@ use Magento\Framework\Model\Resource\Db\AbstractDb; class Quote extends AbstractDb { /** - * @var \Magento\Eav\Model\Config + * @var \Magento\SalesSequence\Model\Manager */ - protected $_config; + protected $sequenceManager; /** * @param \Magento\Framework\Model\Resource\Db\Context $context - * @param \Magento\Eav\Model\Config $config - * @param string|null $resourcePrefix + * @param \Magento\SalesSequence\Model\Manager $sequenceManager + * @param null $resourcePrefix */ public function __construct( \Magento\Framework\Model\Resource\Db\Context $context, - \Magento\Eav\Model\Config $config, + \Magento\SalesSequence\Model\Manager $sequenceManager, $resourcePrefix = null ) { parent::__construct($context, $resourcePrefix); - $this->_config = $config; + $this->sequenceManager = $sequenceManager; } /** @@ -156,28 +156,8 @@ class Quote extends AbstractDb */ public function getReservedOrderId($quote) { - $storeId = (int)$quote->getStoreId(); - return $this->_config->getEntityType(\Magento\Sales\Model\Order::ENTITY)->fetchNewIncrementId($storeId); - } - - /** - * Check is order increment id use in sales/order table - * - * @param int $orderIncrementId - * @return bool - */ - public function isOrderIncrementIdUsed($orderIncrementId) - { - $adapter = $this->_getReadAdapter(); - $bind = [':increment_id' => $orderIncrementId]; - $select = $adapter->select(); - $select->from($this->getTable('sales_order'), 'entity_id')->where('increment_id = :increment_id'); - $entity_id = $adapter->fetchOne($select, $bind); - if ($entity_id > 0) { - return true; - } - - return false; + return $this->sequenceManager->getSequence(\Magento\Sales\Model\Order::ENTITY, (int)$quote->getStoreId()) + ->getNextValue(); } /** diff --git a/app/code/Magento/Quote/Model/Resource/Quote/Address/Rate/Collection.php b/app/code/Magento/Quote/Model/Resource/Quote/Address/Rate/Collection.php index 6801bb83f5e43e43ad241ac5fed14dae285e9302..f21945483c6873facccac4eb9efeebe611ba723c 100644 --- a/app/code/Magento/Quote/Model/Resource/Quote/Address/Rate/Collection.php +++ b/app/code/Magento/Quote/Model/Resource/Quote/Address/Rate/Collection.php @@ -24,7 +24,7 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Quote\Model\Quote\Address\CarrierFactoryInterface $carrierFactory + * @param \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory * @param \Zend_Db_Adapter_Abstract $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ @@ -33,7 +33,7 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Quote\Model\Quote\Address\CarrierFactoryInterface $carrierFactory, + \Magento\Shipping\Model\CarrierFactoryInterface $carrierFactory, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/ToOrderTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/ToOrderTest.php index 8dea99e3bed4cc480d50780aff182647a8d95a37..0859ec68fe7bde8d106915f6a98a7c013813872b 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/ToOrderTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/ToOrderTest.php @@ -84,7 +84,7 @@ class ToOrderTest extends \PHPUnit_Framework_TestCase $object = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false); $quote = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); - $object->expects($this->exactly(4))->method('getQuote')->willReturn($quote); + $object->expects($this->exactly(5))->method('getQuote')->willReturn($quote); $quote->expects($this->once())->method('getId')->willReturn($quoteId); $quote->expects($this->once())->method('getStoreId')->willReturn($storeId); $this->objectCopyMock->expects($this->once())->method('getDataFromFieldset')->with( diff --git a/app/code/Magento/Quote/Test/Unit/Model/Resource/QuoteTest.php b/app/code/Magento/Quote/Test/Unit/Model/Resource/QuoteTest.php deleted file mode 100644 index 33885a47c6bb30365fdff0b0ca2ed287dc4a2bf8..0000000000000000000000000000000000000000 --- a/app/code/Magento/Quote/Test/Unit/Model/Resource/QuoteTest.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Quote\Test\Unit\Model\Resource; - -class QuoteTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Quote\Model\Resource\Quote - */ - protected $model; - - /** - * @var \Magento\Framework\App\Resource - */ - protected $resourceMock; - - /** - * @var \Magento\Eav\Model\Config - */ - protected $configMock; - - /** - * @var \Magento\Framework\DB\Adapter\Pdo\Mysql - */ - protected $adapterMock; - - /** - * @var \Magento\Framework\DB\Select - */ - protected $selectMock; - - protected function setUp() - { - $this->selectMock = $this->getMock('\Magento\Framework\DB\Select', [], [], '', false); - $this->selectMock->expects($this->any())->method('from')->will($this->returnSelf()); - $this->selectMock->expects($this->any())->method('where'); - - $this->adapterMock = $this->getMock('\Magento\Framework\DB\Adapter\Pdo\Mysql', [], [], '', false); - $this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock)); - - $this->resourceMock = $this->getMock('\Magento\Framework\App\Resource', [], [], '', false); - $this->resourceMock->expects( - $this->any() - )->method( - 'getConnection' - )->will( - $this->returnValue($this->adapterMock) - ); - - $this->configMock = $this->getMock('\Magento\Eav\Model\Config', [], [], '', false); - - $contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false); - $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock); - - $this->model = new \Magento\Quote\Model\Resource\Quote( - $contextMock, - $this->configMock - ); - } - - /** - * @param $value - * @dataProvider isOrderIncrementIdUsedDataProvider - */ - public function testIsOrderIncrementIdUsed($value) - { - $expectedBind = [':increment_id' => $value]; - $this->adapterMock->expects($this->once())->method('fetchOne')->with($this->selectMock, $expectedBind); - $this->model->isOrderIncrementIdUsed($value); - } - - /** - * @return array - */ - public function isOrderIncrementIdUsedDataProvider() - { - return [[100000001], ['10000000001'], ['M10000000001']]; - } -} diff --git a/app/code/Magento/Quote/composer.json b/app/code/Magento/Quote/composer.json index 2d867ccca552b0bf3dee8361003601c036092d3a..173e239f796d8072845d23365a02360f0f45a16d 100644 --- a/app/code/Magento/Quote/composer.json +++ b/app/code/Magento/Quote/composer.json @@ -10,6 +10,8 @@ "magento/module-authorization": "0.74.0-beta4", "magento/module-payment": "0.74.0-beta4", "magento/module-sales": "0.74.0-beta4", + "magento/module-shipping": "0.74.0-beta4", + "magento/module-sales-sequence": "0.74.0-beta4", "magento/module-backend": "0.74.0-beta4", "magento/module-directory": "0.74.0-beta4", "magento/module-eav": "0.74.0-beta4", diff --git a/app/code/Magento/Sales/Model/Order.php b/app/code/Magento/Sales/Model/Order.php index 517a40fe28ed150a3f02cd66cf834f7f0e80fc41..94847e91dbe200c9ea34764d4981d08ac986db98 100644 --- a/app/code/Magento/Sales/Model/Order.php +++ b/app/code/Magento/Sales/Model/Order.php @@ -521,7 +521,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface */ protected function _canVoidOrder() { - return !($this->canUnhold() || $this->isPaymentReview()); + return !($this->isCanceled() || $this->canUnhold() || $this->isPaymentReview()); } /** diff --git a/app/code/Magento/Sales/Test/Unit/Model/OrderTest.php b/app/code/Magento/Sales/Test/Unit/Model/OrderTest.php index d3a0a17afb3e01472852a13c96b1c486fe9f0572..b222a99d487454639b77b3a2552c45115a8f1919 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/OrderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/OrderTest.php @@ -348,6 +348,11 @@ class OrderTest extends \PHPUnit_Framework_TestCase $order->setData('state', $orderState); $payment = $this->_prepareOrderPayment($order); $canVoidOrder = true; + + if ($orderState == \Magento\Sales\Model\Order::STATE_CANCELED) { + $canVoidOrder = false; + } + if ($orderState == \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW) { $canVoidOrder = false; } diff --git a/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php index fd793ff3d03a7945feee7850449a192985b97485..04e8bc658ade10cc6a5f6d42ce34d7835710a5f4 100644 --- a/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php +++ b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php @@ -8,10 +8,12 @@ namespace Magento\Shipping\Model\Carrier; -use Magento\Quote\Model\Quote\Address\AbstractCarrierInterface; use Magento\Quote\Model\Quote\Address\RateResult\Error; use Magento\Shipping\Model\Shipment\Request; +/** + * Class AbstractCarrier + */ abstract class AbstractCarrier extends \Magento\Framework\Object implements AbstractCarrierInterface { /** @@ -137,6 +139,7 @@ abstract class AbstractCarrier extends \Magento\Framework\Object implements Abst * @param string $field * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * @api */ public function getConfigFlag($field) { @@ -154,11 +157,11 @@ abstract class AbstractCarrier extends \Magento\Framework\Object implements Abst /** * Collect and get rates * - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return \Magento\Shipping\Model\Rate\Result|bool|null * @abstract */ - abstract public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request); + abstract public function collectRates(\Magento\Framework\Object $request); /** * Do request to shipment @@ -276,11 +279,11 @@ abstract class AbstractCarrier extends \Magento\Framework\Object implements Abst } /** - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return $this|bool|false|\Magento\Framework\Model\AbstractModel * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function checkAvailableShipCountries(\Magento\Quote\Model\Quote\Address\RateRequest $request) + public function checkAvailableShipCountries(\Magento\Framework\Object $request) { $speCountriesAllow = $this->getConfigData('sallowspecific'); /* @@ -323,11 +326,11 @@ abstract class AbstractCarrier extends \Magento\Framework\Object implements Abst /** * Processing additional validation to check is carrier applicable. * - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request - * @return $this|bool|Error + * @param \Magento\Framework\Object $request + * @return $this|bool|\Magento\Framework\Object * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function proccessAdditionalValidation(\Magento\Quote\Model\Quote\Address\RateRequest $request) + public function proccessAdditionalValidation(\Magento\Framework\Object $request) { return $this; } @@ -593,6 +596,7 @@ abstract class AbstractCarrier extends \Magento\Framework\Object implements Abst * * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * @api */ public function getDebugFlag() { diff --git a/app/code/Magento/Quote/Model/Quote/Address/AbstractCarrierInterface.php b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrierInterface.php similarity index 83% rename from app/code/Magento/Quote/Model/Quote/Address/AbstractCarrierInterface.php rename to app/code/Magento/Shipping/Model/Carrier/AbstractCarrierInterface.php index acc4f1b93d48291383afedf533b76438717bdaca..a8a9f2f747c31adfd37f69aae90489b571b69298 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/AbstractCarrierInterface.php +++ b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrierInterface.php @@ -3,8 +3,11 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Quote\Model\Quote\Address; +namespace Magento\Shipping\Model\Carrier; +/** + * Interface AbstractCarrierInterface + */ interface AbstractCarrierInterface { /** @@ -12,16 +15,18 @@ interface AbstractCarrierInterface * * @param string $field * @return mixed + * @api */ public function getConfigData($field); /** * Collect and get rates * - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return \Magento\Framework\Object|bool|null + * @api */ - public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request); + public function collectRates(\Magento\Framework\Object $request); /** * Do request to shipment @@ -29,6 +34,7 @@ interface AbstractCarrierInterface * * @param \Magento\Framework\Object $request * @return \Magento\Framework\Object + * @api */ public function requestToShipment($request); @@ -38,6 +44,7 @@ interface AbstractCarrierInterface * * @param \Magento\Framework\Object $request * @return \Magento\Framework\Object + * @api */ public function returnOfShipment($request); @@ -46,6 +53,7 @@ interface AbstractCarrierInterface * * @param \Magento\Framework\Object|null $params * @return array + * @api */ public function getContainerTypes(\Magento\Framework\Object $params = null); @@ -53,6 +61,7 @@ interface AbstractCarrierInterface * Get Container Types, that could be customized * * @return array + * @api */ public function getCustomizableContainerTypes(); @@ -61,27 +70,31 @@ interface AbstractCarrierInterface * * @param \Magento\Framework\Object|null $params * @return array + * @api */ public function getDeliveryConfirmationTypes(\Magento\Framework\Object $params = null); /** - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return $this|bool|false|\Magento\Framework\Model\AbstractModel + * @api */ - public function checkAvailableShipCountries(\Magento\Quote\Model\Quote\Address\RateRequest $request); + public function checkAvailableShipCountries(\Magento\Framework\Object $request); /** * Processing additional validation to check is carrier applicable. * - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request - * @return $this|\Magento\Quote\Model\Quote\Address\RateResult\Error|boolean + * @param \Magento\Framework\Object $request + * @return $this|\Magento\Framework\Object|boolean + * @api */ - public function proccessAdditionalValidation(\Magento\Quote\Model\Quote\Address\RateRequest $request); + public function proccessAdditionalValidation(\Magento\Framework\Object $request); /** * Determine whether current carrier enabled for activity * * @return bool + * @api */ public function isActive(); @@ -89,6 +102,7 @@ interface AbstractCarrierInterface * Whether this carrier has fixed rates calculation * * @return bool + * @api */ public function isFixed(); @@ -96,6 +110,7 @@ interface AbstractCarrierInterface * Check if carrier has shipping tracking option available * * @return bool + * @api */ public function isTrackingAvailable(); @@ -103,6 +118,7 @@ interface AbstractCarrierInterface * Check if carrier has shipping label option available * * @return bool + * @api */ public function isShippingLabelsAvailable(); @@ -110,6 +126,7 @@ interface AbstractCarrierInterface * Retrieve sort order of current carrier * * @return string|null + * @api */ public function getSortOrder(); @@ -118,6 +135,7 @@ interface AbstractCarrierInterface * * @param float $cost * @return float final price for shipping method + * @api */ public function getFinalPriceWithHandlingFee($cost); @@ -126,6 +144,7 @@ interface AbstractCarrierInterface * * @param int $weight in someone measure * @return float Weight in pounds + * @api */ public function convertWeightToLbs($weight); @@ -134,6 +153,7 @@ interface AbstractCarrierInterface * * @param int|float $weight * @return int|float weight + * @api */ public function getTotalNumOfBoxes($weight); @@ -141,6 +161,7 @@ interface AbstractCarrierInterface * Is state province required * * @return bool + * @api */ public function isStateProvinceRequired(); @@ -148,6 +169,7 @@ interface AbstractCarrierInterface * Check if city option required * * @return bool + * @api */ public function isCityRequired(); @@ -156,6 +178,7 @@ interface AbstractCarrierInterface * * @param string|null $countryId * @return bool + * @api */ public function isZipCodeRequired($countryId = null); @@ -164,6 +187,7 @@ interface AbstractCarrierInterface * * @param mixed $debugData * @return void + * @api */ public function debugData($debugData); @@ -171,6 +195,7 @@ interface AbstractCarrierInterface * Getter for carrier code * * @return string + * @api */ public function getCarrierCode(); @@ -179,6 +204,7 @@ interface AbstractCarrierInterface * * @param \Magento\Framework\Object $params * @return array + * @api */ public function getContentTypes(\Magento\Framework\Object $params); } diff --git a/app/code/Magento/Shipping/Model/Carrier/AbstractCarrierOnline.php b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrierOnline.php index e4f38e73beec05dc3b6955429b04c0ffa6af97e8..99e544593f16bc73c2b191233afa2ffe99184657 100644 --- a/app/code/Magento/Shipping/Model/Carrier/AbstractCarrierOnline.php +++ b/app/code/Magento/Shipping/Model/Carrier/AbstractCarrierOnline.php @@ -157,6 +157,7 @@ abstract class AbstractCarrierOnline extends AbstractCarrier * * @param string $code * @return $this + * @api */ public function setActiveFlag($code = 'active') { @@ -179,6 +180,7 @@ abstract class AbstractCarrierOnline extends AbstractCarrier * * @param string $tracking * @return string|false + * @api */ public function getTrackingInfo($tracking) { @@ -249,6 +251,7 @@ abstract class AbstractCarrierOnline extends AbstractCarrier * @param RateRequest $request * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @api */ public function getAllItems(RateRequest $request) { @@ -279,12 +282,12 @@ abstract class AbstractCarrierOnline extends AbstractCarrier /** * Processing additional validation to check if carrier applicable. * - * @param RateRequest $request - * @return $this|bool|Error + * @param \Magento\Framework\Object $request + * @return $this|bool|\Magento\Framework\Object * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function proccessAdditionalValidation(RateRequest $request) + public function proccessAdditionalValidation(\Magento\Framework\Object $request) { //Skip by item validation if there is no items in request if (!count($this->getAllItems($request))) { @@ -523,6 +526,7 @@ abstract class AbstractCarrierOnline extends AbstractCarrier * * @todo implement rollback logic * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function rollBack($data) { @@ -572,6 +576,7 @@ abstract class AbstractCarrierOnline extends AbstractCarrier * @param null|string $countyDest * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @api */ public function isGirthAllowed($countyDest = null) { @@ -581,6 +586,7 @@ abstract class AbstractCarrierOnline extends AbstractCarrier /** * @param \Magento\Framework\Object|null $request * @return $this + * @api */ public function setRawRequest($request) { @@ -594,6 +600,7 @@ abstract class AbstractCarrierOnline extends AbstractCarrier * @param string $cost * @param string $method * @return float|string + * @api */ public function getMethodPrice($cost, $method = '') { @@ -615,6 +622,7 @@ abstract class AbstractCarrierOnline extends AbstractCarrier * @param string $customSimplexml * * @return \SimpleXMLElement|bool + * @api */ public function parseXml($xmlContent, $customSimplexml = 'SimpleXMLElement') { diff --git a/app/code/Magento/Shipping/Model/Carrier/CarrierInterface.php b/app/code/Magento/Shipping/Model/Carrier/CarrierInterface.php index 980fe636356a5edcac7dc153e174085d21ac2c28..f422d20a9e3a3ed33ce3c5f560c1d4d57589d84a 100644 --- a/app/code/Magento/Shipping/Model/Carrier/CarrierInterface.php +++ b/app/code/Magento/Shipping/Model/Carrier/CarrierInterface.php @@ -11,6 +11,7 @@ interface CarrierInterface * Check if carrier has shipping tracking option available * * @return boolean + * @api */ public function isTrackingAvailable(); @@ -18,6 +19,7 @@ interface CarrierInterface * Get allowed shipping methods * * @return array + * @api */ public function getAllowedMethods(); } diff --git a/app/code/Magento/Shipping/Model/CarrierFactory.php b/app/code/Magento/Shipping/Model/CarrierFactory.php index ac7dcc25146347f60e41e5e6696a02b171dc1c1a..699a7a3be09aa754363f208b337b5d3e416fa832 100644 --- a/app/code/Magento/Shipping/Model/CarrierFactory.php +++ b/app/code/Magento/Shipping/Model/CarrierFactory.php @@ -5,8 +5,9 @@ */ namespace Magento\Shipping\Model; -use Magento\Quote\Model\Quote\Address\CarrierFactoryInterface; - +/** + * Class CarrierFactory + */ class CarrierFactory implements CarrierFactoryInterface { /** diff --git a/app/code/Magento/Quote/Model/Quote/Address/CarrierFactoryInterface.php b/app/code/Magento/Shipping/Model/CarrierFactoryInterface.php similarity index 83% rename from app/code/Magento/Quote/Model/Quote/Address/CarrierFactoryInterface.php rename to app/code/Magento/Shipping/Model/CarrierFactoryInterface.php index 9cd570db6feeccecbecad70df05a0ba2a58ab44e..2c0ac4c801d2f21ae0746930329689e5fb0f2e11 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/CarrierFactoryInterface.php +++ b/app/code/Magento/Shipping/Model/CarrierFactoryInterface.php @@ -3,8 +3,13 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Quote\Model\Quote\Address; +namespace Magento\Shipping\Model; +use Magento\Shipping\Model\Carrier\AbstractCarrierInterface; + +/** + * Interface CarrierFactoryInterface + */ interface CarrierFactoryInterface { /** @@ -12,6 +17,7 @@ interface CarrierFactoryInterface * * @param string $carrierCode * @return bool|AbstractCarrierInterface + * @api */ public function get($carrierCode); @@ -21,6 +27,7 @@ interface CarrierFactoryInterface * @param string $carrierCode * @param int|null $storeId * @return bool|AbstractCarrierInterface + * @api */ public function create($carrierCode, $storeId = null); @@ -29,6 +36,7 @@ interface CarrierFactoryInterface * * @param string $carrierCode * @return bool|AbstractCarrierInterface + * @api */ public function getIfActive($carrierCode); @@ -38,6 +46,7 @@ interface CarrierFactoryInterface * @param string $carrierCode * @param null|int $storeId * @return bool|AbstractCarrierInterface + * @api */ public function createIfActive($carrierCode, $storeId = null); } diff --git a/app/code/Magento/Shipping/etc/di.xml b/app/code/Magento/Shipping/etc/di.xml index 92fad82f65d25fb31c36ebc8f3de56a5b3abb8d7..9b785dac596f1f2a0bf2addc690fa8ca8cec1799 100644 --- a/app/code/Magento/Shipping/etc/di.xml +++ b/app/code/Magento/Shipping/etc/di.xml @@ -7,6 +7,6 @@ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <preference for="Magento\Quote\Model\Quote\Address\RateCollectorInterface" type="Magento\Shipping\Model\Shipping" /> - <preference for="Magento\Quote\Model\Quote\Address\CarrierFactoryInterface" type="Magento\Shipping\Model\CarrierFactory" /> + <preference for="Magento\Shipping\Model\CarrierFactoryInterface" type="Magento\Shipping\Model\CarrierFactory" /> <preference for="Magento\Shipping\Model\Carrier\Source\GenericInterface" type="\Magento\Shipping\Model\Carrier\Source\GenericDefault" /> </config> diff --git a/app/code/Magento/Ups/Model/Carrier.php b/app/code/Magento/Ups/Model/Carrier.php index e88b68ea433cafc08dba11c7c4dbec7547c6aaf8..3085a8b35c988766d5d48820d5727fc498c1bf65 100644 --- a/app/code/Magento/Ups/Model/Carrier.php +++ b/app/code/Magento/Ups/Model/Carrier.php @@ -184,10 +184,10 @@ class Carrier extends AbstractCarrierOnline implements CarrierInterface /** * Collect and get rates * - * @param RateRequest $request + * @param \Magento\Framework\Object $request * @return Result|bool|null */ - public function collectRates(RateRequest $request) + public function collectRates(\Magento\Framework\Object $request) { if (!$this->getConfigFlag($this->_activeFlag)) { return false; diff --git a/app/code/Magento/Usps/Model/Carrier.php b/app/code/Magento/Usps/Model/Carrier.php index 49976c39fef46b183e6fd46190f5a28edfd11336..2d7845696c840f6695756459fa162e9c1832b5b5 100644 --- a/app/code/Magento/Usps/Model/Carrier.php +++ b/app/code/Magento/Usps/Model/Carrier.php @@ -177,10 +177,10 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C /** * Collect and get rates * - * @param \Magento\Quote\Model\Quote\Address\RateRequest $request + * @param \Magento\Framework\Object $request * @return Result|bool|null */ - public function collectRates(\Magento\Quote\Model\Quote\Address\RateRequest $request) + public function collectRates(\Magento\Framework\Object $request) { if (!$this->getConfigFlag($this->_activeFlag)) { return false; diff --git a/bin/magento b/bin/magento old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json index c8721c87609c6a84b5b35d2abd2e15b2f0fddbdb..907d23ff711529e697064e42d0eab2a6c2465669 100644 --- a/composer.json +++ b/composer.json @@ -63,6 +63,7 @@ "magento/module-backend": "self.version", "magento/module-backup": "self.version", "magento/module-bundle": "self.version", + "magento/module-cache-invalidate": "self.version", "magento/module-captcha": "self.version", "magento/module-catalog": "self.version", "magento/module-catalog-import-export": "self.version", diff --git a/composer.lock b/composer.lock index 02e531e791e517c23da1202be3be61491553ec1d..1850375542413cf443c72fd68f36fd6fe6b21d7f 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": "974fa7d59a25f8a31c70ea53068944cd", + "hash": "35d05640e3dc260b7a5b09310611194a", "packages": [ { "name": "composer/composer", @@ -2007,16 +2007,16 @@ }, { "name": "fabpot/php-cs-fixer", - "version": "v1.6.1", + "version": "v1.6.2", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "14f802b2c00b672676d55612e3c0d03465b69bf6" + "reference": "a574ba148953fea1f78428d4b7c6843e759711f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/14f802b2c00b672676d55612e3c0d03465b69bf6", - "reference": "14f802b2c00b672676d55612e3c0d03465b69bf6", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/a574ba148953fea1f78428d4b7c6843e759711f3", + "reference": "a574ba148953fea1f78428d4b7c6843e759711f3", "shasum": "" }, "require": { @@ -2056,7 +2056,7 @@ } ], "description": "A script to automatically fix Symfony Coding Standard", - "time": "2015-04-09 19:10:26" + "time": "2015-04-13 21:33:33" }, { "name": "league/climate", @@ -2272,16 +2272,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "2.0.15", + "version": "2.0.16", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "34cc484af1ca149188d0d9e91412191e398e0b67" + "reference": "934fd03eb6840508231a7f73eb8940cf32c3b66c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/34cc484af1ca149188d0d9e91412191e398e0b67", - "reference": "34cc484af1ca149188d0d9e91412191e398e0b67", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/934fd03eb6840508231a7f73eb8940cf32c3b66c", + "reference": "934fd03eb6840508231a7f73eb8940cf32c3b66c", "shasum": "" }, "require": { @@ -2330,7 +2330,7 @@ "testing", "xunit" ], - "time": "2015-01-24 10:06:35" + "time": "2015-04-11 04:35:00" }, { "name": "phpunit/php-file-iterator", diff --git a/dev/tests/api-functional/config/install-config-mysql.php.dist b/dev/tests/api-functional/config/install-config-mysql.php.dist index 96949ee5bf8ab889adceb33e4a1d353e73dc3dac..535cfb7232e8f1ef2a58a98916fe49b98bea5d6a 100644 --- a/dev/tests/api-functional/config/install-config-mysql.php.dist +++ b/dev/tests/api-functional/config/install-config-mysql.php.dist @@ -12,7 +12,7 @@ return [ 'db_host' => 'localhost', 'db_name' => 'magento_functional_tests', 'db_user' => 'root', - 'db_pass' => '', + 'db_password' => '', 'backend_frontname' => 'backend', 'base_url' => 'http://localhost/', 'use_secure' => '0', @@ -20,7 +20,7 @@ return [ 'admin_lastname' => 'Admin', 'admin_firstname' => 'Admin', 'admin_email' => 'admin@example.com', - 'admin_username' => 'admin', + 'admin_user' => 'admin', 'admin_password' => '123123q', 'admin_use_security_key' => '0', /* PayPal has limitation for order number - 20 characters. 10 digits prefix + 8 digits number is good enough */ diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php b/dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php index 0695e5fbe7dd5b3dc5349d9bd9fc029cbec26229..56936fa716784c7ea003afd93e87ab31da048817 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php @@ -33,7 +33,7 @@ class WebApiApplication extends Application /* Install application */ if ($installOptions) { - $installCmd = 'php -f ' . BP . '/setup/index.php install'; + $installCmd = 'php -f ' . BP . '/bin/magento setup:install'; $installArgs = []; foreach ($installOptions as $optionName => $optionValue) { if (is_bool($optionValue)) { diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php index 74ec107e09a60690f1292e847fbc0a5c289f41b0..fbfb262f1206d798a750dcfede4c913b96eed3c5 100644 --- a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php +++ b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.php @@ -90,7 +90,7 @@ class InstallTest extends Injectable { $magentoBaseDir = dirname(dirname(dirname(MTF_BP))); // Uninstall Magento. - shell_exec("php -f $magentoBaseDir/setup/index.php uninstall"); + shell_exec("php -f $magentoBaseDir/bin/magento setup:uninstall -n"); $this->installPage = $installPage; $this->homePage = $homePage; } diff --git a/dev/tests/integration/etc/install-config-mysql.php.dist b/dev/tests/integration/etc/install-config-mysql.php.dist index 391e1a7679b00c152b165b379be8bd5d9ea508bb..0d8fb591eb14454b4d3c46045e3606ab6e47dea3 100644 --- a/dev/tests/integration/etc/install-config-mysql.php.dist +++ b/dev/tests/integration/etc/install-config-mysql.php.dist @@ -7,11 +7,11 @@ return [ 'db_host' => 'localhost', 'db_user' => 'root', - 'db_pass' => '', + 'db_password' => '', 'db_name' => 'magento_integration_tests', 'db_prefix' => '', 'backend_frontname' => 'backend', - 'admin_username' => \Magento\TestFramework\Bootstrap::ADMIN_NAME, + 'admin_user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME, 'admin_password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD, 'admin_email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL, 'admin_firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME, diff --git a/dev/tests/integration/etc/install-config-mysql.travis.php.dist b/dev/tests/integration/etc/install-config-mysql.travis.php.dist index e91586f30315cc3503c109520869dfca388ac02d..a0e25fd80384beb21201843bca7e59a435a26c34 100644 --- a/dev/tests/integration/etc/install-config-mysql.travis.php.dist +++ b/dev/tests/integration/etc/install-config-mysql.travis.php.dist @@ -7,11 +7,11 @@ return [ 'db_host' => '127.0.0.1', 'db_user' => 'travis', - 'db_pass' => '', + 'db_password' => '', 'db_name' => 'magento_integration_tests', 'db_prefix' => 'travis_', 'backend_frontname' => 'backend', - 'admin_username' => \Magento\TestFramework\Bootstrap::ADMIN_NAME, + 'admin_user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME, 'admin_password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD, 'admin_email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL, 'admin_firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME, diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index 385e1a76b951607ec52a9ce1f6a8e383c2ae7952..d8aee09eb186a8a531ec1fb6f49790fc770d038d 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -174,7 +174,7 @@ class Application $installConfig = $this->getInstallConfig(); $host = $installConfig['db_host']; $user = $installConfig['db_user']; - $password = $installConfig['db_pass']; + $password = $installConfig['db_password']; $dbName = $installConfig['db_name']; } $this->_db = new Db\Mysql( @@ -371,12 +371,16 @@ class Application */ public function cleanup() { + $this->_ensureDirExists($this->installDir); + $this->_ensureDirExists($this->_configDir); + + $this->copyAppConfigFiles(); /** * @see \Magento\Setup\Mvc\Bootstrap\InitParamListener::BOOTSTRAP_PARAM */ $this->_shell->execute( - 'php -f %s uninstall --magento_init_params=%s', - [BP . '/setup/index.php', $this->getInitParamsQuery()] + 'php -f %s setup:uninstall -n --magento_init_params=%s', + [BP . '/bin/magento', $this->getInitParamsQuery()] ); } @@ -407,8 +411,8 @@ class Application // run install script $this->_shell->execute( - 'php -f %s install ' . implode(' ', array_keys($installParams)), - array_merge([BP . '/setup/index.php'], array_values($installParams)) + 'php -f %s setup:install ' . implode(' ', array_keys($installParams)), + array_merge([BP . '/bin/magento'], array_values($installParams)) ); // enable only specified list of caches diff --git a/dev/tests/integration/framework/Magento/TestFramework/ObjectManager/Configurator.php b/dev/tests/integration/framework/Magento/TestFramework/ObjectManager/Configurator.php index 24f9e0bf8799f6f3e9e7a92eef545625cddf847a..c236ee4aa214ca8bf07112c729277d7aedd2f0db 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/ObjectManager/Configurator.php +++ b/dev/tests/integration/framework/Magento/TestFramework/ObjectManager/Configurator.php @@ -16,7 +16,6 @@ class Configurator implements \Magento\Framework\ObjectManager\DynamicConfigInte { return [ 'preferences' => [ - 'Magento\Framework\Stdlib\Cookie' => 'Magento\TestFramework\Cookie', 'Magento\Framework\Stdlib\CookieManagerInterface' => 'Magento\TestFramework\CookieManager', ] ]; diff --git a/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php b/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php index 8cebbc8f76dfcfe7677bb0c52a03950f3bdf9cac..e499e0d929ae159842558b2b45a4ece21bde8438 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php +++ b/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php @@ -95,7 +95,6 @@ class ObjectManagerFactory extends \Magento\Framework\App\ObjectManagerFactory 'Magento\Framework\Stdlib\CookieManagerInterface' => 'Magento\TestFramework\CookieManager', 'Magento\Framework\ObjectManager\DynamicConfigInterface' => '\Magento\TestFramework\ObjectManager\Configurator', - 'Magento\Framework\Stdlib\Cookie' => 'Magento\TestFramework\Cookie', 'Magento\Framework\App\RequestInterface' => 'Magento\TestFramework\Request', 'Magento\Framework\App\Request\Http' => 'Magento\TestFramework\Request', 'Magento\Framework\App\ResponseInterface' => 'Magento\TestFramework\Response', diff --git a/dev/tests/integration/testsuite/Magento/Framework/Module/Plugin/DbStatusValidatorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Module/Plugin/DbStatusValidatorTest.php index e9d78a0385a79b2f798f4fbb21ad8fc7b0881520..3591424ed146ec0e576106d5cd9bbb1203ffb7c2 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Module/Plugin/DbStatusValidatorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Module/Plugin/DbStatusValidatorTest.php @@ -15,7 +15,7 @@ class DbStatusValidatorTest extends \Magento\TestFramework\TestCase\AbstractCont /** * @magentoDbIsolation enabled * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Please update your database + * @expectedExceptionMessage Please upgrade your database */ public function testValidationOutdatedDb() { diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Resource/QuoteTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Resource/QuoteTest.php deleted file mode 100644 index 7b3f1e37c8db98dd810ec1553d1033b9159022dd..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/Resource/QuoteTest.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Sales\Model\Resource; - -class QuoteTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Quote\Model\Resource\Quote - */ - protected $_resourceModel; - - protected function setUp() - { - $this->_resourceModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - 'Magento\Quote\Model\Resource\Quote' - ); - } - - /** - * @magentoDataFixture Magento/Sales/_files/order.php - */ - public function testIsOrderIncrementIdUsedNumericIncrementId() - { - $this->assertTrue($this->_resourceModel->isOrderIncrementIdUsed('100000001')); - } - - /** - * @magentoDataFixture Magento/Sales/_files/order_alphanumeric_id.php - */ - public function testIsOrderIncrementIdUsedAlphanumericIncrementId() - { - $this->assertTrue($this->_resourceModel->isOrderIncrementIdUsed('M00000001')); - } -} diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order_info.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order_info.php index 1862adfcee81f7a0d9a509e88b0d51b9febd2b05..c476e27898e83aa6c0632abe182c97d668349729 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/order_info.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/order_info.php @@ -48,7 +48,7 @@ $quote->setCustomerIsGuest( 'Magento\Store\Model\StoreManagerInterface' )->getStore()->getId() )->setReservedOrderId( - 'test01' + '100000001' )->setBillingAddress( $billingAddress )->setShippingAddress( diff --git a/dev/tests/performance/config.php.dist b/dev/tests/performance/config.php.dist index 64c8f2f5c2ec30e6160500dc4b3a65d63b750ca3..e145b9768ffe2d8b6178edc2e718e0c8220d0770 100644 --- a/dev/tests/performance/config.php.dist +++ b/dev/tests/performance/config.php.dist @@ -16,14 +16,14 @@ return array( 'db_host' => 'localhost', 'db_name' => 'magento', 'db_user' => 'root', - 'db_pass' => '', + 'db_password' => '', 'use_secure' => '0', 'use_secure_admin' => '0', 'use_rewrites' => '0', 'admin_lastname' => 'Admin', 'admin_firstname' => 'Admin', 'admin_email' => 'admin@example.com', - 'admin_username' => 'admin', + 'admin_user' => 'admin', 'admin_password' => '123123q', 'admin_use_security_key' => '0', 'backend_frontname' => 'backend', diff --git a/dev/tests/performance/framework/Magento/TestFramework/Application.php b/dev/tests/performance/framework/Magento/TestFramework/Application.php index d3728db16b2fb43d6959c29772b3104c7a5d4647..d236858ef259a39473edec5fc8df71fdae81d41a 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Application.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Application.php @@ -63,9 +63,9 @@ class Application \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\Shell $shell ) { - $shellDir = $config->getApplicationBaseDir() . '/setup'; + $shellDir = $config->getApplicationBaseDir() . '/bin'; $this->_objectManager = $objectManager; - $this->_script = $this->_assertPath($shellDir . '/index.php'); + $this->_script = $this->_assertPath($shellDir . '/magento'); $this->_config = $config; $this->_shell = $shell; } @@ -130,7 +130,7 @@ class Application */ protected function _uninstall() { - $this->_shell->execute('php -f %s uninstall', [$this->_script]); + $this->_shell->execute('php -f %s setup:uninstall -n', [$this->_script]); $this->_isInstalled = false; $this->_fixtures = []; @@ -157,7 +157,7 @@ class Application // Populate install options with global options $baseUrl = 'http://' . $this->_config->getApplicationUrlHost() . $this->_config->getApplicationUrlPath(); $installOptions = array_merge($installOptions, ['base_url' => $baseUrl, 'base_url_secure' => $baseUrl]); - $installCmd = 'php -f %s install'; + $installCmd = 'php -f %s setup:install'; $installCmdArgs = [$this->_script]; foreach ($installOptions as $optionName => $optionValue) { $installCmd .= " --{$optionName}=%s"; diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Config.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Config.php index f0a6f141fad07c67e1da25ee39666e4c0bcc44da..bd01b881c6bb9bb427690147be710d7a21a1900f 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Config.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Config.php @@ -117,7 +117,7 @@ class Config } // Validate admin options data - $requiredAdminKeys = ['admin_username', 'admin_password', 'backend_frontname']; + $requiredAdminKeys = ['admin_user', 'admin_password', 'backend_frontname']; foreach ($requiredAdminKeys as $requiredKeyName) { if (empty($configData['application']['installation']['options'][$requiredKeyName])) { throw new \Magento\Framework\Exception\LocalizedException( @@ -278,7 +278,7 @@ class Config \Magento\TestFramework\Performance\Scenario::ARG_PATH => $this->getApplicationUrlPath(), \Magento\TestFramework\Performance\Scenario::ARG_BASEDIR => $this->getApplicationBaseDir(), \Magento\TestFramework\Performance\Scenario::ARG_BACKEND_FRONTNAME => $options['backend_frontname'], - \Magento\TestFramework\Performance\Scenario::ARG_ADMIN_USERNAME => $options['admin_username'], + \Magento\TestFramework\Performance\Scenario::ARG_ADMIN_USER => $options['admin_user'], \Magento\TestFramework\Performance\Scenario::ARG_ADMIN_PASSWORD => $options['admin_password'], 'jmeter.save.saveservice.output_format' => 'xml', ]; diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario.php index 8de697f07f641922b5c676589db8b1d6e754defd..ab19c64f5aebea70028fa971cd2b2c8a96995ee8 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario.php @@ -24,7 +24,7 @@ class Scenario const ARG_BASEDIR = 'basedir'; - const ARG_ADMIN_USERNAME = 'admin_username'; + const ARG_ADMIN_USER = 'admin_user'; const ARG_ADMIN_PASSWORD = 'admin_password'; diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php index f6598461c8823a3e7bc721677b0532bb6c426471..1ae2bf1fbe1424a68c21aa0449f40fed380ebee7 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/ApplicationTest.php @@ -49,7 +49,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $this->_fixtureDir = __DIR__ . '/Performance/_files'; $this->_fixtureConfigData = require $this->_fixtureDir . '/config_data.php'; - $this->_script = realpath($this->_fixtureDir . '/app_base_dir/setup/index.php'); + $this->_script = realpath($this->_fixtureDir . '/app_base_dir/bin/magento'); $this->_config = new \Magento\TestFramework\Performance\Config( $this->_fixtureConfigData, diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/ConfigTest.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/ConfigTest.php index 7b2513aa5756a363d5c01953e33d2614a6829735..39685b58894125220e63fd532b39f5b0f54282ac 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/ConfigTest.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/ConfigTest.php @@ -145,7 +145,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase 'option1' => 'value 1', 'option2' => 'value 2', 'backend_frontname' => 'backend', - 'admin_username' => 'admin', + 'admin_user' => 'admin', 'admin_password' => 'password1', ]; $this->assertEquals($expectedOptions, $this->_object->getInstallOptions()); @@ -174,7 +174,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase \Magento\TestFramework\Performance\Scenario::ARG_HOST => '127.0.0.1', \Magento\TestFramework\Performance\Scenario::ARG_PATH => '/', \Magento\TestFramework\Performance\Scenario::ARG_BACKEND_FRONTNAME => 'backend', - \Magento\TestFramework\Performance\Scenario::ARG_ADMIN_USERNAME => 'admin', + \Magento\TestFramework\Performance\Scenario::ARG_ADMIN_USER => 'admin', \Magento\TestFramework\Performance\Scenario::ARG_ADMIN_PASSWORD => 'password1', \Magento\TestFramework\Performance\Scenario::ARG_BASEDIR => $this->_getFixtureAppBaseDir(), 'arg1' => 'value 1', diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/app_base_dir/setup/index.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/app_base_dir/bin/magento old mode 100644 new mode 100755 similarity index 63% rename from dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/app_base_dir/setup/index.php rename to dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/app_base_dir/bin/magento index 05d5a3da741d1b858cb44e560f8d7943b3a37b61..977e41071374b98a96f51beca2295bccb6257f31 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/app_base_dir/setup/index.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/app_base_dir/bin/magento @@ -1,7 +1,6 @@ +#!/usr/bin/env php <?php /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. - */ - -/* Magento console installer and uninstaller stub */ + */ \ No newline at end of file diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_dist/config.php.dist b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_dist/config.php.dist index 0cd631bf84000bc11af10f98f8c5323a8b9a4ffb..6db1c505bff49c76b7f1472e68c6f83022d73eb4 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_dist/config.php.dist +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_dist/config.php.dist @@ -11,7 +11,7 @@ return array( 'installation' => array( 'options' => array( 'backend_frontname' => 'backend', - 'admin_username' => 'admin', + 'admin_user' => 'admin', 'admin_password' => 'password1', ), ), diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_normal/config.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_normal/config.php index 2b9ae184e4992ef733eea09018062572bf32aab3..463b896d34d68ed13d2a2b1dd7c1c70e1d8e9126 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_normal/config.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_normal/config.php @@ -11,7 +11,7 @@ return [ 'installation' => [ 'options' => [ 'backend_frontname' => 'backend', - 'admin_username' => 'admin', + 'admin_user' => 'admin', 'admin_password' => 'password1', ], ], diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_normal/config.php.dist b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_normal/config.php.dist index 3683444b83ec9d789b85c0fb65de468d69470ea0..577aadcc45bac471f1262da433d3ae0decc30fd3 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_normal/config.php.dist +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/bootstrap/config_normal/config.php.dist @@ -11,7 +11,7 @@ return array( 'installation' => array( 'options' => array( 'backend_frontname' => 'backend', - 'admin_username' => 'admin', + 'admin_user' => 'admin', 'admin_password' => 'password1', ), ), diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/config_data.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/config_data.php index 71ccf65e663e82806a1a7ed62047427848b32367..eaa852c5e31a6ece36b932dfac4c552430aee3dd 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/config_data.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/config_data.php @@ -13,7 +13,7 @@ return [ 'option1' => 'value 1', 'option2' => 'value 2', 'backend_frontname' => 'backend', - 'admin_username' => 'admin', + 'admin_user' => 'admin', 'admin_password' => 'password1', ], ], diff --git a/dev/tests/performance/testsuite/backend.jmx b/dev/tests/performance/testsuite/backend.jmx index 676738bf52fca0704c7d0423b354fb8cc2677d68..fbf480529e8084e7895f66a1541972d697f9e046 100644 --- a/dev/tests/performance/testsuite/backend.jmx +++ b/dev/tests/performance/testsuite/backend.jmx @@ -25,9 +25,9 @@ <stringProp name="Argument.value">${__P(path,/)}${__P(backend_frontname,backend)}/</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> - <elementProp name="ADMIN_USERNAME" elementType="Argument"> - <stringProp name="Argument.name">ADMIN_USERNAME</stringProp> - <stringProp name="Argument.value">${__P(admin_username,admin)}</stringProp> + <elementProp name="ADMIN_USER" elementType="Argument"> + <stringProp name="Argument.name">ADMIN_USER</stringProp> + <stringProp name="Argument.value">${__P(admin_user,admin)}</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="ADMIN_PASSWORD" elementType="Argument"> diff --git a/dev/tests/performance/testsuite/checkout.jmx b/dev/tests/performance/testsuite/checkout.jmx index d456fecd95ab1f6b634fec4e1e95de92482da39c..5dda04cb25a9e0a66328da0833506d92c7f7a71a 100644 --- a/dev/tests/performance/testsuite/checkout.jmx +++ b/dev/tests/performance/testsuite/checkout.jmx @@ -45,9 +45,9 @@ <stringProp name="Argument.value">${__P(path,/)}${__P(backend_frontname,backend)}/</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> - <elementProp name="ADMIN_USERNAME" elementType="Argument"> - <stringProp name="Argument.name">ADMIN_USERNAME</stringProp> - <stringProp name="Argument.value">${__P(admin_username,admin)}</stringProp> + <elementProp name="ADMIN_USER" elementType="Argument"> + <stringProp name="Argument.name">ADMIN_USER</stringProp> + <stringProp name="Argument.value">${__P(admin_user,admin)}</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="ADMIN_PASSWORD" elementType="Argument"> diff --git a/dev/tests/performance/testsuite/product_edit.jmx b/dev/tests/performance/testsuite/product_edit.jmx index 67fb78717f44d4004e5a090a50f44c97f26b4403..199c36235c16396d48dcfed93ed116ec14dd5b72 100644 --- a/dev/tests/performance/testsuite/product_edit.jmx +++ b/dev/tests/performance/testsuite/product_edit.jmx @@ -35,9 +35,9 @@ <stringProp name="Argument.value">${__P(loops,1)}</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> - <elementProp name="ADMIN_USERNAME" elementType="Argument"> - <stringProp name="Argument.name">ADMIN_USERNAME</stringProp> - <stringProp name="Argument.value">${__P(admin_username,admin)}</stringProp> + <elementProp name="ADMIN_USER" elementType="Argument"> + <stringProp name="Argument.name">ADMIN_USER</stringProp> + <stringProp name="Argument.value">${__P(admin_user,admin)}</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="ADMIN_PASSWORD" elementType="Argument"> diff --git a/dev/tests/performance/testsuite/reusable/admin_login.jmx b/dev/tests/performance/testsuite/reusable/admin_login.jmx index 96d8b96335ba6781c68e07645844f0665bc4e80a..6d271217d8989d6d97eb0aaf52f9627c5ddcb9f8 100644 --- a/dev/tests/performance/testsuite/reusable/admin_login.jmx +++ b/dev/tests/performance/testsuite/reusable/admin_login.jmx @@ -10,7 +10,7 @@ <jmeterTestPlan version="1.2" properties="2.4" jmeter="2.9 r1437961"> <hashTree> <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Admin - Login" enabled="true"> - <stringProp name="TestPlan.comments">Reusable scenario to log-in to admin backend. Needs: HOST, ADMIN_PATH, ADMIN_USERNAME, ADMIN_PASSWORD, Http Cookie Manager</stringProp> + <stringProp name="TestPlan.comments">Reusable scenario to log-in to admin backend. Needs: HOST, ADMIN_PATH, ADMIN_USER, ADMIN_PASSWORD, Http Cookie Manager</stringProp> <boolProp name="TestPlan.functional_mode">false</boolProp> <boolProp name="TestPlan.serialize_threadgroups">false</boolProp> <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> @@ -77,7 +77,7 @@ <collectionProp name="Arguments.arguments"> <elementProp name="login[username]" elementType="HTTPArgument"> <boolProp name="HTTPArgument.always_encode">false</boolProp> - <stringProp name="Argument.value">${ADMIN_USERNAME}</stringProp> + <stringProp name="Argument.value">${ADMIN_USER}</stringProp> <stringProp name="Argument.metadata">=</stringProp> <boolProp name="HTTPArgument.use_equals">true</boolProp> <stringProp name="Argument.name">login[username]</stringProp> @@ -110,7 +110,7 @@ <hashTree> <ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Assert logged-in" enabled="true"> <collectionProp name="Asserion.test_strings"> - <stringProp name="934841248">${ADMIN_USERNAME}</stringProp> + <stringProp name="934841248">${ADMIN_USER}</stringProp> <stringProp name="-989788387">Account Setting</stringProp> <stringProp name="374398571">Sign Out</stringProp> </collectionProp> @@ -162,9 +162,9 @@ <stringProp name="Argument.value">${__P(path,/)}${__P(backend_frontname,backend)}/</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> - <elementProp name="ADMIN_USERNAME" elementType="Argument"> - <stringProp name="Argument.name">ADMIN_USERNAME</stringProp> - <stringProp name="Argument.value">${__P(admin_username,admin)}</stringProp> + <elementProp name="ADMIN_USER" elementType="Argument"> + <stringProp name="Argument.name">ADMIN_USER</stringProp> + <stringProp name="Argument.value">${__P(admin_user,admin)}</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="ADMIN_PASSWORD" elementType="Argument"> diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php index 0d5d3848cfe6a4cc34ec66e67c47b5dbe432755f..b190aee7f88acc5bd18af6e1f986472dd6c35627 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ClassesTest.php @@ -69,7 +69,7 @@ class ClassesTest extends \PHPUnit_Framework_TestCase $this->_assertClassesExist($classes, $file); }, - \Magento\Framework\App\Utility\Files::init()->getPhpFiles() + \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, true, true, true, false) ); } @@ -530,29 +530,11 @@ class ClassesTest extends \PHPUnit_Framework_TestCase { $files = \Magento\Framework\App\Utility\Files::init(); $errors = []; - $fileList = $files->getFiles( - [ - BP . '/dev/tests/integration', - BP . '/app/code/*/*/Test/Unit', - BP . '/lib/internal/*/*/*/Test/Unit', - BP . '/lib/internal/Magento/Framework/Test/Unit', - BP . '/dev/tools/Magento/Tools/*/Test/Unit', - BP . '/setup/src/Magento/Setup/Test/Unit', - ], - '*.php' - ); - foreach ($fileList as $file) { + foreach ($files->getFiles([BP . '/dev/tests/{integration,unit}'], '*') as $file) { $code = file_get_contents($file); - if (preg_match_all( - '/@covers(DefaultClass)?\s+([\w\\\\]+)(::([\w\\\\]+))?/', - $code, - $matchesAll, - PREG_SET_ORDER - )) { - foreach ($matchesAll as $matches) { - if ($this->isNonexistentEntityCovered($matches)) { - $errors[] = $file . ': ' . $matches[0]; - } + if (preg_match('/@covers(DefaultClass)?\s+([\w\\\\]+)(::([\w\\\\]+))?/', $code, $matches)) { + if ($this->isNonexistentEntityCovered($matches)) { + $errors[] = $file . ': ' . $matches[0]; } } } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php index 8ed450ec926d9b46f33524ecb020ea74f99288e5..834e90911948bcba3d3ecc1a6dd945fbd9ef8988 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php @@ -428,7 +428,7 @@ class DependencyTest extends \PHPUnit_Framework_TestCase $files, $this->_prepareFiles( 'php', - \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, false, false, true), + \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, false, false, true, false), true ) ); @@ -490,7 +490,7 @@ class DependencyTest extends \PHPUnit_Framework_TestCase $pattern = '/(?<namespace>[A-Z][a-z]+)[_\/\\\\](?<module>[A-Z][a-zA-Z]+)\/Controller\/' . '(?<path>[\/\w]*).php/'; - $files = \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, false, false, false); + $files = \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, false, false, false, false); foreach ($files as $file) { if (preg_match($pattern, $file, $matches)) { $module = $matches['namespace'] . '\\' . $matches['module']; diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Layout/BlocksTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Layout/BlocksTest.php index ea2765ce171036f64a88335bd242ad4ff7bdbea4..16c026a76a57eba3b88e91c1acac28b2bdf85d39 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Layout/BlocksTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Layout/BlocksTest.php @@ -7,6 +7,8 @@ */ namespace Magento\Test\Integrity\Layout; +use Magento\Framework\App\Utility\Files; + class BlocksTest extends \PHPUnit_Framework_TestCase { /** @@ -24,7 +26,7 @@ class BlocksTest extends \PHPUnit_Framework_TestCase */ public static function setUpBeforeClass() { - foreach (\Magento\Framework\App\Utility\Files::init()->getLayoutFiles([], false) as $file) { + foreach (Files::init()->getLayoutFiles([], false) as $file) { $xml = simplexml_load_file($file); $elements = $xml->xpath('/layout//*[self::container or self::block]') ?: []; /** @var $node \SimpleXMLElement */ @@ -94,7 +96,7 @@ class BlocksTest extends \PHPUnit_Framework_TestCase public function getChildBlockDataProvider() { $result = []; - foreach (\Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, false, true, false) as $file) { + foreach (Files::init()->getPhpFiles(true, false, true, false, false) as $file) { $aliases = \Magento\Framework\App\Utility\Classes::getAllMatches( file_get_contents($file), '/\->getChildBlock\(\'([^\']+)\'\)/x' diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php index 3f6f7bfc288ee5b93346a83c38095c467e60604c..8d6cfb9d34ced8af8e26a9f4dfab7a415ab610fa 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Library/DependencyTest.php @@ -85,7 +85,7 @@ class DependencyTest extends \PHPUnit_Framework_TestCase ); } }, - $files->getPhpFiles(false, true, false) + $files->getPhpFiles(false, true, false, true, false) ); } diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/ClassesTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/ClassesTest.php index 69688b876fff576a26792afe985d4c246b04e8b5..593dd9d1c16bc91581c77c4362c4f384e970e8f6 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/ClassesTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/ClassesTest.php @@ -22,7 +22,7 @@ class ClassesTest extends \PHPUnit_Framework_TestCase $classes = \Magento\Framework\App\Utility\Classes::collectPhpCodeClasses(file_get_contents($file)); $this->_assertNonFactoryName($classes, $file); }, - \Magento\Framework\App\Utility\Files::init()->getPhpFiles() + \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, true, true, true, false) ); } diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/TableTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/TableTest.php index c1c8f263120d80a785bae0f27d3d3b4fbfe1e60d..6e99ef361a84dc2a1d2818e7f1a015f77d951639 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/TableTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/TableTest.php @@ -32,7 +32,7 @@ class TableTest extends \PHPUnit_Framework_TestCase $message = $this->_composeFoundsMessage($legacyTables); $this->assertEmpty($message, $message); }, - \Magento\Framework\App\Utility\Files::init()->getPhpFiles() + \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, true, true, true, false) ); } diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 23caf9785d635c97cb990dca0de79c1f5397aa92..5128893ec60054f5ef58a8bb2bf51abf9b76f694 100755 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3151,6 +3151,20 @@ return [ ['Magento\CatalogRule\CatalogRuleException'], ['Magento\Payment\Exception'], ['Magento\UrlRewrite\Model\Storage\DuplicateEntryException'], + ['Magento\Framework\App\DeploymentConfig\BackendConfig'], + ['Magento\Framework\App\DeploymentConfig\DbConfig'], + ['Magento\Framework\App\DeploymentConfig\InstallConfig'], + ['Magento\Framework\App\DeploymentConfig\ResourceConfig'], + ['Magento\Framework\App\DeploymentConfig\SessionConfig'], + ['Magento\Framework\App\DeploymentConfig\CacheConfig'], + ['Magento\Setup\Model\DeploymentConfigMapper'], + ['Magento\Framework\App\DeploymentConfig\EncryptConfig'], + ['Magento\Setup\Mvc\Console\RouteListener'], + ['Magento\Setup\Mvc\Console\RouteMatcher'], + ['Magento\Setup\Mvc\Console\VerboseValidator'], + ['Magento\Setup\Controller\ConsoleController'], + ['Magento\Setup\Model\UserConfigurationDataMapper', 'Magento\Setup\Model\StoreConfigurationDataMapper'], + ['Magento\Framework\App\State\Cleanup', 'Magento\Framework\App\State\CleanupFiles'], ['Magento\Eav\Exception'], ['Magento\Framework\Exception\File\ValidatorException'], ['Magento\Framework\Filesystem\FilesystemException', 'Magento\Framework\Exception\FileSystemException'], diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index 36a143317f30e558a4695c544ff38b9660c2ecc0..6a1f2846a85df46a6293a7fc8c210feddce5d60d 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -2163,4 +2163,5 @@ return [ ['addOrderedQty', 'Magento\Reports\Model\Resource\Product\Collection'], ['prepareForProductsInCarts', 'Magento\Reports\Model\Resource\Quote\Collection'], ['getOrdersSubSelect', 'Magento\Reports\Model\Resource\Quote\Collection'], + ['isOrderIncrementIdUsed', 'Magento\Quote\Model\Resource\Quote'], ]; diff --git a/dev/tools/Magento/Tools/Migration/factory_names.php b/dev/tools/Magento/Tools/Migration/factory_names.php index 9e17d616dbe8eeea9c9c7f7c2246ab46507f6b77..96b3dbe8c1b2ed15ca957706b2e1fb6159cc4306 100644 --- a/dev/tools/Magento/Tools/Migration/factory_names.php +++ b/dev/tools/Magento/Tools/Migration/factory_names.php @@ -8,7 +8,7 @@ require realpath(dirname(dirname(dirname(dirname(dirname(__DIR__)))))) . '/dev/tests/static/framework/bootstrap.php'; // PHP code -foreach (\Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, true, true, false) as $file) { +foreach (\Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, true, true, false, false) as $file) { $content = file_get_contents($file); $classes = \Magento\Framework\App\Utility\Classes::collectPhpCodeClasses($content); $factoryNames = array_filter($classes, 'isFactoryName'); diff --git a/dev/tools/Magento/Tools/Migration/factory_table_names.php b/dev/tools/Magento/Tools/Migration/factory_table_names.php index f38c8a35c724b07349d98a5b7e63b5b6cded5eac..6dfaa0a8e22fde0b3778387594b800a9d47e316d 100644 --- a/dev/tools/Magento/Tools/Migration/factory_table_names.php +++ b/dev/tools/Magento/Tools/Migration/factory_table_names.php @@ -32,7 +32,7 @@ require realpath(dirname(dirname(dirname(__DIR__)))) . '/dev/tests/static/framew $tablesAssociation = getFilesCombinedArray(__DIR__ . '/FactoryTableNames', 'replace_*.php'); $blackList = getFilesCombinedArray(__DIR__ . '/FactoryTableNames', 'blacklist_*.php'); -$phpFiles = \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, false, false, false); +$phpFiles = \Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, false, false, false, false); $replacementResult = false; if (!$isSearchTables || $isDryRunMode) { diff --git a/dev/tools/Magento/Tools/Migration/get_aliases_map.php b/dev/tools/Magento/Tools/Migration/get_aliases_map.php index 0db788c57f8900322e3de7c1d75c770c319717d6..d1abe748f9204b671afa01cb8fd07e8100f9b3bb 100644 --- a/dev/tools/Magento/Tools/Migration/get_aliases_map.php +++ b/dev/tools/Magento/Tools/Migration/get_aliases_map.php @@ -39,7 +39,7 @@ $utilityFiles = new Magento\Framework\App\Utility\Files($magentoBaseDir); $map = []; $compositeModules = getFilesCombinedArray(__DIR__ . '/aliases_map', '/^composite_modules_.*\.php$/'); // PHP code -foreach ($utilityFiles->getPhpFiles(true, true, true, false) as $file) { +foreach ($utilityFiles->getPhpFiles(true, true, true, false, false) as $file) { $content = file_get_contents($file); $classes = \Magento\Framework\App\Utility\Classes::collectPhpCodeClasses($content); if ($classes) { diff --git a/lib/internal/Magento/Framework/App/Bootstrap.php b/lib/internal/Magento/Framework/App/Bootstrap.php index 2099ee76e92d7d14fdbf45bca1f4b20a61d48b45..aaf238eadacaa007b8a7abe560095b6125d99c40 100644 --- a/lib/internal/Magento/Framework/App/Bootstrap.php +++ b/lib/internal/Magento/Framework/App/Bootstrap.php @@ -274,11 +274,11 @@ class Bootstrap $isOn = $this->maintenance->isOn(isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : ''); if ($isOn && !$isExpected) { $this->errorCode = self::ERR_MAINTENANCE; - throw new \Exception('Unable to proceed: the maintenance mode is enabled.'); + throw new \Exception('Unable to proceed: the maintenance mode is enabled. '); } if (!$isOn && $isExpected) { $this->errorCode = self::ERR_MAINTENANCE; - throw new \Exception('Unable to proceed: the maintenance mode must be enabled first.'); + throw new \Exception('Unable to proceed: the maintenance mode must be enabled first. '); } } @@ -298,11 +298,11 @@ class Bootstrap $isInstalled = $this->isInstalled(); if (!$isInstalled && $isExpected) { $this->errorCode = self::ERR_IS_INSTALLED; - throw new \Exception('Application is not installed yet.'); + throw new \Exception('Error: Application is not installed yet. '); } if ($isInstalled && !$isExpected) { $this->errorCode = self::ERR_IS_INSTALLED; - throw new \Exception('Application is already installed.'); + throw new \Exception('Error: Application is already installed. '); } } @@ -406,7 +406,7 @@ class Bootstrap if ($this->isDeveloperMode()) { echo $e; } else { - $message = "An error has happened during application run. See debug log for details.\n"; + $message = "An error has happened during application run. See exception log for details.\n"; try { if (!$this->objectManager) { throw new \DomainException(); diff --git a/lib/internal/Magento/Framework/App/State/Cleanup.php b/lib/internal/Magento/Framework/App/State/CleanupFiles.php similarity index 50% rename from lib/internal/Magento/Framework/App/State/Cleanup.php rename to lib/internal/Magento/Framework/App/State/CleanupFiles.php index 2a832f611b739386b9a244621dfe14b489dd335c..5509d78d60dc0dc0c7832db3da324afdd31ea501 100644 --- a/lib/internal/Magento/Framework/App/State/Cleanup.php +++ b/lib/internal/Magento/Framework/App/State/CleanupFiles.php @@ -6,23 +6,15 @@ namespace Magento\Framework\App\State; -use Magento\Framework\App\Cache\Frontend\Pool; use Magento\Framework\Filesystem; +use Magento\Framework\Exception\FileSystemException; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\View\Asset\Source; /** * A service for cleaning up application state */ -class Cleanup +class CleanupFiles { - /** - * Cache frontend pool - * - * @var Pool - */ - private $cachePool; - /** * File system * @@ -33,58 +25,60 @@ class Cleanup /** * Constructor * - * @param Pool $cachePool * @param Filesystem $filesystem */ - public function __construct(Pool $cachePool, Filesystem $filesystem) + public function __construct(Filesystem $filesystem) { - $this->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 + * @return string[] */ public function clearCodeGeneratedFiles() { - $this->clearCodeGeneratedClasses(); - $this->clearMaterializedViewFiles(); + return array_merge( + $this->clearCodeGeneratedClasses(), + $this->clearMaterializedViewFiles() + ); } /** * Clears code-generated classes * - * @return void + * @return string[] */ public function clearCodeGeneratedClasses() { - $this->emptyDir(DirectoryList::GENERATION); + return $this->emptyDir(DirectoryList::GENERATION); } /** * Clears materialized static view files * - * @return void + * @return string[] */ public function clearMaterializedViewFiles() { - $this->emptyDir(DirectoryList::STATIC_VIEW); - $this->emptyDir(DirectoryList::VAR_DIR, DirectoryList::TMP_MATERIALIZATION_DIR); + return array_merge( + $this->emptyDir(DirectoryList::STATIC_VIEW), + $this->emptyDir(DirectoryList::VAR_DIR, DirectoryList::TMP_MATERIALIZATION_DIR) + ); + } + + /** + * Clears all files + * + * @return string[] + */ + public function clearAllFiles() + { + return array_merge( + $this->emptyDir(DirectoryList::STATIC_VIEW), + $this->emptyDir(DirectoryList::VAR_DIR) + ); } /** @@ -92,15 +86,29 @@ class Cleanup * * @param string $code * @param string|null $subPath - * @return void + * @return string[] */ private function emptyDir($code, $subPath = null) { + $messages = []; + $dir = $this->filesystem->getDirectoryWrite($code); + $dirPath = $dir->getAbsolutePath(); + if (!$dir->isExist()) { + $messages[] = "The directory '{$dirPath}' doesn't exist - skipping cleanup"; + return $messages; + } foreach ($dir->search('*', $subPath) as $path) { if (false === strpos($path, '.')) { - $dir->delete($path); + $messages[] = $dirPath . $path; + try { + $dir->delete($path); + } catch (FilesystemException $e) { + $messages[] = $e->getMessage(); + } } } + + return $messages; } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/State/CleanupTest.php b/lib/internal/Magento/Framework/App/Test/Unit/State/CleanupFilesTest.php similarity index 57% rename from lib/internal/Magento/Framework/App/Test/Unit/State/CleanupTest.php rename to lib/internal/Magento/Framework/App/Test/Unit/State/CleanupFilesTest.php index ad3740f90d515796723b9503609e734adf506a09..f1290dcc139bc8bef9d1efff92947d1e2f5d6a11 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/State/CleanupTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/State/CleanupFilesTest.php @@ -6,63 +6,27 @@ namespace Magento\Framework\App\Test\Unit\State; -use \Magento\Framework\App\State\Cleanup; +use \Magento\Framework\App\State\CleanupFiles; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; -class CleanupTest extends \PHPUnit_Framework_TestCase +class CleanupFilesTest extends \PHPUnit_Framework_TestCase { - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $cachePool; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject[] - */ - private $cache; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ private $filesystem; /** - * @var Cleanup + * @var CleanupFiles */ private $object; protected function setUp() { - $this->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])); + $this->object = new CleanupFiles($this->filesystem); } public function testClearCodeGeneratedClasses() @@ -97,6 +61,7 @@ class CleanupTest extends \PHPUnit_Framework_TestCase $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'); + $dir->expects($this->once())->method('isExist')->will($this->returnValue(true)); return $dir; } } diff --git a/lib/internal/Magento/Framework/App/Utility/Classes.php b/lib/internal/Magento/Framework/App/Utility/Classes.php index 6671bd6a0464da30ef79dd001742cd2ff6ad43ef..f49118641b3f4de5d3dd08e4cef4ddd9d46bef51 100644 --- a/lib/internal/Magento/Framework/App/Utility/Classes.php +++ b/lib/internal/Magento/Framework/App/Utility/Classes.php @@ -7,6 +7,8 @@ */ namespace Magento\Framework\App\Utility; +use Magento\Framework\App\Utility\Files; + class Classes { /** @@ -185,11 +187,11 @@ class Classes public static function collectModuleClasses($subTypePattern = '[A-Za-z]+') { $pattern = '/^' . preg_quote( - \Magento\Framework\App\Utility\Files::init()->getPathToSource(), + Files::init()->getPathToSource(), '/' ) . '\/app\/code\/([A-Za-z]+)\/([A-Za-z]+)\/(' . $subTypePattern . '\/.+)\.php$/'; $result = []; - foreach (\Magento\Framework\App\Utility\Files::init()->getPhpFiles(true, false, false, false) as $file) { + foreach (Files::init()->getPhpFiles(true, false, false, false, false) as $file) { if (preg_match($pattern, $file, $matches)) { $module = "{$matches[1]}_{$matches[2]}"; $class = "{$module}" . '\\' . str_replace( @@ -214,7 +216,7 @@ class Classes if (!empty(self::$_virtualClasses)) { return self::$_virtualClasses; } - $configFiles = \Magento\Framework\App\Utility\Files::init()->getDiConfigs(); + $configFiles = Files::init()->getDiConfigs(); foreach ($configFiles as $fileName) { $configDom = new \DOMDocument(); $configDom->load($fileName); diff --git a/lib/internal/Magento/Framework/App/Utility/Files.php b/lib/internal/Magento/Framework/App/Utility/Files.php index 15869c4be7c49c67c886bab1b14484c2f5b1b5ea..57fe340acda362fa1a17839ee8c54c515f5907cb 100644 --- a/lib/internal/Magento/Framework/App/Utility/Files.php +++ b/lib/internal/Magento/Framework/App/Utility/Files.php @@ -109,9 +109,10 @@ class Files * @param bool $otherCode non-application PHP-code (doesn't include "dev" directory) * @param bool $templates application PHTML-code * @param bool $asDataSet + * @param bool $tests tests folder * @return array */ - public function getPhpFiles($appCode = true, $otherCode = true, $templates = true, $asDataSet = true) + public function getPhpFiles($appCode = true, $otherCode = true, $templates = true, $asDataSet = true, $tests = true) { $key = __METHOD__ . "/{$this->_path}/{$appCode}/{$otherCode}/{$templates}"; if (!isset(self::$_cache[$key])) { @@ -137,6 +138,12 @@ class Files self::getFiles(["{$this->_path}/dev/tools/Magento/Tools/SampleData"], '*.php') ); } + if ($tests) { + $files = array_merge( + $files, + self::getFiles(["{$this->_path}/dev/tests"], '*.php') + ); + } if ($templates) { $files = array_merge($files, $this->getPhtmlFiles(false, false)); } diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php index 8930487dd35c7950364fbf994eab3a0715045517..c7f4ac934ae47cf91fd90dff233df5c24a611a3c 100644 --- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php +++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php @@ -25,7 +25,7 @@ class ConfigGenerator ConfigOptionsList::INPUT_KEY_DB_HOST => ConfigOptionsList::KEY_HOST, ConfigOptionsList::INPUT_KEY_DB_NAME => ConfigOptionsList::KEY_NAME, ConfigOptionsList::INPUT_KEY_DB_USER => ConfigOptionsList::KEY_USER, - ConfigOptionsList::INPUT_KEY_DB_PASS => ConfigOptionsList::KEY_PASS, + ConfigOptionsList::INPUT_KEY_DB_PASSWORD => ConfigOptionsList::KEY_PASSWORD, ConfigOptionsList::INPUT_KEY_DB_PREFIX => ConfigOptionsList::KEY_PREFIX, ConfigOptionsList::INPUT_KEY_DB_MODEL => ConfigOptionsList::KEY_MODEL, ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS => ConfigOptionsList::KEY_INIT_STATEMENTS, @@ -152,7 +152,7 @@ class ConfigGenerator ConfigOptionsList::INPUT_KEY_DB_HOST, ConfigOptionsList::INPUT_KEY_DB_NAME, ConfigOptionsList::INPUT_KEY_DB_USER, - ConfigOptionsList::INPUT_KEY_DB_PASS, + ConfigOptionsList::INPUT_KEY_DB_PASSWORD, ConfigOptionsList::INPUT_KEY_DB_MODEL, ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS, ]; diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php index 817835ed0d0fdb6460653e50c330fb2ec2743654..ac1a90652f40c07dc382b094e655a4cd289a5700 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php @@ -37,7 +37,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface const INPUT_KEY_DB_HOST = 'db_host'; const INPUT_KEY_DB_NAME = 'db_name'; const INPUT_KEY_DB_USER = 'db_user'; - const INPUT_KEY_DB_PASS = 'db_pass'; + const INPUT_KEY_DB_PASSWORD = 'db_password'; const INPUT_KEY_DB_PREFIX = 'db_prefix'; const INPUT_KEY_DB_MODEL = 'db_model'; const INPUT_KEY_DB_INIT_STATEMENTS = 'db_init_statements'; @@ -62,7 +62,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface const KEY_HOST = 'host'; const KEY_NAME = 'dbname'; const KEY_USER = 'username'; - const KEY_PASS = 'password'; + const KEY_PASSWORD = 'password'; const KEY_PREFIX = 'table_prefix'; const KEY_MODEL = 'model'; const KEY_INIT_STATEMENTS = 'initStatements'; @@ -155,9 +155,9 @@ class ConfigOptionsList implements ConfigOptionsListInterface 'root' ), new TextConfigOption( - self::INPUT_KEY_DB_PASS, + self::INPUT_KEY_DB_PASSWORD, TextConfigOption::FRONTEND_WIZARD_PASSWORD, - self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::KEY_PASS, + self::CONFIG_PATH_DB_CONNECTION_DEFAULT . self::KEY_PASSWORD, 'Database server password', '' ), diff --git a/lib/internal/Magento/Framework/Console/CommandList.php b/lib/internal/Magento/Framework/Console/CommandList.php index a75d096466bf0bc0a3aefc657cee7eae077cfe60..99519a396d16b66eeaa68481d31514fc85da65e1 100644 --- a/lib/internal/Magento/Framework/Console/CommandList.php +++ b/lib/internal/Magento/Framework/Console/CommandList.php @@ -6,12 +6,8 @@ namespace Magento\Framework\Console; -use Magento\Framework\ObjectManagerInterface; - /** * Class CommandList has a list of commands, which can be extended via DI configuration. - * - * @package Magento\Framework\Console */ class CommandList { diff --git a/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php b/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php index e8ff84ee476765a4ef471c9bc92b3a8489a53e1c..16526b3fb40bfe1526aa06fd9d47080ff5fa318f 100644 --- a/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php +++ b/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php @@ -57,7 +57,8 @@ class DbStatusValidator $formattedErrors = $this->formatErrors($errors); throw new \Magento\Framework\Exception\LocalizedException( new \Magento\Framework\Phrase( - 'Please update your database: Run "php -f index.php update" from the Magento root/setup directory. %1The following modules are outdated:%2%3', + 'Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory.' + . ' %1The following modules are outdated:%2%3', [PHP_EOL, PHP_EOL, implode(PHP_EOL, $formattedErrors)] ) ); diff --git a/lib/internal/Magento/Framework/Module/Status.php b/lib/internal/Magento/Framework/Module/Status.php index 0c93b19feec2989b781306be7cce4e43b997d3ee..897c7cc10eb1366ef242d9c3037f0ff2cc9ccd96 100644 --- a/lib/internal/Magento/Framework/Module/Status.php +++ b/lib/internal/Magento/Framework/Module/Status.php @@ -7,7 +7,6 @@ namespace Magento\Framework\Module; use Magento\Framework\App\DeploymentConfig\Writer; -use Magento\Framework\App\State\Cleanup; use Magento\Framework\Config\File\ConfigFilePool; /** @@ -38,13 +37,6 @@ class Status */ private $writer; - /** - * Application state cleanup service - * - * @var Cleanup - */ - private $cleanup; - /** * Dependency Checker * @@ -65,7 +57,6 @@ class Status * @param ModuleList\Loader $loader * @param ModuleList $list * @param Writer $writer - * @param Cleanup $cleanup * @param ConflictChecker $conflictChecker * @param DependencyChecker $dependencyChecker */ @@ -73,14 +64,12 @@ class Status ModuleList\Loader $loader, ModuleList $list, Writer $writer, - Cleanup $cleanup, ConflictChecker $conflictChecker, DependencyChecker $dependencyChecker ) { $this->loader = $loader; $this->list = $list; $this->writer = $writer; - $this->cleanup = $cleanup; $this->conflictChecker = $conflictChecker; $this->dependencyChecker = $dependencyChecker; } @@ -134,7 +123,7 @@ class Status foreach ($errorModulesConflict as $moduleName => $conflictingModules) { if (!empty($conflictingModules)) { - $errorMessages[] = "Cannot enable $moduleName, conflicting with other modules:"; + $errorMessages[] = "Cannot enable $moduleName because it conflicts with other modules:"; $errorMessages[] = implode("\n", $conflictingModules); } } @@ -163,8 +152,6 @@ class Status } } $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]], true); - $this->cleanup->clearCaches(); - $this->cleanup->clearCodeGeneratedFiles(); } /** @@ -239,9 +226,9 @@ class Status private function createVerboseErrorMessage($isEnabled, $moduleName, $missingDependencies) { if ($isEnabled) { - $errorMessages[] = "Cannot enable $moduleName, depending on disabled modules:"; + $errorMessages[] = "Cannot enable $moduleName because it depends on disabled modules:"; } else { - $errorMessages[] = "Cannot disable $moduleName, modules depending on it:"; + $errorMessages[] = "Cannot disable $moduleName because modules depend on it:"; } foreach ($missingDependencies as $errorModule => $path) { $errorMessages[] = "$errorModule: " . implode('->', $path); diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php index 10e21e701802b59a7be38144bb7fb5d1cbf684d6..b3b521a216ec13af3a473786bf6cb3787da43463 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php @@ -117,7 +117,7 @@ class DbStatusValidatorTest extends \PHPUnit_Framework_TestCase * * @dataProvider aroundDispatchExceptionDataProvider * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage Please update your database: + * @expectedExceptionMessage Please upgrade your database: */ public function testAroundDispatchException(array $dbVersionErrors) { diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php index 697677f6b1044bb727462becdfe747a70278ebd9..dbdf293df705bd3e6adf44567ec67535334a7833 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/StatusTest.php @@ -26,11 +26,6 @@ class StatusTest extends \PHPUnit_Framework_TestCase */ private $writer; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $cleanup; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -51,14 +46,12 @@ class StatusTest extends \PHPUnit_Framework_TestCase $this->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->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->writer, - $this->cleanup, $this->conflictChecker, $this->dependencyChecker ); @@ -95,13 +88,13 @@ class StatusTest extends \PHPUnit_Framework_TestCase )); $result = $this->object->checkConstraints(true, ['Module_Foo' => '', 'Module_Bar' => ''], [], false); $expect = [ - 'Cannot enable Module_Foo, depending on disabled modules:', + 'Cannot enable Module_Foo because it depends on disabled modules:', "Module_Baz: Module_Foo->Module_Baz", - 'Cannot enable Module_Bar, depending on disabled modules:', + 'Cannot enable Module_Bar because it depends on disabled modules:', "Module_Baz: Module_Bar->Module_Baz", - 'Cannot enable Module_Foo, conflicting with other modules:', + 'Cannot enable Module_Foo because it conflicts with other modules:', "Module_Bar", - 'Cannot enable Module_Bar, conflicting with other modules:', + 'Cannot enable Module_Bar because it conflicts with other modules:', "Module_Foo", ]; $this->assertEquals($expect, $result); @@ -124,9 +117,9 @@ class StatusTest extends \PHPUnit_Framework_TestCase $expect = [ 'Cannot enable Module_Foo', 'Cannot enable Module_Bar', - 'Cannot enable Module_Foo, conflicting with other modules:', + 'Cannot enable Module_Foo because it conflicts with other modules:', "Module_Bar", - 'Cannot enable Module_Bar, conflicting with other modules:', + 'Cannot enable Module_Bar because it conflicts with other modules:', "Module_Foo", ]; $this->assertEquals($expect, $result); @@ -153,9 +146,9 @@ class StatusTest extends \PHPUnit_Framework_TestCase )); $result = $this->object->checkConstraints(false, ['Module_Foo' => '', 'Module_Bar' => '']); $expect = [ - 'Cannot disable Module_Foo, modules depending on it:', + 'Cannot disable Module_Foo because modules depend on it:', "Module_Baz: Module_Baz->Module_Foo", - 'Cannot disable Module_Bar, modules depending on it:', + 'Cannot disable Module_Bar because modules depend on it:', "Module_Baz: Module_Baz->Module_Bar", ]; $this->assertEquals($expect, $result); @@ -171,8 +164,6 @@ class StatusTest extends \PHPUnit_Framework_TestCase $expectedModules = ['Module_Foo' => 1, 'Module_Bar' => 1, 'Module_Baz' => 0]; $this->writer->expects($this->once())->method('saveConfig') ->with([ConfigFilePool::APP_CONFIG => ['modules' => $expectedModules]]); - $this->cleanup->expects($this->once())->method('clearCaches'); - $this->cleanup->expects($this->once())->method('clearCodeGeneratedFiles'); $this->object->setIsEnabled(true, ['Module_Foo', 'Module_Bar']); } diff --git a/setup/config/application.config.php b/setup/config/application.config.php index 296854b1141211c1575e52fd11cd4f47c638d587..6bda9ee81bcb49d418ce8971ff28bf3c5f875877 100644 --- a/setup/config/application.config.php +++ b/setup/config/application.config.php @@ -18,7 +18,7 @@ return [ __DIR__ . '/autoload/{,*.}{global,local}.php', ], ], - 'listeners' => ['Magento\Setup\Mvc\Bootstrap\InitParamListener', 'Magento\Setup\Mvc\Console\RouteListener'], + 'listeners' => ['Magento\Setup\Mvc\Bootstrap\InitParamListener'], 'service_manager' => [ 'factories' => [ InitParamListener::BOOTSTRAP_PARAM => 'Magento\Setup\Mvc\Bootstrap\InitParamListener', diff --git a/setup/config/di.config.php b/setup/config/di.config.php index b6bd0b18ae50dd11e50e0928a619fc1d4c626931..8d0f258ba828764481e37cc435a4fbddddc63cff 100644 --- a/setup/config/di.config.php +++ b/setup/config/di.config.php @@ -20,7 +20,6 @@ return [ 'Magento\Setup\Controller\CreateAdminAccount', 'Magento\Setup\Controller\Install', 'Magento\Setup\Controller\Success', - 'Magento\Setup\Controller\ConsoleController', 'Magento\Setup\Controller\Modules', ], 'instance' => [ diff --git a/setup/config/router.config.php b/setup/config/router.config.php index 817ed642dd515824dd487d8ad57a3be0a890b26f..1a16b1c7d1cfa3f834d55f59ca96fa3b015e6fb0 100644 --- a/setup/config/router.config.php +++ b/setup/config/router.config.php @@ -4,7 +4,6 @@ * See COPYING.txt for license details. */ -use Magento\Setup\Controller\ConsoleController; return [ 'router' => [ @@ -36,5 +35,4 @@ return [ ], ], ], - 'console' => ['router' => ['routes' => ConsoleController::getRouterConfig()]], ]; diff --git a/setup/index.php b/setup/index.php index 7f06ced03ba339d9c93f355ebb048a9bcc7c36c0..7c7b069afc31cd45bff2c2e2cf69d7fbc37c877c 100644 --- a/setup/index.php +++ b/setup/index.php @@ -4,13 +4,15 @@ * See COPYING.txt for license details. */ +if (PHP_SAPI == 'cli') { + echo "You cannot run this from the command line." . PHP_EOL . + "Run \"php bin/magento\" instead." . PHP_EOL; + exit(1); +} try { require __DIR__ . '/../app/bootstrap.php'; } catch (\Exception $e) { - if (PHP_SAPI == 'cli') { - echo 'Autoload error: ' . $e->getMessage(); - } else { - echo <<<HTML + echo <<<HTML <div style="font:12px/1.35em arial, helvetica, sans-serif;"> <div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;"> <h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;"> @@ -19,7 +21,6 @@ try { <p>{$e->getMessage()}</p> </div> HTML; - } exit(1); } \Zend\Mvc\Application::init(require __DIR__ . '/config/application.config.php')->run(); diff --git a/setup/src/Magento/Setup/Console/Command/AbstractMaintenanceCommand.php b/setup/src/Magento/Setup/Console/Command/AbstractMaintenanceCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..fab2e492b31e8dcebdfab023fc8f40612e19e493 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/AbstractMaintenanceCommand.php @@ -0,0 +1,88 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +use Magento\Framework\App\MaintenanceMode; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +abstract class AbstractMaintenanceCommand extends AbstractSetupCommand +{ + /** + * Names of input option + */ + const INPUT_KEY_IP = 'ip'; + + /** + * @var MaintenanceMode $maintenanceMode + */ + protected $maintenanceMode; + + /** + * Constructor + * + * @param MaintenanceMode $maintenanceMode + */ + public function __construct(MaintenanceMode $maintenanceMode) + { + $this->maintenanceMode = $maintenanceMode; + parent::__construct(); + } + + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $options = [ + new InputOption( + self::INPUT_KEY_IP, + null, + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, + 'Allowed IP addresses' + ), + ]; + $this->setDefinition($options); + parent::configure(); + } + + /** + * Get maintenance mode to set + * + * @return bool + */ + abstract protected function isEnable(); + + /** + * Get display string after mode is set + * + * @return string + */ + abstract protected function getDisplayString(); + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $addresses = $input->getOption(self::INPUT_KEY_IP); + $this->maintenanceMode->set($this->isEnable()); + $output->writeln($this->getDisplayString()); + + if (!empty($addresses)) { + $addresses = implode(',', $addresses); + $addresses = ('none' == $addresses) ? '' : $addresses; + $this->maintenanceMode->setAddresses($addresses); + $output->writeln( + '<info>Set exempt IP-addresses: ' . (implode(', ', $this->maintenanceMode->getAddressInfo()) ?: 'none') + . '</info>' + ); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/AbstractModuleCommand.php b/setup/src/Magento/Setup/Console/Command/AbstractModuleCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..9777b233790617c6a2ad3d9b9941069b3d93ce82 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/AbstractModuleCommand.php @@ -0,0 +1,175 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +use Magento\Setup\Model\ObjectManagerProvider; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Abstract class for Enable and Disable commands to consolidate common logic + */ +abstract class AbstractModuleCommand extends AbstractSetupCommand +{ + /** + * Names of input arguments or options + */ + const INPUT_KEY_MODULES = 'module'; + const INPUT_KEY_ALL = 'all'; + const INPUT_KEY_FORCE = 'force'; + const INPUT_KEY_CLEAR_STATIC_CONTENT = 'clear-static-content'; + + /** + * Object manager provider + * + * @var ObjectManagerProvider + */ + private $objectManagerProvider; + + /** + * Inject dependencies + * + * @param ObjectManagerProvider $objectManagerProvider + */ + public function __construct(ObjectManagerProvider $objectManagerProvider) + { + $this->objectManagerProvider = $objectManagerProvider; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setDefinition([ + new InputArgument( + self::INPUT_KEY_MODULES, + InputArgument::IS_ARRAY | InputArgument::OPTIONAL, + 'Name of the module' + ), + new InputOption( + self::INPUT_KEY_CLEAR_STATIC_CONTENT, + 'c', + InputOption::VALUE_NONE, + 'Clear generated static view files. Necessary, if the module(s) have static view files' + ), + new InputOption( + self::INPUT_KEY_FORCE, + 'f', + InputOption::VALUE_NONE, + 'Bypass dependencies check' + ), + new InputOption( + self::INPUT_KEY_ALL, + null, + InputOption::VALUE_NONE, + ($this->isEnable() ? 'Enable' : 'Disable') . ' all modules' + ), + ]); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $isEnable = $this->isEnable(); + if ($input->getOption(self::INPUT_KEY_ALL)) { + /** @var \Magento\Framework\Module\FullModuleList $fullModulesList */ + $fullModulesList = $this->objectManagerProvider->get()->get('Magento\Framework\Module\FullModuleList'); + $modules = $fullModulesList->getNames(); + } else { + $modules = $input->getArgument(self::INPUT_KEY_MODULES); + } + if (empty($modules)) { + throw new \InvalidArgumentException( + 'No modules specified. Specify a space-separated list of modules or use the --all option' + ); + } + /** + * @var \Magento\Framework\Module\Status $status + */ + $status = $this->objectManagerProvider->get()->get('Magento\Framework\Module\Status'); + $modulesToChange = $status->getModulesToChange($isEnable, $modules); + if (!empty($modulesToChange)) { + $force = $input->getOption(self::INPUT_KEY_FORCE); + if (!$force) { + $constraints = $status->checkConstraints($isEnable, $modulesToChange); + if ($constraints) { + $output->writeln( + "<error>Unable to change status of modules because of the following constraints:</error>" + ); + $output->writeln('<error>' . implode("\n", $constraints) . '</error>'); + return; + } + } + $status->setIsEnabled($isEnable, $modulesToChange); + if ($isEnable) { + $output->writeln('<info>The following modules have been enabled:</info>'); + $output->writeln('<info>- ' . implode("\n- ", $modulesToChange) . '</info>'); + $output->writeln(''); + $output->writeln( + '<info>To make sure that the enabled modules are properly registered,' + . " run 'setup:upgrade'.</info>" + ); + } else { + $output->writeln('<info>The following modules have been disabled:</info>'); + $output->writeln('<info>- ' . implode("\n- ", $modulesToChange) . '</info>'); + $output->writeln(''); + } + $this->cleanup($input, $output); + if ($force) { + $output->writeln( + '<error>Alert: You used the --force option.' + . ' As a result, modules might not function properly.</error>' + ); + } + } else { + $output->writeln('<info>No modules were changed.</info>'); + } + } + + /** + * Is it "enable" or "disable" command + * + * @return bool + */ + abstract protected function isEnable(); + + /** + * Cleanup after updated modules status + * + * @param InputInterface $input + * @param OutputInterface $output + * @return void + */ + private function cleanup(InputInterface $input, OutputInterface $output) + { + $objectManager = $this->objectManagerProvider->get(); + /** @var \Magento\Framework\App\Cache $cache */ + $cache = $objectManager->get('Magento\Framework\App\Cache'); + $cache->clean(); + $output->writeln('Cache cleared successfully.'); + /** @var \Magento\Framework\App\State\CleanupFiles $cleanupFiles */ + $cleanupFiles = $objectManager->get('Magento\Framework\App\State\CleanupFiles'); + $cleanupFiles->clearCodeGeneratedClasses(); + $output->writeln('Generated classes cleared successfully.'); + if ($input->getOption(self::INPUT_KEY_CLEAR_STATIC_CONTENT)) { + $cleanupFiles->clearMaterializedViewFiles(); + $output->writeln('Generated static view files cleared successfully.'); + } else { + $output->writeln( + '<error>Alert: Generated static view files were not cleared.' + . ' You can clear them using the --' . self::INPUT_KEY_CLEAR_STATIC_CONTENT . ' option.' + . ' Failure to clear static view files might cause display issues in the Admin and storefront.' + ); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/AbstractSetupCommand.php b/setup/src/Magento/Setup/Console/Command/AbstractSetupCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..3b8975c02de354a3b9f94cd8763ce934429a4559 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/AbstractSetupCommand.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +use Magento\Setup\Mvc\Bootstrap\InitParamListener; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputOption; + +/** + * An abstract class for all Magento Setup command. + * It adds InitParamListener's magento_init_params option to all setup command. + */ +abstract class AbstractSetupCommand extends Command +{ + /** + * Initialize basic Magento Setup command + * + * @return void + */ + protected function configure() + { + $this->addOption( + InitParamListener::BOOTSTRAP_PARAM, + null, + InputOption::VALUE_REQUIRED, + 'Add to any command to customize Magento initialization parameters' . PHP_EOL . + "For example: 'MAGE_MODE=developer&MAGE_DIRS[base][path]" . + "=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache'" + ); + } +} diff --git a/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php b/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..3dd27d09e0c5f080e697eff9867f49e434495a48 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php @@ -0,0 +1,98 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Magento\Setup\Model\AdminAccount; +use Magento\Setup\Model\ConsoleLogger; +use Magento\Setup\Model\InstallerFactory; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class AdminUserCreateCommand extends AbstractSetupCommand +{ + /** + * @var InstallerFactory + */ + private $installerFactory; + + /** + * @param InstallerFactory $installerFactory + */ + public function __construct(InstallerFactory $installerFactory) + { + $this->installerFactory = $installerFactory; + parent::__construct(); + } + + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $this->setName('admin:user:create') + ->setDescription('Creates admin user') + ->setDefinition($this->getOptionsList()); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $errors = $this->validate($input); + if ($errors) { + throw new \InvalidArgumentException(implode("\n", $errors)); + } + $installer = $this->installerFactory->create(new ConsoleLogger($output)); + $installer->installAdminUser($input->getOptions()); + $output->writeln('<info>Created admin user ' . $input->getOption(AdminAccount::KEY_USER) . '</info>'); + } + + /** + * Get list of arguments for the command + * + * @return InputOption[] + */ + public function getOptionsList() + { + return [ + new InputOption(AdminAccount::KEY_USER, null, InputOption::VALUE_REQUIRED, 'Admin user'), + new InputOption(AdminAccount::KEY_PASSWORD, null, InputOption::VALUE_REQUIRED, 'Admin password'), + new InputOption(AdminAccount::KEY_EMAIL, null, InputOption::VALUE_REQUIRED, 'Admin email'), + new InputOption(AdminAccount::KEY_FIRST_NAME, null, InputOption::VALUE_REQUIRED, 'Admin first name'), + new InputOption(AdminAccount::KEY_LAST_NAME, null, InputOption::VALUE_REQUIRED, 'Admin last name'), + ]; + } + + /** + * Check if all admin options are provided + * + * @param InputInterface $input + * @return string[] + */ + public function validate(InputInterface $input) + { + $errors = []; + $required = [ + AdminAccount::KEY_USER, + AdminAccount::KEY_PASSWORD, + AdminAccount::KEY_EMAIL, + AdminAccount::KEY_FIRST_NAME, + AdminAccount::KEY_LAST_NAME, + ]; + foreach ($required as $key) { + if (!$input->getOption($key)) { + $errors[] = 'Missing option ' . $key; + } + } + return $errors; + } +} diff --git a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php index 0a95ba642a39c1eaba8d578889b304afb88116be..6a86ee2ce9a8ab85b92442a104cf17c71e516ffc 100644 --- a/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php @@ -9,11 +9,10 @@ namespace Magento\Setup\Console\Command; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Module\ModuleList; use Magento\Setup\Model\ConfigModel; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class ConfigSetCommand extends Command +class ConfigSetCommand extends AbstractSetupCommand { /** * @var ConfigModel @@ -63,7 +62,7 @@ class ConfigSetCommand extends Command ->setDescription('Sets deployment configuration') ->setDefinition($options); - $this->ignoreValidationErrors(); + parent::configure(); } /** @@ -84,7 +83,7 @@ class ConfigSetCommand extends Command $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation( $output, - '<question>Overwrite the existing configuration for ' . $option->getName() . '?[Y|n]</question>' + '<question>Overwrite the existing configuration for ' . $option->getName() . '?[Y/n]</question>' )) { $inputOptions[$option->getName()] = null; } diff --git a/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..b915fa2a83067e27757b3d24ba884edac8c671b3 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/DbDataUpgradeCommand.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Magento\Framework\App\DeploymentConfig; +use Magento\Setup\Model\InstallerFactory; +use Magento\Setup\Model\ConsoleLogger; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Command for install and update of data in DB + */ +class DbDataUpgradeCommand extends AbstractSetupCommand +{ + /** + * Factory to create installer + * + * @var InstallerFactory + */ + private $installFactory; + + /** + * Deployment configuration + * + * @var DeploymentConfig + */ + private $deploymentConfig; + + /** + * Inject dependencies + * + * @param InstallerFactory $installFactory + * @param DeploymentConfig $deploymentConfig + */ + public function __construct(InstallerFactory $installFactory, DeploymentConfig $deploymentConfig) + { + $this->installFactory = $installFactory; + $this->deploymentConfig = $deploymentConfig; + parent::__construct(); + } + + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $this->setName('setup:db-data:upgrade')->setDescription('Installs and upgrades data in the DB'); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!$this->deploymentConfig->isAvailable()) { + $output->writeln("<info>No information is available: the application is not installed.</info>"); + return; + } + $installer = $this->installFactory->create(new ConsoleLogger($output)); + $installer->installDataFixtures(); + } +} diff --git a/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..fc3f5bd9888acbd89a44216d1f144650e6f4403d --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/DbSchemaUpgradeCommand.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Magento\Framework\App\DeploymentConfig; +use Magento\Setup\Model\InstallerFactory; +use Magento\Setup\Model\ConsoleLogger; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Command for install and update of DB schema + */ +class DbSchemaUpgradeCommand extends AbstractSetupCommand +{ + /** + * Factory to create installer + * + * @var InstallerFactory + */ + private $installFactory; + + /** + * Deployment configuration + * + * @var DeploymentConfig + */ + private $deploymentConfig; + + /** + * Inject dependencies + * + * @param InstallerFactory $installFactory + * @param DeploymentConfig $deploymentConfig + */ + public function __construct(InstallerFactory $installFactory, DeploymentConfig $deploymentConfig) + { + $this->installFactory = $installFactory; + $this->deploymentConfig = $deploymentConfig; + parent::__construct(); + } + + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $this->setName('setup:db-schema:upgrade')->setDescription('Installs and upgrades the DB schema'); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!$this->deploymentConfig->isAvailable()) { + $output->writeln("<info>No information is available: the application is not installed.</info>"); + return; + } + $installer = $this->installFactory->create(new ConsoleLogger($output)); + $installer->installSchema(); + } +} diff --git a/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php b/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..7d996aec45e7e2a928a44a14ce237557fc029a10 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php @@ -0,0 +1,103 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +use Composer\Package\Version\VersionParser; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Module\DbVersionInfo; +use Magento\Setup\Model\ObjectManagerProvider; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Command for checking if DB version is in sync with the code base version + */ +class DbStatusCommand extends AbstractSetupCommand +{ + /** + * Object manager provider + * + * @var ObjectManagerProvider + */ + private $objectManagerProvider; + + /** + * Deployment configuration + * + * @var DeploymentConfig + */ + private $deploymentConfig; + + /** + * Inject dependencies + * + * @param ObjectManagerProvider $objectManagerProvider + * @param DeploymentConfig $deploymentConfig + */ + public function __construct(ObjectManagerProvider $objectManagerProvider, DeploymentConfig $deploymentConfig) + { + $this->objectManagerProvider = $objectManagerProvider; + $this->deploymentConfig = $deploymentConfig; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('setup:db:status') + ->setDescription('Checks if update of DB schema or data is required'); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!$this->deploymentConfig->isAvailable()) { + $output->writeln("<info>No information is available: the application is not installed.</info>"); + return; + } + /** @var DbVersionInfo $dbVersionInfo */ + $dbVersionInfo = $this->objectManagerProvider->get() + ->get('Magento\Framework\Module\DbVersionInfo'); + $outdated = $dbVersionInfo->getDbVersionErrors(); + if (!empty($outdated)) { + $output->writeln("<info>The module code base doesn't match the DB schema and data.</info>"); + $versionParser = new VersionParser(); + $codebaseUpdateNeeded = false; + foreach ($outdated as $row) { + if (!$codebaseUpdateNeeded && $row[DbVersionInfo::KEY_CURRENT] !== 'none') { + // check if module code base update is needed + $currentVersion = $versionParser->parseConstraints($row[DbVersionInfo::KEY_CURRENT]); + $requiredVersion = $versionParser->parseConstraints('>' . $row[DbVersionInfo::KEY_REQUIRED]); + if ($requiredVersion->matches($currentVersion)) { + $codebaseUpdateNeeded = true; + }; + } + $output->writeln(sprintf( + "<info>%20s %10s: %11s -> %-11s</info>", + $row[DbVersionInfo::KEY_MODULE], + $row[DbVersionInfo::KEY_TYPE], + $row[DbVersionInfo::KEY_CURRENT], + $row[DbVersionInfo::KEY_REQUIRED] + )); + } + if ($codebaseUpdateNeeded) { + $output->writeln( + '<info>Some modules use code versions newer or older than the database. ' . + "First update the module code, then run 'setup:upgrade'.</info>" + ); + } else { + $output->writeln("<info>Run 'setup:upgrade' to update your DB schema and data.</info>"); + } + } else { + $output->writeln('<info>All modules are up to date.</info>'); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..4e2aba2b3ab857521cbffda4cdcd20b09d94b0af --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/InfoCurrencyListCommand.php @@ -0,0 +1,55 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Command\Command; +use Magento\Setup\Model\Lists; + +/** + * Command prints list of available currencies + */ +class InfoCurrencyListCommand extends Command +{ + /** + * List model provides lists of available options for currency, language locales, timezones + * + * @var Lists + */ + private $lists; + + /** + * @param Lists $lists + */ + public function __construct(Lists $lists) + { + $this->lists = $lists; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('info:currency:list') + ->setDescription('Prints list of available currencies'); + + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + foreach ($this->lists->getCurrencyList() as $key => $currency) { + $output->writeln($key . ' => ' . $currency); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..6066baeadda4fb8f77bf45a3b893d33406d99894 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/InfoLanguageListCommand.php @@ -0,0 +1,55 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Command\Command; +use Magento\Setup\Model\Lists; + +/** + * Command prints list of available language locales + */ +class InfoLanguageListCommand extends Command +{ + /** + * List model provides lists of available options for currency, language locales, timezones + * + * @var Lists + */ + private $lists; + + /** + * @param Lists $lists + */ + public function __construct(Lists $lists) + { + $this->lists = $lists; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('info:language:list') + ->setDescription('Prints list of available language locales'); + + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + foreach ($this->lists->getLocaleList() as $key => $locale) { + $output->writeln($key . ' => ' . $locale); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php b/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..4cb013b4dfa07041a5c95f40f581a81ca9eeb735 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php @@ -0,0 +1,55 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Command\Command; +use Magento\Setup\Model\Lists; + +/** + * Command prints list of available timezones + */ +class InfoTimezoneListCommand extends Command +{ + /** + * List model provides lists of available options for currency, language locales, timezones + * + * @var Lists + */ + private $lists; + + /** + * @param Lists $lists + */ + public function __construct(Lists $lists) + { + $this->lists = $lists; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('info:timezone:list') + ->setDescription('Prints list of available timezones'); + + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + foreach ($this->lists->getTimezoneList() as $key => $timezone) { + $output->writeln($key . ' => ' . $timezone); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/InstallCommand.php b/setup/src/Magento/Setup/Console/Command/InstallCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..2601e45b7aa1e5eb9fa960670e7055e7c9ce433f --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/InstallCommand.php @@ -0,0 +1,144 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Magento\Setup\Model\InstallerFactory; +use Magento\Setup\Model\ConsoleLogger; +use Symfony\Component\Console\Input\InputOption; +use Magento\Setup\Model\ConfigModel; + +/** + * Command to install Magento application + */ +class InstallCommand extends AbstractSetupCommand +{ + /** + * Parameter indicating command whether to cleanup database in the install routine + */ + const INPUT_KEY_CLEANUP_DB = 'cleanup_database'; + + /** + * Parameter to specify an order_increment_prefix + */ + const INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX = 'sales_order_increment_prefix'; + + /** + * Parameter indicating command whether to install Sample Data + */ + const INPUT_KEY_USE_SAMPLE_DATA = 'use_sample_data'; + + /** + * Installer service factory + * + * @var InstallerFactory + */ + private $installerFactory; + + /** + * @var ConfigModel + */ + protected $configModel; + + /** + * @var InstallStoreConfigurationCommand + */ + protected $userConfig; + + /** + * @var AdminUserCreateCommand + */ + protected $adminUser; + + /** + * Constructor + * + * @param InstallerFactory $installerFactory + * @param ConfigModel $configModel + * @param InstallStoreConfigurationCommand $userConfig + * @param AdminUserCreateCommand $adminUser + */ + public function __construct( + InstallerFactory $installerFactory, + ConfigModel $configModel, + InstallStoreConfigurationCommand $userConfig, + AdminUserCreateCommand $adminUser + ) { + $this->installerFactory = $installerFactory; + $this->configModel = $configModel; + $this->userConfig = $userConfig; + $this->adminUser = $adminUser; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $inputOptions = $this->configModel->getAvailableOptions(); + $inputOptions = array_merge($inputOptions, $this->userConfig->getOptionsList()); + $inputOptions = array_merge($inputOptions, $this->adminUser->getOptionsList()); + $inputOptions = array_merge($inputOptions, [ + new InputOption( + self::INPUT_KEY_CLEANUP_DB, + null, + InputOption::VALUE_NONE, + 'Cleanup the database before installation' + ), + new InputOption( + self::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX, + null, + InputOption::VALUE_REQUIRED, + 'Sales order number prefix' + ), + new InputOption( + self::INPUT_KEY_USE_SAMPLE_DATA, + null, + InputOption::VALUE_NONE, + 'Use sample data' + ) + ]); + $this->setName('setup:install') + ->setDescription('Installs Magento Application') + ->setDefinition($inputOptions); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $consoleLogger = new ConsoleLogger($output); + $installer = $this->installerFactory->create($consoleLogger); + $installer->install($input->getOptions()); + } + + /** + * {@inheritdoc} + */ + protected function initialize(InputInterface $input, OutputInterface $output) + { + $inputOptions = $input->getOptions(); + + $configOptionsToValidate = []; + foreach ($this->configModel->getAvailableOptions() as $option) { + if (array_key_exists($option->getName(), $inputOptions)) { + $configOptionsToValidate[$option->getName()] = $inputOptions[$option->getName()]; + } + } + $errors = $this->configModel->validate($configOptionsToValidate); + $errors = array_merge($errors, $this->adminUser->validate($input)); + if (!empty($errors)) { + foreach ($errors as $error) { + $output->writeln("<error>$error</error>"); + } + throw new \InvalidArgumentException('Parameters validation is failed'); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php b/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..ae4eb99fa86c4c504ac4ab4d07ecb09ee1363173 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php @@ -0,0 +1,136 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Magento\Setup\Model\ConsoleLogger; +use Magento\Framework\App\DeploymentConfig; +use Magento\Setup\Model\InstallerFactory; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Magento\Setup\Model\StoreConfigurationDataMapper; + +class InstallStoreConfigurationCommand extends AbstractSetupCommand +{ + /** + * @var InstallerFactory + */ + private $installerFactory; + + /** + * Deployment configuration + * + * @var DeploymentConfig + */ + private $deploymentConfig; + + /** + * Inject dependencies + * + * @param InstallerFactory $installerFactory + * @param DeploymentConfig $deploymentConfig + */ + public function __construct( + InstallerFactory $installerFactory, + DeploymentConfig $deploymentConfig + ) { + $this->installerFactory = $installerFactory; + $this->deploymentConfig = $deploymentConfig; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('setup:store-config:set') + ->setDescription('Installs store configuration') + ->setDefinition($this->getOptionsList()); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!$this->deploymentConfig->isAvailable()) { + $output->writeln( + "<info>Store settings can't be saved because the Magento application is not installed.</info>" + ); + return; + } + $installer = $this->installerFactory->create(new ConsoleLogger($output)); + $installer->installUserConfig($input->getOptions()); + } + + /** + * Get list of options for the command + * + * @return InputOption[] + */ + public function getOptionsList() + { + return [ + new InputOption( + StoreConfigurationDataMapper::KEY_BASE_URL, + null, + InputOption::VALUE_REQUIRED, + 'URL the store is supposed to be available at' + ), + new InputOption( + StoreConfigurationDataMapper::KEY_LANGUAGE, + null, + InputOption::VALUE_REQUIRED, + 'Default language code' + ), + new InputOption( + StoreConfigurationDataMapper::KEY_TIMEZONE, + null, + InputOption::VALUE_REQUIRED, + 'Default time zone code' + ), + new InputOption( + StoreConfigurationDataMapper::KEY_CURRENCY, + null, + InputOption::VALUE_REQUIRED, + 'Default currency code' + ), + new InputOption( + StoreConfigurationDataMapper::KEY_USE_SEF_URL, + null, + InputOption::VALUE_REQUIRED, + 'Use rewrites' + ), + new InputOption( + StoreConfigurationDataMapper::KEY_IS_SECURE, + null, + InputOption::VALUE_REQUIRED, + 'Use secure URLs. Enable this option only if SSL is available.' + ), + new InputOption( + StoreConfigurationDataMapper::KEY_BASE_URL_SECURE, + null, + InputOption::VALUE_REQUIRED, + 'Base URL for SSL connection' + ), + new InputOption( + StoreConfigurationDataMapper::KEY_IS_SECURE_ADMIN, + null, + InputOption::VALUE_REQUIRED, + 'Run admin interface with SSL' + ), + new InputOption( + StoreConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY, + null, + InputOption::VALUE_REQUIRED, + 'Whether to use a "security key" feature in Magento Admin URLs and forms' + ), + ]; + } +} diff --git a/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php b/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..3aad4d09d16036e24d3dc9265cf0feca8ec4ba70 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php @@ -0,0 +1,90 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Magento\Framework\App\MaintenanceMode; +use Magento\Framework\Module\ModuleList; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Command for setting allowed IPs in maintenance mode + */ +class MaintenanceAllowIpsCommand extends AbstractSetupCommand +{ + /** + * Names of input arguments or options + */ + const INPUT_KEY_IP = 'ip'; + const INPUT_KEY_NONE = 'none'; + + /** + * @var MaintenanceMode $maintenanceMode + */ + private $maintenanceMode; + + /** + * Constructor + * + * @param MaintenanceMode $maintenanceMode + */ + public function __construct(MaintenanceMode $maintenanceMode) + { + $this->maintenanceMode = $maintenanceMode; + parent::__construct(); + } + + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $arguments = [ + new InputArgument( + self::INPUT_KEY_IP, + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + 'Allowed IP addresses' + ), + ]; + $options = [ + new InputOption( + self::INPUT_KEY_NONE, + null, + InputOption::VALUE_NONE, + 'Clear allowed IP addresses' + ), + ]; + $this->setName('maintenance:allow-ips') + ->setDescription('Sets maintenance mode exempt IPs') + ->setDefinition(array_merge($arguments, $options)); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!$input->getOption(self::INPUT_KEY_NONE)) { + $addresses = $input->getArgument(self::INPUT_KEY_IP); + if (!empty($addresses)) { + $this->maintenanceMode->setAddresses(implode(',', $addresses)); + $output->writeln( + '<info>Set exempt IP-addresses: ' . implode(', ', $this->maintenanceMode->getAddressInfo()) . + '</info>' + ); + } + } else { + $this->maintenanceMode->setAddresses(''); + $output->writeln('<info>Set exempt IP-addresses: none</info>'); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/MaintenanceDisableCommand.php b/setup/src/Magento/Setup/Console/Command/MaintenanceDisableCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..988c0628c4d86d02890f322b10af740d9ccd858b --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/MaintenanceDisableCommand.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +/** + * Command for disabling maintenance mode + */ +class MaintenanceDisableCommand extends AbstractMaintenanceCommand +{ + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $this->setName('maintenance:disable')->setDescription('Disables maintenance mode'); + parent::configure(); + } + + /** + * Disable maintenance mode + * + * @return bool + */ + protected function isEnable() + { + return false; + } + + /** + * Get disabled maintenance mode display string + * + * @return string + */ + protected function getDisplayString() + { + return '<info>Disabled maintenance mode</info>'; + } +} diff --git a/setup/src/Magento/Setup/Console/Command/MaintenanceEnableCommand.php b/setup/src/Magento/Setup/Console/Command/MaintenanceEnableCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..85c1579ce659fed69c63f5e71de46d83acb2c14c --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/MaintenanceEnableCommand.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +/** + * Command for enabling maintenance mode + */ +class MaintenanceEnableCommand extends AbstractMaintenanceCommand +{ + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $this->setName('maintenance:enable')->setDescription('Enables maintenance mode'); + parent::configure(); + } + + /** + * Enable maintenance mode + * + * @return bool + */ + protected function isEnable() + { + return true; + } + + /** + * Get enabled maintenance mode display string + * + * @return string + */ + protected function getDisplayString() + { + return '<info>Enabled maintenance mode</info>'; + } +} diff --git a/setup/src/Magento/Setup/Console/Command/MaintenanceStatusCommand.php b/setup/src/Magento/Setup/Console/Command/MaintenanceStatusCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..9ff1c2f97c23f822f676973a90e2938e1bdc0a4b --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/MaintenanceStatusCommand.php @@ -0,0 +1,60 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Magento\Framework\App\MaintenanceMode; +use Magento\Framework\Module\ModuleList; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Command for checking maintenance mode status + */ +class MaintenanceStatusCommand extends AbstractSetupCommand +{ + /** + * @var MaintenanceMode $maintenanceMode + */ + private $maintenanceMode; + + /** + * Constructor + * + * @param MaintenanceMode $maintenanceMode + */ + public function __construct(MaintenanceMode $maintenanceMode) + { + $this->maintenanceMode = $maintenanceMode; + parent::__construct(); + } + + /** + * Initialization of the command + * + * @return void + */ + protected function configure() + { + $this->setName('maintenance:status') + ->setDescription('Checks maintenance mode status'); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln( + '<info>Status: maintenance mode is ' . + ($this->maintenanceMode->isOn() ? 'active' : 'not active') . '</info>' + ); + $addressInfo = $this->maintenanceMode->getAddressInfo(); + $addresses = implode(', ', $addressInfo); + $output->writeln('<info>List of exempt IP-addresses: ' . ($addresses ? $addresses : 'none') . '</info>'); + } +} diff --git a/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..4e12c46331fca12d966f9bc247b8e9fd4840d36f --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/ModuleDisableCommand.php @@ -0,0 +1,32 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +/** + * Command for disabling list or all of modules + */ +class ModuleDisableCommand extends AbstractModuleCommand +{ + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('module:disable') + ->setDescription('Disables specified modules'); + parent::configure(); + } + + /** + * Disable modules + * + * @return bool + */ + protected function isEnable() + { + return false; + } +} diff --git a/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..0efc1d8928aafd83fe8950a28d8ccf9b1af41224 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/ModuleEnableCommand.php @@ -0,0 +1,32 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +/** + * Command for enabling list or all of modules + */ +class ModuleEnableCommand extends AbstractModuleCommand +{ + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('module:enable') + ->setDescription('Enables specified modules'); + parent::configure(); + } + + /** + * Enable modules + * + * @return bool + */ + protected function isEnable() + { + return true; + } +} diff --git a/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..4d802b17637f94495b1324ed723fc77a532ae630 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +use Magento\Setup\Model\ObjectManagerProvider; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Command for displaying status of modules + */ +class ModuleStatusCommand extends AbstractSetupCommand +{ + /** + * Object manager provider + * + * @var ObjectManagerProvider + */ + private $objectManagerProvider; + + /** + * Inject dependencies + * + * @param ObjectManagerProvider $objectManagerProvider + */ + public function __construct(ObjectManagerProvider $objectManagerProvider) + { + $this->objectManagerProvider = $objectManagerProvider; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('module:status') + ->setDescription('Displays status of modules'); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $moduleList = $this->objectManagerProvider->get()->create('Magento\Framework\Module\ModuleList'); + $output->writeln('<info>List of enabled modules:</info>'); + $enabledModules = $moduleList->getNames(); + if (count($enabledModules) === 0) { + $output->writeln('None'); + } else { + $output->writeln(join("\n", $enabledModules)); + } + $output->writeln(''); + + $fullModuleList = $this->objectManagerProvider->get()->create('Magento\Framework\Module\FullModuleList'); + $output->writeln("<info>List of disabled modules:</info>"); + $disabledModules = array_diff($fullModuleList->getNames(), $enabledModules); + if (count($disabledModules) === 0) { + $output->writeln('None'); + } else { + $output->writeln(join("\n", $disabledModules)); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/UninstallCommand.php b/setup/src/Magento/Setup/Console/Command/UninstallCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..0982c6381974d08b8fbd2663b2f9ef700580697b --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/UninstallCommand.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Console\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; +use Magento\Setup\Model\InstallerFactory; +use Magento\Setup\Model\ConsoleLogger; + +class UninstallCommand extends AbstractSetupCommand +{ + /** + * @var InstallerFactory + */ + private $installerFactory; + + /** + * @param InstallerFactory $installerFactory + */ + public function __construct(InstallerFactory $installerFactory) + { + $this->installerFactory = $installerFactory; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('setup:uninstall') + ->setDescription('Uninstalls Magento application'); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion('Are you sure you want to uninstall Magento?[y/N]', false); + + if ($helper->ask($input, $output, $question) || !$input->isInteractive()) { + $installer = $this->installerFactory->create(new ConsoleLogger($output)); + $installer->uninstall(); + } + } +} diff --git a/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..2c7b54bd294f1ed79d6669ed737348d718bcf4f8 --- /dev/null +++ b/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php @@ -0,0 +1,59 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Console\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Magento\Setup\Model\InstallerFactory; +use Magento\Setup\Model\ConsoleLogger; + +/** + * Command for updating installed application after the code base has changed + */ +class UpgradeCommand extends AbstractSetupCommand +{ + /** + * Installer service factory + * + * @var InstallerFactory + */ + private $installerFactory; + + /** + * Constructor + * + * @param InstallerFactory $installerFactory + */ + public function __construct(InstallerFactory $installerFactory) + { + $this->installerFactory = $installerFactory; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('setup:upgrade') + ->setDescription( + 'Upgrades installed application after the code base has changed, ' + . 'including DB schema and data' + ); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $installer = $this->installerFactory->create(new ConsoleLogger($output)); + $installer->updateModulesSequence(); + $installer->installSchema(); + $installer->installDataFixtures(); + } +} diff --git a/setup/src/Magento/Setup/Console/CommandList.php b/setup/src/Magento/Setup/Console/CommandList.php index 0a4f4ef8f281ac3ba882013ed070677cb5968fae..a75ed3b3226553a09390a93911b076192422c820 100644 --- a/setup/src/Magento/Setup/Console/CommandList.php +++ b/setup/src/Magento/Setup/Console/CommandList.php @@ -10,8 +10,6 @@ use Zend\ServiceManager\ServiceManager; /** * Class CommandList contains predefined list of commands for Setup - * - * @package Magento\Setup\Console */ class CommandList { @@ -40,7 +38,25 @@ class CommandList protected function getCommandsClasses() { return [ + 'Magento\Setup\Console\Command\AdminUserCreateCommand', 'Magento\Setup\Console\Command\ConfigSetCommand', + 'Magento\Setup\Console\Command\DbDataUpgradeCommand', + 'Magento\Setup\Console\Command\DbSchemaUpgradeCommand', + 'Magento\Setup\Console\Command\DbStatusCommand', + 'Magento\Setup\Console\Command\InfoCurrencyListCommand', + 'Magento\Setup\Console\Command\InfoLanguageListCommand', + 'Magento\Setup\Console\Command\InfoTimezoneListCommand', + 'Magento\Setup\Console\Command\InstallCommand', + 'Magento\Setup\Console\Command\InstallStoreConfigurationCommand', + 'Magento\Setup\Console\Command\ModuleEnableCommand', + 'Magento\Setup\Console\Command\ModuleDisableCommand', + 'Magento\Setup\Console\Command\ModuleStatusCommand', + 'Magento\Setup\Console\Command\MaintenanceAllowIpsCommand', + 'Magento\Setup\Console\Command\MaintenanceDisableCommand', + 'Magento\Setup\Console\Command\MaintenanceEnableCommand', + 'Magento\Setup\Console\Command\MaintenanceStatusCommand', + 'Magento\Setup\Console\Command\UpgradeCommand', + 'Magento\Setup\Console\Command\UninstallCommand', ]; } diff --git a/setup/src/Magento/Setup/Controller/ConsoleController.php b/setup/src/Magento/Setup/Controller/ConsoleController.php deleted file mode 100644 index eb0ca1f1d1e79cd90eb74511a00aa934c9227a33..0000000000000000000000000000000000000000 --- a/setup/src/Magento/Setup/Controller/ConsoleController.php +++ /dev/null @@ -1,689 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Setup\Controller; - -use Composer\Package\Version\VersionParser; -use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; -use Magento\Framework\App\MaintenanceMode; -use Magento\Setup\Model\AdminAccount; -use Magento\Framework\Config\ConfigOptionsList as SetupConfigOptionsList; -use Magento\Setup\Model\ConsoleLogger; -use Magento\Setup\Model\Installer; -use Magento\Setup\Model\InstallerFactory; -use Magento\Setup\Model\Lists; -use Magento\Setup\Model\UserConfigurationDataMapper as UserConfig; -use Magento\Setup\Mvc\Bootstrap\InitParamListener; -use Zend\Console\Request as ConsoleRequest; -use Zend\EventManager\EventManagerInterface; -use Zend\Mvc\Controller\AbstractActionController; -use Magento\Setup\Model\ObjectManagerProvider; -use Magento\Framework\Module\DbVersionInfo; - -/** - * Controller that handles all setup commands via command line interface. - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ -class ConsoleController extends AbstractActionController -{ - /**#@+ - * Supported command types - */ - const CMD_HELP = 'help'; - const CMD_INSTALL = 'install'; - const CMD_INSTALL_CONFIG = 'install-configuration'; - const CMD_INSTALL_SCHEMA = 'install-schema'; - const CMD_INSTALL_DATA = 'install-data'; - const CMD_INSTALL_USER_CONFIG = 'install-user-configuration'; - const CMD_INSTALL_ADMIN_USER = 'install-admin-user'; - const CMD_UPDATE = 'update'; - const CMD_DB_STATUS = 'db-status'; - const CMD_UNINSTALL = 'uninstall'; - const CMD_MAINTENANCE = 'maintenance'; - const CMD_MODULE_ENABLE = 'module-enable'; - 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 - * - * @var string[] - */ - private static $actions = [ - self::CMD_HELP => 'help', - self::CMD_INSTALL => 'install', - self::CMD_INSTALL_SCHEMA => 'installSchema', - self::CMD_INSTALL_DATA => 'installData', - self::CMD_INSTALL_USER_CONFIG => 'installUserConfig', - self::CMD_INSTALL_ADMIN_USER => 'installAdminUser', - self::CMD_UPDATE => 'update', - self::CMD_DB_STATUS => 'dbStatus', - self::CMD_UNINSTALL => 'uninstall', - self::CMD_MAINTENANCE => 'maintenance', - self::CMD_MODULE_ENABLE => 'module', - self::CMD_MODULE_DISABLE => 'module', - ]; - - /** - * Options for "help" command - * - * @var string[] - */ - private static $helpOptions = [ - self::CMD_INSTALL, - self::CMD_INSTALL_SCHEMA, - self::CMD_INSTALL_DATA, - self::CMD_INSTALL_USER_CONFIG, - self::CMD_INSTALL_ADMIN_USER, - self::CMD_UPDATE, - self::CMD_DB_STATUS, - self::CMD_UNINSTALL, - self::CMD_MAINTENANCE, - self::CMD_MODULE_ENABLE, - self::CMD_MODULE_DISABLE, - UserConfig::KEY_LANGUAGE, - UserConfig::KEY_CURRENCY, - UserConfig::KEY_TIMEZONE, - self::HELP_LIST_OF_MODULES, - ]; - - /** - * Logger - * - * @var ConsoleLogger - */ - private $log; - - /** - * Options Lists - * - * @var Lists - */ - private $options; - - /** - * Installer service - * - * @var Installer - */ - private $installer; - - /** - * Object manager provider - * - * @var ObjectManagerProvider - */ - private $objectManagerProvider; - - /** - * Gets router configuration to be used in module definition - * - * @return array - */ - public static function getRouterConfig() - { - $result = []; - $config = self::getCliConfig(); - foreach (self::$actions as $type => $action) { - $result[$type] = ['options' => [ - 'route' => $config[$type]['route'], - 'defaults' => ['controller' => __CLASS__, 'action' => $action], - ]]; - } - return $result; - } - - /** - * Gets console usage to be used in module definition - * - * @return array - */ - public static function getConsoleUsage() - { - $result = ["Usage:\n"]; - foreach (self::getCliConfig() as $cmd) { - $result[$cmd['usage_short']] = $cmd['usage_desc']; - } - foreach (self::$helpOptions as $type) { - $result[] = ' ' . ConsoleController::CMD_HELP . ' ' . $type; - } - return $result; - } - - /** - * Gets command usage - * - * @return array - */ - public static function getCommandUsage() - { - $result = []; - foreach (self::getCliConfig() as $key => $cmd) { - $result[$key] = $cmd['usage']; - } - return $result; - } - - /** - * The CLI that this controller implements - * - * @return array - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - private static function getCliConfig() - { - $deployConfig = '--' . SetupConfigOptionsList::INPUT_KEY_DB_HOST . '=' - . ' --' . SetupConfigOptionsList::INPUT_KEY_DB_NAME . '=' - . ' --' . SetupConfigOptionsList::INPUT_KEY_DB_USER . '=' - . ' --' . BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME . '=' - . ' [--' . SetupConfigOptionsList::INPUT_KEY_DB_PASS . '=]' - . ' [--' . SetupConfigOptionsList::INPUT_KEY_DB_PREFIX . '=]' - . ' [--' . SetupConfigOptionsList::INPUT_KEY_DB_MODEL . '=]' - . ' [--' . SetupConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS . '=]' - . ' [--' . SetupConfigOptionsList::INPUT_KEY_SESSION_SAVE . '=]' - . ' [--' . SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY . '=]' - . ' [--' . Installer::ENABLE_MODULES . '=]' - . ' [--' . Installer::DISABLE_MODULES . '=]'; - $userConfig = '[--' . UserConfig::KEY_BASE_URL . '=]' - . ' [--' . UserConfig::KEY_LANGUAGE . '=]' - . ' [--' . UserConfig::KEY_TIMEZONE . '=]' - . ' [--' . UserConfig::KEY_CURRENCY . '=]' - . ' [--' . UserConfig::KEY_USE_SEF_URL . '=]' - . ' [--' . UserConfig::KEY_IS_SECURE . '=]' - . ' [--' . UserConfig::KEY_BASE_URL_SECURE . '=]' - . ' [--' . UserConfig::KEY_IS_SECURE_ADMIN . '=]' - . ' [--' . UserConfig::KEY_ADMIN_USE_SECURITY_KEY . '=]'; - $adminUser = '--' . AdminAccount::KEY_USERNAME . '=' - . ' --' . AdminAccount::KEY_PASSWORD . '=' - . ' --' . AdminAccount::KEY_EMAIL . '=' - . ' --' . AdminAccount::KEY_FIRST_NAME . '=' - . ' --' . AdminAccount::KEY_LAST_NAME . '='; - $salesConfig = '[--' . Installer::SALES_ORDER_INCREMENT_PREFIX . '=]'; - return [ - self::CMD_INSTALL => [ - 'route' => self::CMD_INSTALL - . " {$deployConfig} {$userConfig} {$adminUser} {$salesConfig}" - . ' [--' . Installer::CLEANUP_DB . ']' - . ' [--' . Installer::USE_SAMPLE_DATA . '=]', - 'usage' => "{$deployConfig} {$userConfig} {$adminUser} {$salesConfig}" - . ' [--' . Installer::CLEANUP_DB . ']' - . ' [--' . Installer::USE_SAMPLE_DATA . '=]', - 'usage_short' => self::CMD_INSTALL . ' <options>', - 'usage_desc' => 'Install Magento application', - ], - self::CMD_UPDATE => [ - 'route' => self::CMD_UPDATE, - 'usage' => '', - 'usage_short' => self::CMD_UPDATE, - 'usage_desc' => 'Update database schema and data', - ], - self::CMD_DB_STATUS => [ - 'route' => self::CMD_DB_STATUS, - 'usage' => '', - 'usage_short' => self::CMD_DB_STATUS, - 'usage_desc' => 'Check if update of DB schema or data is required', - ], - self::CMD_UNINSTALL => [ - 'route' => self::CMD_UNINSTALL, - 'usage' => '', - 'usage_short' => self::CMD_UNINSTALL, - 'usage_desc' => 'Uninstall Magento application', - ], - self::CMD_INSTALL_SCHEMA => [ - 'route' => self::CMD_INSTALL_SCHEMA, - 'usage' => '', - 'usage_short' => self::CMD_INSTALL_SCHEMA, - 'usage_desc' => 'Install DB schema', - ], - self::CMD_INSTALL_DATA => [ - 'route' => self::CMD_INSTALL_DATA, - 'usage' => '', - 'usage_short' => self::CMD_INSTALL_DATA, - 'usage_desc' => 'Install data fixtures', - ], - self::CMD_INSTALL_USER_CONFIG => [ - 'route' => self::CMD_INSTALL_USER_CONFIG . ' ' . $userConfig, - 'usage' => $userConfig, - 'usage_short' => self::CMD_INSTALL_USER_CONFIG . ' <options>', - 'usage_desc' => 'Install user configuration', - ], - self::CMD_INSTALL_ADMIN_USER => [ - 'route' => self::CMD_INSTALL_ADMIN_USER . ' ' . $adminUser, - 'usage' => $adminUser, - 'usage_short' => self::CMD_INSTALL_ADMIN_USER . ' <options>', - 'usage_desc' => 'Install admin user account', - ], - self::CMD_MAINTENANCE => [ - 'route' => self::CMD_MAINTENANCE . ' [--set=] [--addresses=]', - 'usage' => '[--set=1|0] [--addresses=127.0.0.1,...|none]', - '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) . '>', - 'usage_short' => self::CMD_HELP . ' <topic>', - 'usage_desc' => 'Help about particular command or topic:', - ], - ]; - } - - /** - * Constructor - * - * @param ConsoleLogger $consoleLogger - * @param Lists $options - * @param InstallerFactory $installerFactory - * @param MaintenanceMode $maintenanceMode - * @param ObjectManagerProvider $objectManagerProvider - */ - public function __construct( - ConsoleLogger $consoleLogger, - Lists $options, - InstallerFactory $installerFactory, - MaintenanceMode $maintenanceMode, - ObjectManagerProvider $objectManagerProvider - ) { - $this->log = $consoleLogger; - $this->options = $options; - $this->installer = $installerFactory->create($consoleLogger); - $this->maintenanceMode = $maintenanceMode; - $this->objectManagerProvider = $objectManagerProvider; - // By default we use our customized error handler, but for CLI we want to display all errors - restore_error_handler(); - } - - /** - * Adding Check for Allowing only console application to come through - * - * {@inheritdoc} - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - */ - public function setEventManager(EventManagerInterface $events) - { - parent::setEventManager($events); - $controller = $this; - $events->attach('dispatch', function ($action) use ($controller) { - /** @var $action \Zend\Mvc\Controller\AbstractActionController */ - // Make sure that we are running in a console and the user has not tricked our - // application into running this action from a public web server. - if (!$action->getRequest() instanceof ConsoleRequest) { - throw new \RuntimeException('You can only use this action from a console!'); - } - }, 100); // execute before executing action logic - return $this; - } - - /** - * {@inheritdoc} - */ - public function onDispatch(\Zend\Mvc\MvcEvent $e) - { - try { - return parent::onDispatch($e); - } catch (\Magento\Setup\Exception $exception) { - $this->log->log($exception->getMessage()); - return $this->getResponse(); - } - } - - /** - * Controller for Install Command - * - * @return void - */ - public function installAction() - { - /** @var \Zend\Console\Request $request */ - $request = $this->getRequest(); - $this->installer->install($request->getParams()); - } - - /** - * Installs and updates database schema - * - * @return void - */ - public function installSchemaAction() - { - $this->installer->installSchema(); - } - - /** - * Installs and updates data fixtures - * - * @return void - */ - public function installDataAction() - { - $this->installer->installDataFixtures(); - } - - /** - * Updates database schema and data - * - * @return void - */ - public function updateAction() - { - $this->installer->updateModulesSequence(); - $this->installer->installSchema(); - $this->installer->installDataFixtures(); - } - - /** - * Checks if DB schema or data upgrade is required - * - * @return void - */ - public function dbStatusAction() - { - /** @var DbVersionInfo $dbVersionInfo */ - $dbVersionInfo = $this->objectManagerProvider->get() - ->get('Magento\Framework\Module\DbVersionInfo'); - $outdated = $dbVersionInfo->getDbVersionErrors(); - if (!empty($outdated)) { - $this->log->log("The module code base doesn't match the DB schema and data."); - $versionParser = new VersionParser(); - $codebaseUpdateNeeded = false; - foreach ($outdated as $row) { - if (!$codebaseUpdateNeeded && $row[DbVersionInfo::KEY_CURRENT] !== 'none') { - // check if module code base update is needed - $currentVersion = $versionParser->parseConstraints($row[DbVersionInfo::KEY_CURRENT]); - $requiredVersion = $versionParser->parseConstraints('>' . $row[DbVersionInfo::KEY_REQUIRED]); - if ($requiredVersion->matches($currentVersion)) { - $codebaseUpdateNeeded = true; - }; - } - $this->log->log(sprintf( - "%20s %10s: %11s -> %-11s", - $row[DbVersionInfo::KEY_MODULE], - $row[DbVersionInfo::KEY_TYPE], - $row[DbVersionInfo::KEY_CURRENT], - $row[DbVersionInfo::KEY_REQUIRED] - )); - } - if ($codebaseUpdateNeeded) { - $this->log->log( - 'Some modules use code versions newer or older than the database. ' . - 'First update the module code, then run the "Update" command.' - ); - } else { - $this->log->log('Run the "Update" command to update your DB schema and data'); - } - } else { - $this->log->log('All modules are up to date'); - } - } - - /** - * Installs user configuration - * - * @return void - */ - public function installUserConfigAction() - { - /** @var \Zend\Console\Request $request */ - $request = $this->getRequest(); - $this->installer->installUserConfig($request->getParams()); - } - - /** - * Installs admin user - * - * @return void - */ - public function installAdminUserAction() - { - /** @var \Zend\Console\Request $request */ - $request = $this->getRequest(); - $this->installer->installAdminUser($request->getParams()); - } - - /** - * Controller for Uninstall Command - * - * @return void - */ - public function uninstallAction() - { - $this->installer->uninstall(); - } - - /** - * Action for "maintenance" command - * - * @return void - * @SuppressWarnings(PHPMD.NPathComplexity) - * - */ - public function maintenanceAction() - { - /** @var \Zend\Console\Request $request */ - $request = $this->getRequest(); - $set = $request->getParam('set'); - $addresses = $request->getParam('addresses'); - - if (null !== $set) { - if (1 == $set) { - $this->log->log('Enabling maintenance mode...'); - $this->maintenanceMode->set(true); - } else { - $this->log->log('Disabling maintenance mode...'); - $this->maintenanceMode->set(false); - } - } - if (null !== $addresses) { - $addresses = ('none' == $addresses) ? '' : $addresses; - $this->maintenanceMode->setAddresses($addresses); - } - - $this->log->log('Status: maintenance mode is ' . ($this->maintenanceMode->isOn() ? 'active' : 'not active')); - $addressInfo = $this->maintenanceMode->getAddressInfo(); - if (!empty($addressInfo)) { - $addresses = implode(', ', $addressInfo); - $this->log->log('List of exempt IP-addresses: ' . ($addresses ? $addresses : 'none')); - } - } - - /** - * 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->objectManagerProvider->get()->create('Magento\Framework\Module\Status'); - - $modulesToChange = $status->getModulesToChange($isEnable, $modules); - $message = ''; - if (!empty($modulesToChange)) { - if (!$request->getParam('force')) { - $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); - } - } else { - $message .= 'Alert: Your store may not operate properly because of ' - . "dependencies and conflicts of this module(s).\n"; - } - $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) . $updateAfterEnableMessage; - } else { - $message .= 'There have been no changes to any modules.'; - } - $this->log->log($message); - } - - /** - * Shows necessary information for installing Magento - * - * @return string - * @throws \InvalidArgumentException - */ - public function helpAction() - { - $type = $this->getRequest()->getParam('type'); - if ($type === false) { - $usageInfo = $this->formatConsoleFullUsageInfo( - array_merge(self::getConsoleUsage(), InitParamListener::getConsoleUsage()) - ); - return $usageInfo; - } - switch($type) { - case UserConfig::KEY_LANGUAGE: - return $this->arrayToString($this->options->getLocaleList()); - case UserConfig::KEY_CURRENCY: - return $this->arrayToString($this->options->getCurrencyList()); - case UserConfig::KEY_TIMEZONE: - return $this->arrayToString($this->options->getTimezoneList()); - case self::HELP_LIST_OF_MODULES: - return $this->getModuleListMsg(); - default: - $usages = self::getCommandUsage(); - if (isset($usages[$type])) { - if ($usages[$type]) { - $formatted = $this->formatCliUsage($usages[$type]); - return "\nAvailable parameters:\n{$formatted}\n"; - } - return "\nThis command has no parameters.\n"; - } - throw new \InvalidArgumentException("Unknown type: {$type}"); - } - } - - /** - * Formats full usage info for console when user inputs 'help' command with no type - * - * @param array $usageInfo - * @return string - */ - private function formatConsoleFullUsageInfo($usageInfo) - { - $result = "\n==-------------------==\n" - . " Magento Setup CLI \n" - . "==-------------------==\n"; - $mask = "%-50s %-30s\n"; - $script = 'index.php'; - foreach ($usageInfo as $key => $value) { - if ($key === 0) { - $result .= sprintf($mask, "\n$value", ''); - } elseif (is_numeric($key)) { - if (is_array($value)) { - $result .= sprintf($mask, " " . $value[0], $value[1]); - } else { - $result .= sprintf($mask, '', $value); - } - } else { - $result .= sprintf($mask, " $script " . $key, $value); - } - } - return $result; - } - - /** - * Formats output of "usage" into more readable format by grouping required/optional parameters and wordwrapping - * - * @param string $text - * @return string - */ - private function formatCliUsage($text) - { - $result = ['required' => [], 'optional' => []]; - foreach (explode(' ', $text) as $value) { - if (empty($value)) { - continue; - } - if (strpos($value, '[') === 0) { - $group = 'optional'; - } else { - $group = 'required'; - } - $result[$group][] = $value; - } - - return wordwrap(implode(' ', $result['required']) . "\n" . implode(' ', $result['optional']), 120); - } - - /** - * Convert an array to string - * - * @param array $input - * @return string - */ - private function arrayToString($input) - { - $result = ''; - foreach ($input as $key => $value) { - $result .= "$key => $value\n"; - } - return $result; - } - - /** - * Get formatted message containing list of enabled and disabled modules - * - * @return string - */ - private function getModuleListMsg() - { - $moduleList = $this->objectManagerProvider->get()->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->objectManagerProvider->get()->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; - } -} diff --git a/setup/src/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php index 0618df92d08c81e9974c73079cf7ab6a66e8d078..87ca5ba26940acc55ddbe6b159aba0f0f01afe37 100644 --- a/setup/src/Magento/Setup/Controller/Install.php +++ b/setup/src/Magento/Setup/Controller/Install.php @@ -12,12 +12,13 @@ use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; use Magento\Setup\Model\Installer; use Magento\Setup\Model\Installer\ProgressFactory; use Magento\Setup\Model\InstallerFactory; -use Magento\Setup\Model\UserConfigurationDataMapper as UserConfig; +use Magento\Setup\Model\StoreConfigurationDataMapper as UserConfig; use Magento\Setup\Model\WebLogger; use Zend\Json\Json; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\JsonModel; use Zend\View\Model\ViewModel; +use Magento\Setup\Console\Command\InstallCommand; /** * Install controller @@ -131,7 +132,7 @@ class Install extends AbstractActionController $result[SetupConfigOptionsList::INPUT_KEY_DB_HOST] = isset($source['db']['host']) ? $source['db']['host'] : ''; $result[SetupConfigOptionsList::INPUT_KEY_DB_NAME] = isset($source['db']['name']) ? $source['db']['name'] : ''; $result[SetupConfigOptionsList::INPUT_KEY_DB_USER] = isset($source['db']['user']) ? $source['db']['user'] :''; - $result[SetupConfigOptionsList::INPUT_KEY_DB_PASS] = + $result[SetupConfigOptionsList::INPUT_KEY_DB_PASSWORD] = isset($source['db']['password']) ? $source['db']['password'] : ''; $result[SetupConfigOptionsList::INPUT_KEY_DB_PREFIX] = isset($source['db']['tablePrefix']) ? $source['db']['tablePrefix'] : ''; @@ -175,7 +176,7 @@ class Install extends AbstractActionController ? $source['store']['timezone'] : ''; $result[UserConfig::KEY_CURRENCY] = isset($source['store']['currency']) ? $source['store']['currency'] : ''; - $result[Installer::USE_SAMPLE_DATA] = isset($source['store']['useSampleData']) + $result[InstallCommand::INPUT_KEY_USE_SAMPLE_DATA] = isset($source['store']['useSampleData']) ? $source['store']['useSampleData'] : ''; return $result; } @@ -189,11 +190,11 @@ class Install extends AbstractActionController { $source = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); $result = []; - $result[AdminAccount::KEY_USERNAME] = isset($source['admin']['username']) ? $source['admin']['username'] : ''; + $result[AdminAccount::KEY_USER] = isset($source['admin']['username']) ? $source['admin']['username'] : ''; $result[AdminAccount::KEY_PASSWORD] = isset($source['admin']['password']) ? $source['admin']['password'] : ''; $result[AdminAccount::KEY_EMAIL] = isset($source['admin']['email']) ? $source['admin']['email'] : ''; - $result[AdminAccount::KEY_FIRST_NAME] = $result[AdminAccount::KEY_USERNAME]; - $result[AdminAccount::KEY_LAST_NAME] = $result[AdminAccount::KEY_USERNAME]; + $result[AdminAccount::KEY_FIRST_NAME] = $result[AdminAccount::KEY_USER]; + $result[AdminAccount::KEY_LAST_NAME] = $result[AdminAccount::KEY_USER]; return $result; } } diff --git a/setup/src/Magento/Setup/Model/AdminAccount.php b/setup/src/Magento/Setup/Model/AdminAccount.php index 2bd64aaecd675d2315be375e6a8761ab8d733b16..7e52b2b604e10f76f660e28d50f26cf59f3d2c6e 100644 --- a/setup/src/Magento/Setup/Model/AdminAccount.php +++ b/setup/src/Magento/Setup/Model/AdminAccount.php @@ -17,7 +17,7 @@ class AdminAccount /**#@+ * Data keys */ - const KEY_USERNAME = 'admin_username'; + const KEY_USER = 'admin_user'; const KEY_PASSWORD = 'admin_password'; const KEY_EMAIL = 'admin_email'; const KEY_FIRST_NAME = 'admin_firstname'; @@ -102,7 +102,7 @@ class AdminAccount $result = $this->setup->getConnection()->fetchRow( 'SELECT user_id, username, email FROM ' . $this->setup->getTable('admin_user') . ' ' . 'WHERE username = :username OR email = :email', - ['username' => $this->data[self::KEY_USERNAME], 'email' => $this->data[self::KEY_EMAIL]] + ['username' => $this->data[self::KEY_USER], 'email' => $this->data[self::KEY_EMAIL]] ); if (!empty($result)) { @@ -113,11 +113,11 @@ class AdminAccount $this->setup->getConnection()->update( $this->setup->getTable('admin_user'), $adminData, - $this->setup->getConnection()->quoteInto('username = ?', $this->data[self::KEY_USERNAME]) + $this->setup->getConnection()->quoteInto('username = ?', $this->data[self::KEY_USER]) ); } else { // User does not exist, create it - $adminData['username'] = $this->data[self::KEY_USERNAME]; + $adminData['username'] = $this->data[self::KEY_USER]; $adminData['email'] = $this->data[self::KEY_EMAIL]; $adminData['extra'] = serialize(null); $this->setup->getConnection()->insert( @@ -140,18 +140,18 @@ class AdminAccount private function validateUserMatches($username, $email) { if ((strcasecmp($email, $this->data[self::KEY_EMAIL]) == 0) && - (strcasecmp($username, $this->data[self::KEY_USERNAME]) != 0)) { + (strcasecmp($username, $this->data[self::KEY_USER]) != 0)) { // email matched but username did not throw new \Exception( - 'An existing user has the given email but different username. ' . self::KEY_USERNAME . + 'An existing user has the given email but different username. ' . self::KEY_USER . ' and ' . self::KEY_EMAIL . ' both need to match an existing user or both be new.' ); } - if ((strcasecmp($username, $this->data[self::KEY_USERNAME]) == 0) && + if ((strcasecmp($username, $this->data[self::KEY_USER]) == 0) && (strcasecmp($email, $this->data[self::KEY_EMAIL]) != 0)) { // username matched but email did not throw new \Exception( - 'An existing user has the given username but different email. ' . self::KEY_USERNAME . + 'An existing user has the given username but different email. ' . self::KEY_USER . ' and ' . self::KEY_EMAIL . ' both need to match an existing user or both be new.' ); } @@ -180,7 +180,7 @@ class AdminAccount 'role_type' => User::ROLE_TYPE, 'user_id' => $adminId, 'user_type' => UserContextInterface::USER_TYPE_ADMIN, - 'role_name' => $this->data[self::KEY_USERNAME], + 'role_name' => $this->data[self::KEY_USER], ]; $this->setup->getConnection()->insert($this->setup->getTable('authorization_role'), $adminRoleData); } diff --git a/setup/src/Magento/Setup/Model/ConsoleLogger.php b/setup/src/Magento/Setup/Model/ConsoleLogger.php index e0c0aa147272977e68f05fd731614284be45b5b5..3bcd21aabe083ce1066554ca661e2b4e270e2916 100644 --- a/setup/src/Magento/Setup/Model/ConsoleLogger.php +++ b/setup/src/Magento/Setup/Model/ConsoleLogger.php @@ -6,8 +6,8 @@ namespace Magento\Setup\Model; -use Zend\Console\ColorInterface; -use Zend\Console\Console; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; /** * Console Logger @@ -26,16 +26,21 @@ class ConsoleLogger implements LoggerInterface /** * Console * - * @var \Zend\Console\Adapter\AdapterInterface + * @var OutputInterface */ protected $console; /** * Constructor + * + * @param OutputInterface $output */ - public function __construct() + public function __construct(OutputInterface $output) { - $this->console = Console::getInstance(); + $this->console = $output; + $outputFormatter = $this->console->getFormatter(); + $outputFormatter->setStyle('detail', new OutputFormatterStyle('blue')); + $outputFormatter->setStyle('metadata', new OutputFormatterStyle('cyan')); } /** @@ -44,7 +49,7 @@ class ConsoleLogger implements LoggerInterface public function logSuccess($message) { $this->terminateLine(); - $this->console->writeLine("[SUCCESS]" . ($message ? ": $message" : ''), ColorInterface::LIGHT_GREEN); + $this->console->writeln("<info>[SUCCESS]" . ($message ? ": $message" : '') . '</info>'); } /** @@ -53,7 +58,7 @@ class ConsoleLogger implements LoggerInterface public function logError(\Exception $e) { $this->terminateLine(); - $this->console->writeLine("[ERROR]: " . $e, ColorInterface::LIGHT_RED); + $this->console->writeln("<error>[ERROR]: " . $e . '</error>'); } /** @@ -62,7 +67,7 @@ class ConsoleLogger implements LoggerInterface public function log($message) { $this->terminateLine(); - $this->console->writeLine($message, ColorInterface::LIGHT_BLUE); + $this->console->writeln('<detail>' . $message . '</detail>'); } /** @@ -71,7 +76,7 @@ class ConsoleLogger implements LoggerInterface public function logInline($message) { $this->isInline = true; - $this->console->write($message, ColorInterface::LIGHT_BLUE); + $this->console->write('<detail>' . $message . '</detail>'); } /** @@ -80,7 +85,7 @@ class ConsoleLogger implements LoggerInterface public function logMeta($message) { $this->terminateLine(); - $this->console->writeLine($message, ColorInterface::GRAY); + $this->console->writeln('<metadata>' . $message . '</metadata>'); } /** @@ -92,7 +97,7 @@ class ConsoleLogger implements LoggerInterface { if ($this->isInline) { $this->isInline = false; - $this->console->writeLine(''); + $this->console->writeln(''); } } } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 451c0c06800a1fe01d04d079bc34b8e503ddbe15..5db3a546a66113ea49ff556c9f346281ec8afc44 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -29,6 +29,8 @@ use Magento\Store\Model\Store; use Magento\Setup\Module\ConnectionFactory; use Magento\Setup\Module\Setup; use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\App\State\CleanupFiles; +use Magento\Setup\Console\Command\InstallCommand; /** * Class Installer contains the logic to install Magento application. @@ -39,11 +41,6 @@ use Magento\Framework\Config\File\ConfigFilePool; */ class Installer { - /** - * Parameter indicating command whether to cleanup database in the install routine - */ - const CLEANUP_DB = 'cleanup_database'; - /**#@+ * Parameters for enabling/disabling modules */ @@ -51,16 +48,6 @@ class Installer const DISABLE_MODULES = 'disable_modules'; /**#@- */ - /** - * Parameter indicating command whether to install Sample Data - */ - const USE_SAMPLE_DATA = 'use_sample_data'; - - /** - * Parameter to specify an order_increment_prefix - */ - const SALES_ORDER_INCREMENT_PREFIX = 'sales_order_increment_prefix'; - /**#@+ * Formatting for progress log */ @@ -193,6 +180,11 @@ class Installer */ private $setupConfigModel; + /** + * @var CleanupFiles + */ + private $cleanupFiles; + /** * Constructor * @@ -211,7 +203,8 @@ class Installer * @param ObjectManagerProvider $objectManagerProvider * @param Context $context * @param SetupConfigModel $setupConfigModel - * + * @param CleanupFiles $cleanupFiles + * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -229,7 +222,8 @@ class Installer SampleData $sampleData, ObjectManagerProvider $objectManagerProvider, Context $context, - SetupConfigModel $setupConfigModel + SetupConfigModel $setupConfigModel, + CleanupFiles $cleanupFiles ) { $this->filePermissions = $filePermissions; $this->deploymentConfigWriter = $deploymentConfigWriter; @@ -247,6 +241,7 @@ class Installer $this->objectManagerProvider = $objectManagerProvider; $this->context = $context; $this->setupConfigModel = $setupConfigModel; + $this->cleanupFiles = $cleanupFiles; } /** @@ -261,22 +256,22 @@ class Installer $script[] = ['File permissions check...', 'checkInstallationFilePermissions', []]; $script[] = ['Enabling Maintenance Mode...', 'setMaintenanceMode', [1]]; $script[] = ['Installing deployment configuration...', 'installDeploymentConfig', [$request]]; - if (!empty($request[self::CLEANUP_DB])) { + if (!empty($request[InstallCommand::INPUT_KEY_CLEANUP_DB])) { $script[] = ['Cleaning up database...', 'cleanupDb', []]; } $script[] = ['Installing database schema:', 'installSchema', []]; $script[] = ['Installing user configuration...', 'installUserConfig', [$request]]; $script[] = ['Installing data...', 'installDataFixtures', []]; - if (!empty($request[self::SALES_ORDER_INCREMENT_PREFIX])) { + if (!empty($request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX])) { $script[] = [ 'Creating sales order increment prefix...', 'installOrderIncrementPrefix', - [$request[self::SALES_ORDER_INCREMENT_PREFIX]], + [$request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX]], ]; } $script[] = ['Installing admin user...', 'installAdminUser', [$request]]; $script[] = ['Enabling caches:', 'enableCaches', []]; - if (!empty($request[Installer::USE_SAMPLE_DATA]) && $this->sampleData->isDeployed()) { + if (!empty($request[InstallCommand::INPUT_KEY_USE_SAMPLE_DATA]) && $this->sampleData->isDeployed()) { $script[] = ['Installing sample data:', 'installSampleData', [$request]]; } $script[] = ['Disabling Maintenance Mode:', 'setMaintenanceMode', [0]]; @@ -420,12 +415,7 @@ class Installer { $this->checkInstallationFilePermissions(); $userData = is_array($data) ? $data : $data->getArrayCopy(); - - // TODO: remove this when moving install command to symfony - $userData = $this->setDefaultValues($userData); - $this->setupConfigModel->process($userData); - if ($this->deploymentConfig->isAvailable()) { $deploymentConfigData = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY); if (isset($deploymentConfigData)) { @@ -435,32 +425,6 @@ class Installer // reset object manager now that there is a deployment config $this->objectManagerProvider->reset(); } - - /** - * Sets defaults if user input is missing - * - * @param array $userData - * @return array - */ - private function setDefaultValues(array $userData) - { - if (!isset($userData[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) { - $userData[ConfigOptionsList::INPUT_KEY_SESSION_SAVE] = ConfigOptionsList::SESSION_SAVE_FILES; - } - if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_PASS])) { - $userData[ConfigOptionsList::INPUT_KEY_DB_PASS] = ''; - } - if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_MODEL])) { - $userData[ConfigOptionsList::INPUT_KEY_DB_MODEL] = 'mysql4'; - } - if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS])) { - $userData[ConfigOptionsList::INPUT_KEY_DB_INIT_STATEMENTS] = 'SET NAMES utf8;'; - } - if (!isset($userData[ConfigOptionsList::INPUT_KEY_DB_PREFIX])) { - $userData[ConfigOptionsList::INPUT_KEY_DB_PREFIX] = ''; - } - return $userData; - } /** * Set up setup_module table to register modules' versions, skip this process if it already exists @@ -822,7 +786,7 @@ class Installer */ public function installUserConfig($data) { - $userConfig = new UserConfigurationDataMapper(); + $userConfig = new StoreConfigurationDataMapper(); $configData = $userConfig->getConfigData($data); if (count($configData) === 0) { return; @@ -909,9 +873,14 @@ class Installer public function updateModulesSequence() { $this->assertDeploymentConfigExists(); + + $this->clearCache(); + $this->log->log('File system cleanup:'); - $this->deleteDirContents(DirectoryList::GENERATION); - $this->deleteDirContents(DirectoryList::CACHE); + $messages = $this->cleanupFiles->clearCodeGeneratedClasses(); + foreach ($messages as $message) { + $this->log->log($message); + } $this->log->log('Updating modules:'); $this->createModulesConfig([]); } @@ -926,14 +895,31 @@ class Installer $this->log->log('Starting Magento uninstallation:'); $this->cleanupDb(); + $this->clearCache(); + $this->log->log('File system cleanup:'); - $this->deleteDirContents(DirectoryList::VAR_DIR); - $this->deleteDirContents(DirectoryList::STATIC_VIEW); + $messages = $this->cleanupFiles->clearAllFiles(); + foreach ($messages as $message) { + $this->log->log($message); + } + $this->deleteDeploymentConfig(); $this->log->logSuccess('Magento uninstallation complete.'); } + /** + * Clears cache + * + * @return void + */ + private function clearCache() + { + $cache = $this->objectManagerProvider->get()->create('Magento\Framework\App\Cache'); + $cache->clean(); + $this->log->log('Cache cleared successfully'); + } + /** * Enables caches after installing application * @@ -1065,33 +1051,6 @@ class Installer $this->log->log('No database connection defined - skipping database cleanup'); } - /** - * Removes contents of a directory - * - * @param string $type - * @return void - */ - private function deleteDirContents($type) - { - $dir = $this->filesystem->getDirectoryWrite($type); - $dirPath = $dir->getAbsolutePath(); - if (!$dir->isExist()) { - $this->log->log("The directory '{$dirPath}' doesn't exist - skipping cleanup"); - return; - } - foreach ($dir->read() as $path) { - if (preg_match('/^\./', $path)) { - continue; - } - $this->log->log("{$dirPath}{$path}"); - try { - $dir->delete($path); - } catch (FileSystemException $e) { - $this->log->log($e->getMessage()); - } - } - } - /** * Removes deployment configuration * @@ -1140,7 +1099,7 @@ class Installer $connectionConfig[ConfigOptionsList::KEY_NAME], $connectionConfig[ConfigOptionsList::KEY_HOST], $connectionConfig[ConfigOptionsList::KEY_USER], - $connectionConfig[ConfigOptionsList::KEY_PASS] + $connectionConfig[ConfigOptionsList::KEY_PASSWORD] ); if (isset($connectionConfig[ConfigOptionsList::KEY_PREFIX])) { $this->checkDatabaseTablePrefix($connectionConfig[ConfigOptionsList::KEY_PREFIX]); @@ -1157,7 +1116,7 @@ class Installer */ private function installSampleData($request) { - $userName = isset($request[AdminAccount::KEY_USERNAME]) ? $request[AdminAccount::KEY_USERNAME] : ''; + $userName = isset($request[AdminAccount::KEY_USER]) ? $request[AdminAccount::KEY_USER] : ''; $this->sampleData->install($this->objectManagerProvider->get(), $this->log, $userName); } diff --git a/setup/src/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php index 3f12a06c8ffd7b46cdcf62d183f0defdc2e62c55..ce6bb1c99434580b03b8e8385b3deb7dd148bc2e 100644 --- a/setup/src/Magento/Setup/Model/InstallerFactory.php +++ b/setup/src/Magento/Setup/Model/InstallerFactory.php @@ -9,6 +9,7 @@ namespace Magento\Setup\Model; use Zend\ServiceManager\ServiceLocatorInterface; use Magento\Setup\Module\ResourceFactory; use Magento\Framework\App\ErrorHandler; +use Magento\Framework\App\State\CleanupFiles; class InstallerFactory { @@ -66,7 +67,8 @@ class InstallerFactory $this->serviceLocator->get('Magento\Framework\Model\Resource\Db\TransactionManager'), $this->serviceLocator->get('Magento\Framework\Model\Resource\Db\ObjectRelationProcessor') ), - $this->serviceLocator->get('Magento\Setup\Model\ConfigModel') + $this->serviceLocator->get('Magento\Setup\Model\ConfigModel'), + $this->serviceLocator->get('Magento\Framework\App\State\CleanupFiles') ); } diff --git a/setup/src/Magento/Setup/Model/UserConfigurationDataMapper.php b/setup/src/Magento/Setup/Model/StoreConfigurationDataMapper.php similarity index 70% rename from setup/src/Magento/Setup/Model/UserConfigurationDataMapper.php rename to setup/src/Magento/Setup/Model/StoreConfigurationDataMapper.php index e9985cb4d52cc4d420bd9f04f94b44f1566e7262..0fa3c235244568c8a4e7dbf2595c658f87f9dd68 100644 --- a/setup/src/Magento/Setup/Model/UserConfigurationDataMapper.php +++ b/setup/src/Magento/Setup/Model/StoreConfigurationDataMapper.php @@ -17,7 +17,7 @@ use Magento\Store\Model\Store; * * @package Magento\Setup\Model */ -class UserConfigurationDataMapper +class StoreConfigurationDataMapper { /**#@+ * Model data keys @@ -43,6 +43,8 @@ class UserConfigurationDataMapper Store::XML_PATH_UNSECURE_BASE_URL => self::KEY_BASE_URL, Store::XML_PATH_SECURE_BASE_URL => self::KEY_BASE_URL_SECURE, Data::XML_PATH_DEFAULT_LOCALE => self::KEY_LANGUAGE, + Store::XML_PATH_SECURE_IN_FRONTEND => self::KEY_IS_SECURE, + Store::XML_PATH_SECURE_IN_ADMINHTML => self::KEY_IS_SECURE_ADMIN, Data::XML_PATH_DEFAULT_TIMEZONE => self::KEY_TIMEZONE, Currency::XML_PATH_CURRENCY_BASE => self::KEY_CURRENCY, Currency::XML_PATH_CURRENCY_DEFAULT => self::KEY_CURRENCY, @@ -59,20 +61,6 @@ class UserConfigurationDataMapper public function getConfigData($installParamData) { $configData = []; - if (!$this->isSecureUrlNeeded($installParamData) && isset($installParamData[self::KEY_BASE_URL_SECURE])) { - unset($installParamData[self::KEY_BASE_URL_SECURE]); - } - - // Base URL is secure, add secure entries - if (isset($installParamData[self::KEY_BASE_URL_SECURE])) { - $this->pathDataMap = array_merge( - $this->pathDataMap, - [ - Store::XML_PATH_SECURE_IN_FRONTEND => self::KEY_IS_SECURE, - Store::XML_PATH_SECURE_IN_ADMINHTML => self::KEY_IS_SECURE_ADMIN - ] - ); - } foreach ($this->pathDataMap as $path => $key) { $configData = $this->addParamToConfigData($configData, $installParamData, $key, $path); @@ -80,18 +68,6 @@ class UserConfigurationDataMapper return $configData; } - /** - * Determine if secure URL is needed (use_secure or use_secure_admin flag is set.) - * - * @param array $installParamData - * @return bool - */ - private function isSecureUrlNeeded($installParamData) - { - return ((isset($installParamData[self::KEY_IS_SECURE]) && $installParamData[self::KEY_IS_SECURE]) - || (isset($installParamData[self::KEY_IS_SECURE_ADMIN]) && $installParamData[self::KEY_IS_SECURE_ADMIN])); - } - /** * Adds an install parameter value to the configData structure * diff --git a/setup/src/Magento/Setup/Module.php b/setup/src/Magento/Setup/Module.php index 10141ca8f7e6416d1589a676da4268501e9b1ba8..55dd70b8c7b68ef24bf3c840b3bcd43a729998a5 100644 --- a/setup/src/Magento/Setup/Module.php +++ b/setup/src/Magento/Setup/Module.php @@ -6,7 +6,6 @@ namespace Magento\Setup; -use Magento\Setup\Mvc\Bootstrap\InitParamListener; use Magento\Setup\Mvc\View\Http\InjectTemplateListener; use Zend\EventManager\EventInterface; use Zend\ModuleManager\Feature\BootstrapListenerInterface; @@ -66,7 +65,6 @@ class Module implements include __DIR__ . '/../../../config/states.config.php', include __DIR__ . '/../../../config/languages.config.php' ); - $result = InitParamListener::attachToConsoleRoutes($result); return $result; } } diff --git a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php index 19e6317e96e43c24b996cc194c1c8addc238fe41..1d229e825f9c8f43c165e93bf62574ea9b34c0af 100644 --- a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php +++ b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php @@ -39,45 +39,6 @@ class InitParamListener implements ListenerAggregateInterface, FactoryInterface */ private $listeners = []; - /** - * Registers itself to every command in console routes - * - * @param array $config - * @return array - */ - public static function attachToConsoleRoutes($config) - { - if (isset($config['console']['router']['routes'])) { - foreach ($config['console']['router']['routes'] as &$route) { - $route['options']['route'] .= ' [--' . self::BOOTSTRAP_PARAM . '=]'; - } - } - return $config; - } - - /** - * Adds itself to CLI usage instructions - * - * @return array - */ - public static function getConsoleUsage() - { - $result = ['']; - $result[] = [ - '[--' . self::BOOTSTRAP_PARAM . sprintf('=%s]', escapeshellarg('<query>')), - 'Add to any command to customize Magento initialization parameters', - ]; - $mode = State::PARAM_MODE; - $dirs = AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS; - $examples = [ - "{$mode}=developer", - "{$dirs}[base][path]=/var/www/example.com", - "{$dirs}[cache][path]=/var/tmp/cache", - ]; - $result[] = ['', sprintf('For example: %s', escapeshellarg(implode('&', $examples)))]; - return $result; - } - /** * {@inheritdoc} */ diff --git a/setup/src/Magento/Setup/Mvc/Console/RouteListener.php b/setup/src/Magento/Setup/Mvc/Console/RouteListener.php deleted file mode 100644 index 5b4dcbfde5a8c935edd544627be8aeae85ee70a7..0000000000000000000000000000000000000000 --- a/setup/src/Magento/Setup/Mvc/Console/RouteListener.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Setup\Mvc\Console; - -use Zend\View\Model\ConsoleModel; -use Zend\Mvc\Router\RouteMatch; -use Zend\Mvc\MvcEvent; -use Zend\Console\ColorInterface; -use Zend\EventManager\EventManagerInterface; - -/** - * Custom route listener to validate user parameters - */ -class RouteListener extends \Zend\Mvc\RouteListener -{ - /** - * {@inheritdoc} - */ - public function onRoute($e) - { - $request = $e->getRequest(); - // propagates to default RouteListener if not CLI - if (!$request instanceof \Zend\Console\Request) { - return null; - } - - $router = $e->getRouter(); - $match = $router->match($request); - - // CLI routing miss, checks for missing/extra parameters - if (!$match instanceof RouteMatch) { - $content = $request->getContent(); - $config = $e->getApplication()->getServiceManager()->get('Config')['console']['router']['routes']; - - $verboseValidator = new VerboseValidator(); - $validationMessages = $verboseValidator->validate($content, $config); - - if ('' !== $validationMessages) { - $this->displayMessages($e, $validationMessages); - // set error to stop propagation - $e->setError('default_error'); - } - } - return null; - } - - /** - * Display messages on console - * - * @param MvcEvent $e - * @param string $validationMessages - * @return void - */ - private function displayMessages(MvcEvent $e, $validationMessages) - { - /** @var \Zend\Console\Adapter\AdapterInterface $console */ - $console = $e->getApplication()->getServiceManager()->get('console'); - $validationMessages = $console->colorize($validationMessages, ColorInterface::RED); - $model = new ConsoleModel(); - $model->setErrorLevel(1); - $model->setResult($validationMessages); - $e->setResult($model); - } - - /** - * {@inheritdoc} - */ - public function attach(EventManagerInterface $events) - { - // set a higher priority than default route listener so it gets triggered first - $this->listeners[] = $events->attach(MvcEvent::EVENT_ROUTE, [$this, 'onRoute'], 10); - } -} diff --git a/setup/src/Magento/Setup/Mvc/Console/RouteMatcher.php b/setup/src/Magento/Setup/Mvc/Console/RouteMatcher.php deleted file mode 100644 index 7e2fc9dfd558f98dc4331c5ac60a3e864657c2b7..0000000000000000000000000000000000000000 --- a/setup/src/Magento/Setup/Mvc/Console/RouteMatcher.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Setup\Mvc\Console; - -/** - * Extending ZF RouteMatcher for a public getter - */ -class RouteMatcher extends \Zend\Console\RouteMatcher\DefaultRouteMatcher -{ - /** - * Public getter of parts, used for parameters validation - * - * @return array - */ - public function getParts() - { - return $this->parts; - } -} diff --git a/setup/src/Magento/Setup/Mvc/Console/VerboseValidator.php b/setup/src/Magento/Setup/Mvc/Console/VerboseValidator.php deleted file mode 100644 index 1da4628b2b3573380d6363c22e5ecc32183afae1..0000000000000000000000000000000000000000 --- a/setup/src/Magento/Setup/Mvc/Console/VerboseValidator.php +++ /dev/null @@ -1,237 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Setup\Mvc\Console; - -use Magento\Setup\Controller\ConsoleController; - -/** - * Validator for checking parameters in CLI - */ -class VerboseValidator -{ - /** - * Checks parameters and returns validation messages - * - * @param array $data - * @param array $config - * @return string - */ - public function validate(array $data, array $config) - { - $validationMessages = ''; - $userAction = null; - if (!empty($data)) { - $userAction = $data[0]; - array_shift($data); - } - if (isset($userAction) && isset($config[$userAction])) { - // parse the expected parameters of the action - $matcher = new RouteMatcher($config[$userAction]['options']['route']); - $parts = $matcher->getParts(); - array_shift($parts); - $expectedParams = []; - foreach ($parts as $part) { - $expectedParams[$part['name']] = $part; - } - // parse user parameters - $userParams = $this->parseUserParams($data); - $validationMessages = $this->validateParameters($expectedParams, $userParams); - - // add usage message - $usages = ConsoleController::getCommandUsage(); - $validationMessages .= 'Usage:' . PHP_EOL . "{$userAction} "; - $validationMessages .= $usages[$userAction] . PHP_EOL . PHP_EOL; - - } else { - if (!is_null($userAction)) { - $validationMessages .= PHP_EOL . "Unknown action name '{$userAction}'." . PHP_EOL . PHP_EOL; - } else { - $validationMessages .= PHP_EOL . "No action is given in the command." . PHP_EOL . PHP_EOL; - } - $validationMessages .= 'Available options: ' . PHP_EOL; - foreach (array_keys($config) as $action) { - $validationMessages .= $action . PHP_EOL; - } - $validationMessages .= PHP_EOL; - } - - return $validationMessages; - } - - /** - * Parse user input - * - * @param array $content - * @return array - */ - private function parseUserParams(array $content) - { - $parameters = []; - foreach ($content as $param) { - $parsed = explode('=', $param, 2); - $value = isset($parsed[1]) ? $parsed[1] : ''; - if (strpos($parsed[0], '--') !== false) { - $key = substr($parsed[0], 2, strlen($parsed[0]) - 2); - } else { - $key = $parsed[0]; - } - - $parameters[$key] = $value; - } - return $parameters; - } - /** - * Check for any missing parameters - * - * @param array $expectedParams - * @param array $actualParams - * @return array - */ - public function checkMissingParameter($expectedParams, $actualParams) - { - $missingParams = array_diff(array_keys($expectedParams), array_keys($actualParams)); - foreach ($missingParams as $key => $missingParam) { - /* disregard if optional parameter */ - if (!$expectedParams[$missingParam]['required']) { - unset($missingParams[$key]); - } - } - // some parameters have alternative names, verify user input with theses alternative names - foreach ($missingParams as $key => $missingParam) { - foreach (array_keys($actualParams) as $actualParam) { - if (isset($expectedParams[$missingParam]['alternatives'])) { - foreach ($expectedParams[$missingParam]['alternatives'] as $alternative) { - if ($actualParam === $alternative) { - unset($missingParams[$key]); - break 2; - } - } - } - } - } - return $missingParams; - } - - /** - * Check for any extra parameters - * - * @param array $expectedParams - * @param array $actualParams - * @return array - */ - public function checkExtraParameter($expectedParams, $actualParams) - { - $extraParams = array_diff(array_keys($actualParams), array_keys($expectedParams)); - // some parameters have alternative names, make sure $extraParams doesn't contain these alternatives names - foreach ($extraParams as $key => $extraParam) { - foreach ($expectedParams as $expectedParam) { - if (isset($expectedParam['alternatives'])) { - foreach ($expectedParam['alternatives'] as $alternative) { - if ($extraParam === $alternative) { - unset($extraParams[$key]); - break 2; - } - } - } - } - } - return $extraParams; - } - - /** - * Checks for parameters that are missing values - * - * @param array $expectedParams - * @param array $actualParams - * @return array - */ - public function checkMissingValue($expectedParams, $actualParams) - { - $missingValues = []; - foreach ($actualParams as $param => $value) { - if (isset($expectedParams[$param])) { - if ($value === '' && $expectedParams[$param]['hasValue']) { - $missingValues[] = $param; - } - } - } - return $missingValues; - } - - /** - * Checks for parameters that do not need values - * - * @param array $expectedParams - * @param array $actualParams - * @return array - */ - public function checkExtraValue($expectedParams, $actualParams) - { - $extraValues = []; - foreach ($actualParams as $param => $value) { - if (isset($expectedParams[$param])) { - if ($value !== '' && !$expectedParams[$param]['hasValue']) { - $extraValues[] = $param; - } - } - } - return $extraValues; - } - - /** - * Validates the parameters. - * - * @param array $expectedParams - * @param array $userParams - * @return string - * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - private function validateParameters($expectedParams, $userParams) - { - $missingParams = $this->checkMissingParameter($expectedParams, $userParams); - $extraParams = $this->checkExtraParameter($expectedParams, $userParams); - $missingValues = $this->checkMissingValue($expectedParams, $userParams); - $extraValues = $this->checkExtraValue($expectedParams, $userParams); - $validationMessages = PHP_EOL; - if (!empty($missingParams)) { - $validationMessages .= 'Missing required parameters:' . PHP_EOL; - foreach ($missingParams as $missingParam) { - $validationMessages .= $missingParam . PHP_EOL; - } - $validationMessages .= PHP_EOL; - } - if (!empty($extraParams)) { - $validationMessages .= 'Unidentified parameters:' . PHP_EOL; - foreach ($extraParams as $extraParam) { - $validationMessages .= $extraParam . PHP_EOL; - } - $validationMessages .= PHP_EOL; - } - if (!empty($missingValues)) { - $validationMessages .= 'Parameters missing value:' . PHP_EOL; - foreach ($missingValues as $missingValue) { - $validationMessages .= $missingValue . PHP_EOL; - } - $validationMessages .= PHP_EOL; - } - if (!empty($extraValues)) { - $validationMessages .= 'Parameters that don\'t need value:' . PHP_EOL; - foreach ($extraValues as $extraValue) { - $validationMessages .= $extraValue . PHP_EOL; - } - $validationMessages .= PHP_EOL; - } - if (empty($missingParams) && empty($extraParams) && empty($missingValues) && empty($extraValue)) { - $validationMessages .= 'Please make sure parameters are in correct format and are not repeated.'; - $validationMessages .= PHP_EOL . PHP_EOL; - return $validationMessages; - } - return $validationMessages; - } -} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3e8ad803fd37af25053bb648cfe69412a42348d6 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php @@ -0,0 +1,92 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Model\AdminAccount; +use Magento\Setup\Console\Command\AdminUserCreateCommand; +use Magento\Setup\Mvc\Bootstrap\InitParamListener; +use Symfony\Component\Console\Tester\CommandTester; + +class AdminUserCreateCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\InstallerFactory + */ + private $installerFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|AdminUserCreateCommand + */ + private $command; + + public function setUp() + { + $this->installerFactoryMock = $this->getMock('Magento\Setup\Model\InstallerFactory', [], [], '', false); + $this->command = new AdminUserCreateCommand($this->installerFactoryMock); + } + + public function testExecute() + { + $options = [ + '--' . AdminAccount::KEY_USER => 'user', + '--' . AdminAccount::KEY_PASSWORD => '123123q', + '--' . AdminAccount::KEY_EMAIL => 'test@test.com', + '--' . AdminAccount::KEY_FIRST_NAME => 'John', + '--' . AdminAccount::KEY_LAST_NAME => 'Doe', + ]; + $data = [ + AdminAccount::KEY_USER => 'user', + AdminAccount::KEY_PASSWORD => '123123q', + AdminAccount::KEY_EMAIL => 'test@test.com', + AdminAccount::KEY_FIRST_NAME => 'John', + AdminAccount::KEY_LAST_NAME => 'Doe', + InitParamListener::BOOTSTRAP_PARAM => null, + ]; + $commandTester = new CommandTester($this->command); + $installerMock = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false); + $installerMock->expects($this->once())->method('installAdminUser')->with($data); + $this->installerFactoryMock->expects($this->once())->method('create')->willReturn($installerMock); + $commandTester->execute($options); + $this->assertEquals('Created admin user user' . PHP_EOL, $commandTester->getDisplay()); + } + + public function testGetOptionsList() + { + /* @var $argsList \Symfony\Component\Console\Input\InputArgument[] */ + $argsList = $this->command->getOptionsList(); + $this->assertEquals(AdminAccount::KEY_EMAIL, $argsList[2]->getName()); + } + + /** + * @dataProvider validateDataProvider + * @param bool[] $options + * @param string[] $errors + */ + public function testValidate(array $options, array $errors) + { + $inputMock = $this->getMockForAbstractClass('Symfony\Component\Console\Input\InputInterface', [], '', false); + $index = 0; + foreach ($options as $option) { + $inputMock->expects($this->at($index++))->method('getOption')->willReturn($option); + } + $this->assertEquals($errors, $this->command->validate($inputMock)); + } + + /** + * @return array + */ + public function validateDataProvider() + { + return [ + [[false, true, true, true, true], ['Missing option ' . AdminAccount::KEY_USER]], + [ + [true, false, false, true, true], + ['Missing option ' . AdminAccount::KEY_PASSWORD, 'Missing option ' . AdminAccount::KEY_EMAIL], + ], + [[true, true, true, true, true], []], + ]; + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php index 857ea54b8f51818c45f61b28e1a1792887b41e6b..11e08c4faf7784e8af19f186640dc30ef82b7461 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ConfigSetCommandTest.php @@ -27,8 +27,6 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase */ private $command; - - public function setUp() { $option = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DbDataUpgradeCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DbDataUpgradeCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..50494cd968b1ccf56db4596f6303f68eb8d59bf8 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DbDataUpgradeCommandTest.php @@ -0,0 +1,58 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Framework\Module\ModuleList; +use Magento\Setup\Console\Command\DbDataUpgradeCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class DbDataUpgradeCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Setup\Model\InstallerFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $installerFactory; + + /** + * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject + */ + protected $deploymentConfig; + + protected function setup() + { + $this->installerFactory = $this->getMock('Magento\Setup\Model\InstallerFactory', [], [], '', false); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + } + + public function testExecute() + { + $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); + $installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false); + $this->installerFactory->expects($this->once())->method('create')->will($this->returnValue($installer)); + $installer->expects($this->once())->method('installDataFixtures'); + + $commandTester = new CommandTester( + new DbDataUpgradeCommand($this->installerFactory, $this->deploymentConfig) + ); + $commandTester->execute([]); + } + + public function testExecuteNoConfig() + { + $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); + $this->installerFactory->expects($this->never())->method('create'); + + $commandTester = new CommandTester( + new DbDataUpgradeCommand($this->installerFactory, $this->deploymentConfig) + ); + $commandTester->execute([]); + $this->assertStringMatchesFormat( + 'No information is available: the application is not installed.%w', + $commandTester->getDisplay() + ); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DbSchemaUpgradeCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DbSchemaUpgradeCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..6300175f95926f4c476d23ecc9252ea545d819ec --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DbSchemaUpgradeCommandTest.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Framework\Module\ModuleList; +use Magento\Setup\Console\Command\DbSchemaUpgradeCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class DbSchemaUpgradeCommandTest extends DbDataUpgradeCommandTest +{ + public function testExecute() + { + $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); + $installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false); + $this->installerFactory->expects($this->once())->method('create')->will($this->returnValue($installer)); + $installer->expects($this->once())->method('installSchema'); + + $commandTester = new CommandTester( + new DbSchemaUpgradeCommand($this->installerFactory, $this->deploymentConfig) + ); + $commandTester->execute([]); + } + + public function testExecuteNoConfig() + { + $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); + $this->installerFactory->expects($this->never())->method('create'); + + $commandTester = new CommandTester( + new DbSchemaUpgradeCommand($this->installerFactory, $this->deploymentConfig) + ); + $commandTester->execute([]); + $this->assertStringMatchesFormat( + 'No information is available: the application is not installed.%w', + $commandTester->getDisplay() + ); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DbStatusCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DbStatusCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d16758b51e6c99d4437423e59564f0b095c8621c --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DbStatusCommandTest.php @@ -0,0 +1,130 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Framework\Module\DbVersionInfo; +use Magento\Setup\Console\Command\DbStatusCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class DbStatusCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\Module\DbVersionInfo|\PHPUnit_Framework_MockObject_MockObject + */ + private $dbVersionInfo; + + /** + * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject + */ + private $deploymentConfig; + + /** + * @var DbStatusCommand + */ + private $command; + + protected function setUp() + { + $this->dbVersionInfo = $this->getMock('Magento\Framework\Module\DbVersionInfo', [], [], '', false); + $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false); + $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $objectManagerProvider->expects($this->any()) + ->method('get') + ->will($this->returnValue($objectManager)); + $objectManager->expects($this->any()) + ->method('get') + ->will($this->returnValue($this->dbVersionInfo)); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $this->command = new DbStatusCommand($objectManagerProvider, $this->deploymentConfig); + } + + /** + * @param array $outdatedInfo + * @param string $expectedMessage + * + * @dataProvider executeDataProvider + */ + public function testExecute(array $outdatedInfo, $expectedMessage) + { + $this->deploymentConfig->expects($this->once()) + ->method('isAvailable') + ->will($this->returnValue(true)); + $this->dbVersionInfo->expects($this->once()) + ->method('getDbVersionErrors') + ->will($this->returnValue($outdatedInfo)); + $tester = new CommandTester($this->command); + $tester->execute([]); + $this->assertStringMatchesFormat($expectedMessage, $tester->getDisplay()); + } + + public function executeDataProvider() + { + return [ + 'DB is up to date' => [ + [], + 'All modules are up to date%a' + ], + 'DB is outdated' => [ + [ + [ + DbVersionInfo::KEY_MODULE => 'module_a', + DbVersionInfo::KEY_TYPE => 'schema', + DbVersionInfo::KEY_CURRENT => '1.0.0', + DbVersionInfo::KEY_REQUIRED => '2.0.0' + ] + ], + '%amodule_a%aschema%a1%a->%a2' + . "%aRun 'setup:upgrade' to update your DB schema and data%a", + ], + 'code is outdated' => [ + [ + [ + DbVersionInfo::KEY_MODULE => 'module_a', + DbVersionInfo::KEY_TYPE => 'data', + DbVersionInfo::KEY_CURRENT => '2.0.0', + DbVersionInfo::KEY_REQUIRED => '1.0.0' + ] + ], + '%amodule_a%adata%a2.0.0%a->%a1.0.0' + . '%aSome modules use code versions newer or older than the database%a', + ], + 'both DB and code is outdated' => [ + [ + [ + DbVersionInfo::KEY_MODULE => 'module_a', + DbVersionInfo::KEY_TYPE => 'schema', + DbVersionInfo::KEY_CURRENT => '1.0.0', + DbVersionInfo::KEY_REQUIRED => '2.0.0' + ], + [ + DbVersionInfo::KEY_MODULE => 'module_b', + DbVersionInfo::KEY_TYPE => 'data', + DbVersionInfo::KEY_CURRENT => '2.0.0', + DbVersionInfo::KEY_REQUIRED => '1.0.0' + ] + ], + '%amodule_a%aschema%a1.0.0%a->%a2.0.0' + . '%amodule_b%adata%a2.0.0%a->%a1.0.0' + . '%aSome modules use code versions newer or older than the database%a', + ], + ]; + } + + public function testExecuteNotInstalled() + { + $this->deploymentConfig->expects($this->once()) + ->method('isAvailable') + ->will($this->returnValue(false)); + $this->dbVersionInfo->expects($this->never()) + ->method('getDbVersionErrors'); + $tester = new CommandTester($this->command); + $tester->execute([]); + $this->assertStringMatchesFormat( + 'No information is available: the application is not installed.%w', + $tester->getDisplay() + ); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoCurrencyListCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoCurrencyListCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a7e087f94bd2b3f68ca6d01a767202d1873ebbd5 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoCurrencyListCommandTest.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\InfoCurrencyListCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class InfoCurrencyListCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testExecute() + { + $currencies = [ + 'CUR' => 'Currency description' + ]; + + /** @var \Magento\Setup\Model\Lists|\PHPUnit_Framework_MockObject_MockObject $list */ + $list = $this->getMock('Magento\Setup\Model\Lists', [], [], '', false); + $list->expects($this->once())->method('getCurrencyList')->will($this->returnValue($currencies)); + $commandTester = new CommandTester(new InfoCurrencyListCommand($list)); + $commandTester->execute([]); + $this->assertStringMatchesFormat( + 'CUR => Currency description', + $commandTester->getDisplay() + ); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoLanguageListCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoLanguageListCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..938fb53f72590df1a99758d588ffd2129f23a09a --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoLanguageListCommandTest.php @@ -0,0 +1,29 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\InfoLanguageListCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class InfoLanguageListCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testExecute() + { + $languages = [ + 'LNG' => 'Language description' + ]; + /** @var \Magento\Setup\Model\Lists|\PHPUnit_Framework_MockObject_MockObject $list */ + $list = $this->getMock('Magento\Setup\Model\Lists', [], [], '', false); + $list->expects($this->once())->method('getLocaleList')->will($this->returnValue($languages)); + $commandTester = new CommandTester(new InfoLanguageListCommand($list)); + $commandTester->execute([]); + $this->assertStringMatchesFormat( + 'LNG => Language description', + $commandTester->getDisplay() + ); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoTimezoneListCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoTimezoneListCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..6b1be6a5e9bc122e58d4845d116de5a14bd13e51 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/InfoTimezoneListCommandTest.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\InfoTimezoneListCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class InfoTimezoneListCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testExecute() + { + $timezones = [ + 'timezone' => 'timezone description' + ]; + + /** @var \Magento\Setup\Model\Lists|\PHPUnit_Framework_MockObject_MockObject $list */ + $list = $this->getMock('Magento\Setup\Model\Lists', [], [], '', false); + $list->expects($this->once())->method('getTimezoneList')->will($this->returnValue($timezones)); + $commandTester = new CommandTester(new InfoTimezoneListCommand($list)); + $commandTester->execute([]); + $this->assertStringMatchesFormat( + 'timezone => timezone description', + $commandTester->getDisplay() + ); + + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a358368092f032e951ecfcbba5d8f92a240367fd --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php @@ -0,0 +1,178 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\InstallCommand; +use Symfony\Component\Console\Tester\CommandTester; +use Magento\Setup\Model\AdminAccount; +use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsList as SetupConfigOptionsList; +use Magento\Setup\Console\Command\InstallStoreConfigurationCommand; +use Magento\Setup\Model\StoreConfigurationDataMapper; + +class InstallCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testExecute() + { + $input = [ + '--' . SetupConfigOptionsList::INPUT_KEY_DB_HOST => 'localhost', + '--' . SetupConfigOptionsList::INPUT_KEY_DB_NAME => 'magento', + '--' . SetupConfigOptionsList::INPUT_KEY_DB_USER => 'root', + '--' . BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin', + '--' . StoreConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/magento2ce/', + '--' . StoreConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + '--' . StoreConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + '--' . StoreConfigurationDataMapper::KEY_CURRENCY => 'USD', + '--' . AdminAccount::KEY_USER => 'user', + '--' . AdminAccount::KEY_PASSWORD => '123123q', + '--' . AdminAccount::KEY_EMAIL => 'test@test.com', + '--' . AdminAccount::KEY_FIRST_NAME => 'John', + '--' . AdminAccount::KEY_LAST_NAME => 'Doe', + ]; + + $configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); + $configModel + ->expects($this->exactly(2)) + ->method('getAvailableOptions') + ->will($this->returnValue($this->getOptionsListDeployConfig())); + $configModel + ->expects($this->once()) + ->method('validate') + ->will($this->returnValue([])); + + $userConfig = $this->getMock( + 'Magento\Setup\Console\Command\InstallStoreConfigurationCommand', + [], + [], + '', + false + ); + $userConfig + ->expects($this->once()) + ->method('getOptionsList') + ->will($this->returnValue($this->getOptionsListUserConfig())); + + $adminUser = $this->getMock('Magento\Setup\Console\Command\AdminUserCreateCommand', [], [], '', false); + $adminUser + ->expects($this->once()) + ->method('getOptionsList') + ->will($this->returnValue($this->getOptionsListAdminUser())); + $adminUser + ->expects($this->once()) + ->method('validate') + ->will($this->returnValue([])); + + $installerFactory = $this->getMock('Magento\Setup\Model\InstallerFactory', [], [], '', false); + $installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false); + $installerFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($installer)); + $installer->expects($this->once())->method('install'); + $commandTester = new CommandTester(new InstallCommand( + $installerFactory, + $configModel, + $userConfig, + $adminUser + )); + $commandTester->execute($input); + } + + /** + * Get list of options for deployment configuration + * + * @return array + */ + private function getOptionsListDeployConfig() + { + $option1 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option1 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(SetupConfigOptionsList::INPUT_KEY_DB_HOST)); + $option2 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option2 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(SetupConfigOptionsList::INPUT_KEY_DB_NAME)); + $option3 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option3 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(SetupConfigOptionsList::INPUT_KEY_DB_USER)); + $option4 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option4 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME)); + return [$option1, $option2, $option3, $option4]; + } + + /** + * Get list of options for user configuration + * + * @return array + */ + private function getOptionsListUserConfig() + { + $option1 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option1 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(StoreConfigurationDataMapper::KEY_BASE_URL)); + $option2 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option2 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(StoreConfigurationDataMapper::KEY_LANGUAGE)); + $option3 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option3 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(StoreConfigurationDataMapper::KEY_TIMEZONE)); + $option4 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option4 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(StoreConfigurationDataMapper::KEY_CURRENCY)); + return [$option1, $option2, $option3, $option4]; + } + + /** + * Get list of options for admin user + * + * @return array + */ + private function getOptionsListAdminUser() + { + $option1 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option1 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(AdminAccount::KEY_USER)); + $option2 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option2 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(AdminAccount::KEY_PASSWORD)); + $option3 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option3 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(AdminAccount::KEY_EMAIL)); + $option4 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option4 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(AdminAccount::KEY_FIRST_NAME)); + $option5 = $this->getMock('Magento\Framework\Setup\Option\TextConfigOption', [], [], '', false); + $option5 + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue(AdminAccount::KEY_LAST_NAME)); + return [$option1, $option2, $option3, $option4, $option5]; + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallStoreConfigurationCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallStoreConfigurationCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..65e5ded76910b01334ae1e93134cfca621a8e9ec --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallStoreConfigurationCommandTest.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\InstallStoreConfigurationCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class InstallStoreConfigurationCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject + */ + private $deploymentConfig; + + /** + * @var \Magento\Setup\Model\InstallerFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $installerFactory; + + /** + * @var Installer|\PHPUnit_Framework_MockObject_MockObject + */ + private $installer; + + /** + * @var InstallStoreConfigurationCommand + */ + private $command; + + protected function setUp() + { + $this->installerFactory = $this->getMock('Magento\Setup\Model\InstallerFactory', [], [], '', false); + $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $this->installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false); + $this->command = new InstallStoreConfigurationCommand($this->installerFactory, $this->deploymentConfig); + } + + public function testExecute() + { + $this->deploymentConfig->expects($this->once()) + ->method('isAvailable') + ->will($this->returnValue(true)); + $this->installer->expects($this->once()) + ->method('installUserConfig'); + $this->installerFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($this->installer)); + $tester = new CommandTester($this->command); + $tester->execute([]); + } + + public function testExecuteNotInstalled() + { + $this->deploymentConfig->expects($this->once()) + ->method('isAvailable') + ->will($this->returnValue(false)); + $this->installerFactory->expects($this->never()) + ->method('create'); + $tester = new CommandTester($this->command); + $tester->execute([]); + $this->assertStringMatchesFormat( + "Store settings can't be saved because the Magento application is not installed.%w", + $tester->getDisplay() + ); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b129552455218f84445a91f2d602c79326610be8 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\MaintenanceAllowIpsCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class MaintenanceAllowIpsCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\App\MaintenanceMode|\PHPUnit_Framework_MockObject_MockObject + */ + private $maintenanceMode; + + /** + * @var MaintenanceAllowIpsCommand + */ + private $command; + + public function setUp() + { + $this->maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false); + $this->command = new MaintenanceAllowIpsCommand($this->maintenanceMode); + } + + /** + * @param array $input + * @param string $expectedMessage + * @dataProvider executeDataProvider + */ + public function testExecute(array $input, $expectedMessage) + { + if (isset($input['--none']) && !$input['--none'] && isset($input['ip'])) { + $this->maintenanceMode + ->expects($this->once()) + ->method('getAddressInfo') + ->willReturn($input['ip']); + } + $tester = new CommandTester($this->command); + $tester->execute($input); + $this->assertEquals($expectedMessage, $tester->getDisplay()); + + } + + /** + * return array + */ + public function executeDataProvider() + { + return [ + [ + ['ip' => ['127.0.0.1', '127.0.0.2'], '--none' => false], + 'Set exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL + ], + [ + ['--none' => true], + 'Set exempt IP-addresses: none' . PHP_EOL + ], + [ + ['ip' => ['127.0.0.1', '127.0.0.2'], '--none' => true], + 'Set exempt IP-addresses: none' . PHP_EOL + ], + [ + [], + '' + ] + ]; + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceDisableCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceDisableCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e32acacb15aaa7d23197b77e166941d636d1f95a --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceDisableCommandTest.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\MaintenanceDisableCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class MaintenanceDisableCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\App\MaintenanceMode|\PHPUnit_Framework_MockObject_MockObject + */ + private $maintenanceMode; + + /** + * @var MaintenanceDisableCommand + */ + private $command; + + public function setUp() + { + $this->maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false); + $this->command = new MaintenanceDisableCommand($this->maintenanceMode); + } + + /** + * @param array $input + * @param string $expectedMessage + * @dataProvider executeDataProvider + */ + public function testExecute(array $input, $expectedMessage) + { + $return = isset($input['--ip']) ? ($input['--ip'] !== ['none'] ? $input['--ip'] : []) : []; + $this->maintenanceMode + ->expects($this->any()) + ->method('getAddressInfo') + ->willReturn($return); + $tester = new CommandTester($this->command); + $tester->execute($input); + $this->assertEquals($expectedMessage, $tester->getDisplay()); + } + + /** + * return array + */ + public function executeDataProvider() + { + return [ + [ + ['--ip' => ['127.0.0.1', '127.0.0.2']], + 'Disabled maintenance mode' . PHP_EOL . + 'Set exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL + ], + [ + [], + 'Disabled maintenance mode' . PHP_EOL + ], + [ + ['--ip' => ['none']], + 'Disabled maintenance mode' . PHP_EOL . + 'Set exempt IP-addresses: none' . PHP_EOL + ], + ]; + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceEnableCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceEnableCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7615de13c617e951cfb965c8390ff1e46444b76a --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceEnableCommandTest.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\MaintenanceEnableCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class MaintenanceEnableCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\App\MaintenanceMode|\PHPUnit_Framework_MockObject_MockObject + */ + private $maintenanceMode; + + /** + * @var MaintenanceEnableCommand + */ + private $command; + + public function setUp() + { + $this->maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false); + $this->command = new MaintenanceEnableCommand($this->maintenanceMode); + } + + /** + * @param array $input + * @param string $expectedMessage + * @dataProvider executeDataProvider + */ + public function testExecute(array $input, $expectedMessage) + { + $return = isset($input['--ip']) ? ($input['--ip'] !== ['none'] ? $input['--ip'] : []) : []; + $this->maintenanceMode + ->expects($this->any()) + ->method('getAddressInfo') + ->willReturn($return); + $tester = new CommandTester($this->command); + $tester->execute($input); + $this->assertEquals($expectedMessage, $tester->getDisplay()); + + } + + /** + * return array + */ + public function executeDataProvider() + { + return [ + [ + ['--ip' => ['127.0.0.1', '127.0.0.2']], + 'Enabled maintenance mode' . PHP_EOL . + 'Set exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL + ], + [ + ['--ip' => ['none']], + 'Enabled maintenance mode' . PHP_EOL . + 'Set exempt IP-addresses: none' . PHP_EOL + ], + [ + [], + 'Enabled maintenance mode' . PHP_EOL + ], + ]; + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceStatusCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceStatusCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8205bf8277b2c21e11861df672061398146939df --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceStatusCommandTest.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\MaintenanceStatusCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class MaintenanceStatusCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Framework\App\MaintenanceMode|\PHPUnit_Framework_MockObject_MockObject + */ + private $maintenanceMode; + + /** + * @var MaintenanceStatusCommand + */ + private $command; + + public function setUp() + { + $this->maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false); + $this->command = new MaintenanceStatusCommand($this->maintenanceMode); + } + + /** + * @param array $maintenanceData + * @param string $expectedMessage + * @dataProvider executeDataProvider + */ + public function testExecute(array $maintenanceData, $expectedMessage) + { + $this->maintenanceMode->expects($this->once())->method('isOn')->willReturn($maintenanceData[0]); + $this->maintenanceMode->expects($this->once())->method('getAddressInfo')->willReturn($maintenanceData[1]); + $tester = new CommandTester($this->command); + $tester->execute([]); + $this->assertEquals($expectedMessage, $tester->getDisplay()); + + } + + /** + * return array + */ + public function executeDataProvider() + { + return [ + [ + [true, ['127.0.0.1', '127.0.0.2']], + 'Status: maintenance mode is active' . PHP_EOL . + 'List of exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL + ], + [ + [true, []], + 'Status: maintenance mode is active' . PHP_EOL . 'List of exempt IP-addresses: none' . PHP_EOL + ], + [ + [false, []], + 'Status: maintenance mode is not active' . PHP_EOL . 'List of exempt IP-addresses: none' . PHP_EOL + ], + [ + [false, ['127.0.0.1', '127.0.0.2']], + 'Status: maintenance mode is not active' . PHP_EOL . + 'List of exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL + ], + ]; + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleEnableDisableCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleEnableDisableCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b0fdb27794887177ecaee65f25d2d057ee3d97da --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleEnableDisableCommandTest.php @@ -0,0 +1,278 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\ModuleDisableCommand; +use Magento\Setup\Console\Command\ModuleEnableCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class ModuleEnableDisableCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Setup\Model\ObjectManagerProvider|\PHPUnit_Framework_MockObject_MockObject + */ + private $objectManagerProvider; + + /** + * @var \Magento\Framework\Module\Status|\PHPUnit_Framework_MockObject_MockObject + */ + private $status; + + /** + * @var \Magento\Framework\App\Cache|\PHPUnit_Framework_MockObject_MockObject + */ + private $cache; + + /** + * @var \Magento\Framework\App\State\CleanupFiles|\PHPUnit_Framework_MockObject_MockObject + */ + private $cleanupFiles; + + /** + * @var \Magento\Framework\Module\FullModuleList|\PHPUnit_Framework_MockObject_MockObject + */ + private $fullModuleList; + + protected function setUp() + { + $this->objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false); + $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $this->objectManagerProvider->expects($this->any()) + ->method('get') + ->will($this->returnValue($objectManager)); + $this->status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); + $this->cache = $this->getMock('Magento\Framework\App\Cache', [], [], '', false); + $this->cleanupFiles = $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false); + $this->fullModuleList = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); + $objectManager->expects($this->any()) + ->method('get') + ->will($this->returnValueMap([ + ['Magento\Framework\Module\Status', $this->status], + ['Magento\Framework\App\Cache', $this->cache], + ['Magento\Framework\App\State\CleanupFiles', $this->cleanupFiles], + ['Magento\Framework\Module\FullModuleList', $this->fullModuleList], + ])); + } + + /** + * @param bool $isEnable + * @param bool $clearStaticContent + * @param string $expectedMessage + * + * @dataProvider executeDataProvider + */ + public function testExecute($isEnable, $clearStaticContent, $expectedMessage) + { + $this->status->expects($this->once()) + ->method('getModulesToChange') + ->with($isEnable, ['Magento_Module1', 'Magento_Module2']) + ->will($this->returnValue(['Magento_Module1'])); + + $this->status->expects($this->any()) + ->method('checkConstraints') + ->will($this->returnValue([])); + + $this->status->expects($this->once()) + ->method('setIsEnabled') + ->with($isEnable, ['Magento_Module1']); + + $this->cache->expects($this->once()) + ->method('clean'); + $this->cleanupFiles->expects($this->once()) + ->method('clearCodeGeneratedClasses'); + $this->cleanupFiles->expects($clearStaticContent ? $this->once() : $this->never()) + ->method('clearMaterializedViewFiles'); + + $commandTester = $isEnable + ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider)) + : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider)); + $input = ['module' => ['Magento_Module1', 'Magento_Module2']]; + if ($clearStaticContent) { + $input['--clear-static-content'] = true; + } + $commandTester->execute($input); + $this->assertStringMatchesFormat($expectedMessage, $commandTester->getDisplay()); + } + + /** + * @return array + */ + public function executeDataProvider() + { + return [ + 'enable, do not clear static content' => [ + true, + false, + '%amodules have been enabled%aMagento_Module1%aGenerated static view files were not cleared%a' + ], + 'disable, do not clear static content' => [ + false, + false, + '%amodules have been disabled%aMagento_Module1%aGenerated static view files were not cleared%a' + ], + 'enable, clear static content' => [ + true, + true, + '%amodules have been enabled%aMagento_Module1%aGenerated static view files cleared%a' + ], + 'disable, clear static content' => [ + false, + true, + '%amodules have been disabled%aMagento_Module1%aGenerated static view files cleared%a' + ], + ]; + } + + /** + * @param bool $isEnable + * @param string $expectedMessage + * + * @dataProvider executeAllDataProvider + */ + public function testExecuteAll($isEnable, $expectedMessage) + { + $this->fullModuleList->expects($this->once()) + ->method('getNames') + ->will($this->returnValue(['Magento_Module1', 'Magento_Module2'])); + + $this->status->expects($this->once()) + ->method('getModulesToChange') + ->with($isEnable, ['Magento_Module1', 'Magento_Module2']) + ->will($this->returnValue(['Magento_Module1'])); + + $this->status->expects($this->any()) + ->method('checkConstraints') + ->will($this->returnValue([])); + + $this->status->expects($this->once()) + ->method('setIsEnabled') + ->with($isEnable, ['Magento_Module1']); + + $commandTester = $isEnable + ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider)) + : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider)); + $input = ['--all' => true]; + $commandTester->execute($input); + $this->assertStringMatchesFormat($expectedMessage, $commandTester->getDisplay()); + } + + /** + * @return array + */ + public function executeAllDataProvider() + { + return [ + 'enable' => [true, '%amodules have been enabled%aMagento_Module1%a'], + 'disable' => [false, '%amodules have been disabled%aMagento_Module1%a'], + ]; + } + + /** + * @param bool $isEnable + * + * @dataProvider executeWithConstraintsDataProvider + */ + public function testExecuteWithConstraints($isEnable) + { + $this->status->expects($this->once()) + ->method('getModulesToChange') + ->with($isEnable, ['Magento_Module1', 'Magento_Module2']) + ->will($this->returnValue(['Magento_Module1'])); + + $this->status->expects($this->any()) + ->method('checkConstraints') + ->will($this->returnValue(['constraint1', 'constraint2'])); + + $this->status->expects($this->never()) + ->method('setIsEnabled'); + + $commandTester = $isEnable + ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider)) + : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider)); + $commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2']]); + $this->assertStringMatchesFormat( + 'Unable to change status of modules%aconstraint1%aconstraint2%a', + $commandTester->getDisplay() + ); + } + + /** + * @return array + */ + public function executeWithConstraintsDataProvider() + { + return [ + 'enable' => [true], + 'disable' => [false], + ]; + } + + /** + * @param bool $isEnable + * @param string $expectedMessage + * + * @dataProvider executeExecuteForceDataProvider + */ + public function testExecuteForce($isEnable, $expectedMessage) + { + $this->status->expects($this->once()) + ->method('getModulesToChange') + ->with($isEnable, ['Magento_Module1', 'Magento_Module2']) + ->will($this->returnValue(['Magento_Module1'])); + + $this->status->expects($this->never()) + ->method('checkConstraints'); + + $this->status->expects($this->once()) + ->method('setIsEnabled') + ->with($isEnable, ['Magento_Module1']); + + $commandTester = $isEnable + ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider)) + : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider)); + $commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2'], '--force' => true]); + $this->assertStringMatchesFormat( + $expectedMessage . '%amodules might not function properly%a', + $commandTester->getDisplay() + ); + } + + /** + * @return array + */ + public function executeExecuteForceDataProvider() + { + return [ + 'enable' => [true, '%amodules have been enabled%aMagento_Module1%a'], + 'disable' => [false, '%amodules have been disabled%aMagento_Module1%a'], + ]; + } + + /** + * @param bool $isEnable + * + * @dataProvider executeWithConstraintsDataProvider + */ + public function testExecuteNoChanges($isEnable) + { + $this->status->expects($this->once()) + ->method('getModulesToChange') + ->with($isEnable, ['Magento_Module1', 'Magento_Module2']) + ->will($this->returnValue([])); + + $this->status->expects($this->never()) + ->method('setIsEnabled'); + + $commandTester = $isEnable + ? new CommandTester(new ModuleEnableCommand($this->objectManagerProvider)) + : new CommandTester(new ModuleDisableCommand($this->objectManagerProvider)); + $commandTester->execute(['module' => ['Magento_Module1', 'Magento_Module2']]); + $this->assertStringMatchesFormat( + 'No modules were changed%a', + $commandTester->getDisplay() + ); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleStatusCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleStatusCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2010188f4a8c552e88f95a8ffbe015617f5016db --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleStatusCommandTest.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\ModuleStatusCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class ModuleStatusCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testExecute() + { + $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false); + $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $objectManagerProvider->expects($this->any()) + ->method('get') + ->will($this->returnValue($objectManager)); + $moduleList = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false); + $fullModuleList = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); + $objectManager->expects($this->any()) + ->method('create') + ->will($this->returnValueMap([ + ['Magento\Framework\Module\ModuleList', [], $moduleList], + ['Magento\Framework\Module\FullModuleList', [], $fullModuleList], + ])); + $moduleList->expects($this->any()) + ->method('getNames') + ->will($this->returnValue(['Magento_Module1', 'Magento_Module2'])); + $fullModuleList->expects($this->any()) + ->method('getNames') + ->will($this->returnValue(['Magento_Module1', 'Magento_Module2', 'Magento_Module3'])); + $commandTester = new CommandTester(new ModuleStatusCommand($objectManagerProvider)); + $commandTester->execute([]); + $this->assertStringMatchesFormat( + 'List of enabled modules%aMagento_Module1%aMagento_Module2%a' + . 'List of disabled modules%aMagento_Module3%a', + $commandTester->getDisplay() + ); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/UninstallCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/UninstallCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..14090e2388ea3d5cad1f1b5aa11ef8e45d78b7ce --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/UninstallCommandTest.php @@ -0,0 +1,74 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Model\InstallerFactory; +use Magento\Setup\Console\Command\UninstallCommand; +use Symfony\Component\Console\Tester\CommandTester; +use Magento\Setup\Model\Installer; + +class UninstallCommandTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var InstallerFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $installerFactory; + + /** + * @var Installer|\PHPUnit_Framework_MockObject_MockObject + */ + private $installer; + + /** + * @var UninstallCommand|\PHPUnit_Framework_MockObject_MockObject + */ + private $command; + + public function setUp() + { + $this->installerFactory = $this->getMock('Magento\Setup\Model\InstallerFactory', [], [], '', false); + $this->installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false); + $this->command = new UninstallCommand($this->installerFactory); + } + + public function testExecuteInteractionYes() + { + $this->installer->expects($this->once())->method('uninstall'); + $this->installerFactory->expects($this->once())->method('create')->will($this->returnValue($this->installer)); + + $this->checkInteraction(true); + } + + public function testExecuteInteractionNo() + { + $this->installer->expects($this->exactly(0))->method('uninstall'); + $this->installerFactory->expects($this->exactly(0))->method('create'); + + $this->checkInteraction(false); + } + + public function checkInteraction($answer) + { + $question = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper', [], [], '', false); + $question + ->expects($this->once()) + ->method('ask') + ->will($this->returnValue($answer)); + + /** @var \Symfony\Component\Console\Helper\HelperSet|\PHPUnit_Framework_MockObject_MockObject $helperSet */ + $helperSet = $this->getMock('Symfony\Component\Console\Helper\HelperSet', [], [], '', false); + $helperSet + ->expects($this->once()) + ->method('get') + ->with('question') + ->will($this->returnValue($question)); + $this->command->setHelperSet($helperSet); + + $tester = new CommandTester($this->command); + $tester->execute([]); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php new file mode 100644 index 0000000000000000000000000000000000000000..41ed13c09d4e829435cbe392bd04b96e08397390 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php @@ -0,0 +1,24 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Setup\Test\Unit\Console\Command; + +use Magento\Setup\Console\Command\UpgradeCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class UpgradeCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testExecute() + { + $installerFactory = $this->getMock('Magento\Setup\Model\InstallerFactory', [], [], '', false); + $installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false); + $installer->expects($this->at(0))->method('updateModulesSequence'); + $installer->expects($this->at(1))->method('installSchema'); + $installer->expects($this->at(2))->method('installDataFixtures'); + $installerFactory->expects($this->once())->method('create')->willReturn($installer); + $commandTester = new CommandTester(new UpgradeCommand($installerFactory)); + $commandTester->execute([]); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php index 3e0d5bd666a426f36004c7a99cd6d8d2f181286b..39e78dc660683bd3b555ed6553dfc9e09f591c63 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/CommandListTest.php @@ -28,9 +28,34 @@ class CommandListTest extends \PHPUnit_Framework_TestCase public function testGetCommands() { - $this->serviceManager->expects($this->at(0)) - ->method('create') - ->with('Magento\Setup\Console\Command\ConfigSetCommand'); + $commands = [ + 'Magento\Setup\Console\Command\AdminUserCreateCommand', + 'Magento\Setup\Console\Command\ConfigSetCommand', + 'Magento\Setup\Console\Command\DbDataUpgradeCommand', + 'Magento\Setup\Console\Command\DbSchemaUpgradeCommand', + 'Magento\Setup\Console\Command\DbStatusCommand', + 'Magento\Setup\Console\Command\InfoCurrencyListCommand', + 'Magento\Setup\Console\Command\InfoLanguageListCommand', + 'Magento\Setup\Console\Command\InfoTimezoneListCommand', + 'Magento\Setup\Console\Command\InstallCommand', + 'Magento\Setup\Console\Command\InstallStoreConfigurationCommand', + 'Magento\Setup\Console\Command\ModuleEnableCommand', + 'Magento\Setup\Console\Command\ModuleDisableCommand', + 'Magento\Setup\Console\Command\ModuleStatusCommand', + 'Magento\Setup\Console\Command\MaintenanceAllowIpsCommand', + 'Magento\Setup\Console\Command\MaintenanceDisableCommand', + 'Magento\Setup\Console\Command\MaintenanceEnableCommand', + 'Magento\Setup\Console\Command\MaintenanceStatusCommand', + 'Magento\Setup\Console\Command\UpgradeCommand', + 'Magento\Setup\Console\Command\UninstallCommand', + ]; + $index = 0; + foreach ($commands as $command) { + $this->serviceManager->expects($this->at($index++)) + ->method('create') + ->with($command); + } + $this->commandList->getCommands(); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php deleted file mode 100644 index 6a5abfd72e66e018024faefac3ebd3b965913e89..0000000000000000000000000000000000000000 --- a/setup/src/Magento/Setup/Test/Unit/Controller/ConsoleControllerTest.php +++ /dev/null @@ -1,663 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -namespace Magento\Setup\Test\Unit\Controller; - -use \Magento\Setup\Controller\ConsoleController; - -use Magento\Framework\Module\DbVersionInfo; -use Magento\Setup\Model\UserConfigurationDataMapper as UserConfig; - -class ConsoleControllerTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ConsoleLogger - */ - private $consoleLogger; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\Lists - */ - private $options; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\Installer - */ - private $installer; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\MaintenanceMode - */ - private $maintenanceMode; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Zend\Mvc\MvcEvent - */ - private $mvcEvent; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Zend\Console\Request - */ - private $request; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Zend\Stdlib\Parameters - */ - private $parameters; - - /** - * @var ConsoleController - */ - private $controller; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\ObjectManagerInterface - */ - private $objectManager; - - 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); - $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('not-found'); - $this->mvcEvent->expects($this->any())->method('getRouteMatch')->willReturn($routeMatch); - - $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); - $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false); - $objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager); - - $this->controller = new ConsoleController( - $this->consoleLogger, - $this->options, - $installerFactory, - $this->maintenanceMode, - $objectManagerProvider - ); - $this->controller->setEvent($this->mvcEvent); - $this->controller->dispatch($this->request, $response); - } - - public function testGetRouterConfig() - { - $controller = $this->controller; - $actualRoute = $controller::getRouterConfig(); - 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() - { - $eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); - $eventManager->expects($this->atLeastOnce())->method('attach'); - $returnValue = $this->controller->setEventManager($eventManager); - $this->assertSame($returnValue, $this->controller); - } - - public function testOnDispatch() - { - $returnValue = $this->controller->onDispatch($this->mvcEvent); - $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', ['getCode'], [$errorMessage]); - $event->expects($this->once())->method('getRouteMatch')->willThrowException($exception); - $this->consoleLogger->expects($this->once())->method('log')->with($errorMessage); - $this->controller->onDispatch($event); - } - - public function testInstallAction() - { - $this->installer->expects($this->once())->method('install')->with($this->parameters); - $this->controller->installAction(); - } - - 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->at(0))->method('updateModulesSequence'); - $this->installer->expects($this->at(1))->method('installSchema'); - $this->installer->expects($this->at(2))->method('installDataFixtures'); - $this->controller->updateAction(); - } - - /** - * @param array $outdated - * @param array $expected - * - * @dataProvider dbStatusActionDataProvider - */ - public function testDbStatusAction(array $outdated, array $expected) - { - $dbVersionInfo = $this->getMock('\Magento\Framework\Module\DbVersionInfo', [], [], '', false); - $this->objectManager->expects($this->once()) - ->method('get') - ->with('Magento\Framework\Module\DbVersionInfo') - ->will($this->returnValue($dbVersionInfo)); - $dbVersionInfo->expects($this->once()) - ->method('getDbVersionErrors') - ->will($this->returnValue($outdated)); - foreach ($expected as $at => $message) { - $this->consoleLogger->expects($this->at($at)) - ->method('log') - ->with($this->matches($message)); - } - $this->controller->dbStatusAction(); - } - - /** - * @return array - */ - public function dbStatusActionDataProvider() - { - return [ - 'one outdated module' => [ - [[ - DbVersionInfo::KEY_MODULE => 'Module_One', - DbVersionInfo::KEY_TYPE => 'schema', - DbVersionInfo::KEY_CURRENT => '1.0.0', - DbVersionInfo::KEY_REQUIRED => '1.0.1', - ]], - [ - 1 => '%wModule_One%wschema:%w1.0.0%w->%w1.0.1%w', - 2 => 'Run the "Update" command to update your DB schema and data' - ], - ], - 'no outdated modules' => [ - [], - [0 => 'All modules are up to date'], - ], - 'one newer module' => [ - [[ - DbVersionInfo::KEY_MODULE => 'Module_One', - DbVersionInfo::KEY_TYPE => 'schema', - DbVersionInfo::KEY_CURRENT => '1.0.1', - DbVersionInfo::KEY_REQUIRED => '1.0.0', - ]], - [ - 1 => '%wModule_One%wschema:%w1.0.1%w->%w1.0.0%w', - 2 => 'Some modules use code versions newer or older than the database. ' . - 'First update the module code, then run the "Update" command.' - ], - ], - 'one none module' => [ - [[ - DbVersionInfo::KEY_MODULE => 'Module_One', - DbVersionInfo::KEY_TYPE => 'schema', - DbVersionInfo::KEY_CURRENT => 'none', - DbVersionInfo::KEY_REQUIRED => '1.0.0', - ]], - [ - 1 => '%wModule_One%wschema:%wnone%w->%w1.0.0%w', - 2 => 'Run the "Update" command to update your DB schema and data' - ], - ] - ]; - } - - 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 int $setCount - * @param int $logCount - * - * @dataProvider maintenanceActionDataProvider - */ - public function testMaintenanceAction($maintenanceMode, $setCount, $logCount) - { - $mapGetParam = [ - ['set', null, $maintenanceMode], - ['addresses', null, null], - ]; - $this->request->expects($this->exactly(2))->method('getParam')->will($this->returnValueMap($mapGetParam)); - $this->maintenanceMode->expects($this->exactly($setCount))->method('set'); - $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([]); - $this->consoleLogger->expects($this->exactly($logCount))->method('log'); - $this->controller->maintenanceAction(); - } - - /** - * @return array - */ - public function maintenanceActionDataProvider() - { - return [ - [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 $expectedValue - * - * @dataProvider helpActionForLanguageCurrencyTimezoneDataProvider - */ - public function testHelpActionForLanguageCurrencyTimezone($type, $method, $expectedValue) - { - $this->request->expects($this->once())->method('getParam')->willReturn($type); - $this->options->expects($this->once())->method($method)->willReturn($expectedValue); - $returnValue = $this->controller->helpAction(); - - //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]; - } - - $this->assertSame($expectedValue, $actual); - } - - /** - * @return array - */ - public function helpActionForLanguageCurrencyTimezoneDataProvider() - { - return [ - [UserConfig::KEY_LANGUAGE, 'getLocaleList', [ - 'someCode1' => 'some country', - 'someCode2' => 'some country2', - ] - ], - [UserConfig::KEY_CURRENCY, 'getCurrencyList', [ - 'currencyCode1' => 'some currency1', - 'currencyCode2' => 'some currency2', - ] - ], - [UserConfig::KEY_TIMEZONE, 'getTimezoneList', [ - 'timezone1' => 'some specific timezone1', - 'timezone2' => 'some specific timezone2', - ] - ], - ]; - } - - 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_Theme', 'Magento_Store'])); - $fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false); - $fullModuleListMock - ->expects($this->once()) - ->method('getNames') - ->will($this->returnValue(['Magento_Theme', '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" - . " Magento Setup CLI \n" - . "==-------------------==\n"; - $this->request->expects($this->once())->method('getParam')->willReturn(false); - $returnValue = $this->controller->helpAction(); - $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, 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'); - $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']], - ]; - } - - /** - * @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 - * @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('getModulesToChange') - ->with($expectedIsEnabled, $expectedModules) - ->willReturn([]); - $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[] $modulesToChange - * @dataProvider moduleActionPartialNoChangesDataProvider - */ - public function testModuleActionPartialNoChanges( - $command, - $modules, - $isForce, - $expectedIsEnabled, - $modulesToChange - ) { - $status = $this->getModuleActionMocks($command, $modules, $isForce, false); - $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, $modulesToChange); - $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_Bar'], - ], - [ - ConsoleController::CMD_MODULE_ENABLE, - 'Module_Foo,Module_Bar', - true, - true, - ['Module_Bar'], - ], - [ - ConsoleController::CMD_MODULE_DISABLE, - 'Module_Foo,Module_Bar', - false, - false, - ['Module_Bar'], - ], - [ - ConsoleController::CMD_MODULE_DISABLE, - 'Module_Foo,Module_Bar', - true, - false, - ['Module_Bar'], - ], - ]; - } - - /** - * 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, $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); - if (!$isUnchanged) { - $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('create') - ->will($this->returnValue($status)); - return $status; - } - - /** - * @expectedException \Magento\Setup\Exception - * @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, - false - ); - $status->expects($this->once())->method('getModulesToChange')->willReturn(['Module_Foo', 'Module_Bar']); - $status->expects($this->once()) - ->method('checkConstraints') - ->willReturn(['Circular dependency of Foo and Bar']); - $status->expects($this->never())->method('setIsEnabled'); - $this->controller->moduleAction(); - } - - /** - * @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-schema', $noParameters], - ['install-data', $noParameters], - ['install-user-configuration', ''], - ['install-admin-user', ''], - ['maintenance', ''], - ['help', ''], - ]; - } -} diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/ModulesTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/ModulesTest.php index 1607eebca1f174e42adbdf5936c7c9af878ac91d..96a30e19ac7a847092e8c1211c0e3f52f55d5c3e 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/ModulesTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/ModulesTest.php @@ -35,7 +35,6 @@ class ModulesTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); - $this->status = $this->getMock('Magento\Framework\Module\Status', [], [], '', false); /** @var * $objectManagerProvider \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ObjectManagerProvider */ diff --git a/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php b/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php index 938c72b9b2693f89975184f03958aa04fb0dc467..598641f1b844c84309a107b93c109ba0a88ab3d9 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php @@ -58,7 +58,7 @@ class AdminAccountTest extends \PHPUnit_Framework_TestCase AdminAccount::KEY_LAST_NAME => 'Doe', AdminAccount::KEY_EMAIL => 'john.doe@test.com', AdminAccount::KEY_PASSWORD => '123123q', - AdminAccount::KEY_USERNAME => 'admin', + AdminAccount::KEY_USER => 'admin', ]; $this->adminAccount = new AdminAccount($this->setUpMock, $this->randomMock, $data); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConsoleLoggerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConsoleLoggerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..af381ada33f4db5564b64cc1ad1cfe359c3a68ac --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConsoleLoggerTest.php @@ -0,0 +1,85 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Model; + +use Magento\Setup\Model\ConsoleLogger; + +class ConsoleLoggerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\Console\Output\OutputInterface + */ + private $console; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Setup\Model\ConsoleLogger + */ + private $consoleLoggerModel; + + public function setUp() + { + $this->console = $this->getMock('Symfony\Component\Console\Output\OutputInterface', [], [], '', false); + $outputFormatter = $this->getMock( + 'Symfony\Component\Console\Formatter\OutputFormatterInterface', + [], + [], + '', + false + ); + $this->console + ->expects($this->once()) + ->method('getFormatter') + ->willReturn($outputFormatter); + $this->consoleLoggerModel = new ConsoleLogger($this->console); + } + + public function testLogSuccess() + { + $this->console + ->expects($this->once()) + ->method('writeln') + ->with('<info>[SUCCESS]: Success message.</info>'); + $this->consoleLoggerModel->logSuccess('Success message.'); + } + + public function testLogError() + { + $exception = $this->getMock('\Exception', [], [], '', false); + $this->console + ->expects($this->once()) + ->method('writeln') + ->with('<error>[ERROR]: </error>'); + $this->consoleLoggerModel->logError($exception); + } + + public function testLog() + { + $this->console + ->expects($this->once()) + ->method('writeln') + ->with('<detail>Detail message.</detail>'); + $this->consoleLoggerModel->log('Detail message.'); + } + + public function testLogInline() + { + $this->console + ->expects($this->once()) + ->method('write') + ->with('<detail>Detail message.</detail>'); + $this->consoleLoggerModel->logInline('Detail message.'); + } + + public function testLogMeta() + { + $this->console + ->expects($this->once()) + ->method('writeln') + ->with('<metadata>Meta message.</metadata>'); + $this->consoleLoggerModel->logMeta('Meta message.'); + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php index b211b970509dd0b5bba1e6aeb23cf04d9152b6b8..291fee230a4bc3e33bd60c1d0cb16fee12bd2df5 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php @@ -73,6 +73,10 @@ class InstallerFactoryTest extends \PHPUnit_Framework_TestCase 'Magento\Setup\Model\ConfigModel', $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false), ], + [ + 'Magento\Framework\App\State\CleanupFiles', + $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false), + ], ]; $serviceLocatorMock = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']); $serviceLocatorMock diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 2423d8c903342da47c4b165d772771a8dda64c7c..553c5c8ed4c1ec544a824a240237a1b0eb505dca 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -9,10 +9,10 @@ namespace Magento\Setup\Test\Unit\Model; use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; use Magento\Framework\Config\ConfigOptionsList as SetupConfigOptionsList; use \Magento\Setup\Model\Installer; -use Magento\Framework\Config\ConfigOptionsList; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\App\State\CleanupFiles; /** * @SuppressWarnings(PHPMD.TooManyFields) @@ -105,6 +105,11 @@ class InstallerTest extends \PHPUnit_Framework_TestCase */ private $configModel; + /** + * @var CleanupFiles|\PHPUnit_Framework_MockObject_MockObject + */ + private $cleanupFiles; + /** * Sample DB configuration segment * @@ -117,7 +122,7 @@ class InstallerTest extends \PHPUnit_Framework_TestCase SetupConfigOptionsList::KEY_HOST => '127.0.0.1', SetupConfigOptionsList::KEY_NAME => 'magento', SetupConfigOptionsList::KEY_USER => 'magento', - SetupConfigOptionsList::KEY_PASS => '', + SetupConfigOptionsList::KEY_PASSWORD => '', ], ], ]; @@ -153,6 +158,7 @@ class InstallerTest extends \PHPUnit_Framework_TestCase $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); $this->contextMock = $this->getMock('Magento\Framework\Model\Resource\Db\Context', [], [], '', false); $this->configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); + $this->cleanupFiles = $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false); $this->object = $this->createObject(); } @@ -189,7 +195,8 @@ class InstallerTest extends \PHPUnit_Framework_TestCase $this->sampleData, $objectManagerProvider, $this->contextMock, - $this->configModel + $this->configModel, + $this->cleanupFiles ); } @@ -300,18 +307,27 @@ class InstallerTest extends \PHPUnit_Framework_TestCase public function testUpdateModulesSequence() { - $varDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); - $varDir->expects($this->exactly(2))->method('getAbsolutePath')->willReturn('/var'); - $this->filesystem - ->expects($this->exactly(2)) - ->method('getDirectoryWrite') - ->willReturn($varDir); - $allModules = [ 'Foo_One' => [], 'Bar_Two' => [], 'New_Module' => [], ]; + $this->cleanupFiles->expects($this->once())->method('clearCodeGeneratedClasses')->will( + $this->returnValue( + [ + "The directory '/generation' doesn't exist - skipping cleanup", + ] + ) + ); + + $cache = $this->getMock('Magento\Framework\App\Cache', [], [], '', false); + $cache->expects($this->once())->method('clean'); + $this->objectManager->expects($this->once()) + ->method('create') + ->will($this->returnValueMap([ + ['Magento\Framework\App\Cache', [], $cache], + ])); + $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules); $expectedModules = [ @@ -330,9 +346,10 @@ class InstallerTest extends \PHPUnit_Framework_TestCase $this->configReader->expects($this->once())->method('load') ->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0] ]); $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules); - $this->logger->expects($this->at(0))->method('log')->with('File system cleanup:'); - $this->logger->expects($this->at(1))->method('log') - ->with('The directory \'/var\' doesn\'t exist - skipping cleanup'); + $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully'); + $this->logger->expects($this->at(1))->method('log')->with('File system cleanup:'); + $this->logger->expects($this->at(2))->method('log') + ->with('The directory \'/generation\' doesn\'t exist - skipping cleanup'); $this->logger->expects($this->at(3))->method('log')->with('Updating modules:'); $newObject->updateModulesSequence(); } @@ -340,18 +357,12 @@ class InstallerTest extends \PHPUnit_Framework_TestCase 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'); - $staticDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); - $staticDir->expects($this->once())->method('getAbsolutePath')->willReturn('/static'); $configDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $configDir->expects($this->once())->method('getAbsolutePath')->willReturn('/config/config.php'); $this->filesystem ->expects($this->any()) ->method('getDirectoryWrite') ->will($this->returnValueMap([ - [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:'); @@ -359,20 +370,36 @@ class InstallerTest extends \PHPUnit_Framework_TestCase ->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:'); + $cache = $this->getMock('Magento\Framework\App\Cache', [], [], '', false); + $cache->expects($this->once())->method('clean'); + $this->objectManager->expects($this->once()) + ->method('create') + ->will($this->returnValueMap([ + ['Magento\Framework\App\Cache', [], $cache], + ])); + $this->logger->expects($this->at(2))->method('log')->with('Cache cleared successfully'); + $this->logger->expects($this->at(3))->method('log')->with('File system cleanup:'); $this->logger - ->expects($this->at(3)) + ->expects($this->at(4)) ->method('log') ->with("The directory '/var' doesn't exist - skipping cleanup"); $this->logger - ->expects($this->at(4)) + ->expects($this->at(5)) ->method('log') ->with("The directory '/static' doesn't exist - skipping cleanup"); $this->logger - ->expects($this->at(5)) + ->expects($this->at(6)) ->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->cleanupFiles->expects($this->once())->method('clearAllFiles')->will( + $this->returnValue( + [ + "The directory '/var' doesn't exist - skipping cleanup", + "The directory '/static' doesn't exist - skipping cleanup" + ] + ) + ); $this->object->uninstall(); } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/StoreConfigurationDataMapperTest.php b/setup/src/Magento/Setup/Test/Unit/Model/StoreConfigurationDataMapperTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9385ce4105e405cf38a9d1c9f4df8705ed6a5c90 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Model/StoreConfigurationDataMapperTest.php @@ -0,0 +1,147 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Setup\Test\Unit\Model; + +use \Magento\Setup\Model\StoreConfigurationDataMapper; + +use Magento\Backend\Model\Url; +use Magento\Directory\Helper\Data; +use Magento\Directory\Model\Currency; +use Magento\Setup\Module\Setup; +use Magento\Store\Model\Store; + +class StoreConfigurationDataMapperTest extends \PHPUnit_Framework_TestCase +{ + /** + * @param array $data + * @param array $expected + * @dataProvider getConfigDataDataProvider + */ + public function testGetConfigData(array $data, array $expected) + { + $userConfigurationDataMapper = new StoreConfigurationDataMapper(); + $this->assertEquals($expected, $userConfigurationDataMapper->getConfigData($data)); + } + + /** + * @return array + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function getConfigDataDataProvider() + { + return [ + 'valid' => + [ + [ + StoreConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => '1', + StoreConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1/', + StoreConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1/', + StoreConfigurationDataMapper::KEY_CURRENCY => 'USD', + StoreConfigurationDataMapper::KEY_IS_SECURE => '1', + StoreConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + StoreConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + StoreConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + StoreConfigurationDataMapper::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', + ], + ], + 'valid alphabet url' => [ + [ + StoreConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => '1', + StoreConfigurationDataMapper::KEY_BASE_URL => 'http://example.com/', + StoreConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://example.com/', + StoreConfigurationDataMapper::KEY_CURRENCY => 'USD', + StoreConfigurationDataMapper::KEY_IS_SECURE => '1', + StoreConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + StoreConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + StoreConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + StoreConfigurationDataMapper::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' => + [ + [ + StoreConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => '1', + StoreConfigurationDataMapper::KEY_BASE_URL => 'http://127.0.0.1', + StoreConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://127.0.0.1', + StoreConfigurationDataMapper::KEY_CURRENCY => 'USD', + StoreConfigurationDataMapper::KEY_IS_SECURE => '1', + StoreConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + StoreConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + StoreConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + StoreConfigurationDataMapper::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, alphabet url' => + [ + [ + StoreConfigurationDataMapper::KEY_ADMIN_USE_SECURITY_KEY => '1', + StoreConfigurationDataMapper::KEY_BASE_URL => 'http://example.com', + StoreConfigurationDataMapper::KEY_BASE_URL_SECURE => 'https://example.com', + StoreConfigurationDataMapper::KEY_CURRENCY => 'USD', + StoreConfigurationDataMapper::KEY_IS_SECURE => '1', + StoreConfigurationDataMapper::KEY_IS_SECURE_ADMIN => '1', + StoreConfigurationDataMapper::KEY_LANGUAGE => 'en_US', + StoreConfigurationDataMapper::KEY_TIMEZONE => 'America/Chicago', + StoreConfigurationDataMapper::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', + ], + ], + ]; + } +} diff --git a/setup/src/Magento/Setup/Test/Unit/Model/UserConfigurationDataMapperTest.php b/setup/src/Magento/Setup/Test/Unit/Model/UserConfigurationDataMapperTest.php deleted file mode 100644 index 442ee985c7c604385aa80b9993776b52110e402b..0000000000000000000000000000000000000000 --- a/setup/src/Magento/Setup/Test/Unit/Model/UserConfigurationDataMapperTest.php +++ /dev/null @@ -1,236 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Setup\Test\Unit\Model; - -use \Magento\Setup\Model\UserConfigurationDataMapper; - -use Magento\Backend\Model\Url; -use Magento\Directory\Helper\Data; -use Magento\Directory\Model\Currency; -use Magento\Setup\Module\Setup; -use Magento\Store\Model\Store; - -class UserConfigurationDataMapperTest extends \PHPUnit_Framework_TestCase -{ - /** - * @param array $data - * @param array $expected - * @dataProvider getConfigDataDataProvider - */ - public function testGetConfigData(array $data, array $expected) - { - $userConfigurationDataMapper = new UserConfigurationDataMapper(); - $this->assertEquals($expected, $userConfigurationDataMapper->getConfigData($data)); - } - - /** - * @return array - * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - 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', - ], - ], - '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' => - [ - [ - 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, 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' => - [ - [ - 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/setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php b/setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php index c59c2c3f1337f5a84778534329b2d97b973d595a..778c734d7e599e59722858d38fa04c110adc3fc5 100644 --- a/setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php @@ -29,73 +29,6 @@ class InitParamListenerTest extends \PHPUnit_Framework_TestCase $this->listener = new InitParamListener(); } - public function testAttachToConsoleRoutesEmpty() - { - $inputConfig = []; - $expectedConfig = []; - $this->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(); - - // usage statement should be an array and have a blank line followed by a line containing the parameter - $this->assertArrayHasKey(0, $usage); - $this->assertGreaterThanOrEqual(2, count($usage)); - - // First element should be a blank line - $this->assertEquals('', $usage[0]); - - // Parameter definition is added to the usage statement - $this->assertContains(InitParamListener::BOOTSTRAP_PARAM, implode($usage[1])); - } - public function testAttach() { $events = $this->prepareEventManager(); diff --git a/setup/src/Magento/Setup/Test/Unit/Mvc/Console/RouteListenerTest.php b/setup/src/Magento/Setup/Test/Unit/Mvc/Console/RouteListenerTest.php deleted file mode 100644 index 6ec5166de20f78467e738550ea2ab9feff6771c5..0000000000000000000000000000000000000000 --- a/setup/src/Magento/Setup/Test/Unit/Mvc/Console/RouteListenerTest.php +++ /dev/null @@ -1,163 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Setup\Test\Unit\Mvc\Console; - -use \Magento\Setup\Mvc\Console\RouteListener; - -use Zend\Mvc\MvcEvent; - -/** - * Tests Magento\Setup\Mvc\Console\RouteListener - */ -class RouteListenerTest extends \PHPUnit_Framework_TestCase -{ - - /** @var RouteListener */ - private $routeListener; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - private $request; - - /** @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(); - } - - public function testOnRouteHttpRequest() - { - /** @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($this->routeListener->onRoute($mvcEvent)); - } - - public function testOnRouteMatch() - { - $mvcEvent = $this->prepareEvent(); - - $match = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch')->disableOriginalConstructor()->getMock(); - $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($this->routeListener->onRoute($mvcEvent)); - } - - public function testOnRouteError() - { - $mvcEvent = $this->prepareEvent(); - - $this->router->expects($this->any())->method('match')->willReturn(null); - $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']]]]); - - // Verify the error is set - $mvcEvent->expects($this->once())->method('setError'); - - // Should always return null - $this->assertNull($this->routeListener->onRoute($mvcEvent)); - } - - public function testOnRouteNoError() - { - $mvcEvent = $this->prepareEvent(); - - $routeMatch = $this->getMockBuilder('Zend\Mvc\Router\RouteMatch')->disableOriginalConstructor()->getMock(); - $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($this->routeListener->onRoute($mvcEvent)); - } - - - public function testOnRouteValidationMessage() - { - $mvcEvent = $this->prepareEvent(); - - $this->router->expects($this->any())->method('match')->willReturn(null); - $mvcEvent->expects($this->any())->method('getRouter')->willReturn($this->router); - - $this->request->expects($this->any())->method('getContent')->willReturn(['install']); - - $this->prepareOnRoute( - $mvcEvent, - ['console' => ['router' => ['routes' => ['install' => ['options' => ['route' => 'testRoute']]]]]] - ); - - // 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($this->routeListener->onRoute($mvcEvent)); - } - - - public function testAttach() - { - /** @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($this->routeListener), - 10 - ); - $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 - ->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); - } -}