From 729991a83b3ff0bc06890745a683440c58eac7f3 Mon Sep 17 00:00:00 2001 From: Joan He Date: Mon, 30 Mar 2015 10:10:22 -0500 Subject: [PATCH 01/68] MAGETWO-35005: Investigate and Annotate @api to classes and/or methods --- .../Adminhtml/Order/EditInterface.php | 11 -- .../Magento/Framework/App/Resource.php | 2 + .../Framework/App/Route/ConfigInterface.php | 9 +- .../Framework/DB/Adapter/AdapterInterface.php | 1 + .../Magento/Framework/DB/Ddl/Table.php | 113 ++++++++++++++++-- .../Model/Resource/AbstractResource.php | 6 + .../Model/Resource/Db/AbstractDb.php | 4 + .../Framework/Url/ScopeResolverInterface.php | 2 +- 8 files changed, 124 insertions(+), 24 deletions(-) delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Order/EditInterface.php diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/EditInterface.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/EditInterface.php deleted file mode 100644 index 79fefe2a18515..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/EditInterface.php +++ /dev/null @@ -1,11 +0,0 @@ - + * @api */ interface AdapterInterface { diff --git a/lib/internal/Magento/Framework/DB/Ddl/Table.php b/lib/internal/Magento/Framework/DB/Ddl/Table.php index e42dfa1f6c2d7..249fb6167919e 100644 --- a/lib/internal/Magento/Framework/DB/Ddl/Table.php +++ b/lib/internal/Magento/Framework/DB/Ddl/Table.php @@ -16,68 +16,147 @@ class Table { /** - * Types of columns + * Column type boolean + * @api */ const TYPE_BOOLEAN = 'boolean'; + /** + * Column type smallint + * @api + */ const TYPE_SMALLINT = 'smallint'; + /** + * Column type integer + * @api + */ const TYPE_INTEGER = 'integer'; + /** + * Column type bigint + * @api + */ const TYPE_BIGINT = 'bigint'; + /** + * Column type float + * @api + */ const TYPE_FLOAT = 'float'; + /** + * Column type numeric + * @api + */ const TYPE_NUMERIC = 'numeric'; + /** + * Column type decimal + * @api + */ const TYPE_DECIMAL = 'decimal'; + /** + * Column type date + * @api + */ const TYPE_DATE = 'date'; + /** + * Column type timestamp + * @api + */ const TYPE_TIMESTAMP = 'timestamp'; - // Capable to support date-time from 1970 + auto-triggers in some RDBMS + /** + * Column type datetime, capable to support date-time from 1970 + auto-triggers in some RDBMS + * @api + */ const TYPE_DATETIME = 'datetime'; - // Capable to support long date-time before 1970 + /** + * Column type text, capable to support long date-time before 1970 + * @api + */ const TYPE_TEXT = 'text'; + /** + * Column type blob + * @api + */ const TYPE_BLOB = 'blob'; - // Used for back compatibility, when query param can't use statement options + /** + * Column type varbinary, used for back compatibility, when query param can't use statement options + * @api + */ const TYPE_VARBINARY = 'varbinary'; - // A real blob, stored as binary inside DB - /** - * Default and maximal TEXT and BLOB columns sizes we can support for different DB systems. + * Default TEXT columns sizes + * @api */ const DEFAULT_TEXT_SIZE = 1024; + /** + * Maximal TEXT columns sizes + * @api + */ const MAX_TEXT_SIZE = 2147483648; + /** + * Maximal BLOB columns sizes + * @api + */ const MAX_VARBINARY_SIZE = 2147483648; /** - * Default values for timestampses - fill with current timestamp on inserting record, on changing and both cases + * Default value for timestamps - fill with current timestamp on inserting record, on changing and both cases + * @api */ const TIMESTAMP_INIT_UPDATE = 'TIMESTAMP_INIT_UPDATE'; + /** + * Default value for timestamps - fill with current timestamp only on inserting record + * @api + */ const TIMESTAMP_INIT = 'TIMESTAMP_INIT'; + /** + * Default value for timestamps - fill with current timestamp only on changing record + * @api + */ const TIMESTAMP_UPDATE = 'TIMESTAMP_UPDATE'; /** - * Actions used for foreign keys + * Cascade action used for foreign keys + * @api */ const ACTION_CASCADE = 'CASCADE'; + /** + * Set null action used for foreign keys + * @api + */ const ACTION_SET_NULL = 'SET NULL'; + /** + * No action action used for foreign keys + * @api + */ const ACTION_NO_ACTION = 'NO ACTION'; + /** + * Restrict action used for foreign keys + * @api + */ const ACTION_RESTRICT = 'RESTRICT'; + /** + * Set default action used for foreign keys + * @api + */ const ACTION_SET_DEFAULT = 'SET DEFAULT'; /** @@ -182,6 +261,7 @@ class Table * * @param string $name * @return $this + * @api */ public function setName($name) { @@ -197,6 +277,7 @@ public function setName($name) * * @param string $name * @return $this + * @api */ public function setSchema($name) { @@ -209,6 +290,7 @@ public function setSchema($name) * * @param string $comment * @return $this + * @api */ public function setComment($comment) { @@ -221,6 +303,7 @@ public function setComment($comment) * * @return string * @throws \Zend_Db_Exception + * @api */ public function getName() { @@ -234,6 +317,7 @@ public function getName() * Get schema name * * @return string|null + * @api */ public function getSchema() { @@ -244,6 +328,7 @@ public function getSchema() * Return comment for table * * @return string + * @api */ public function getComment() { @@ -273,6 +358,7 @@ public function getComment() * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @api */ public function addColumn($name, $type, $size = null, $options = [], $comment = null) { @@ -409,6 +495,7 @@ public function addColumn($name, $type, $size = null, $options = [], $comment = * @return $this * @throws \Zend_Db_Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @api */ public function addForeignKey($fkName, $column, $refTable, $refColumn, $onDelete = null, $onUpdate = null) { @@ -460,6 +547,7 @@ public function addForeignKey($fkName, $column, $refTable, $refColumn, $onDelete * @return $this * @throws \Zend_Db_Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @api */ public function addIndex($indexName, $fields, $options = []) { @@ -527,6 +615,7 @@ public function addIndex($indexName, $fields, $options = []) * @param bool $normalized * @see $this->_columns * @return array + * @api */ public function getColumns($normalized = true) { @@ -542,6 +631,7 @@ public function getColumns($normalized = true) * @param array $column * @see $this->_columns * @return $this + * @api */ public function setColumn($column) { @@ -555,6 +645,7 @@ public function setColumn($column) * * @see $this->_indexes * @return array + * @api */ public function getIndexes() { @@ -566,6 +657,7 @@ public function getIndexes() * * @see $this->_foreignKeys * @return array + * @api */ public function getForeignKeys() { @@ -578,6 +670,7 @@ public function getForeignKeys() * @param string $key * @param string $value * @return $this + * @api */ public function setOption($key, $value) { @@ -591,6 +684,7 @@ public function setOption($key, $value) * * @param string $key * @return null|string + * @api */ public function getOption($key) { @@ -604,6 +698,7 @@ public function getOption($key) * Retrieve array of table options * * @return array + * @api */ public function getOptions() { diff --git a/lib/internal/Magento/Framework/Model/Resource/AbstractResource.php b/lib/internal/Magento/Framework/Model/Resource/AbstractResource.php index 831dcf5ae71fb..accaab8379783 100644 --- a/lib/internal/Magento/Framework/Model/Resource/AbstractResource.php +++ b/lib/internal/Magento/Framework/Model/Resource/AbstractResource.php @@ -47,6 +47,7 @@ abstract protected function _construct(); * Retrieve connection for read data * * @return \Magento\Framework\DB\Adapter\AdapterInterface + * @api */ abstract protected function _getReadAdapter(); @@ -54,6 +55,7 @@ abstract protected function _getReadAdapter(); * Retrieve connection for write data * * @return \Magento\Framework\DB\Adapter\AdapterInterface + * @api */ abstract protected function _getWriteAdapter(); @@ -61,6 +63,7 @@ abstract protected function _getWriteAdapter(); * Start resource transaction * * @return $this + * @api */ public function beginTransaction() { @@ -73,6 +76,7 @@ public function beginTransaction() * * @param array $callback * @return $this + * @api */ public function addCommitCallback($callback) { @@ -85,6 +89,7 @@ public function addCommitCallback($callback) * Commit resource transaction * * @return $this + * @api */ public function commit() { @@ -109,6 +114,7 @@ public function commit() * Roll back resource transaction * * @return $this + * @api */ public function rollBack() { diff --git a/lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php b/lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php index 393c90be8e000..8cc88a629a5cf 100644 --- a/lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php +++ b/lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php @@ -233,6 +233,7 @@ protected function _setMainTable($mainTable, $idFieldName = null) * * @throws LocalizedException * @return string + * @api */ public function getIdFieldName() { @@ -248,6 +249,7 @@ public function getIdFieldName() * * @throws LocalizedException * @return string + * @api */ public function getMainTable() { @@ -262,6 +264,7 @@ public function getMainTable() * * @param string $tableName * @return string + * @api */ public function getTable($tableName) { @@ -391,6 +394,7 @@ protected function _getLoadSelect($field, $value, $object) * @param \Magento\Framework\Model\AbstractModel $object * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @api */ public function save(\Magento\Framework\Model\AbstractModel $object) { diff --git a/lib/internal/Magento/Framework/Url/ScopeResolverInterface.php b/lib/internal/Magento/Framework/Url/ScopeResolverInterface.php index 893443659220d..a31ae25c76ea4 100644 --- a/lib/internal/Magento/Framework/Url/ScopeResolverInterface.php +++ b/lib/internal/Magento/Framework/Url/ScopeResolverInterface.php @@ -10,7 +10,7 @@ interface ScopeResolverInterface extends \Magento\Framework\App\ScopeResolverInt /** * Retrieve area code * - * @return \Magento\Framework\Url\ScopeInterface[] + * @return string|null */ public function getAreaCode(); } From 3de5264a32961530037a3a3fc28774ac5faf19d1 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Mon, 30 Mar 2015 13:16:17 -0500 Subject: [PATCH 02/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- .../App/Config/Data/ProcessorFactory.php | 17 +++++++++-------- .../App/Config/Data/ProcessorInterface.php | 11 +++++++---- .../Framework/App/Config/DataInterface.php | 10 ++++++++++ .../App/Config/Resource/ConfigInterface.php | 8 +++++--- .../Magento/Framework/Message/Factory.php | 10 ++++++---- lib/internal/Magento/Framework/Object/Copy.php | 4 ++++ 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Config/Data/ProcessorFactory.php b/lib/internal/Magento/Framework/App/Config/Data/ProcessorFactory.php index 8f473e2a37b2b..8084dcd5d08f4 100644 --- a/lib/internal/Magento/Framework/App/Config/Data/ProcessorFactory.php +++ b/lib/internal/Magento/Framework/App/Config/Data/ProcessorFactory.php @@ -30,21 +30,22 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan /** * Get concrete Processor Interface instance * - * @param string $model + * @param string $processorModel Classname of the instance to get * @return ProcessorInterface - * @throws \InvalidArgumentException + * @throws \InvalidArgumentException In case the given classname is not an instance of ProcessorInterface + * @api */ - public function get($model) + public function get($processorModel) { - if (!isset($this->_pool[$model])) { - $instance = $this->_objectManager->create($model); + if (!isset($this->_pool[$processorModel])) { + $instance = $this->_objectManager->create($processorModel); if (!$instance instanceof ProcessorInterface) { throw new \InvalidArgumentException( - $model . ' is not instance of \Magento\Framework\App\Config\Data\ProcessorInterface' + $processorModel . ' is not instance of \Magento\Framework\App\Config\Data\ProcessorInterface' ); } - $this->_pool[$model] = $instance; + $this->_pool[$processorModel] = $instance; } - return $this->_pool[$model]; + return $this->_pool[$processorModel]; } } diff --git a/lib/internal/Magento/Framework/App/Config/Data/ProcessorInterface.php b/lib/internal/Magento/Framework/App/Config/Data/ProcessorInterface.php index 71102131f42cf..d446733967673 100644 --- a/lib/internal/Magento/Framework/App/Config/Data/ProcessorInterface.php +++ b/lib/internal/Magento/Framework/App/Config/Data/ProcessorInterface.php @@ -1,19 +1,22 @@ Date: Mon, 30 Mar 2015 14:57:30 -0500 Subject: [PATCH 03/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- .../Magento/Backend/Model/Locale/Manager.php | 3 ++- .../Test/Unit/Model/Locale/ManagerTest.php | 4 ++- .../Test/Unit/Block/Widget/DobTest.php | 3 ++- .../Model/Config/Reader/DefaultReader.php | 15 ++++++++--- .../Store/Model/Config/Reader/Store.php | 2 +- .../User/Controller/Adminhtml/User/Edit.php | 4 ++- .../Backend/Model/Locale/ResolverTest.php | 3 ++- .../Magento/Framework/App/Config/Initial.php | 6 ++++- .../Config/MutableScopeConfigInterface.php | 3 +++ .../App/Config/ReinitableConfigInterface.php | 3 +++ .../App/Config/Scope/ReaderInterface.php | 9 ++++++- .../App/Config/ScopeConfigInterface.php | 22 ++++++++++------ .../Framework/App/Config/ValueFactory.php | 2 ++ .../Magento/Framework/App/ScopeInterface.php | 2 ++ .../Framework/Locale/ConfigInterface.php | 9 +++++-- .../Magento/Framework/Locale/Currency.php | 6 ++++- .../Framework/Locale/CurrencyInterface.php | 15 ++++------- .../Magento/Framework/Locale/Resolver.php | 6 ++++- .../Framework/Locale/ResolverInterface.php | 10 ++++---- .../Locale/Test/Unit/CurrencyTest.php | 3 ++- .../Magento/Framework/Locale/Validator.php | 4 ++- .../Magento/Framework/Message/Manager.php | 24 ++++++++++-------- .../Framework/Message/ManagerInterface.php | 25 ++++++++----------- .../Framework/Message/MessageInterface.php | 4 ++- .../Message/Test/Unit/ManagerTest.php | 13 +++++----- .../View/Test/Unit/Element/MessagesTest.php | 3 ++- setup/src/Magento/Setup/Model/Lists.php | 9 ++++--- 27 files changed, 137 insertions(+), 75 deletions(-) diff --git a/app/code/Magento/Backend/Model/Locale/Manager.php b/app/code/Magento/Backend/Model/Locale/Manager.php index 76a327f1364d1..4a91caa23f6c9 100644 --- a/app/code/Magento/Backend/Model/Locale/Manager.php +++ b/app/code/Magento/Backend/Model/Locale/Manager.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Backend\Model\Locale; +use Magento\Framework\Locale\Resolver; /** * Locale manager model @@ -68,7 +69,7 @@ public function switchBackendInterfaceLocale($localeCode) */ public function getUserInterfaceLocale() { - $interfaceLocale = \Magento\Framework\Locale\ResolverInterface::DEFAULT_LOCALE; + $interfaceLocale = Resolver::DEFAULT_LOCALE; $userData = $this->_authSession->getUser(); if ($userData && $userData->getInterfaceLocale()) { diff --git a/app/code/Magento/Backend/Test/Unit/Model/Locale/ManagerTest.php b/app/code/Magento/Backend/Test/Unit/Model/Locale/ManagerTest.php index 000c861f11d8e..a624a526d5dbf 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/Locale/ManagerTest.php +++ b/app/code/Magento/Backend/Test/Unit/Model/Locale/ManagerTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Backend\Test\Unit\Model\Locale; +use Magento\Framework\Locale\Resolver; + class ManagerTest extends \PHPUnit_Framework_TestCase { /** @@ -87,7 +89,7 @@ public function testGetUserInterfaceLocaleDefault() { $locale = $this->_model->getUserInterfaceLocale(); - $this->assertEquals($locale, \Magento\Framework\Locale\ResolverInterface::DEFAULT_LOCALE); + $this->assertEquals($locale, Resolver::DEFAULT_LOCALE); } /** diff --git a/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php b/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php index 5d1e91708b4fc..834c64df6701f 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php @@ -10,6 +10,7 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Customer\Block\Widget\Dob; +use Magento\Framework\Locale\Resolver; class DobTest extends \PHPUnit_Framework_TestCase { @@ -69,7 +70,7 @@ public function setUp() $localeResolver = $this->getMock('\Magento\Framework\Locale\ResolverInterface'); $localeResolver->expects($this->any()) ->method('getLocale') - ->willReturn(\Magento\Framework\Locale\ResolverInterface::DEFAULT_LOCALE); + ->willReturn(Resolver::DEFAULT_LOCALE); $timezone = $objectManager->getObject( 'Magento\Framework\Stdlib\DateTime\Timezone', ['localeResolver' => $localeResolver] diff --git a/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php b/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php index 4f03885e8cd7a..482fecc656199 100644 --- a/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php +++ b/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php @@ -7,6 +7,8 @@ */ namespace Magento\Store\Model\Config\Reader; +use Magento\Framework\App\Config\ScopeConfigInterface; + class DefaultReader implements \Magento\Framework\App\Config\Scope\ReaderInterface { /** @@ -42,14 +44,21 @@ public function __construct( /** * Read configuration data * + * @param null|string $scope + * @throws \Magento\Framework\Exception Exception is thrown when scope other than default is given * @return array */ - public function read() + public function read($scope = ScopeConfigInterface::SCOPE_DEFAULT) { - $config = $this->_initialConfig->getData(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT); + $scope = $scope === null ? ScopeConfigInterface::SCOPE_DEFAULT : $scope; + if ($scope !== ScopeConfigInterface::SCOPE_DEFAULT) { + throw new \Magento\Framework\Exception("Only default scope allowed"); + } + + $config = $this->_initialConfig->getData($scope); $collection = $this->_collectionFactory->create( - ['scope' => \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT] + ['scope' => $scope] ); $dbDefaultConfig = []; foreach ($collection as $item) { diff --git a/app/code/Magento/Store/Model/Config/Reader/Store.php b/app/code/Magento/Store/Model/Config/Reader/Store.php index c5456bcb102f9..f4d5124888c59 100644 --- a/app/code/Magento/Store/Model/Config/Reader/Store.php +++ b/app/code/Magento/Store/Model/Config/Reader/Store.php @@ -66,7 +66,7 @@ public function __construct( /** * Read configuration by code * - * @param string $code + * @param null|string $code * @return array * @throws NoSuchEntityException */ diff --git a/app/code/Magento/User/Controller/Adminhtml/User/Edit.php b/app/code/Magento/User/Controller/Adminhtml/User/Edit.php index 3d3ad64cd201a..39ac43d55391b 100644 --- a/app/code/Magento/User/Controller/Adminhtml/User/Edit.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/Edit.php @@ -6,6 +6,8 @@ */ namespace Magento\User\Controller\Adminhtml\User; +use Magento\Framework\Locale\Resolver; + class Edit extends \Magento\User\Controller\Adminhtml\User { /** @@ -25,7 +27,7 @@ public function execute() return; } } else { - $model->setInterfaceLocale(\Magento\Framework\Locale\ResolverInterface::DEFAULT_LOCALE); + $model->setInterfaceLocale(Resolver::DEFAULT_LOCALE); } // Restore previously entered form data from session diff --git a/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php b/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php index 09c21758cba33..5ce73f4d6f72c 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Backend\Model\Locale; +use Magento\Framework\Locale\Resolver; /** * @magentoAppArea adminhtml @@ -28,7 +29,7 @@ protected function setUp() */ public function testSetLocaleWithDefaultLocale() { - $this->_checkSetLocale(\Magento\Framework\Locale\ResolverInterface::DEFAULT_LOCALE); + $this->_checkSetLocale(Resolver::DEFAULT_LOCALE); } /** diff --git a/lib/internal/Magento/Framework/App/Config/Initial.php b/lib/internal/Magento/Framework/App/Config/Initial.php index 68db7b1eb84d4..c59ba25339968 100644 --- a/lib/internal/Magento/Framework/App/Config/Initial.php +++ b/lib/internal/Magento/Framework/App/Config/Initial.php @@ -50,8 +50,10 @@ public function __construct( /** * Get initial data by given scope * - * @param string $scope + * @param string $scope Format is scope type and scope code separated by pipe: e.g. "type|code" * @return array + * + * @api */ public function getData($scope) { @@ -69,6 +71,8 @@ public function getData($scope) * Get configuration metadata * * @return array + * + * @api */ public function getMetadata() { diff --git a/lib/internal/Magento/Framework/App/Config/MutableScopeConfigInterface.php b/lib/internal/Magento/Framework/App/Config/MutableScopeConfigInterface.php index 37a371b547f40..46df2b6b884fa 100644 --- a/lib/internal/Magento/Framework/App/Config/MutableScopeConfigInterface.php +++ b/lib/internal/Magento/Framework/App/Config/MutableScopeConfigInterface.php @@ -8,6 +8,9 @@ namespace Magento\Framework\App\Config; +/** + * @api + */ interface MutableScopeConfigInterface extends \Magento\Framework\App\Config\ScopeConfigInterface { /** diff --git a/lib/internal/Magento/Framework/App/Config/ReinitableConfigInterface.php b/lib/internal/Magento/Framework/App/Config/ReinitableConfigInterface.php index 5b9d9d78eb3b4..f9fc887a878e0 100644 --- a/lib/internal/Magento/Framework/App/Config/ReinitableConfigInterface.php +++ b/lib/internal/Magento/Framework/App/Config/ReinitableConfigInterface.php @@ -8,6 +8,9 @@ namespace Magento\Framework\App\Config; +/** + * @api + */ interface ReinitableConfigInterface extends \Magento\Framework\App\Config\MutableScopeConfigInterface { /** diff --git a/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php b/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php index bf20ecd1d5308..d456b23bad2bf 100644 --- a/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php +++ b/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php @@ -4,15 +4,22 @@ * * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. + * + * @api */ namespace Magento\Framework\App\Config\Scope; +/** + * @api + */ interface ReaderInterface { /** * Read configuration scope * + * @param string|null $scope + * @throws \Exception May throw an exception if the given scope is invalid * @return array */ - public function read(); + public function read($scope = null); } diff --git a/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php b/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php index ac84e7358b5d2..446d6218dc7b9 100644 --- a/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php +++ b/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php @@ -8,25 +8,33 @@ namespace Magento\Framework\App\Config; +/** + * @api + */ interface ScopeConfigInterface { /** - * Retrieve config value by path and scope + * Default scope type + */ + const SCOPE_DEFAULT = 'default'; + + /** + * Retrieve config value by path and scope. * - * @param string $path - * @param string $scope + * @param string $path The path through the tree of configuration values, e.g., 'general/store_information/name' + * @param string $scope The scope to use to determine config value, e.g., 'store' or 'default' * @param null|string $scopeCode * @return mixed */ - public function getValue($path, $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $scopeCode = null); + public function getValue($path, $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_DEFAULT, $scopeCode = null); /** * Retrieve config flag by path and scope * - * @param string $path - * @param string $scope + * @param string $path The path through the tree of configuration values, e.g., 'general/store_information/name' + * @param string $scope The scope to use to determine config value, e.g., 'store' or 'default' * @param null|string $scopeCode * @return bool */ - public function isSetFlag($path, $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $scopeCode = null); + public function isSetFlag($path, $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_DEFAULT, $scopeCode = null); } diff --git a/lib/internal/Magento/Framework/App/Config/ValueFactory.php b/lib/internal/Magento/Framework/App/Config/ValueFactory.php index 3163d2ccb4cfb..74a51691f2ce6 100644 --- a/lib/internal/Magento/Framework/App/Config/ValueFactory.php +++ b/lib/internal/Magento/Framework/App/Config/ValueFactory.php @@ -44,6 +44,8 @@ public function __construct( * @param array $data * @return \Magento\Framework\App\Config\ValueInterface * @throws \InvalidArgumentException + * + * @api */ public function create(array $data = []) { diff --git a/lib/internal/Magento/Framework/App/ScopeInterface.php b/lib/internal/Magento/Framework/App/ScopeInterface.php index d244ec5bf3a1f..9f9204426f469 100644 --- a/lib/internal/Magento/Framework/App/ScopeInterface.php +++ b/lib/internal/Magento/Framework/App/ScopeInterface.php @@ -9,6 +9,8 @@ interface ScopeInterface { /** * Default scope type + * + * @deprecated Use \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_DEFAULT */ const SCOPE_DEFAULT = 'default'; diff --git a/lib/internal/Magento/Framework/Locale/ConfigInterface.php b/lib/internal/Magento/Framework/Locale/ConfigInterface.php index 3539f09409a80..e0f28fd015c33 100644 --- a/lib/internal/Magento/Framework/Locale/ConfigInterface.php +++ b/lib/internal/Magento/Framework/Locale/ConfigInterface.php @@ -5,19 +5,24 @@ */ namespace Magento\Framework\Locale; +/** + * Provides access to locale-related config information + * + * @api + */ interface ConfigInterface { /** * Get list pre-configured allowed locales * - * @return array + * @return string[] */ public function getAllowedLocales(); /** * Get list pre-configured allowed currencies * - * @return array + * @return string[] */ public function getAllowedCurrencies(); } diff --git a/lib/internal/Magento/Framework/Locale/Currency.php b/lib/internal/Magento/Framework/Locale/Currency.php index 5d3c5a9ec9b7e..b58cfacad571c 100644 --- a/lib/internal/Magento/Framework/Locale/Currency.php +++ b/lib/internal/Magento/Framework/Locale/Currency.php @@ -7,6 +7,10 @@ class Currency implements \Magento\Framework\Locale\CurrencyInterface { + /** + * Default currency + */ + const DEFAULT_CURRENCY = 'USD'; /** * @var array */ @@ -51,7 +55,7 @@ public function __construct( */ public function getDefaultCurrency() { - return \Magento\Framework\Locale\CurrencyInterface::DEFAULT_CURRENCY; + return self::DEFAULT_CURRENCY; } /** diff --git a/lib/internal/Magento/Framework/Locale/CurrencyInterface.php b/lib/internal/Magento/Framework/Locale/CurrencyInterface.php index 774f7d5120f3c..addb657021038 100644 --- a/lib/internal/Magento/Framework/Locale/CurrencyInterface.php +++ b/lib/internal/Magento/Framework/Locale/CurrencyInterface.php @@ -5,18 +5,13 @@ */ namespace Magento\Framework\Locale; +/** + * Provides access to currency config information + * + * @api + */ interface CurrencyInterface { - /** - * Default currency - */ - const DEFAULT_CURRENCY = 'USD'; - - /** - * XML path to installed currencies - */ - const XML_PATH_ALLOW_CURRENCIES_INSTALLED = 'system/currency/installed'; - /** * Retrieve currency code * diff --git a/lib/internal/Magento/Framework/Locale/Resolver.php b/lib/internal/Magento/Framework/Locale/Resolver.php index b78be470920ec..6a81f60cc5a0c 100644 --- a/lib/internal/Magento/Framework/Locale/Resolver.php +++ b/lib/internal/Magento/Framework/Locale/Resolver.php @@ -9,6 +9,10 @@ class Resolver implements ResolverInterface { + /** + * Default locale + */ + const DEFAULT_LOCALE = 'en_US'; /** * Default locale code * @@ -85,7 +89,7 @@ public function getDefaultLocale() if (!$this->defaultLocale) { $locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType); if (!$locale) { - $locale = ResolverInterface::DEFAULT_LOCALE; + $locale = self::DEFAULT_LOCALE; } $this->defaultLocale = $locale; } diff --git a/lib/internal/Magento/Framework/Locale/ResolverInterface.php b/lib/internal/Magento/Framework/Locale/ResolverInterface.php index 08add444266f0..a17932ed86288 100644 --- a/lib/internal/Magento/Framework/Locale/ResolverInterface.php +++ b/lib/internal/Magento/Framework/Locale/ResolverInterface.php @@ -5,13 +5,13 @@ */ namespace Magento\Framework\Locale; +/** + * Manages locale config information + * + * @api + */ interface ResolverInterface { - /** - * Default locale - */ - const DEFAULT_LOCALE = 'en_US'; - /** * Return path to default locale * diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/CurrencyTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/CurrencyTest.php index 01552d3a97229..226e8d4d8508b 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/CurrencyTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/CurrencyTest.php @@ -8,6 +8,7 @@ namespace Magento\Framework\Locale\Test\Unit; +use Magento\Framework\Locale\Currency; use Magento\Framework\Locale\CurrencyInterface; class CurrencyTest extends \PHPUnit_Framework_TestCase @@ -68,7 +69,7 @@ public function setUp() public function testGetDefaultCurrency() { - $expectedDefaultCurrency = CurrencyInterface::DEFAULT_CURRENCY; + $expectedDefaultCurrency = Currency::DEFAULT_CURRENCY; $retrievedDefaultCurrency = $this->testCurrencyObject->getDefaultCurrency(); $this->assertEquals($expectedDefaultCurrency, $retrievedDefaultCurrency); } diff --git a/lib/internal/Magento/Framework/Locale/Validator.php b/lib/internal/Magento/Framework/Locale/Validator.php index b30727562c457..0cdf265af01b3 100644 --- a/lib/internal/Magento/Framework/Locale/Validator.php +++ b/lib/internal/Magento/Framework/Locale/Validator.php @@ -29,10 +29,12 @@ public function __construct(\Magento\Framework\Locale\ConfigInterface $localeCon } /** - * Validate locale code + * Validate locale code. Code must be in the list of allowed locales. * * @param string $localeCode * @return bool + * + * @api */ public function isValid($localeCode) { diff --git a/lib/internal/Magento/Framework/Message/Manager.php b/lib/internal/Magento/Framework/Message/Manager.php index 73b212a58e3ee..f92da3dc2fb76 100644 --- a/lib/internal/Magento/Framework/Message/Manager.php +++ b/lib/internal/Magento/Framework/Message/Manager.php @@ -14,6 +14,10 @@ */ class Manager implements ManagerInterface { + /** + * Default message group + */ + const DEFAULT_GROUP = 'default'; /** * @var Session */ @@ -74,7 +78,7 @@ public function __construct( } /** - * Retrieve default message group + * @inheritdoc * * @return string */ @@ -95,7 +99,7 @@ protected function prepareGroup($group) } /** - * Retrieve messages + * @inheritdoc * * @param string|null $group * @param bool $clear @@ -118,7 +122,7 @@ public function getMessages($clear = false, $group = null) } /** - * Adding new message to message collection + * @inheritdoc * * @param MessageInterface $message * @param string|null $group @@ -133,7 +137,7 @@ public function addMessage(MessageInterface $message, $group = null) } /** - * Adding messages array to message collection + * @inheritdoc * * @param MessageInterface[] $messages * @param string|null $group @@ -148,7 +152,7 @@ public function addMessages(array $messages, $group = null) } /** - * Adding new error message + * @inheritdoc * * @param string $message * @param string|null $group @@ -161,7 +165,7 @@ public function addError($message, $group = null) } /** - * Adding new warning message + * @inheritdoc * * @param string $message * @param string|null $group @@ -174,7 +178,7 @@ public function addWarning($message, $group = null) } /** - * Adding new notice message + * @inheritdoc * * @param string $message * @param string|null $group @@ -187,7 +191,7 @@ public function addNotice($message, $group = null) } /** - * Adding new success message + * @inheritdoc * * @param string $message * @param string|null $group @@ -200,7 +204,7 @@ public function addSuccess($message, $group = null) } /** - * Adds messages array to message collection, but doesn't add duplicates to it + * @inheritdoc * * @param MessageInterface[]|MessageInterface $messages * @param string|null $group @@ -244,7 +248,7 @@ public function addUniqueMessages($messages, $group = null) } /** - * Not Magento exception handling + * @inheritdoc * * @param \Exception $exception * @param string $alternativeText diff --git a/lib/internal/Magento/Framework/Message/ManagerInterface.php b/lib/internal/Magento/Framework/Message/ManagerInterface.php index 36851dc866c49..dd73d2a2fcfbc 100644 --- a/lib/internal/Magento/Framework/Message/ManagerInterface.php +++ b/lib/internal/Magento/Framework/Message/ManagerInterface.php @@ -6,15 +6,12 @@ namespace Magento\Framework\Message; /** - * Message manager interface + * Adds different types of messages to the session, and allows access to existing messages. + * + * @api */ interface ManagerInterface { - /** - * Default message group - */ - const DEFAULT_GROUP = 'default'; - /** * Retrieve messages * @@ -32,7 +29,7 @@ public function getMessages($clear = false, $group = null); public function getDefaultGroup(); /** - * Adding new message to message collection + * Adds new message to message collection * * @param MessageInterface $message * @param string|null $group @@ -41,7 +38,7 @@ public function getDefaultGroup(); public function addMessage(MessageInterface $message, $group = null); /** - * Adding messages array to message collection + * Adds messages array to message collection * * @param array $messages * @param string|null $group @@ -50,7 +47,7 @@ public function addMessage(MessageInterface $message, $group = null); public function addMessages(array $messages, $group = null); /** - * Adding new error message + * Adds new error message * * @param string $message * @param string|null $group @@ -59,7 +56,7 @@ public function addMessages(array $messages, $group = null); public function addError($message, $group = null); /** - * Adding new warning message + * Adds new warning message * * @param string $message * @param string|null $group @@ -68,7 +65,7 @@ public function addError($message, $group = null); public function addWarning($message, $group = null); /** - * Adding new notice message + * Adds new notice message * * @param string $message * @param string|null $group @@ -77,7 +74,7 @@ public function addWarning($message, $group = null); public function addNotice($message, $group = null); /** - * Adding new success message + * Adds new success message * * @param string $message * @param string|null $group @@ -86,7 +83,7 @@ public function addNotice($message, $group = null); public function addSuccess($message, $group = null); /** - * Adds messages array to message collection, but doesn't add duplicates to it + * Adds messages array to message collection, without adding duplicate messages * * @param array|MessageInterface $messages * @param string|null $group @@ -95,7 +92,7 @@ public function addSuccess($message, $group = null); public function addUniqueMessages($messages, $group = null); /** - * Not Magento exception handling + * Adds a message describing an exception. Does not contain Exception handling logic. * * @param \Exception $exception * @param string $alternativeText diff --git a/lib/internal/Magento/Framework/Message/MessageInterface.php b/lib/internal/Magento/Framework/Message/MessageInterface.php index e5342f49ac042..d9d60e047b171 100644 --- a/lib/internal/Magento/Framework/Message/MessageInterface.php +++ b/lib/internal/Magento/Framework/Message/MessageInterface.php @@ -6,7 +6,9 @@ namespace Magento\Framework\Message; /** - * Interface for message + * Represent a message with a type, content text, and an isSticky attribute to prevent message from being cleared. + * + * @api */ interface MessageInterface { diff --git a/lib/internal/Magento/Framework/Message/Test/Unit/ManagerTest.php b/lib/internal/Magento/Framework/Message/Test/Unit/ManagerTest.php index c4980974bc289..d65a5459a4ee9 100644 --- a/lib/internal/Magento/Framework/Message/Test/Unit/ManagerTest.php +++ b/lib/internal/Magento/Framework/Message/Test/Unit/ManagerTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\Message\Test\Unit; +use Magento\Framework\Message\Manager; use Magento\Framework\Message\MessageInterface; use Magento\Framework\Message\ManagerInterface; @@ -86,7 +87,7 @@ public function setUp() public function testGetDefaultGroup() { - $this->assertEquals(ManagerInterface::DEFAULT_GROUP, $this->model->getDefaultGroup()); + $this->assertEquals(Manager::DEFAULT_GROUP, $this->model->getDefaultGroup()); $customDefaultGroup = 'some_group'; $customManager = $this->objectManager->getObject( @@ -117,7 +118,7 @@ public function testGetMessages() )->method( 'getData' )->with( - ManagerInterface::DEFAULT_GROUP + Manager::DEFAULT_GROUP )->will( $this->returnValue(null) ); @@ -126,7 +127,7 @@ public function testGetMessages() )->method( 'setData' )->with( - ManagerInterface::DEFAULT_GROUP, + Manager::DEFAULT_GROUP, $messageCollection )->will( $this->returnValue($this->session) @@ -136,7 +137,7 @@ public function testGetMessages() )->method( 'getData' )->with( - ManagerInterface::DEFAULT_GROUP + Manager::DEFAULT_GROUP )->will( $this->returnValue($messageCollection) ); @@ -161,7 +162,7 @@ public function testGetMessagesWithClear() )->method( 'getData' )->with( - ManagerInterface::DEFAULT_GROUP + Manager::DEFAULT_GROUP )->will( $this->returnValue($messageCollection) ); @@ -209,7 +210,7 @@ public function testAddException() )->method( 'getData' )->with( - ManagerInterface::DEFAULT_GROUP + Manager::DEFAULT_GROUP )->will( $this->returnValue($messageCollection) ); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/MessagesTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/MessagesTest.php index bd18ebe344f88..6f552656be534 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/MessagesTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/MessagesTest.php @@ -9,6 +9,7 @@ */ namespace Magento\Framework\View\Test\Unit\Element; +use Magento\Framework\Message\Manager; use \Magento\Framework\View\Element\Messages; use Magento\Framework\Message\ManagerInterface; @@ -229,7 +230,7 @@ public function testGetCacheKeyInfo() $this->assertEquals($emptyMessagesCacheKey, $this->messages->getCacheKeyInfo()); $messagesCacheKey = ['storage_types' => 'a:1:{i:0;s:7:"default";}']; - $this->messages->addStorageType(ManagerInterface::DEFAULT_GROUP); + $this->messages->addStorageType(Manager::DEFAULT_GROUP); $this->assertEquals($messagesCacheKey, $this->messages->getCacheKeyInfo()); } diff --git a/setup/src/Magento/Setup/Model/Lists.php b/setup/src/Magento/Setup/Model/Lists.php index e898ed40c16c3..e52e921594cae 100644 --- a/setup/src/Magento/Setup/Model/Lists.php +++ b/setup/src/Magento/Setup/Model/Lists.php @@ -10,6 +10,7 @@ use Magento\Framework\Locale\Bundle\LanguageBundle; use Magento\Framework\Locale\Bundle\RegionBundle; use Magento\Framework\Locale\ConfigInterface; +use Magento\Framework\Locale\Resolver; use Magento\Framework\Locale\ResolverInterface; class Lists @@ -42,7 +43,7 @@ public function getTimezoneList() $list[$code] = \IntlTimeZone::createTimeZone($code)->getDisplayName( false, \IntlTimeZone::DISPLAY_LONG, - ResolverInterface::DEFAULT_LOCALE + Resolver::DEFAULT_LOCALE ) . ' (' . $code . ')'; } asort($list); @@ -56,7 +57,7 @@ public function getTimezoneList() */ public function getCurrencyList() { - $currencies = (new CurrencyBundle())->get(ResolverInterface::DEFAULT_LOCALE)['Currencies']; + $currencies = (new CurrencyBundle())->get(Resolver::DEFAULT_LOCALE)['Currencies']; $list = []; foreach ($currencies as $code => $data) { $list[$code] = $data[1] . ' (' . $code . ')'; @@ -72,8 +73,8 @@ public function getCurrencyList() */ public function getLocaleList() { - $languages = (new LanguageBundle())->get(ResolverInterface::DEFAULT_LOCALE)['Languages']; - $countries = (new RegionBundle())->get(ResolverInterface::DEFAULT_LOCALE)['Countries']; + $languages = (new LanguageBundle())->get(Resolver::DEFAULT_LOCALE)['Languages']; + $countries = (new RegionBundle())->get(Resolver::DEFAULT_LOCALE)['Countries']; $locales = \ResourceBundle::getLocales(null); $list = []; From b53cbb7f274af82681a0eddf1b271dd64c73b646 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Mon, 30 Mar 2015 14:59:05 -0500 Subject: [PATCH 04/68] MAGETWO-32624: Define Public API - Extensibility (PS) - Merge changes from MAGETWO-35006: Investigate and Annote @api to classes and/or methods --- .../Magento/Framework/App/Area/FrontNameResolverInterface.php | 4 ++++ lib/internal/Magento/Framework/App/AreaInterface.php | 3 +++ lib/internal/Magento/Framework/App/AreaList.php | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/lib/internal/Magento/Framework/App/Area/FrontNameResolverInterface.php b/lib/internal/Magento/Framework/App/Area/FrontNameResolverInterface.php index bbdd3787b1825..e8a3e92263e7d 100644 --- a/lib/internal/Magento/Framework/App/Area/FrontNameResolverInterface.php +++ b/lib/internal/Magento/Framework/App/Area/FrontNameResolverInterface.php @@ -7,6 +7,10 @@ */ namespace Magento\Framework\App\Area; +/** + * Interface FrontNameResolverInterface + * @api + */ interface FrontNameResolverInterface { /** diff --git a/lib/internal/Magento/Framework/App/AreaInterface.php b/lib/internal/Magento/Framework/App/AreaInterface.php index 806a798342459..544ac56e19e6f 100644 --- a/lib/internal/Magento/Framework/App/AreaInterface.php +++ b/lib/internal/Magento/Framework/App/AreaInterface.php @@ -6,6 +6,9 @@ */ namespace Magento\Framework\App; +/** + * Interface AreaInterface + */ interface AreaInterface { const PART_CONFIG = 'config'; diff --git a/lib/internal/Magento/Framework/App/AreaList.php b/lib/internal/Magento/Framework/App/AreaList.php index 270fb22e36675..c010388797d87 100644 --- a/lib/internal/Magento/Framework/App/AreaList.php +++ b/lib/internal/Magento/Framework/App/AreaList.php @@ -63,6 +63,7 @@ public function __construct( * * @param string $frontName * @return null|string + * @api */ public function getCodeByFrontName($frontName) { @@ -84,6 +85,7 @@ public function getCodeByFrontName($frontName) * * @param string $areaCode * @return string + * @api */ public function getFrontName($areaCode) { @@ -94,6 +96,7 @@ public function getFrontName($areaCode) * Retrieve area codes * * @return string[] + * @api */ public function getCodes() { @@ -105,6 +108,7 @@ public function getCodes() * * @param string $areaCode * @return string + * @api */ public function getDefaultRouter($areaCode) { From f9cb01216f8cf71dbce4f72ed68b17829126ae72 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Mon, 30 Mar 2015 15:04:31 -0500 Subject: [PATCH 05/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- .../Magento/Framework/App/Config/Scope/ReaderPoolInterface.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/internal/Magento/Framework/App/Config/Scope/ReaderPoolInterface.php b/lib/internal/Magento/Framework/App/Config/Scope/ReaderPoolInterface.php index b0b9d6a2ffd6c..e74f5fb49b04e 100644 --- a/lib/internal/Magento/Framework/App/Config/Scope/ReaderPoolInterface.php +++ b/lib/internal/Magento/Framework/App/Config/Scope/ReaderPoolInterface.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\App\Config\Scope; +/** + * @api + */ interface ReaderPoolInterface { /** From 1f4cacbf748603335533bdc02b056b3906b1c799 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Mon, 30 Mar 2015 15:21:10 -0500 Subject: [PATCH 06/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- lib/internal/Magento/Framework/App/Config/ValueFactory.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Config/ValueFactory.php b/lib/internal/Magento/Framework/App/Config/ValueFactory.php index 74a51691f2ce6..3163d2ccb4cfb 100644 --- a/lib/internal/Magento/Framework/App/Config/ValueFactory.php +++ b/lib/internal/Magento/Framework/App/Config/ValueFactory.php @@ -44,8 +44,6 @@ public function __construct( * @param array $data * @return \Magento\Framework\App\Config\ValueInterface * @throws \InvalidArgumentException - * - * @api */ public function create(array $data = []) { From 7f31d2d99934cbb5d54de3e914f19a1a4f84d65d Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Mon, 30 Mar 2015 15:23:40 -0500 Subject: [PATCH 07/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- .../Magento/Framework/App/Config/Scope/ReaderInterface.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php b/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php index d456b23bad2bf..74766f5300d16 100644 --- a/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php +++ b/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php @@ -4,8 +4,6 @@ * * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. - * - * @api */ namespace Magento\Framework\App\Config\Scope; From b5779a58232e8fcfa99758b0549c271f184d976d Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Mon, 30 Mar 2015 16:08:57 -0500 Subject: [PATCH 08/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- lib/internal/Magento/Framework/App/Config/Data.php | 11 ++--------- .../Magento/Framework/App/Config/DataInterface.php | 8 +++++++- lib/internal/Magento/Framework/Locale/Currency.php | 9 ++------- .../Magento/Framework/Locale/CurrencyInterface.php | 4 ++-- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Config/Data.php b/lib/internal/Magento/Framework/App/Config/Data.php index 3b5f17fe71639..38389e71e40aa 100644 --- a/lib/internal/Magento/Framework/App/Config/Data.php +++ b/lib/internal/Magento/Framework/App/Config/Data.php @@ -42,10 +42,7 @@ public function getSource() } /** - * Retrieve configuration value by path - * - * @param null|string $path - * @return array|string + * @inheritdoc */ public function getValue($path = null) { @@ -65,11 +62,7 @@ public function getValue($path = null) } /** - * Set configuration value - * - * @param string $path - * @param mixed $value - * @return void + * @inheritdoc */ public function setValue($path, $value) { diff --git a/lib/internal/Magento/Framework/App/Config/DataInterface.php b/lib/internal/Magento/Framework/App/Config/DataInterface.php index b89cdc05f87ea..b07ca0e0df1fc 100644 --- a/lib/internal/Magento/Framework/App/Config/DataInterface.php +++ b/lib/internal/Magento/Framework/App/Config/DataInterface.php @@ -6,17 +6,23 @@ namespace Magento\Framework\App\Config; /** + * Configuration data storage + * * @api */ interface DataInterface { /** + * Retrieve configuration value by path + * * @param string|null $path - * @return string|array + * @return mixed */ public function getValue($path); /** + * Set configuration value by path + * * @param string $path * @param mixed $value * @return void diff --git a/lib/internal/Magento/Framework/Locale/Currency.php b/lib/internal/Magento/Framework/Locale/Currency.php index b58cfacad571c..f0be6c1217227 100644 --- a/lib/internal/Magento/Framework/Locale/Currency.php +++ b/lib/internal/Magento/Framework/Locale/Currency.php @@ -49,9 +49,7 @@ public function __construct( } /** - * Retrieve currency code - * - * @return string + * @inheritdoc */ public function getDefaultCurrency() { @@ -59,10 +57,7 @@ public function getDefaultCurrency() } /** - * Create \Zend_Currency object for current locale - * - * @param string $currency - * @return \Magento\Framework\Currency + * @inheritdoc */ public function getCurrency($currency) { diff --git a/lib/internal/Magento/Framework/Locale/CurrencyInterface.php b/lib/internal/Magento/Framework/Locale/CurrencyInterface.php index addb657021038..00bbc4452eedd 100644 --- a/lib/internal/Magento/Framework/Locale/CurrencyInterface.php +++ b/lib/internal/Magento/Framework/Locale/CurrencyInterface.php @@ -13,14 +13,14 @@ interface CurrencyInterface { /** - * Retrieve currency code + * Retrieve default currency code * * @return string */ public function getDefaultCurrency(); /** - * Create \Magento\Framework\Currency object for current locale + * Create Currency object for current locale * * @param string $currency * @return \Magento\Framework\Currency From 96625e6d78858a66d717dace4a6288e105fb0219 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Tue, 31 Mar 2015 09:23:26 -0500 Subject: [PATCH 09/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- app/code/Magento/Backend/Model/Locale/Manager.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Backend/Model/Locale/Manager.php b/app/code/Magento/Backend/Model/Locale/Manager.php index 4a91caa23f6c9..4f9584c96a817 100644 --- a/app/code/Magento/Backend/Model/Locale/Manager.php +++ b/app/code/Magento/Backend/Model/Locale/Manager.php @@ -4,7 +4,6 @@ * See COPYING.txt for license details. */ namespace Magento\Backend\Model\Locale; -use Magento\Framework\Locale\Resolver; /** * Locale manager model @@ -69,7 +68,7 @@ public function switchBackendInterfaceLocale($localeCode) */ public function getUserInterfaceLocale() { - $interfaceLocale = Resolver::DEFAULT_LOCALE; + $interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE; $userData = $this->_authSession->getUser(); if ($userData && $userData->getInterfaceLocale()) { From 7e25478f770d24d98203fd9b459e99a5a80350cf Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Tue, 31 Mar 2015 10:13:40 -0500 Subject: [PATCH 10/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- .../testsuite/Magento/Backend/Model/Locale/ResolverTest.php | 1 + .../Magento/Framework/App/Config/ScopeConfigInterface.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php b/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php index 5ce73f4d6f72c..c0cc101fd36bf 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Backend\Model\Locale; + use Magento\Framework\Locale\Resolver; /** diff --git a/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php b/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php index 446d6218dc7b9..8d790d5126f11 100644 --- a/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php +++ b/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php @@ -26,7 +26,7 @@ interface ScopeConfigInterface * @param null|string $scopeCode * @return mixed */ - public function getValue($path, $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_DEFAULT, $scopeCode = null); + public function getValue($path, $scope = ScopeConfigInterface::SCOPE_DEFAULT, $scopeCode = null); /** * Retrieve config flag by path and scope @@ -36,5 +36,5 @@ public function getValue($path, $scope = \Magento\Framework\App\Config\ScopeConf * @param null|string $scopeCode * @return bool */ - public function isSetFlag($path, $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_DEFAULT, $scopeCode = null); + public function isSetFlag($path, $scope = ScopeConfigInterface::SCOPE_DEFAULT, $scopeCode = null); } From 613e4ea2041990fe69dde8a80224301ac285e99b Mon Sep 17 00:00:00 2001 From: Joan He Date: Thu, 2 Apr 2015 14:32:58 -0500 Subject: [PATCH 11/68] MAGETWO-35005: Investigate and Annotate @api to classes and/or methods --- .../Magento/Framework/App/Resource.php | 1 - .../Framework/DB/Adapter/AdapterInterface.php | 1 - .../Magento/Framework/DB/Ddl/Table.php | 113 ++---------------- .../Model/Resource/AbstractResource.php | 2 - 4 files changed, 9 insertions(+), 108 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php index 8509d97e9eee1..5243def717b4f 100644 --- a/lib/internal/Magento/Framework/App/Resource.php +++ b/lib/internal/Magento/Framework/App/Resource.php @@ -86,7 +86,6 @@ public function __construct( * * @param string $resourceName * @return \Magento\Framework\DB\Adapter\AdapterInterface|false - * @api */ public function getConnection($resourceName) { diff --git a/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php b/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php index 42dd2eb1edb24..84ab04e316702 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php +++ b/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php @@ -11,7 +11,6 @@ * Magento Database Adapter Interface * * @author Magento Core Team - * @api */ interface AdapterInterface { diff --git a/lib/internal/Magento/Framework/DB/Ddl/Table.php b/lib/internal/Magento/Framework/DB/Ddl/Table.php index 249fb6167919e..e42dfa1f6c2d7 100644 --- a/lib/internal/Magento/Framework/DB/Ddl/Table.php +++ b/lib/internal/Magento/Framework/DB/Ddl/Table.php @@ -16,147 +16,68 @@ class Table { /** - * Column type boolean - * @api + * Types of columns */ const TYPE_BOOLEAN = 'boolean'; - /** - * Column type smallint - * @api - */ const TYPE_SMALLINT = 'smallint'; - /** - * Column type integer - * @api - */ const TYPE_INTEGER = 'integer'; - /** - * Column type bigint - * @api - */ const TYPE_BIGINT = 'bigint'; - /** - * Column type float - * @api - */ const TYPE_FLOAT = 'float'; - /** - * Column type numeric - * @api - */ const TYPE_NUMERIC = 'numeric'; - /** - * Column type decimal - * @api - */ const TYPE_DECIMAL = 'decimal'; - /** - * Column type date - * @api - */ const TYPE_DATE = 'date'; - /** - * Column type timestamp - * @api - */ const TYPE_TIMESTAMP = 'timestamp'; - /** - * Column type datetime, capable to support date-time from 1970 + auto-triggers in some RDBMS - * @api - */ + // Capable to support date-time from 1970 + auto-triggers in some RDBMS const TYPE_DATETIME = 'datetime'; - /** - * Column type text, capable to support long date-time before 1970 - * @api - */ + // Capable to support long date-time before 1970 const TYPE_TEXT = 'text'; - /** - * Column type blob - * @api - */ const TYPE_BLOB = 'blob'; - /** - * Column type varbinary, used for back compatibility, when query param can't use statement options - * @api - */ + // Used for back compatibility, when query param can't use statement options const TYPE_VARBINARY = 'varbinary'; + // A real blob, stored as binary inside DB + /** - * Default TEXT columns sizes - * @api + * Default and maximal TEXT and BLOB columns sizes we can support for different DB systems. */ const DEFAULT_TEXT_SIZE = 1024; - /** - * Maximal TEXT columns sizes - * @api - */ const MAX_TEXT_SIZE = 2147483648; - /** - * Maximal BLOB columns sizes - * @api - */ const MAX_VARBINARY_SIZE = 2147483648; /** - * Default value for timestamps - fill with current timestamp on inserting record, on changing and both cases - * @api + * Default values for timestampses - fill with current timestamp on inserting record, on changing and both cases */ const TIMESTAMP_INIT_UPDATE = 'TIMESTAMP_INIT_UPDATE'; - /** - * Default value for timestamps - fill with current timestamp only on inserting record - * @api - */ const TIMESTAMP_INIT = 'TIMESTAMP_INIT'; - /** - * Default value for timestamps - fill with current timestamp only on changing record - * @api - */ const TIMESTAMP_UPDATE = 'TIMESTAMP_UPDATE'; /** - * Cascade action used for foreign keys - * @api + * Actions used for foreign keys */ const ACTION_CASCADE = 'CASCADE'; - /** - * Set null action used for foreign keys - * @api - */ const ACTION_SET_NULL = 'SET NULL'; - /** - * No action action used for foreign keys - * @api - */ const ACTION_NO_ACTION = 'NO ACTION'; - /** - * Restrict action used for foreign keys - * @api - */ const ACTION_RESTRICT = 'RESTRICT'; - /** - * Set default action used for foreign keys - * @api - */ const ACTION_SET_DEFAULT = 'SET DEFAULT'; /** @@ -261,7 +182,6 @@ class Table * * @param string $name * @return $this - * @api */ public function setName($name) { @@ -277,7 +197,6 @@ public function setName($name) * * @param string $name * @return $this - * @api */ public function setSchema($name) { @@ -290,7 +209,6 @@ public function setSchema($name) * * @param string $comment * @return $this - * @api */ public function setComment($comment) { @@ -303,7 +221,6 @@ public function setComment($comment) * * @return string * @throws \Zend_Db_Exception - * @api */ public function getName() { @@ -317,7 +234,6 @@ public function getName() * Get schema name * * @return string|null - * @api */ public function getSchema() { @@ -328,7 +244,6 @@ public function getSchema() * Return comment for table * * @return string - * @api */ public function getComment() { @@ -358,7 +273,6 @@ public function getComment() * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - * @api */ public function addColumn($name, $type, $size = null, $options = [], $comment = null) { @@ -495,7 +409,6 @@ public function addColumn($name, $type, $size = null, $options = [], $comment = * @return $this * @throws \Zend_Db_Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @api */ public function addForeignKey($fkName, $column, $refTable, $refColumn, $onDelete = null, $onUpdate = null) { @@ -547,7 +460,6 @@ public function addForeignKey($fkName, $column, $refTable, $refColumn, $onDelete * @return $this * @throws \Zend_Db_Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @api */ public function addIndex($indexName, $fields, $options = []) { @@ -615,7 +527,6 @@ public function addIndex($indexName, $fields, $options = []) * @param bool $normalized * @see $this->_columns * @return array - * @api */ public function getColumns($normalized = true) { @@ -631,7 +542,6 @@ public function getColumns($normalized = true) * @param array $column * @see $this->_columns * @return $this - * @api */ public function setColumn($column) { @@ -645,7 +555,6 @@ public function setColumn($column) * * @see $this->_indexes * @return array - * @api */ public function getIndexes() { @@ -657,7 +566,6 @@ public function getIndexes() * * @see $this->_foreignKeys * @return array - * @api */ public function getForeignKeys() { @@ -670,7 +578,6 @@ public function getForeignKeys() * @param string $key * @param string $value * @return $this - * @api */ public function setOption($key, $value) { @@ -684,7 +591,6 @@ public function setOption($key, $value) * * @param string $key * @return null|string - * @api */ public function getOption($key) { @@ -698,7 +604,6 @@ public function getOption($key) * Retrieve array of table options * * @return array - * @api */ public function getOptions() { diff --git a/lib/internal/Magento/Framework/Model/Resource/AbstractResource.php b/lib/internal/Magento/Framework/Model/Resource/AbstractResource.php index accaab8379783..c2a9bd81aad96 100644 --- a/lib/internal/Magento/Framework/Model/Resource/AbstractResource.php +++ b/lib/internal/Magento/Framework/Model/Resource/AbstractResource.php @@ -47,7 +47,6 @@ abstract protected function _construct(); * Retrieve connection for read data * * @return \Magento\Framework\DB\Adapter\AdapterInterface - * @api */ abstract protected function _getReadAdapter(); @@ -55,7 +54,6 @@ abstract protected function _getReadAdapter(); * Retrieve connection for write data * * @return \Magento\Framework\DB\Adapter\AdapterInterface - * @api */ abstract protected function _getWriteAdapter(); From 53a85a27d121bc0e4f8c5f3d6bf4db6652410384 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Thu, 2 Apr 2015 15:06:06 -0500 Subject: [PATCH 12/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- app/code/Magento/Backend/App/Config.php | 8 +++++--- .../Block/Page/System/Config/Robots/Reset.php | 4 +++- .../Magento/Config/Model/Config/Backend/File.php | 5 +++-- .../Magento/Config/Model/Config/Backend/Locale.php | 4 +++- .../Magento/Config/Model/Config/ScopeDefiner.php | 3 ++- .../Model/Config/Structure/AbstractElement.php | 3 ++- .../Test/Unit/Model/Config/ScopeDefinerTest.php | 3 ++- .../Model/Config/Structure/AbstractElementTest.php | 12 +++++++----- .../Customer/Model/Config/Backend/Address/Street.php | 4 +++- app/code/Magento/Customer/Model/Customer.php | 3 ++- app/code/Magento/Email/Model/BackendTemplate.php | 3 ++- .../Store/Model/Config/Reader/DefaultReader.php | 6 +++--- app/code/Magento/Store/Model/Config/Reader/Store.php | 3 ++- .../Magento/Store/Model/Config/Reader/Website.php | 4 +++- app/code/Magento/Store/Model/Store.php | 7 ++++--- .../Unit/Model/Config/Reader/DefaultReaderTest.php | 4 +++- app/code/Magento/Store/Test/Unit/Model/StoreTest.php | 3 ++- .../Adminhtml/Tax/IgnoreTaxNotification.php | 4 +++- app/code/Magento/Tax/Model/Config/Notification.php | 4 +++- .../Adminhtml/Tax/IgnoreTaxNotificationTest.php | 3 ++- app/code/Magento/Theme/Model/Config.php | 4 +++- app/code/Magento/Theme/Model/View/Design.php | 3 ++- .../TestFramework/Annotation/ConfigFixture.php | 4 +++- .../testsuite/Magento/Payment/Model/ObserverTest.php | 3 ++- .../Tax/Model/Sales/Total/Quote/SetupUtil.php | 3 ++- .../fixtures/catalog_category_flat_enabled.php | 3 ++- .../fixtures/catalog_product_flat_enabled.php | 3 ++- .../testsuite/fixtures/shipping_flatrate_enabled.php | 3 ++- lib/internal/Magento/Framework/App/Config.php | 6 ++++-- .../Magento/Framework/App/Config/Initial.php | 8 +++----- .../App/Config/MutableScopeConfigInterface.php | 4 ++-- .../App/Config/Resource/ConfigInterface.php | 2 -- .../Framework/App/Config/Scope/ReaderInterface.php | 7 ++----- .../App/Config/Scope/ReaderPoolInterface.php | 3 --- .../Framework/App/Config/ScopeConfigInterface.php | 10 +++++----- .../Magento/Framework/App/Config/ScopePool.php | 6 ++++-- .../Magento/Framework/App/Config/Storage/Writer.php | 6 ++++-- .../Framework/App/Config/Storage/WriterInterface.php | 6 ++++-- lib/internal/Magento/Framework/App/Config/Value.php | 3 ++- .../Magento/Framework/App/MutableScopeConfig.php | 3 ++- lib/internal/Magento/Framework/App/Request/Http.php | 3 ++- .../Magento/Framework/App/ScopeInterface.php | 7 ------- .../App/Test/Unit/Config/Storage/WriterTest.php | 5 +++-- .../Framework/App/Test/Unit/Request/HttpTest.php | 3 ++- lib/internal/Magento/Framework/Message/Factory.php | 7 +++---- lib/internal/Magento/Framework/Message/Manager.php | 4 +--- .../Framework/Search/Dynamic/DataProviderFactory.php | 2 +- .../Framework/Search/Dynamic/IntervalFactory.php | 2 +- .../Test/Unit/Adapter/Mysql/DimensionsTest.php | 3 ++- .../Search/Test/Unit/Dynamic/IntervalFactoryTest.php | 7 ++++--- 50 files changed, 128 insertions(+), 95 deletions(-) diff --git a/app/code/Magento/Backend/App/Config.php b/app/code/Magento/Backend/App/Config.php index d8eaa7af14254..0ac5211b41d9f 100644 --- a/app/code/Magento/Backend/App/Config.php +++ b/app/code/Magento/Backend/App/Config.php @@ -10,6 +10,8 @@ namespace Magento\Backend\App; +use Magento\Framework\App\Config\ScopeConfigInterface; + /** * Backend config accessor */ @@ -36,7 +38,7 @@ public function __construct(\Magento\Framework\App\Config\ScopePool $scopePool) */ public function getValue($path) { - return $this->_scopePool->getScope(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, null)->getValue($path); + return $this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path); } /** @@ -48,7 +50,7 @@ public function getValue($path) */ public function setValue($path, $value) { - $this->_scopePool->getScope(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, null)->setValue($path, $value); + $this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->setValue($path, $value); } /** @@ -59,6 +61,6 @@ public function setValue($path, $value) */ public function isSetFlag($path) { - return !!$this->_scopePool->getScope(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, null)->getValue($path); + return !!$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path); } } diff --git a/app/code/Magento/Backend/Block/Page/System/Config/Robots/Reset.php b/app/code/Magento/Backend/Block/Page/System/Config/Robots/Reset.php index d32e99a00d814..827ae18b0b8e1 100644 --- a/app/code/Magento/Backend/Block/Page/System/Config/Robots/Reset.php +++ b/app/code/Magento/Backend/Block/Page/System/Config/Robots/Reset.php @@ -8,6 +8,8 @@ namespace Magento\Backend\Block\Page\System\Config\Robots; +use Magento\Framework\App\Config\ScopeConfigInterface; + /** * "Reset to Defaults" button renderer * @@ -50,7 +52,7 @@ protected function _construct() public function getRobotsDefaultCustomInstructions() { return trim((string)$this->_scopeConfig->getValue( - self::XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + self::XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS, ScopeConfigInterface::SCOPE_TYPE_DEFAULT )); } diff --git a/app/code/Magento/Config/Model/Config/Backend/File.php b/app/code/Magento/Config/Model/Config/Backend/File.php index e7a119f79af9f..a08ed7d4f2389 100644 --- a/app/code/Magento/Config/Model/Config/Backend/File.php +++ b/app/code/Magento/Config/Model/Config/Backend/File.php @@ -5,6 +5,7 @@ */ namespace Magento\Config\Model\Config\Backend; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; @@ -196,7 +197,7 @@ protected function _getUploadDir() protected function _prependScopeInfo($path) { $scopeInfo = $this->getScope(); - if (\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT != $this->getScope()) { + if (ScopeConfigInterface::SCOPE_TYPE_DEFAULT != $this->getScope()) { $scopeInfo .= '/' . $this->getScopeId(); } return $scopeInfo . '/' . $path; @@ -213,7 +214,7 @@ protected function _prependScopeInfo($path) protected function _appendScopeInfo($path) { $path .= '/' . $this->getScope(); - if (\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT != $this->getScope()) { + if (ScopeConfigInterface::SCOPE_TYPE_DEFAULT != $this->getScope()) { $path .= '/' . $this->getScopeId(); } return $path; diff --git a/app/code/Magento/Config/Model/Config/Backend/Locale.php b/app/code/Magento/Config/Model/Config/Backend/Locale.php index 0881afdebfc38..3d057fd6df864 100644 --- a/app/code/Magento/Config/Model/Config/Backend/Locale.php +++ b/app/code/Magento/Config/Model/Config/Backend/Locale.php @@ -9,6 +9,8 @@ */ namespace Magento\Config\Model\Config\Backend; +use Magento\Framework\App\Config\ScopeConfigInterface; + class Locale extends \Magento\Framework\App\Config\Value { /** @@ -91,7 +93,7 @@ public function afterSave() } switch ($data->getScope()) { - case \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT: + case ScopeConfigInterface::SCOPE_TYPE_DEFAULT: $scopeName = __('Default scope'); break; diff --git a/app/code/Magento/Config/Model/Config/ScopeDefiner.php b/app/code/Magento/Config/Model/Config/ScopeDefiner.php index 893496d874009..f2230e2737e05 100644 --- a/app/code/Magento/Config/Model/Config/ScopeDefiner.php +++ b/app/code/Magento/Config/Model/Config/ScopeDefiner.php @@ -5,6 +5,7 @@ */ namespace Magento\Config\Model\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface as StoreScopeInterface; /** @@ -38,6 +39,6 @@ public function getScope() 'store' ) ? StoreScopeInterface::SCOPE_STORE : ($this->_request->getParam( 'website' - ) ? StoreScopeInterface::SCOPE_WEBSITE : \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT); + ) ? StoreScopeInterface::SCOPE_WEBSITE : StoreScopeInterface::SCOPE_DEFAULT); } } diff --git a/app/code/Magento/Config/Model/Config/Structure/AbstractElement.php b/app/code/Magento/Config/Model/Config/Structure/AbstractElement.php index e10a1a1c3e725..03ed66f29abec 100644 --- a/app/code/Magento/Config/Model/Config/Structure/AbstractElement.php +++ b/app/code/Magento/Config/Model/Config/Structure/AbstractElement.php @@ -5,6 +5,7 @@ */ namespace Magento\Config\Model\Config\Structure; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\StoreManagerInterface; abstract class AbstractElement implements ElementInterface @@ -136,7 +137,7 @@ public function isVisible() $showInScope = [ \Magento\Store\Model\ScopeInterface::SCOPE_STORE => $this->_hasVisibilityValue('showInStore'), \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE => $this->_hasVisibilityValue('showInWebsite'), - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT => $this->_hasVisibilityValue('showInDefault'), + ScopeConfigInterface::SCOPE_TYPE_DEFAULT => $this->_hasVisibilityValue('showInDefault'), ]; if ($this->_storeManager->isSingleStoreMode()) { diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/ScopeDefinerTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/ScopeDefinerTest.php index 23069beec258f..e0c64a35053ad 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/ScopeDefinerTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/ScopeDefinerTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Config\Test\Unit\Model\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; class ScopeDefinerTest extends \PHPUnit_Framework_TestCase @@ -31,7 +32,7 @@ protected function setUp() public function testGetScopeReturnsDefaultScopeIfNoScopeDataIsSpecified() { - $this->assertEquals(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $this->_model->getScope()); + $this->assertEquals(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $this->_model->getScope()); } public function testGetScopeReturnsStoreScopeIfStoreIsSpecified() diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/AbstractElementTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/AbstractElementTest.php index 03e9fd8d2266e..778141ab21320 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Structure/AbstractElementTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Structure/AbstractElementTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Config\Test\Unit\Model\Config\Structure; +use Magento\Framework\App\Config\ScopeConfigInterface; + class AbstractElementTest extends \PHPUnit_Framework_TestCase { /** @@ -77,7 +79,7 @@ public function testIsVisibleReturnsTrueInSingleStoreModeForNonHiddenElements() $this->_storeManager->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); $this->_model->setData( ['showInDefault' => 1, 'showInStore' => 0, 'showInWebsite' => 0], - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT ); $this->assertTrue($this->_model->isVisible()); } @@ -87,7 +89,7 @@ public function testIsVisibleReturnsFalseInSingleStoreModeForHiddenElements() $this->_storeManager->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); $this->_model->setData( ['hide_in_single_store_mode' => 1, 'showInDefault' => 1, 'showInStore' => 0, 'showInWebsite' => 0], - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT ); $this->assertFalse($this->_model->isVisible()); } @@ -100,7 +102,7 @@ public function testIsVisibleReturnsFalseInSingleStoreModeForInvisibleElements() $this->_storeManager->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true)); $this->_model->setData( ['showInDefault' => 0, 'showInStore' => 0, 'showInWebsite' => 0], - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT ); $this->assertFalse($this->_model->isVisible()); } @@ -121,7 +123,7 @@ public function isVisibleReturnsTrueForProperScopesDataProvider() return [ [ ['showInDefault' => 1, 'showInStore' => 0, 'showInWebsite' => 0], - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, ], [ ['showInDefault' => 0, 'showInStore' => 1, 'showInWebsite' => 0], @@ -150,7 +152,7 @@ public function isVisibleReturnsFalseForNonProperScopesDataProvider() return [ [ ['showInDefault' => 0, 'showInStore' => 1, 'showInWebsite' => 1], - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, ], [ ['showInDefault' => 1, 'showInStore' => 0, 'showInWebsite' => 1], diff --git a/app/code/Magento/Customer/Model/Config/Backend/Address/Street.php b/app/code/Magento/Customer/Model/Config/Backend/Address/Street.php index 7e187a71e5c08..b25f4c6d0b3a3 100644 --- a/app/code/Magento/Customer/Model/Config/Backend/Address/Street.php +++ b/app/code/Magento/Customer/Model/Config/Backend/Address/Street.php @@ -5,6 +5,8 @@ */ namespace Magento\Customer\Model\Config\Backend\Address; +use Magento\Framework\App\Config\ScopeConfigInterface; + /** * Line count config model for customer address street attribute * @@ -64,7 +66,7 @@ public function afterSave() } break; - case \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT: + case ScopeConfigInterface::SCOPE_TYPE_DEFAULT: $attribute->setData('multiline_count', $value); break; } diff --git a/app/code/Magento/Customer/Model/Customer.php b/app/code/Magento/Customer/Model/Customer.php index d6792e7d47c2a..ddc07a2e1e90f 100644 --- a/app/code/Magento/Customer/Model/Customer.php +++ b/app/code/Magento/Customer/Model/Customer.php @@ -12,6 +12,7 @@ use Magento\Customer\Model\Resource\Customer as ResourceCustomer; use Magento\Customer\Api\Data\CustomerInterfaceFactory; use Magento\Customer\Model\Data\Customer as CustomerData; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Reflection\DataObjectProcessor; use Magento\Framework\Exception\EmailNotConfirmedException; use Magento\Framework\Exception\InvalidEmailOrPasswordException; @@ -1304,7 +1305,7 @@ public function getResetPasswordLinkExpirationPeriod() { return (int)$this->_scopeConfig->getValue( self::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD, - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT ); } diff --git a/app/code/Magento/Email/Model/BackendTemplate.php b/app/code/Magento/Email/Model/BackendTemplate.php index be5b232564a67..6584fdbd21575 100644 --- a/app/code/Magento/Email/Model/BackendTemplate.php +++ b/app/code/Magento/Email/Model/BackendTemplate.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Email\Model; +use Magento\Framework\App\Config\ScopeConfigInterface; /** * Adminhtml email template model @@ -78,7 +79,7 @@ public function getSystemConfigPathsWhereUsedAsDefault() return []; } - $configData = $this->_scopeConfig->getValue(null, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT); + $configData = $this->_scopeConfig->getValue(null, ScopeConfigInterface::SCOPE_TYPE_DEFAULT); $paths = $this->_findEmailTemplateUsages($templateCode, $configData, ''); return $paths; } diff --git a/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php b/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php index 482fecc656199..911e9bd8ae155 100644 --- a/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php +++ b/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php @@ -48,10 +48,10 @@ public function __construct( * @throws \Magento\Framework\Exception Exception is thrown when scope other than default is given * @return array */ - public function read($scope = ScopeConfigInterface::SCOPE_DEFAULT) + public function read($scope = null) { - $scope = $scope === null ? ScopeConfigInterface::SCOPE_DEFAULT : $scope; - if ($scope !== ScopeConfigInterface::SCOPE_DEFAULT) { + $scope = $scope === null ? ScopeConfigInterface::SCOPE_TYPE_DEFAULT : $scope; + if ($scope !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { throw new \Magento\Framework\Exception("Only default scope allowed"); } diff --git a/app/code/Magento/Store/Model/Config/Reader/Store.php b/app/code/Magento/Store/Model/Config/Reader/Store.php index f4d5124888c59..151c3625f2b1d 100644 --- a/app/code/Magento/Store/Model/Config/Reader/Store.php +++ b/app/code/Magento/Store/Model/Config/Reader/Store.php @@ -5,6 +5,7 @@ */ namespace Magento\Store\Model\Config\Reader; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\NoSuchEntityException; class Store implements \Magento\Framework\App\Config\Scope\ReaderInterface @@ -74,7 +75,7 @@ public function read($code = null) { if (empty($code)) { $store = $this->_storeManager->getStore(); - } elseif (($code == \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)) { + } elseif (($code == ScopeConfigInterface::SCOPE_TYPE_DEFAULT)) { $store = $this->_storeManager->getDefaultStoreView(); } else { $store = $this->_storeFactory->create(); diff --git a/app/code/Magento/Store/Model/Config/Reader/Website.php b/app/code/Magento/Store/Model/Config/Reader/Website.php index 1448b04bf9afb..7971deb6c9713 100644 --- a/app/code/Magento/Store/Model/Config/Reader/Website.php +++ b/app/code/Magento/Store/Model/Config/Reader/Website.php @@ -5,6 +5,8 @@ */ namespace Magento\Store\Model\Config\Reader; +use Magento\Framework\App\Config\ScopeConfigInterface; + class Website implements \Magento\Framework\App\Config\Scope\ReaderInterface { /** @@ -62,7 +64,7 @@ public function __construct( public function read($code = null) { $config = array_replace_recursive( - $this->_scopePool->getScope(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)->getSource(), + $this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT)->getSource(), $this->_initialConfig->getData("websites|{$code}") ); diff --git a/app/code/Magento/Store/Model/Store.php b/app/code/Magento/Store/Model/Store.php index 7dbf046110e38..46652a6aac51b 100644 --- a/app/code/Magento/Store/Model/Store.php +++ b/app/code/Magento/Store/Model/Store.php @@ -5,6 +5,7 @@ */ namespace Magento\Store\Model; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Http\Context; use Magento\Framework\Model\AbstractModel; @@ -55,7 +56,7 @@ class Store extends AbstractModel implements const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url'; const XML_PATH_SECURE_BASE_URL = 'web/secure/base_url'; - + const XML_PATH_SECURE_IN_FRONTEND = 'web/secure/use_in_frontend'; const XML_PATH_SECURE_IN_ADMINHTML = 'web/secure/use_in_adminhtml'; @@ -479,7 +480,7 @@ protected function _getConfig($path) { $data = $this->_config->getValue($path, ScopeInterface::SCOPE_STORE, $this->getCode()); if (!$data) { - $data = $this->_config->getValue($path, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT); + $data = $this->_config->getValue($path, ScopeConfigInterface::SCOPE_TYPE_DEFAULT); } return $data === false ? null : $data; } @@ -783,7 +784,7 @@ public function getBaseCurrencyCode() if ($configValue == self::PRICE_SCOPE_GLOBAL) { return $this->_config->getValue( \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT ); } else { return $this->_getConfig(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE); diff --git a/app/code/Magento/Store/Test/Unit/Model/Config/Reader/DefaultReaderTest.php b/app/code/Magento/Store/Test/Unit/Model/Config/Reader/DefaultReaderTest.php index 9e91f4b432815..25875ae67dd59 100644 --- a/app/code/Magento/Store/Test/Unit/Model/Config/Reader/DefaultReaderTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/Config/Reader/DefaultReaderTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Store\Test\Unit\Model\Config\Reader; +use Magento\Framework\App\Config\ScopeConfigInterface; + class DefaultReaderTest extends \PHPUnit_Framework_TestCase { /** @@ -46,7 +48,7 @@ public function testRead() )->method( 'getData' )->with( - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT )->will( $this->returnValue(['config' => ['key1' => 'default_value1', 'key2' => 'default_value2']]) ); diff --git a/app/code/Magento/Store/Test/Unit/Model/StoreTest.php b/app/code/Magento/Store/Test/Unit/Model/StoreTest.php index c43af1f004dfe..cfb2001ddd28c 100644 --- a/app/code/Magento/Store/Test/Unit/Model/StoreTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/StoreTest.php @@ -8,6 +8,7 @@ namespace Magento\Store\Test\Unit\Model; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; use Magento\Framework\App\Config\ReinitableConfigInterface; use Magento\Store\Model\Store; @@ -399,7 +400,7 @@ public function testGetBaseCurrency($priceScope, $currencyCode) ['catalog/price/scope', ScopeInterface::SCOPE_STORE, 'scope_code', $priceScope], [ \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, 'USD' ], diff --git a/app/code/Magento/Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php b/app/code/Magento/Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php index 71db454cc3378..de8c5c59336a2 100644 --- a/app/code/Magento/Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php +++ b/app/code/Magento/Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php @@ -6,6 +6,8 @@ */ namespace Magento\Tax\Controller\Adminhtml\Tax; +use Magento\Framework\App\Config\ScopeConfigInterface; + class IgnoreTaxNotification extends \Magento\Tax\Controller\Adminhtml\Tax { /** @@ -41,7 +43,7 @@ public function execute() try { $path = 'tax/notification/ignore_' . $section; $this->_objectManager->get('Magento\Config\Model\Resource\Config') - ->saveConfig($path, 1, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, 0); + ->saveConfig($path, 1, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); } diff --git a/app/code/Magento/Tax/Model/Config/Notification.php b/app/code/Magento/Tax/Model/Config/Notification.php index c886452442406..f4b395a290856 100644 --- a/app/code/Magento/Tax/Model/Config/Notification.php +++ b/app/code/Magento/Tax/Model/Config/Notification.php @@ -5,6 +5,8 @@ */ namespace Magento\Tax\Model\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; + /** * Tax Config Notification */ @@ -59,7 +61,7 @@ public function afterSave() */ protected function _resetNotificationFlag($path) { - $this->resourceConfig->saveConfig($path, 0, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, 0); + $this->resourceConfig->saveConfig($path, 0, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0); return $this; } } diff --git a/app/code/Magento/Tax/Test/Unit/Controller/Adminhtml/Tax/IgnoreTaxNotificationTest.php b/app/code/Magento/Tax/Test/Unit/Controller/Adminhtml/Tax/IgnoreTaxNotificationTest.php index 9a649f3d2d5b9..0b32169035e33 100644 --- a/app/code/Magento/Tax/Test/Unit/Controller/Adminhtml/Tax/IgnoreTaxNotificationTest.php +++ b/app/code/Magento/Tax/Test/Unit/Controller/Adminhtml/Tax/IgnoreTaxNotificationTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Tax\Test\Unit\Controller\Adminhtml\Tax; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; class IgnoreTaxNotificationTest extends \PHPUnit_Framework_TestCase @@ -40,7 +41,7 @@ public function testExecute() ->getMock(); $config->expects($this->once()) ->method('saveConfig') - ->with('tax/notification/ignore_tax', 1, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, 0) + ->with('tax/notification/ignore_tax', 1, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0) ->will($this->returnValue(null)); $manager = $this->getMockBuilder('\Magento\Framework\ObjectManagerInterface') diff --git a/app/code/Magento/Theme/Model/Config.php b/app/code/Magento/Theme/Model/Config.php index 5993e9bf010d5..39332cc9a0b7b 100644 --- a/app/code/Magento/Theme/Model/Config.php +++ b/app/code/Magento/Theme/Model/Config.php @@ -9,6 +9,8 @@ */ namespace Magento\Theme\Model; +use Magento\Framework\App\Config\ScopeConfigInterface; + class Config { /** @@ -173,7 +175,7 @@ protected function _assignThemeToStores($themeId, $stores, $scope, &$isReassigne protected function _assignThemeToDefaultScope($themeId, &$isReassigned) { $configPath = \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID; - $this->_configWriter->save($configPath, $themeId, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT); + $this->_configWriter->save($configPath, $themeId, ScopeConfigInterface::SCOPE_TYPE_DEFAULT); $isReassigned = true; return $this; } diff --git a/app/code/Magento/Theme/Model/View/Design.php b/app/code/Magento/Theme/Model/View/Design.php index f839d6ba900f7..a158874feff56 100644 --- a/app/code/Magento/Theme/Model/View/Design.php +++ b/app/code/Magento/Theme/Model/View/Design.php @@ -5,6 +5,7 @@ */ namespace Magento\Theme\Model\View; +use Magento\Framework\App\Config\ScopeConfigInterface; /** * Keeps design settings for current request @@ -167,7 +168,7 @@ public function getConfigurationDesignTheme($area = null, array $params = []) if ($this->_storeManager->isSingleStoreMode()) { $theme = $this->_scopeConfig->getValue( self::XML_PATH_THEME_ID, - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT ); } else { $theme = (string) $this->_scopeConfig->getValue( diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/ConfigFixture.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/ConfigFixture.php index 9854602a507fc..3809d7f293849 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/ConfigFixture.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/ConfigFixture.php @@ -9,6 +9,8 @@ */ namespace Magento\TestFramework\Annotation; +use Magento\Framework\App\Config\ScopeConfigInterface; + class ConfigFixture { /** @@ -73,7 +75,7 @@ protected function _setConfigValue($configPath, $value, $storeCode = false) )->setValue( $configPath, $value, - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT ); } } else { diff --git a/dev/tests/integration/testsuite/Magento/Payment/Model/ObserverTest.php b/dev/tests/integration/testsuite/Magento/Payment/Model/ObserverTest.php index 14f306766a107..fd30d5b492fc7 100644 --- a/dev/tests/integration/testsuite/Magento/Payment/Model/ObserverTest.php +++ b/dev/tests/integration/testsuite/Magento/Payment/Model/ObserverTest.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Payment\Model; +use Magento\Framework\App\Config\ScopeConfigInterface; /** * @magentoAppArea adminhtml @@ -68,7 +69,7 @@ public function testUpdateOrderStatusForPaymentMethodsEvent() $config->saveConfig( 'payment/checkmo/order_status', $statusCode, - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0 ); diff --git a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php index 861079efbac7d..331bfebab31ad 100644 --- a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php +++ b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php @@ -8,6 +8,7 @@ namespace Magento\Tax\Model\Sales\Total\Quote; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Tax\Model\Config; use Magento\Tax\Model\Calculation; @@ -221,7 +222,7 @@ protected function setConfig($configData) $config->saveConfig( $path, $value, - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0 ); } diff --git a/dev/tests/performance/testsuite/fixtures/catalog_category_flat_enabled.php b/dev/tests/performance/testsuite/fixtures/catalog_category_flat_enabled.php index 00cd8ce5cb1d1..056fe99b81551 100644 --- a/dev/tests/performance/testsuite/fixtures/catalog_category_flat_enabled.php +++ b/dev/tests/performance/testsuite/fixtures/catalog_category_flat_enabled.php @@ -3,6 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +use Magento\Framework\App\Config\ScopeConfigInterface; /** @var \Magento\TestFramework\Application $this */ @@ -13,7 +14,7 @@ $configData->setPath( 'catalog/frontend/flat_catalog_category' )->setScope( - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT )->setScopeId( 0 )->setValue( diff --git a/dev/tests/performance/testsuite/fixtures/catalog_product_flat_enabled.php b/dev/tests/performance/testsuite/fixtures/catalog_product_flat_enabled.php index 2258e72023d4a..e06ed0e26c053 100644 --- a/dev/tests/performance/testsuite/fixtures/catalog_product_flat_enabled.php +++ b/dev/tests/performance/testsuite/fixtures/catalog_product_flat_enabled.php @@ -3,6 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +use Magento\Framework\App\Config\ScopeConfigInterface; /** @var \Magento\TestFramework\Application $this */ @@ -13,7 +14,7 @@ $configData->setPath( 'catalog/frontend/flat_catalog_product' )->setScope( - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT )->setScopeId( 0 )->setValue( diff --git a/dev/tests/performance/testsuite/fixtures/shipping_flatrate_enabled.php b/dev/tests/performance/testsuite/fixtures/shipping_flatrate_enabled.php index e0f50505c4adc..15b445ce1f8b5 100644 --- a/dev/tests/performance/testsuite/fixtures/shipping_flatrate_enabled.php +++ b/dev/tests/performance/testsuite/fixtures/shipping_flatrate_enabled.php @@ -3,6 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +use Magento\Framework\App\Config\ScopeConfigInterface; /** @var \Magento\TestFramework\Application $this */ @@ -13,7 +14,7 @@ $configData->setPath( 'carriers/flatrate/active' )->setScope( - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT )->setScopeId( 0 )->setValue( diff --git a/lib/internal/Magento/Framework/App/Config.php b/lib/internal/Magento/Framework/App/Config.php index 047849f0034bd..898a19a00ea5f 100644 --- a/lib/internal/Magento/Framework/App/Config.php +++ b/lib/internal/Magento/Framework/App/Config.php @@ -7,6 +7,8 @@ */ namespace Magento\Framework\App; +use Magento\Framework\App\Config\ScopeConfigInterface; + class Config implements \Magento\Framework\App\Config\ScopeConfigInterface { /** @@ -37,7 +39,7 @@ public function __construct(\Magento\Framework\App\Config\ScopePool $scopePool) */ public function getValue( $path = null, - $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null ) { return $this->_scopePool->getScope($scope, $scopeCode)->getValue($path); @@ -51,7 +53,7 @@ public function getValue( * @param null|string $scopeCode * @return bool */ - public function isSetFlag($path, $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $scopeCode = null) + public function isSetFlag($path, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null) { return (bool) $this->getValue($path, $scope, $scopeCode); } diff --git a/lib/internal/Magento/Framework/App/Config/Initial.php b/lib/internal/Magento/Framework/App/Config/Initial.php index c59ba25339968..3b2beb5ca3742 100644 --- a/lib/internal/Magento/Framework/App/Config/Initial.php +++ b/lib/internal/Magento/Framework/App/Config/Initial.php @@ -7,6 +7,8 @@ */ namespace Magento\Framework\App\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; + class Initial { /** @@ -52,14 +54,12 @@ public function __construct( * * @param string $scope Format is scope type and scope code separated by pipe: e.g. "type|code" * @return array - * - * @api */ public function getData($scope) { list($scopeType, $scopeCode) = array_pad(explode('|', $scope), 2, null); - if (\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT == $scopeType) { + if (ScopeConfigInterface::SCOPE_TYPE_DEFAULT == $scopeType) { return isset($this->_data[$scopeType]) ? $this->_data[$scopeType] : []; } elseif ($scopeCode) { return isset($this->_data[$scopeType][$scopeCode]) ? $this->_data[$scopeType][$scopeCode] : []; @@ -71,8 +71,6 @@ public function getData($scope) * Get configuration metadata * * @return array - * - * @api */ public function getMetadata() { diff --git a/lib/internal/Magento/Framework/App/Config/MutableScopeConfigInterface.php b/lib/internal/Magento/Framework/App/Config/MutableScopeConfigInterface.php index 46df2b6b884fa..f68048ddc9461 100644 --- a/lib/internal/Magento/Framework/App/Config/MutableScopeConfigInterface.php +++ b/lib/internal/Magento/Framework/App/Config/MutableScopeConfigInterface.php @@ -18,14 +18,14 @@ interface MutableScopeConfigInterface extends \Magento\Framework\App\Config\Scop * * @param string $path * @param mixed $value - * @param string $scope + * @param string $scopeType * @param null|string $scopeCode * @return void */ public function setValue( $path, $value, - $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + $scopeType = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null ); } diff --git a/lib/internal/Magento/Framework/App/Config/Resource/ConfigInterface.php b/lib/internal/Magento/Framework/App/Config/Resource/ConfigInterface.php index 4adaa72ac992c..8084c21ab0d9c 100644 --- a/lib/internal/Magento/Framework/App/Config/Resource/ConfigInterface.php +++ b/lib/internal/Magento/Framework/App/Config/Resource/ConfigInterface.php @@ -7,8 +7,6 @@ /** * Resource for storing store configuration values - * - * @api */ interface ConfigInterface { diff --git a/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php b/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php index 74766f5300d16..cdcbb42828e51 100644 --- a/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php +++ b/lib/internal/Magento/Framework/App/Config/Scope/ReaderInterface.php @@ -7,17 +7,14 @@ */ namespace Magento\Framework\App\Config\Scope; -/** - * @api - */ interface ReaderInterface { /** * Read configuration scope * - * @param string|null $scope + * @param string|null $scopeType * @throws \Exception May throw an exception if the given scope is invalid * @return array */ - public function read($scope = null); + public function read($scopeType = null); } diff --git a/lib/internal/Magento/Framework/App/Config/Scope/ReaderPoolInterface.php b/lib/internal/Magento/Framework/App/Config/Scope/ReaderPoolInterface.php index e74f5fb49b04e..b0b9d6a2ffd6c 100644 --- a/lib/internal/Magento/Framework/App/Config/Scope/ReaderPoolInterface.php +++ b/lib/internal/Magento/Framework/App/Config/Scope/ReaderPoolInterface.php @@ -5,9 +5,6 @@ */ namespace Magento\Framework\App\Config\Scope; -/** - * @api - */ interface ReaderPoolInterface { /** diff --git a/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php b/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php index 8d790d5126f11..e98fe284024f1 100644 --- a/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php +++ b/lib/internal/Magento/Framework/App/Config/ScopeConfigInterface.php @@ -16,25 +16,25 @@ interface ScopeConfigInterface /** * Default scope type */ - const SCOPE_DEFAULT = 'default'; + const SCOPE_TYPE_DEFAULT = 'default'; /** * Retrieve config value by path and scope. * * @param string $path The path through the tree of configuration values, e.g., 'general/store_information/name' - * @param string $scope The scope to use to determine config value, e.g., 'store' or 'default' + * @param string $scopeType The scope to use to determine config value, e.g., 'store' or 'default' * @param null|string $scopeCode * @return mixed */ - public function getValue($path, $scope = ScopeConfigInterface::SCOPE_DEFAULT, $scopeCode = null); + public function getValue($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null); /** * Retrieve config flag by path and scope * * @param string $path The path through the tree of configuration values, e.g., 'general/store_information/name' - * @param string $scope The scope to use to determine config value, e.g., 'store' or 'default' + * @param string $scopeType The scope to use to determine config value, e.g., 'store' or 'default' * @param null|string $scopeCode * @return bool */ - public function isSetFlag($path, $scope = ScopeConfigInterface::SCOPE_DEFAULT, $scopeCode = null); + public function isSetFlag($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null); } diff --git a/lib/internal/Magento/Framework/App/Config/ScopePool.php b/lib/internal/Magento/Framework/App/Config/ScopePool.php index 34b24deb0028b..1a15575b1a514 100644 --- a/lib/internal/Magento/Framework/App/Config/ScopePool.php +++ b/lib/internal/Magento/Framework/App/Config/ScopePool.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\App\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; + class ScopePool { const CACHE_TAG = 'config_scopes'; @@ -78,7 +80,7 @@ public function getScope($scopeType, $scopeCode = null) $data = unserialize($data); } else { $reader = $this->_readerPool->getReader($scopeType); - if ($scopeType === \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT) { + if ($scopeType === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { $data = $reader->read(); } else { $data = $reader->read($scopeCode); @@ -111,7 +113,7 @@ public function clean() protected function _getScopeCode($scopeType, $scopeCode) { if (($scopeCode === null || is_numeric($scopeCode)) - && $scopeType !== \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + && $scopeType !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT ) { $scopeResolver = $this->_scopeResolverPool->get($scopeType); $scopeCode = $scopeResolver->getScope($scopeCode); diff --git a/lib/internal/Magento/Framework/App/Config/Storage/Writer.php b/lib/internal/Magento/Framework/App/Config/Storage/Writer.php index b98e4074efa1b..63b5ae83dfec6 100644 --- a/lib/internal/Magento/Framework/App/Config/Storage/Writer.php +++ b/lib/internal/Magento/Framework/App/Config/Storage/Writer.php @@ -7,6 +7,8 @@ */ namespace Magento\Framework\App\Config\Storage; +use Magento\Framework\App\Config\ScopeConfigInterface; + class Writer implements \Magento\Framework\App\Config\Storage\WriterInterface { /** @@ -32,7 +34,7 @@ public function __construct(\Magento\Framework\App\Config\Resource\ConfigInterfa * @param int $scopeId * @return void */ - public function delete($path, $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $scopeId = 0) + public function delete($path, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0) { $this->_resource->deleteConfig(rtrim($path, '/'), $scope, $scopeId); } @@ -46,7 +48,7 @@ public function delete($path, $scope = \Magento\Framework\App\ScopeInterface::SC * @param int $scopeId * @return void */ - public function save($path, $value, $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $scopeId = 0) + public function save($path, $value, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0) { $this->_resource->saveConfig(rtrim($path, '/'), $value, $scope, $scopeId); } diff --git a/lib/internal/Magento/Framework/App/Config/Storage/WriterInterface.php b/lib/internal/Magento/Framework/App/Config/Storage/WriterInterface.php index 3a3a3af624136..67b2aebd5d4a6 100644 --- a/lib/internal/Magento/Framework/App/Config/Storage/WriterInterface.php +++ b/lib/internal/Magento/Framework/App/Config/Storage/WriterInterface.php @@ -7,6 +7,8 @@ */ namespace Magento\Framework\App\Config\Storage; +use Magento\Framework\App\Config\ScopeConfigInterface; + interface WriterInterface { /** @@ -17,7 +19,7 @@ interface WriterInterface * @param int $scopeId * @return void */ - public function delete($path, $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $scopeId = 0); + public function delete($path, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); /** * Save config value to storage @@ -28,5 +30,5 @@ public function delete($path, $scope = \Magento\Framework\App\ScopeInterface::SC * @param int $scopeId * @return void */ - public function save($path, $value, $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $scopeId = 0); + public function save($path, $value, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); } diff --git a/lib/internal/Magento/Framework/App/Config/Value.php b/lib/internal/Magento/Framework/App/Config/Value.php index 17c50d20b8b3a..64263bc7b69e8 100644 --- a/lib/internal/Magento/Framework/App/Config/Value.php +++ b/lib/internal/Magento/Framework/App/Config/Value.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Framework\App\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; /** * Config data model @@ -91,7 +92,7 @@ public function getOldValue() { return (string)$this->_config->getValue( $this->getPath(), - $this->getScope() ?: \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + $this->getScope() ?: ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $this->getScopeCode() ); } diff --git a/lib/internal/Magento/Framework/App/MutableScopeConfig.php b/lib/internal/Magento/Framework/App/MutableScopeConfig.php index c94fb73f9d5e4..418817465bd6f 100644 --- a/lib/internal/Magento/Framework/App/MutableScopeConfig.php +++ b/lib/internal/Magento/Framework/App/MutableScopeConfig.php @@ -9,6 +9,7 @@ namespace Magento\Framework\App; use Magento\Framework\App\Config\MutableScopeConfigInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; class MutableScopeConfig extends Config implements MutableScopeConfigInterface { @@ -24,7 +25,7 @@ class MutableScopeConfig extends Config implements MutableScopeConfigInterface public function setValue( $path, $value, - $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, + $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null ) { if (empty($scopeCode)) { diff --git a/lib/internal/Magento/Framework/App/Request/Http.php b/lib/internal/Magento/Framework/App/Request/Http.php index c09ead13054e7..e6e502cf38171 100644 --- a/lib/internal/Magento/Framework/App/Request/Http.php +++ b/lib/internal/Magento/Framework/App/Request/Http.php @@ -7,6 +7,7 @@ */ namespace Magento\Framework\App\Request; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\Route\ConfigInterface\Proxy as ConfigInterface; use Magento\Framework\HTTP\PhpEnvironment\Request; @@ -384,7 +385,7 @@ public function isSecure() $offLoaderHeader = trim( (string)$config->getValue( self::XML_PATH_OFFLOADER_HEADER, - \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT + ScopeConfigInterface::SCOPE_TYPE_DEFAULT ) ); diff --git a/lib/internal/Magento/Framework/App/ScopeInterface.php b/lib/internal/Magento/Framework/App/ScopeInterface.php index 9f9204426f469..77c8a8b890ac2 100644 --- a/lib/internal/Magento/Framework/App/ScopeInterface.php +++ b/lib/internal/Magento/Framework/App/ScopeInterface.php @@ -7,13 +7,6 @@ interface ScopeInterface { - /** - * Default scope type - * - * @deprecated Use \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_DEFAULT - */ - const SCOPE_DEFAULT = 'default'; - /** * Retrieve scope code * diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Config/Storage/WriterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Config/Storage/WriterTest.php index 57040f09ee4dd..887a1cf477663 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Config/Storage/WriterTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Config/Storage/WriterTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\App\Test\Unit\Config\Storage; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\ScopeInterface; class WriterTest extends \PHPUnit_Framework_TestCase @@ -40,7 +41,7 @@ public function testDelete() { $this->resource->expects($this->once()) ->method('deleteConfig') - ->with('path', ScopeInterface::SCOPE_DEFAULT, 0); + ->with('path', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0); $this->model->delete('path'); } @@ -58,7 +59,7 @@ public function testSave() { $this->resource->expects($this->once()) ->method('saveConfig') - ->with('path', 'value', ScopeInterface::SCOPE_DEFAULT, 0); + ->with('path', 'value', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0); $this->model->save('path', 'value'); } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php index 090580da27266..8bfb9be2f3bb2 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Request/HttpTest.php @@ -9,6 +9,7 @@ namespace Magento\Framework\App\Test\Unit\Request; +use Magento\Framework\App\Config\ScopeConfigInterface; use \Magento\Framework\App\Request\Http; use Magento\Framework\App\ScopeInterface; use Zend\Stdlib\Parameters; @@ -325,7 +326,7 @@ public function testIsSecure($isSecure, $serverHttps, $headerOffloadKey, $header ->getMock(); $configMock->expects($this->exactly($configCall)) ->method('getValue') - ->with(\Magento\Framework\App\Request\Http::XML_PATH_OFFLOADER_HEADER, ScopeInterface::SCOPE_DEFAULT) + ->with(\Magento\Framework\App\Request\Http::XML_PATH_OFFLOADER_HEADER, ScopeConfigInterface::SCOPE_TYPE_DEFAULT) ->willReturn($configOffloadHeader); $this->objectManager->expects($this->exactly($configCall)) ->method('get') diff --git a/lib/internal/Magento/Framework/Message/Factory.php b/lib/internal/Magento/Framework/Message/Factory.php index 979892f9ee350..be7e3c9bb566a 100644 --- a/lib/internal/Magento/Framework/Message/Factory.php +++ b/lib/internal/Magento/Framework/Message/Factory.php @@ -47,12 +47,11 @@ public function __construct(ObjectManagerInterface $objectManager) /** * Create a message instance of a given type with given text. * - * @param string $type The message type to create, must implement \Magento\Framework\Message\MessageInterface + * @param string $type The message type to create, must correspond to a message type under the + * namespace Magento\Framework\Message\ * @param string $text The text to inject into the message - * @throws \InvalidArgumentException Exception gets thrown if given type does not implement MessageInterface + * @throws \InvalidArgumentException Exception gets thrown if type does not correspond to a valid Magento message * @return MessageInterface - * - * @api */ public function create($type, $text) { diff --git a/lib/internal/Magento/Framework/Message/Manager.php b/lib/internal/Magento/Framework/Message/Manager.php index f92da3dc2fb76..815296c80bad2 100644 --- a/lib/internal/Magento/Framework/Message/Manager.php +++ b/lib/internal/Magento/Framework/Message/Manager.php @@ -78,9 +78,7 @@ public function __construct( } /** - * @inheritdoc - * - * @return string + * {@inheritdoc} */ public function getDefaultGroup() { diff --git a/lib/internal/Magento/Framework/Search/Dynamic/DataProviderFactory.php b/lib/internal/Magento/Framework/Search/Dynamic/DataProviderFactory.php index 1cfc1477a7957..1b534b4dbf499 100644 --- a/lib/internal/Magento/Framework/Search/Dynamic/DataProviderFactory.php +++ b/lib/internal/Magento/Framework/Search/Dynamic/DataProviderFactory.php @@ -33,7 +33,7 @@ public function __construct( ScopeConfigInterface $scopeConfig, $configPath, $dataProviders, - $scope = ScopeInterface::SCOPE_DEFAULT + $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT ) { $this->objectManager = $objectManager; $configValue = $scopeConfig->getValue($configPath, $scope); diff --git a/lib/internal/Magento/Framework/Search/Dynamic/IntervalFactory.php b/lib/internal/Magento/Framework/Search/Dynamic/IntervalFactory.php index bba9824e19083..80ac66bb04e62 100644 --- a/lib/internal/Magento/Framework/Search/Dynamic/IntervalFactory.php +++ b/lib/internal/Magento/Framework/Search/Dynamic/IntervalFactory.php @@ -33,7 +33,7 @@ public function __construct( ScopeConfigInterface $scopeConfig, $configPath, $intervals, - $scope = ScopeInterface::SCOPE_DEFAULT + $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT ) { $this->objectManager = $objectManager; $configValue = $scopeConfig->getValue($configPath, $scope); diff --git a/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/DimensionsTest.php b/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/DimensionsTest.php index 3b37a0bf3d574..5b0736c5fa2ef 100644 --- a/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/DimensionsTest.php +++ b/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/DimensionsTest.php @@ -6,6 +6,7 @@ namespace Magento\Framework\Search\Test\Unit\Adapter\Mysql; +use Magento\Framework\App\Config\ScopeConfigInterface; use \Magento\Framework\Search\Adapter\Mysql\Dimensions; use Magento\Framework\Search\Adapter\Mysql\Dimensions as DimensionsBuilder; @@ -103,7 +104,7 @@ public function testBuildDimensionWithDefaultScope() { $tableAlias = 'search_index'; $name = 'scope'; - $value = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT; + $value = ScopeConfigInterface::SCOPE_TYPE_DEFAULT; $scopeId = -123456; $this->dimension->expects($this->once()) diff --git a/lib/internal/Magento/Framework/Search/Test/Unit/Dynamic/IntervalFactoryTest.php b/lib/internal/Magento/Framework/Search/Test/Unit/Dynamic/IntervalFactoryTest.php index 0d7b52e00630a..232f789de3ae7 100644 --- a/lib/internal/Magento/Framework/Search/Test/Unit/Dynamic/IntervalFactoryTest.php +++ b/lib/internal/Magento/Framework/Search/Test/Unit/Dynamic/IntervalFactoryTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\Search\Test\Unit\Dynamic; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Search\Dynamic\IntervalInterface; use Magento\Framework\App\ScopeInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; @@ -63,7 +64,7 @@ public function testCreate() { $this->scopeConfig->expects($this->once()) ->method('getValue') - ->with(self::CONFIG_PATH, ScopeInterface::SCOPE_DEFAULT) + ->with(self::CONFIG_PATH, ScopeConfigInterface::SCOPE_TYPE_DEFAULT) ->willReturn(self::CONFIG_PATH . 't'); $this->objectManager->expects($this->once()) ->method('create') @@ -83,7 +84,7 @@ public function testCreateIntervalNotFoundException() { $this->scopeConfig->expects($this->once()) ->method('getValue') - ->with(self::CONFIG_PATH, ScopeInterface::SCOPE_DEFAULT) + ->with(self::CONFIG_PATH, ScopeConfigInterface::SCOPE_TYPE_DEFAULT) ->willReturn('t'); $this->factoryCreate(); @@ -97,7 +98,7 @@ public function testCreateIntervalNotImplementedInterfaceException() { $this->scopeConfig->expects($this->once()) ->method('getValue') - ->with(self::CONFIG_PATH, ScopeInterface::SCOPE_DEFAULT) + ->with(self::CONFIG_PATH, ScopeConfigInterface::SCOPE_TYPE_DEFAULT) ->willReturn(self::CONFIG_PATH . 't'); $this->objectManager->expects($this->once()) ->method('create') From d1db7e3ca6a8723e876fc6453820bfe862a1aebd Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Mon, 6 Apr 2015 15:36:05 -0500 Subject: [PATCH 13/68] MAGETWO-35004: Investigate and Annotate @api to classes and/or methods --- .../Test/Legacy/_files/obsolete_constants.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php index 250f9b13074a5..2317184010094 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php @@ -697,4 +697,26 @@ 'Use \Magento\Eav\Model\Entity\Type::getDefaultAttributeSetId() method instead', ], ['CONFIG_PATH_WSDL_CACHE_ENABLED', 'Magento\Webapi\Model\Soap\Server'], + ['ENTITY', 'Magento\Framework\App\Config\ValueInterface'], + ['XML_PATH_ALLOW_CURRENCIES_INSTALLED', 'Magento\Framework\Locale\CurrencyInterface'], + [ + 'DEFAULT_CURRENCY', + 'Magento\Framework\Locale\CurrencyInterface', + 'Magento\Framework\Locale\Currency::DEFAULT_CURRENCY' + ], + [ + 'DEFAULT_LOCALE', + 'Magento\Framework\Locale\ResolverInterface', + 'Magento\Framework\Locale\Resolver::DEFAULT_LOCALE' + ], + [ + 'DEFAULT_GROUP', + 'Magento\Framework\Message\ManagerInterface', + 'Magento\Framework\Message\Manager::DEFAULT_GROUP' + ], + [ + 'SCOPE_DEFAULT', + 'Magento\Framework\App\ScopeInterface', + 'Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT' + ] ]; From ccc271b3ec0df9e844df402ed5448f607fbcb612 Mon Sep 17 00:00:00 2001 From: Joan He Date: Wed, 15 Apr 2015 16:47:49 -0500 Subject: [PATCH 14/68] MAGETWO-36178: Update constructor - Magento\Catalog\Block\Product\ProductList and test --- .../Block/Product/ProductList/Toolbar.php | 42 +++++---- .../Block/Product/ProductList/ToolbarTest.php | 93 +++++++++++++++++-- 2 files changed, 113 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php index a79466c6007bf..13a595aae164d 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php @@ -29,7 +29,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template * * @var array */ - protected $_availableOrder = []; + protected $_availableOrder = null; /** * List of available view types @@ -146,19 +146,6 @@ public function __construct( parent::__construct($context, $data); } - /** - * Init Toolbar - * - * @return null - */ - protected function _construct() - { - parent::_construct(); - $this->_orderField = $this->_productListHelper->getDefaultSortField(); - $this->_availableOrder = $this->_catalogConfig->getAttributeUsedForSortByArray(); - $this->_availableMode = $this->_productListHelper->getAvailableViewMode(); - } - /** * Disable list state params memorizing * @@ -241,7 +228,7 @@ public function getCurrentOrder() } $orders = $this->getAvailableOrders(); - $defaultOrder = $this->_orderField; + $defaultOrder = $this->getOrderField(); if (!isset($orders[$defaultOrder])) { $keys = array_keys($orders); @@ -295,6 +282,7 @@ public function getCurrentDirection() */ public function setDefaultOrder($field) { + $this->getAvailableOrders(); if (isset($this->_availableOrder[$field])) { $this->_orderField = $field; } @@ -322,6 +310,9 @@ public function setDefaultDirection($dir) */ public function getAvailableOrders() { + if ($this->_availableOrder === null) { + $this->_availableOrder = $this->_catalogConfig->getAttributeUsedForSortByArray(); + } return $this->_availableOrder; } @@ -346,6 +337,7 @@ public function setAvailableOrders($orders) */ public function addOrderToAvailableOrders($order, $value) { + $this->getAvailableOrders(); $this->_availableOrder[$order] = $value; return $this; } @@ -358,6 +350,7 @@ public function addOrderToAvailableOrders($order, $value) */ public function removeOrderFromAvailableOrders($order) { + $this->getAvailableOrders(); if (isset($this->_availableOrder[$order])) { unset($this->_availableOrder[$order]); } @@ -411,7 +404,7 @@ public function getCurrentMode() if ($mode) { return $mode; } - $defaultMode = $this->_productListHelper->getDefaultViewMode($this->_availableMode); + $defaultMode = $this->_productListHelper->getDefaultViewMode($this->getModes()); $mode = $this->_toolbarModel->getMode(); if (!$mode || !isset($this->_availableMode[$mode])) { $mode = $defaultMode; @@ -439,6 +432,9 @@ public function isModeActive($mode) */ public function getModes() { + if ($this->_availableMode === []) { + $this->_availableMode = $this->_productListHelper->getAvailableViewMode(); + } return $this->_availableMode; } @@ -450,6 +446,7 @@ public function getModes() */ public function setModes($modes) { + $this->getModes(); if (!isset($this->_availableMode)) { $this->_availableMode = $modes; } @@ -691,4 +688,17 @@ public function getWidgetOptionsJson(array $customOptions = []) $options = array_replace_recursive($options, $customOptions); return json_encode(['productListToolbarForm' => $options]); } + + /** + * Get order field + * + * @return null|string + */ + protected function getOrderField() + { + if ($this->_orderField === null) { + $this->_orderField = $this->_productListHelper->getDefaultSortField(); + } + return $this->_orderField; + } } diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/ToolbarTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/ToolbarTest.php index df66448c16037..d4501bd7d0439 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/ToolbarTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/ToolbarTest.php @@ -106,9 +106,6 @@ protected function setUp() '', false ); - $this->catalogConfig->expects($this->any()) - ->method('getAttributeUsedForSortByArray') - ->will($this->returnValue(['name' => [], 'price' => []])); $context = $this->getMock( 'Magento\Framework\View\Element\Template\Context', @@ -133,9 +130,6 @@ protected function setUp() '', false ); - $this->productListHelper->expects($this->any()) - ->method('getAvailableViewMode') - ->will($this->returnValue(['list' => 'List'])); $this->urlEncoder = $this->getMock('Magento\Framework\Url\EncoderInterface', ['encode'], [], '', false); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -187,6 +181,9 @@ public function testGetCurrentOrder() $this->model->expects($this->once()) ->method('getOrder') ->will($this->returnValue($order)); + $this->catalogConfig->expects($this->once()) + ->method('getAttributeUsedForSortByArray') + ->will($this->returnValue(['name' => [], 'price' => []])); $this->assertEquals($order, $this->block->getCurrentOrder()); } @@ -206,6 +203,9 @@ public function testGetCurrentMode() { $mode = 'list'; + $this->productListHelper->expects($this->once()) + ->method('getAvailableViewMode') + ->will($this->returnValue(['list' => 'List'])); $this->model->expects($this->once()) ->method('getMode') ->will($this->returnValue($mode)); @@ -213,6 +213,40 @@ public function testGetCurrentMode() $this->assertEquals($mode, $this->block->getCurrentMode()); } + public function testGetModes() + { + $mode = ['list' => 'List']; + $this->productListHelper->expects($this->once()) + ->method('getAvailableViewMode') + ->will($this->returnValue($mode)); + + $this->assertEquals($mode, $this->block->getModes()); + $this->assertEquals($mode, $this->block->getModes()); + } + + /** + * @param string[] $mode + * @param string[] $expected + * @dataProvider setModesDataProvider + */ + public function testSetModes($mode, $expected) + { + $this->productListHelper->expects($this->once()) + ->method('getAvailableViewMode') + ->will($this->returnValue($mode)); + + $block = $this->block->setModes(['mode' => 'mode']); + $this->assertEquals($expected, $block->getModes()); + } + + public function setModesDataProvider() + { + return [ + [['list' => 'List'], ['list' => 'List']], + [null, ['mode' => 'mode']], + ]; + } + public function testGetLimit() { $mode = 'list'; @@ -232,6 +266,9 @@ public function testGetLimit() ->method('getDefaultLimitPerPageValue') ->with($this->equalTo('list')) ->will($this->returnValue(10)); + $this->productListHelper->expects($this->any()) + ->method('getAvailableViewMode') + ->will($this->returnValue(['list' => 'List'])); $this->assertEquals($limit, $this->block->getLimit()); } @@ -280,4 +317,48 @@ public function testGetPagerHtml() $this->assertTrue($this->block->getPagerHtml()); } + + public function testSetDefaultOrder() + { + $this->catalogConfig->expects($this->atLeastOnce()) + ->method('getAttributeUsedForSortByArray') + ->will($this->returnValue(['name' => [], 'price' => []])); + + $this->block->setDefaultOrder('field'); + } + + public function testGetAvailableOrders() + { + $data = ['name' => [], 'price' => []]; + $this->catalogConfig->expects($this->once()) + ->method('getAttributeUsedForSortByArray') + ->will($this->returnValue($data)); + + $this->assertEquals($data, $this->block->getAvailableOrders()); + $this->assertEquals($data, $this->block->getAvailableOrders()); + } + + public function testAddOrderToAvailableOrders() + { + $data = ['name' => [], 'price' => []]; + $this->catalogConfig->expects($this->once()) + ->method('getAttributeUsedForSortByArray') + ->will($this->returnValue($data)); + $expected = $data; + $expected['order'] = 'value'; + $toolbar = $this->block->addOrderToAvailableOrders('order', 'value'); + $this->assertEquals($expected, $toolbar->getAvailableOrders()); + } + + public function testRemoveOrderFromAvailableOrders() + { + $data = ['name' => [], 'price' => []]; + $this->catalogConfig->expects($this->once()) + ->method('getAttributeUsedForSortByArray') + ->will($this->returnValue($data)); + $toolbar = $this->block->removeOrderFromAvailableOrders('order', 'value'); + $this->assertEquals($data, $toolbar->getAvailableOrders()); + $toolbar2 = $this->block->removeOrderFromAvailableOrders('name'); + $this->assertEquals(['price' => []], $toolbar2->getAvailableOrders()); + } } From 40ee2b5d7e188a422b062d1ed362f2f48abddd5b Mon Sep 17 00:00:00 2001 From: Joan He Date: Thu, 16 Apr 2015 09:05:10 -0500 Subject: [PATCH 15/68] MAGETWO-36178: Update constructor - Magento\Catalog\Model\Attribute\Config\Data --- app/code/Magento/Catalog/etc/di.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 971bebcac3226..3851d2ddcd96a 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -398,6 +398,11 @@ Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile\Proxy + + + Magento\Catalog\Model\Attribute\Config\Data\Proxy + + Magento\Catalog\Model\Layer\Search\ItemCollectionProvider From 5c41f378cec2245954e20b2d191c6ba5608b5371 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Fri, 17 Apr 2015 09:56:32 -0500 Subject: [PATCH 16/68] MAGETWO-36179: Elimination of functional logic in constructors --- app/code/Magento/Catalog/etc/di.xml | 1 + app/code/Magento/CatalogInventory/etc/di.xml | 5 +++++ app/code/Magento/Eav/etc/di.xml | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 971bebcac3226..366df200ec44d 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -98,6 +98,7 @@ Magento\Catalog\Model\Product\Attribute\Source\Status\Proxy + Magento\Catalog\Model\Product\Link\Proxy diff --git a/app/code/Magento/CatalogInventory/etc/di.xml b/app/code/Magento/CatalogInventory/etc/di.xml index 11c98534f7327..1dbf03634d581 100644 --- a/app/code/Magento/CatalogInventory/etc/di.xml +++ b/app/code/Magento/CatalogInventory/etc/di.xml @@ -52,4 +52,9 @@ + + + Magento\Catalog\Model\ProductTypes\Config\Proxy + + diff --git a/app/code/Magento/Eav/etc/di.xml b/app/code/Magento/Eav/etc/di.xml index 3dfebf456c7ff..00524114f784d 100644 --- a/app/code/Magento/Eav/etc/di.xml +++ b/app/code/Magento/Eav/etc/di.xml @@ -57,4 +57,9 @@ + + + Magento\Catalog\Model\Product\ReservedAttributeList\Proxy + + From 009d81d8a64deba2786c6e6b94b4311d93847b6e Mon Sep 17 00:00:00 2001 From: Joan He Date: Fri, 17 Apr 2015 13:26:59 -0500 Subject: [PATCH 17/68] MAGETWO-36178: Update constructor - Magento\Catalog\Model\Observer --- app/code/Magento/Catalog/Model/Observer.php | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Observer.php b/app/code/Magento/Catalog/Model/Observer.php index 39e72883f68ad..90a0daa437caa 100644 --- a/app/code/Magento/Catalog/Model/Observer.php +++ b/app/code/Magento/Catalog/Model/Observer.php @@ -34,7 +34,14 @@ class Observer * * @var \Magento\Catalog\Model\Layer */ - protected $_catalogLayer; + private $_catalogLayer = null; + + /** + * Catalog layer resolver + * + * @var \Magento\Catalog\Model\Layer\Resolver + */ + protected $layerResolver; /** * Store manager @@ -95,7 +102,7 @@ public function __construct( $this->_categoryResource = $categoryResource; $this->_catalogProduct = $catalogProduct; $this->_storeManager = $storeManager; - $this->_catalogLayer = $layerResolver->get(); + $this->layerResolver = $layerResolver; $this->_catalogCategory = $catalogCategory; $this->_catalogData = $catalogData; $this->categoryFlatConfig = $categoryFlatState; @@ -184,11 +191,12 @@ protected function _addCategoriesToMenu($categories, $parentCategoryNode, $block */ protected function hasActive($category) { - if (!$this->_catalogLayer) { + $catalogLayer = $this->getCatalogLayer(); + if (!$catalogLayer) { return false; } - $currentCategory = $this->_catalogLayer->getCurrentCategory(); + $currentCategory = $catalogLayer->getCurrentCategory(); if (!$currentCategory) { return false; } @@ -196,4 +204,12 @@ protected function hasActive($category) $categoryPathIds = explode(',', $currentCategory->getPathInStore()); return in_array($category->getId(), $categoryPathIds); } + + private function getCatalogLayer() + { + if ($this->_catalogLayer === null) { + $this->_catalogLayer = $this->layerResolver->get(); + } + return $this->_catalogLayer; + } } From ae1a8aeb6744c325dfdbd6d08180cc87a2de51a2 Mon Sep 17 00:00:00 2001 From: Joan He Date: Fri, 17 Apr 2015 17:03:19 -0500 Subject: [PATCH 18/68] MAGETWO-36178: Update constructor - Magento\Catalog\Model\Observer fixed static test failure --- app/code/Magento/Catalog/Model/Observer.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Catalog/Model/Observer.php b/app/code/Magento/Catalog/Model/Observer.php index 90a0daa437caa..417a4f61811c9 100644 --- a/app/code/Magento/Catalog/Model/Observer.php +++ b/app/code/Magento/Catalog/Model/Observer.php @@ -205,6 +205,10 @@ protected function hasActive($category) return in_array($category->getId(), $categoryPathIds); } + /** + * Get catalog layer + * @return \Magento\Catalog\Model\Layer + */ private function getCatalogLayer() { if ($this->_catalogLayer === null) { From c6db341ae24507b7c6a314c5ee53756d6578cf89 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Mon, 20 Apr 2015 11:44:56 -0500 Subject: [PATCH 19/68] MAGETWO-36179: Elimination of functional logic in constructors --- .../Model/Resource/Category/Collection.php | 37 +++++++++++++++---- app/code/Magento/Customer/Model/Attribute.php | 2 +- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Resource/Category/Collection.php b/app/code/Magento/Catalog/Model/Resource/Category/Collection.php index 2abc203eccbca..451a76a435e75 100644 --- a/app/code/Magento/Catalog/Model/Resource/Category/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Category/Collection.php @@ -64,9 +64,6 @@ class Collection extends \Magento\Catalog\Model\Resource\Collection\AbstractColl protected function _construct() { $this->_init('Magento\Catalog\Model\Category', 'Magento\Catalog\Model\Resource\Category'); - - $this->_productWebsiteTable = $this->getTable('catalog_product_website'); - $this->_productTable = $this->getTable('catalog_category_product'); } /** @@ -224,7 +221,7 @@ public function loadProductCount($items, $countRegular = true, $countAnchor = tr if (!empty($regularIds)) { $select = $this->_conn->select(); $select->from( - ['main_table' => $this->_productTable], + ['main_table' => $this->getProductTable()], ['category_id', new \Zend_Db_Expr('COUNT(main_table.product_id)')] )->where( $this->_conn->quoteInto('main_table.category_id IN(?)', $regularIds) @@ -233,7 +230,7 @@ public function loadProductCount($items, $countRegular = true, $countAnchor = tr ); if ($websiteId) { $select->join( - ['w' => $this->_productWebsiteTable], + ['w' => $this->getProductWebsiteTable()], 'main_table.product_id = w.product_id', [] )->where( @@ -259,7 +256,7 @@ public function loadProductCount($items, $countRegular = true, $countAnchor = tr $bind = ['entity_id' => $item->getId(), 'c_path' => $item->getPath() . '/%']; $select = $this->_conn->select(); $select->from( - ['main_table' => $this->_productTable], + ['main_table' => $this->getProductTable()], new \Zend_Db_Expr('COUNT(DISTINCT main_table.product_id)') )->joinInner( ['e' => $this->getTable('catalog_category_entity')], @@ -272,7 +269,7 @@ public function loadProductCount($items, $countRegular = true, $countAnchor = tr ); if ($websiteId) { $select->join( - ['w' => $this->_productWebsiteTable], + ['w' => $this->getProductWebsiteTable()], 'main_table.product_id = w.product_id', [] )->where( @@ -416,4 +413,30 @@ public function addOrderField($field) $this->setOrder($field, self::SORT_ORDER_ASC); return $this; } + + /** + * Getter for _productWebsiteTable + * + * @return string + */ + public function getProductWebsiteTable() + { + if (empty($this->_productWebsiteTable)) { + $this->_productWebsiteTable = $this->getTable('catalog_product_website'); + } + return $this->_productWebsiteTable; + } + + /** + * Getter for _productTable + * + * @return string + */ + public function getProductTable() + { + if (empty($this->_productTable)) { + $this->_productTable = $this->getTable('catalog_category_product'); + } + return $this->_productTable; + } } diff --git a/app/code/Magento/Customer/Model/Attribute.php b/app/code/Magento/Customer/Model/Attribute.php index cf87d2683af47..f11dfa07d0c71 100644 --- a/app/code/Magento/Customer/Model/Attribute.php +++ b/app/code/Magento/Customer/Model/Attribute.php @@ -38,6 +38,6 @@ class Attribute extends \Magento\Eav\Model\Attribute */ protected function _construct() { - $this->_init('Magento\Customer\Model\Resource\Attribute'); + $this->_setResourceModel('Magento\Customer\Model\Resource\Attribute'); } } From e303c5394ff7d0392c92c8f95a6ece0ef83bf96a Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Tue, 21 Apr 2015 11:54:31 -0500 Subject: [PATCH 20/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 --- app/code/Magento/CatalogSearch/etc/di.xml | 5 +++++ .../Magento/Framework/Model/AbstractModel.php | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CatalogSearch/etc/di.xml b/app/code/Magento/CatalogSearch/etc/di.xml index 6e20a71762142..6a4cb5594965b 100644 --- a/app/code/Magento/CatalogSearch/etc/di.xml +++ b/app/code/Magento/CatalogSearch/etc/di.xml @@ -230,4 +230,9 @@ + + + Magento\CatalogSearch\Model\Fulltext\Proxy + + diff --git a/lib/internal/Magento/Framework/Model/AbstractModel.php b/lib/internal/Magento/Framework/Model/AbstractModel.php index 43223069055fd..d597ac6e0d32e 100644 --- a/lib/internal/Magento/Framework/Model/AbstractModel.php +++ b/lib/internal/Magento/Framework/Model/AbstractModel.php @@ -234,13 +234,16 @@ protected function _setResourceModel($resourceName, $collectionName = null) */ protected function _getResource() { - if (empty($this->_resourceName) && empty($this->_resource)) { - throw new \Magento\Framework\Exception\LocalizedException( - new \Magento\Framework\Phrase('Resource is not set.') - ); + if (empty($this->_resource)) { + if (empty($this->_resourceName)) { + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Resource is not set.') + ); + } + $this->_resource = \Magento\Framework\App\ObjectManager::getInstance()->get($this->_resourceName); } - return $this->_resource ?: \Magento\Framework\App\ObjectManager::getInstance()->get($this->_resourceName); + return $this->_resource; } /** From babecd48fc816057a75ecbab11685583e7f984e6 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Tue, 21 Apr 2015 11:55:20 -0500 Subject: [PATCH 21/68] MAGETWO-36179: Elimination of functional logic in constructors --- .../Customer/Model/Resource/Address.php | 23 +++++++++---- .../Test/Unit/Model/Resource/AddressTest.php | 34 ++++++++++++------- .../Eav/Model/Entity/AbstractEntity.php | 4 +-- .../Framework/Search/Request/Mapper.php | 20 +++-------- .../Magento/Framework/Validator/Factory.php | 30 ++++++++++------ 5 files changed, 64 insertions(+), 47 deletions(-) diff --git a/app/code/Magento/Customer/Model/Resource/Address.php b/app/code/Magento/Customer/Model/Resource/Address.php index 57a5c1cbcf3d9..3b6ae0a28c8f9 100644 --- a/app/code/Magento/Customer/Model/Resource/Address.php +++ b/app/code/Magento/Customer/Model/Resource/Address.php @@ -45,13 +45,22 @@ public function __construct( */ protected function _construct() { - $resource = $this->_resource; - $this->setType( - 'customer_address' - )->setConnection( - $resource->getConnection('customer_read'), - $resource->getConnection('customer_write') - ); + $this->_read = 'customer_read'; + $this->_write = 'customer_write'; + } + + /** + * Getter and lazy loader for _type + * + * @throws \Magento\Framework\Exception\LocalizedException + * @return \Magento\Eav\Model\Entity\Type + */ + public function getEntityType() + { + if (empty($this->_type)) { + $this->setType('customer_address'); + } + return parent::getEntityType(); } /** diff --git a/app/code/Magento/Customer/Test/Unit/Model/Resource/AddressTest.php b/app/code/Magento/Customer/Test/Unit/Model/Resource/AddressTest.php index fe17aa1aca70e..c15cf1596c824 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Resource/AddressTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Resource/AddressTest.php @@ -18,6 +18,9 @@ class AddressTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Customer\Model\CustomerFactory|\PHPUnit_Framework_MockObject_MockObject */ protected $customerFactory; + /** @var \Magento\Eav\Model\Entity\Type */ + protected $eavConfigType; + protected function setUp() { $this->addressResource = (new ObjectManagerHelper($this))->getObject( @@ -178,16 +181,16 @@ protected function prepareEavConfig() ) ); - $eavConfigType = $this->getMock( + $this->eavConfigType = $this->getMock( 'Magento\Eav\Model\Entity\Type', ['getEntityIdField', 'getId', 'getEntityTable', '__wakeup'], [], '', false ); - $eavConfigType->expects($this->any())->method('getEntityIdField')->willReturn(false); - $eavConfigType->expects($this->any())->method('getId')->willReturn(false); - $eavConfigType->expects($this->any())->method('getEntityTable')->willReturn('customer_address_entity'); + $this->eavConfigType->expects($this->any())->method('getEntityIdField')->willReturn(false); + $this->eavConfigType->expects($this->any())->method('getId')->willReturn(false); + $this->eavConfigType->expects($this->any())->method('getEntityTable')->willReturn('customer_address_entity'); $eavConfig = $this->getMock( 'Magento\Eav\Model\Config', @@ -199,10 +202,10 @@ protected function prepareEavConfig() $eavConfig->expects($this->any()) ->method('getEntityType') ->with('customer_address') - ->willReturn($eavConfigType); + ->willReturn($this->eavConfigType); $eavConfig->expects($this->any()) ->method('getEntityAttributeCodes') - ->with($eavConfigType) + ->with($this->eavConfigType) ->willReturn( [ 'entity_type_id', @@ -217,13 +220,13 @@ protected function prepareEavConfig() $eavConfig->expects($this->any()) ->method('getAttribute') ->willReturnMap([ - [$eavConfigType, 'entity_type_id', $attributeMock], - [$eavConfigType, 'attribute_set_id', $attributeMock], - [$eavConfigType, 'created_at', $attributeMock], - [$eavConfigType, 'updated_at', $attributeMock], - [$eavConfigType, 'parent_id', $attributeMock], - [$eavConfigType, 'increment_id', $attributeMock], - [$eavConfigType, 'entity_id', $attributeMock], + [$this->eavConfigType, 'entity_type_id', $attributeMock], + [$this->eavConfigType, 'attribute_set_id', $attributeMock], + [$this->eavConfigType, 'created_at', $attributeMock], + [$this->eavConfigType, 'updated_at', $attributeMock], + [$this->eavConfigType, 'parent_id', $attributeMock], + [$this->eavConfigType, 'increment_id', $attributeMock], + [$this->eavConfigType, 'entity_id', $attributeMock], ]); return $eavConfig; @@ -261,4 +264,9 @@ protected function prepareCustomerFactory() $this->customerFactory = $this->getMock('Magento\Customer\Model\CustomerFactory', ['create'], [], '', false); return $this->customerFactory; } + + public function testGetType() + { + $this->assertSame($this->eavConfigType, $this->addressResource->getEntityType()); + } } diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php index ac8c5805f4b72..c8fa8214eab58 100755 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -31,14 +31,14 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract /** * Read connection * - * @var \Magento\Framework\DB\Adapter\Pdo\Mysql + * @var \Magento\Framework\DB\Adapter\Pdo\Mysql | string */ protected $_read; /** * Write connection * - * @var \Magento\Framework\DB\Adapter\Pdo\Mysql + * @var \Magento\Framework\DB\Adapter\Pdo\Mysql | string */ protected $_write; diff --git a/lib/internal/Magento/Framework/Search/Request/Mapper.php b/lib/internal/Magento/Framework/Search/Request/Mapper.php index e2dcbef74cda6..286fcd4244122 100644 --- a/lib/internal/Magento/Framework/Search/Request/Mapper.php +++ b/lib/internal/Magento/Framework/Search/Request/Mapper.php @@ -45,9 +45,9 @@ class Mapper private $objectManager; /** - * @var QueryInterface + * @var string */ - private $rootQuery = null; + private $rootQueryName; /** * @param \Magento\Framework\ObjectManagerInterface $objectManager @@ -70,24 +70,22 @@ public function __construct( $this->queries = $queries; $this->aggregations = $aggregations; $this->filters = $filters; - - $this->rootQuery = $this->get($rootQueryName); + $this->rootQueryName = $rootQueryName; } /** * Get Query Interface by name * - * @param string $queryName * @return QueryInterface * @throws \Exception * @throws \InvalidArgumentException * @throws StateException */ - private function get($queryName) + public function getRootQuery() { $this->mappedQueries = []; $this->mappedFilters = []; - $query = $this->mapQuery($queryName); + $query = $this->mapQuery($this->rootQueryName); $this->validate(); return $query; } @@ -304,14 +302,6 @@ private function validateFilters() $this->validateNotUsed($this->filters, $this->mappedFilters, 'Filter %1 is not used in request hierarchy'); } - /** - * @return QueryInterface - */ - public function getRootQuery() - { - return $this->rootQuery; - } - /** * Build BucketInterface[] from array * diff --git a/lib/internal/Magento/Framework/Validator/Factory.php b/lib/internal/Magento/Framework/Validator/Factory.php index a663b91cc745f..ef5679b220c24 100644 --- a/lib/internal/Magento/Framework/Validator/Factory.php +++ b/lib/internal/Magento/Framework/Validator/Factory.php @@ -24,6 +24,11 @@ class Factory */ protected $_configFiles = null; + /** + * @var bool + */ + private $isDefaultTranslatorInitialized = false; + /** * Initialize dependencies * @@ -36,7 +41,6 @@ public function __construct( ) { $this->_objectManager = $objectManager; $this->_configFiles = $moduleReader->getConfigurationFiles('validation.xml'); - $this->_initializeDefaultTranslator(); } /** @@ -46,15 +50,18 @@ public function __construct( */ protected function _initializeDefaultTranslator() { - // Pass translations to \Magento\Framework\TranslateInterface from validators - $translatorCallback = function () { - $argc = func_get_args(); - return (string)new \Magento\Framework\Phrase(array_shift($argc), $argc); - }; - /** @var \Magento\Framework\Translate\Adapter $translator */ - $translator = $this->_objectManager->create('Magento\Framework\Translate\Adapter'); - $translator->setOptions(['translator' => $translatorCallback]); - \Magento\Framework\Validator\AbstractValidator::setDefaultTranslator($translator); + if (!$this->isDefaultTranslatorInitialized) { + // Pass translations to \Magento\Framework\TranslateInterface from validators + $translatorCallback = function () { + $argc = func_get_args(); + return (string)new \Magento\Framework\Phrase(array_shift($argc), $argc); + }; + /** @var \Magento\Framework\Translate\Adapter $translator */ + $translator = $this->_objectManager->create('Magento\Framework\Translate\Adapter'); + $translator->setOptions(['translator' => $translatorCallback]); + \Magento\Framework\Validator\AbstractValidator::setDefaultTranslator($translator); + $this->isDefaultTranslatorInitialized = true; + } } /** @@ -66,6 +73,7 @@ protected function _initializeDefaultTranslator() */ public function getValidatorConfig() { + $this->_initializeDefaultTranslator(); return $this->_objectManager->create('Magento\Framework\Validator\Config', ['configFiles' => $this->_configFiles]); } @@ -79,6 +87,7 @@ public function getValidatorConfig() */ public function createValidatorBuilder($entityName, $groupName, array $builderConfig = null) { + $this->_initializeDefaultTranslator(); return $this->getValidatorConfig()->createValidatorBuilder($entityName, $groupName, $builderConfig); } @@ -92,6 +101,7 @@ public function createValidatorBuilder($entityName, $groupName, array $builderCo */ public function createValidator($entityName, $groupName, array $builderConfig = null) { + $this->_initializeDefaultTranslator(); return $this->getValidatorConfig()->createValidator($entityName, $groupName, $builderConfig); } } From 2f1d644f5d0ca5c3b09c7dcbbdecd13fdda0829b Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Tue, 21 Apr 2015 14:15:13 -0500 Subject: [PATCH 22/68] MAGETWO-36179: Elimination of functional logic in constructors - undid replacement of _init with _setResourceModel in \Magento\Customer\Model\Attribute --- app/code/Magento/Customer/Model/Attribute.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Attribute.php b/app/code/Magento/Customer/Model/Attribute.php index f11dfa07d0c71..cf87d2683af47 100644 --- a/app/code/Magento/Customer/Model/Attribute.php +++ b/app/code/Magento/Customer/Model/Attribute.php @@ -38,6 +38,6 @@ class Attribute extends \Magento\Eav\Model\Attribute */ protected function _construct() { - $this->_setResourceModel('Magento\Customer\Model\Resource\Attribute'); + $this->_init('Magento\Customer\Model\Resource\Attribute'); } } From c43bf943fac0e3eede77e8ad5e2171af8cd5a03a Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Wed, 22 Apr 2015 09:21:30 -0500 Subject: [PATCH 23/68] MAGETWO-36179: Elimination of functional logic in constructors --- .../Magento/Framework/Simplexml/Config.php | 27 +++++++--- .../Magento/Framework/View/Layout.php | 54 +++++++++++++------ .../Framework/View/Test/Unit/LayoutTest.php | 12 +++-- 3 files changed, 65 insertions(+), 28 deletions(-) diff --git a/lib/internal/Magento/Framework/Simplexml/Config.php b/lib/internal/Magento/Framework/Simplexml/Config.php index 4e1265ebd4a4c..2f45cd6550b87 100644 --- a/lib/internal/Magento/Framework/Simplexml/Config.php +++ b/lib/internal/Magento/Framework/Simplexml/Config.php @@ -118,12 +118,12 @@ public function setXml(Element $node) */ public function getNode($path = null) { - if (!$this->_xml instanceof Element) { + if (!$this->getXml() instanceof Element) { return false; } elseif ($path === null) { - return $this->_xml; + return $this->getXml(); } else { - return $this->_xml->descend($path); + return $this->getXml()->descend($path); } } @@ -135,11 +135,12 @@ public function getNode($path = null) */ public function getXpath($xpath) { - if (empty($this->_xml)) { + $xml = $this->getXml(); + if (empty($xml)) { return false; } - if (!($result = @$this->_xml->xpath($xpath))) { + if (!($result = @$xml->xpath($xpath))) { return false; } @@ -476,7 +477,7 @@ public function loadString($string) if (!empty($string)) { $xml = simplexml_load_string($string, $this->_elementClass); if ($xml) { - $this->_xml = $xml; + $this->setXml($xml); return true; } } @@ -493,7 +494,7 @@ public function loadDom(\DOMNode $dom) { $xml = simplexml_import_dom($dom, $this->_elementClass); if ($xml) { - $this->_xml = $xml; + $this->setXml($xml); return true; } @@ -510,7 +511,7 @@ public function loadDom(\DOMNode $dom) */ public function setNode($path, $value, $overwrite = true) { - $this->_xml->setNode($path, $value, $overwrite); + $this->getXml()->setNode($path, $value, $overwrite); return $this; } @@ -575,4 +576,14 @@ public function __destruct() { $this->_xml = null; } + + /** + * Getter for xml element + * + * @return Element + */ + protected function getXml() + { + return $this->_xml; + } } diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index 6c857548d18ed..da8130891b3b0 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -23,6 +23,12 @@ */ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Framework\View\LayoutInterface { + + /** + * Empty layout xml + */ + const LAYOUT_NODE = ''; + /** * Layout Update module * @@ -173,7 +179,6 @@ public function __construct( $cacheable = true ) { $this->_elementClass = 'Magento\Framework\View\Layout\Element'; - $this->setXml(simplexml_load_string('', $this->_elementClass)); $this->_renderingOutput = new \Magento\Framework\Object(); $this->_processorFactory = $processorFactory; @@ -188,8 +193,6 @@ public function __construct( $this->readerContextFactory = $readerContextFactory; $this->generatorContextFactory = $generatorContextFactory; - - $this->readerContext = $this->readerContextFactory->create(); } /** @@ -248,7 +251,7 @@ public function __destruct() $this->_update = null; } $this->_blocks = []; - $this->_xml = null; + parent::__destruct(); } /** @@ -278,14 +281,6 @@ public function generateXml() return $this; } - /** - * @return Layout\Reader\Context - */ - public function getReaderContext() - { - return $this->readerContext; - } - /** * Create structure of elements from the loaded XML configuration * @@ -297,13 +292,12 @@ public function generateElements() $cacheId = 'structure_' . $this->getUpdate()->getCacheId(); $result = $this->cache->load($cacheId); if ($result) { - /** @var Layout\Reader\Context $readerContext */ $this->readerContext = unserialize($result); } else { \Magento\Framework\Profiler::start('build_structure'); - $this->readerPool->interpret($this->readerContext, $this->getNode()); + $this->readerPool->interpret($this->getReaderContext(), $this->getNode()); \Magento\Framework\Profiler::stop('build_structure'); - $this->cache->save(serialize($this->readerContext), $cacheId, $this->getUpdate()->getHandles()); + $this->cache->save(serialize($this->getReaderContext()), $cacheId, $this->getUpdate()->getHandles()); } $generatorContext = $this->generatorContextFactory->create( @@ -314,7 +308,7 @@ public function generateElements() ); \Magento\Framework\Profiler::start('generate_elements'); - $this->generatorPool->process($this->readerContext, $generatorContext); + $this->generatorPool->process($this->getReaderContext(), $generatorContext); \Magento\Framework\Profiler::stop('generate_elements'); $this->addToOutputRootContainers(); @@ -1035,7 +1029,7 @@ protected function _prepareMessageGroup($messageGroups) public function isCacheable() { $this->build(); - $cacheableXml = !(bool)count($this->_xml->xpath('//' . Element::TYPE_BLOCK . '[@cacheable="false"]')); + $cacheableXml = !(bool)count($this->getXml()->xpath('//' . Element::TYPE_BLOCK . '[@cacheable="false"]')); return $this->cacheable && $cacheableXml; } @@ -1060,4 +1054,30 @@ public function setIsPrivate($isPrivate = true) $this->isPrivate = (bool)$isPrivate; return $this; } + + /** + * Getter and lazy loader for xml element + * + * @return \Magento\Framework\Simplexml\Element + */ + protected function getXml() + { + if (!$this->_xml) { + $this->setXml(simplexml_load_string(self::LAYOUT_NODE, $this->_elementClass)); + } + return $this->_xml; + } + + /** + * Getter and lazy loader for reader context + * + * @return Layout\Reader\Context + */ + public function getReaderContext() + { + if (!$this->readerContext) { + $this->readerContext = $this->readerContextFactory->create(); + } + return $this->readerContext; + } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php index 45effcf449e43..3d60c5e411300 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php @@ -134,9 +134,6 @@ protected function setUp() $this->readerContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context') ->disableOriginalConstructor() ->getMock(); - $this->readerContextFactoryMock->expects($this->once()) - ->method('create') - ->willReturn($this->readerContextMock); $this->generatorContextFactoryMock = $this->getMockBuilder( 'Magento\Framework\View\Layout\Generator\ContextFactory' )->disableOriginalConstructor() @@ -683,6 +680,9 @@ public function isCacheableDataProvider() public function testGenerateElementsWithoutCache() { + $this->readerContextFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->readerContextMock); $layoutCacheId = 'layout_cache_id'; $handles = ['default', 'another']; /** @var \Magento\Framework\View\Layout\Element $xml */ @@ -807,4 +807,10 @@ public function testGenerateElementsWithCache() $this->model->generateElements(); } + + public function testGetXml() + { + $xml = ''; + $this->assertSame($xml, \Magento\Framework\View\Layout::LAYOUT_NODE); + } } From 8c45f6d54c21d6aa028cc582d69d8c37c82cf464 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Wed, 22 Apr 2015 09:29:01 -0500 Subject: [PATCH 24/68] MAGETWO-36179: Elimination of functional logic in constructors - fix failure to log in to backend error --- .../Magento/Framework/Model/AbstractModel.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/Model/AbstractModel.php b/lib/internal/Magento/Framework/Model/AbstractModel.php index 42e2c5eb437c9..fcd03252a4160 100644 --- a/lib/internal/Magento/Framework/Model/AbstractModel.php +++ b/lib/internal/Magento/Framework/Model/AbstractModel.php @@ -241,16 +241,13 @@ protected function _setResourceModel($resourceName, $collectionName = null) */ protected function _getResource() { - if (empty($this->_resource)) { - if (empty($this->_resourceName)) { - throw new \Magento\Framework\Exception\LocalizedException( - new \Magento\Framework\Phrase('Resource is not set.') - ); - } - $this->_resource = \Magento\Framework\App\ObjectManager::getInstance()->get($this->_resourceName); + if (empty($this->_resourceName) && empty($this->_resource)) { + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Resource is not set.') + ); } - return $this->_resource; + return $this->_resource ?: \Magento\Framework\App\ObjectManager::getInstance()->get($this->_resourceName); } /** From d6d698e764cdba7c6cbcd5ca75460853f364ff0c Mon Sep 17 00:00:00 2001 From: Joan He Date: Wed, 22 Apr 2015 11:39:16 -0500 Subject: [PATCH 25/68] MAGETWO-36178: Update constructor - Magento\Framework\App\Cache\Type\Config --- .../Framework/App/Cache/Type/Config.php | 36 +++- .../App/Test/Unit/Cache/Type/ConfigTest.php | 175 ++++++++++++++++++ .../Cache/Frontend/Decorator/Bare.php | 26 ++- .../Cache/Frontend/Decorator/TagScope.php | 8 +- 4 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php diff --git a/lib/internal/Magento/Framework/App/Cache/Type/Config.php b/lib/internal/Magento/Framework/App/Cache/Type/Config.php index ded73329969b9..506eff32a8e09 100644 --- a/lib/internal/Magento/Framework/App/Cache/Type/Config.php +++ b/lib/internal/Magento/Framework/App/Cache/Type/Config.php @@ -25,10 +25,40 @@ class Config extends TagScope implements CacheInterface const CACHE_TAG = 'CONFIG'; /** - * @param FrontendPool $cacheFrontendPool + * @var \Magento\Framework\App\Cache\Type\FrontendPool */ - public function __construct(FrontendPool $cacheFrontendPool) + private $cacheFrontendPool; + + /** + * @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool + */ + public function __construct(\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool) + { + $this->cacheFrontendPool = $cacheFrontendPool; + } + + /** + * Retrieve cache frontend instance being decorated + * + * @return \Magento\Framework\Cache\FrontendInterface + */ + protected function _getFrontend() + { + $frontend = parent::_getFrontend(); + if (!$frontend) { + $frontend = $this->cacheFrontendPool->get(self::TYPE_IDENTIFIER); + $this->setFrontend($frontend); + } + return $frontend; + } + + /** + * Retrieve cache tag name + * + * @return string + */ + public function getTag() { - parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG); + return self::CACHE_TAG; } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php new file mode 100644 index 0000000000000..ced9faf3661b4 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php @@ -0,0 +1,175 @@ +getMockBuilder('Magento\Framework\App\Cache\Type\FrontendPool') + ->disableOriginalConstructor() + ->getMock(); + $this->model = (new ObjectManager($this))->getObject( + 'Magento\Framework\App\Cache\Type\Config', + ['cacheFrontendPool' => $cacheFrontendPoolMock] + ); + $this->frontendMock = $this->getMock('Magento\Framework\Cache\FrontendInterface'); + $cacheFrontendPoolMock->expects($this->once()) + ->method('get') + ->with(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER) + ->willReturn($this->frontendMock); + } + + /** + * @param string $method + * @param array $params + * @param mixed $expectedResult + * @dataProvider proxyMethodDataProvider + */ + public function testProxyMethod($method, $params, $expectedResult) + { + $helper = new \Magento\Framework\TestFramework\Unit\Helper\ProxyTesting(); + $result = $helper->invokeWithExpectations($this->model, $this->frontendMock, $method, $params, $expectedResult); + $this->assertSame($expectedResult, $result); + } + + /** + * @return array + */ + public function proxyMethodDataProvider() + { + return [ + ['test', ['record_id'], 111], + ['load', ['record_id'], '111'], +// [ +// 'save', +// ['record_value', 'record_id', ['tag'], 555], +// true +// ], + ['remove', ['record_id'], true], +// ['clean', [\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ['tag']], true], + ['getBackend', [], $this->getMock('Zend_Cache_Backend')], + ['getLowLevelFrontend', [], $this->getMock('Zend_Cache_Core')], + ]; + } + + public function testSave() + { + $expectedResult = new \stdClass(); + $this->frontendMock->expects( + $this->once() + )->method( + 'save' + )->with( + 'test_value', + 'test_id', + ['test_tag_one', 'test_tag_two', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG], + 111 + )->will( + $this->returnValue($expectedResult) + ); + $actualResult = $this->model->save('test_value', 'test_id', ['test_tag_one', 'test_tag_two'], 111); + $this->assertSame($expectedResult, $actualResult); + } + + public function testCleanModeAll() + { + $expectedResult = new \stdClass(); + $this->frontendMock->expects( + $this->once() + )->method( + 'clean' + )->with( + \Zend_Cache::CLEANING_MODE_MATCHING_TAG, + [\Magento\Framework\App\Cache\Type\Config::CACHE_TAG] + )->will( + $this->returnValue($expectedResult) + ); + $actualResult = $this->model->clean( + \Zend_Cache::CLEANING_MODE_ALL, + ['ignored_tag_one', 'ignored_tag_two'] + ); + $this->assertSame($expectedResult, $actualResult); + } + + public function testCleanModeMatchingTag() + { + $expectedResult = new \stdClass(); + $this->frontendMock->expects( + $this->once() + )->method( + 'clean' + )->with( + \Zend_Cache::CLEANING_MODE_MATCHING_TAG, + ['test_tag_one', 'test_tag_two', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG] + )->will( + $this->returnValue($expectedResult) + ); + $actualResult = $this->model->clean( + \Zend_Cache::CLEANING_MODE_MATCHING_TAG, + ['test_tag_one', 'test_tag_two'] + ); + $this->assertSame($expectedResult, $actualResult); + } + + /** + * @param bool $fixtureResultOne + * @param bool $fixtureResultTwo + * @param bool $expectedResult + * @dataProvider cleanModeMatchingAnyTagDataProvider + */ + public function testCleanModeMatchingAnyTag($fixtureResultOne, $fixtureResultTwo, $expectedResult) + { + $this->frontendMock->expects( + $this->at(0) + )->method( + 'clean' + )->with( + \Zend_Cache::CLEANING_MODE_MATCHING_TAG, + ['test_tag_one', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG] + )->will( + $this->returnValue($fixtureResultOne) + ); + $this->frontendMock->expects( + $this->at(1) + )->method( + 'clean' + )->with( + \Zend_Cache::CLEANING_MODE_MATCHING_TAG, + ['test_tag_two', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG] + )->will( + $this->returnValue($fixtureResultTwo) + ); + $actualResult = $this->model->clean( + \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, + ['test_tag_one', 'test_tag_two'] + ); + $this->assertEquals($expectedResult, $actualResult); + } + + public function cleanModeMatchingAnyTagDataProvider() + { + return [ + 'failure, failure' => [false, false, false], + 'failure, success' => [false, true, true], + 'success, failure' => [true, false, true], + 'success, success' => [true, true, true] + ]; + } +} diff --git a/lib/internal/Magento/Framework/Cache/Frontend/Decorator/Bare.php b/lib/internal/Magento/Framework/Cache/Frontend/Decorator/Bare.php index b856e8608aa72..cae35e66ff83d 100644 --- a/lib/internal/Magento/Framework/Cache/Frontend/Decorator/Bare.php +++ b/lib/internal/Magento/Framework/Cache/Frontend/Decorator/Bare.php @@ -27,6 +27,18 @@ public function __construct(\Magento\Framework\Cache\FrontendInterface $frontend $this->_frontend = $frontend; } + /** + * Set frontend + * + * @param \Magento\Framework\Cache\FrontendInterface $frontend + * @return $this + */ + protected function setFrontend(\Magento\Framework\Cache\FrontendInterface $frontend) + { + $this->_frontend = $frontend; + return $this; + } + /** * Retrieve cache frontend instance being decorated * @@ -42,7 +54,7 @@ protected function _getFrontend() */ public function test($identifier) { - return $this->_frontend->test($identifier); + return $this->_getFrontend()->test($identifier); } /** @@ -50,7 +62,7 @@ public function test($identifier) */ public function load($identifier) { - return $this->_frontend->load($identifier); + return $this->_getFrontend()->load($identifier); } /** @@ -60,7 +72,7 @@ public function load($identifier) */ public function save($data, $identifier, array $tags = [], $lifeTime = null) { - return $this->_frontend->save($data, $identifier, $tags, $lifeTime); + return $this->_getFrontend()->save($data, $identifier, $tags, $lifeTime); } /** @@ -68,7 +80,7 @@ public function save($data, $identifier, array $tags = [], $lifeTime = null) */ public function remove($identifier) { - return $this->_frontend->remove($identifier); + return $this->_getFrontend()->remove($identifier); } /** @@ -76,7 +88,7 @@ public function remove($identifier) */ public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = []) { - return $this->_frontend->clean($mode, $tags); + return $this->_getFrontend()->clean($mode, $tags); } /** @@ -84,7 +96,7 @@ public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = []) */ public function getBackend() { - return $this->_frontend->getBackend(); + return $this->_getFrontend()->getBackend(); } /** @@ -92,6 +104,6 @@ public function getBackend() */ public function getLowLevelFrontend() { - return $this->_frontend->getLowLevelFrontend(); + return $this->_getFrontend()->getLowLevelFrontend(); } } diff --git a/lib/internal/Magento/Framework/Cache/Frontend/Decorator/TagScope.php b/lib/internal/Magento/Framework/Cache/Frontend/Decorator/TagScope.php index 32c9e4422417c..0f74b18948657 100644 --- a/lib/internal/Magento/Framework/Cache/Frontend/Decorator/TagScope.php +++ b/lib/internal/Magento/Framework/Cache/Frontend/Decorator/TagScope.php @@ -45,7 +45,7 @@ public function getTag() */ public function save($data, $identifier, array $tags = [], $lifeTime = null) { - $tags[] = $this->_tag; + $tags[] = $this->getTag(); return parent::save($data, $identifier, $tags, $lifeTime); } @@ -59,16 +59,16 @@ public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = []) if ($mode == \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG) { $result = false; foreach ($tags as $tag) { - if (parent::clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [$tag, $this->_tag])) { + if (parent::clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [$tag, $this->getTag()])) { $result = true; } } } else { if ($mode == \Zend_Cache::CLEANING_MODE_ALL) { $mode = \Zend_Cache::CLEANING_MODE_MATCHING_TAG; - $tags = [$this->_tag]; + $tags = [$this->getTag()]; } else { - $tags[] = $this->_tag; + $tags[] = $this->getTag(); } $result = parent::clean($mode, $tags); } From 840117b49fa0f7b2b1ad1c392146fe8fb373ea83 Mon Sep 17 00:00:00 2001 From: Joan He Date: Wed, 22 Apr 2015 12:02:30 -0500 Subject: [PATCH 26/68] MAGETWO-36178: Update constructor - Magento\Search\Model\SearchEngine --- .../Magento/Search/Model/SearchEngine.php | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Search/Model/SearchEngine.php b/app/code/Magento/Search/Model/SearchEngine.php index c4d5c4787a17a..8f9334034d5b8 100644 --- a/app/code/Magento/Search/Model/SearchEngine.php +++ b/app/code/Magento/Search/Model/SearchEngine.php @@ -17,14 +17,21 @@ class SearchEngine implements SearchEngineInterface /** * @var AdapterInterface */ - protected $adapter; + private $adapter = null; + + /** + * Adapter factory + * + * @var AdapterFactory + */ + private $adapterFactory; /** * @param AdapterFactory $adapterFactory */ public function __construct(AdapterFactory $adapterFactory) { - $this->adapter = $adapterFactory->create(); + $this->adapterFactory = $adapterFactory; } /** @@ -32,6 +39,16 @@ public function __construct(AdapterFactory $adapterFactory) */ public function search(RequestInterface $request) { - return $this->adapter->query($request); + return $this->getAdapter()->query($request); + } + + /** + * Get adapter + * + * @return AdapterInterface + */ + protected function getAdapter() + { + return ($this->adapter === null) ? $this->adapterFactory->create() : $this->adapter; } } From 8fde87972605ba1b34375a7d03a2f0642bb164e5 Mon Sep 17 00:00:00 2001 From: Joan He Date: Wed, 22 Apr 2015 13:53:46 -0500 Subject: [PATCH 27/68] MAGETWO-36178: Update constructor - Magento\Framework\App\Cache\Type\Config --- .../Framework/App/Test/Unit/Cache/Type/ConfigTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php index ced9faf3661b4..c6887709da50f 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/Type/ConfigTest.php @@ -57,13 +57,7 @@ public function proxyMethodDataProvider() return [ ['test', ['record_id'], 111], ['load', ['record_id'], '111'], -// [ -// 'save', -// ['record_value', 'record_id', ['tag'], 555], -// true -// ], ['remove', ['record_id'], true], -// ['clean', [\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ['tag']], true], ['getBackend', [], $this->getMock('Zend_Cache_Backend')], ['getLowLevelFrontend', [], $this->getMock('Zend_Cache_Core')], ]; From c303f7ee6e6ce7fc5b83c4ece99a767b4250e6c6 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Wed, 22 Apr 2015 14:07:58 -0500 Subject: [PATCH 28/68] MAGETWO-36179: Elimination of functional logic in constructors --- app/code/Magento/Quote/etc/di.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index 214e414e3207d..d5d6e8f3a5bc4 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -25,4 +25,9 @@ + + + Magento\Quote\Model\Resource\Quote\Collection\Proxy + + From b66392cbd48e76aff8785cf98f7923522a6b2de8 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Wed, 22 Apr 2015 15:33:08 -0500 Subject: [PATCH 29/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 --- .../Magento/Framework/Test/Unit/UrlTest.php | 15 +++-- lib/internal/Magento/Framework/Url.php | 61 ++++++++++++------- .../Magento/Framework/View/Result/Page.php | 4 +- .../View/Test/Unit/Result/PageTest.php | 28 +++++++-- 4 files changed, 73 insertions(+), 35 deletions(-) diff --git a/lib/internal/Magento/Framework/Test/Unit/UrlTest.php b/lib/internal/Magento/Framework/Test/Unit/UrlTest.php index 46d9a13f0bf0a..3393f621fcd1d 100644 --- a/lib/internal/Magento/Framework/Test/Unit/UrlTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/UrlTest.php @@ -73,9 +73,10 @@ protected function setUp() } /** + * @param bool $resolve * @return \Magento\Framework\Url\RouteParamsResolverFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected function getRouteParamsResolver() + protected function getRouteParamsResolver($resolve = true) { $routeParamsResolverFactoryMock = $this->getMock( 'Magento\Framework\Url\RouteParamsResolverFactory', @@ -84,8 +85,10 @@ protected function getRouteParamsResolver() '', false ); - $routeParamsResolverFactoryMock->expects($this->once())->method('create') - ->will($this->returnValue($this->routeParamsResolverMock)); + if ($resolve) { + $routeParamsResolverFactoryMock->expects($this->once())->method('create') + ->will($this->returnValue($this->routeParamsResolverMock)); + } return $routeParamsResolverFactoryMock; } @@ -363,7 +366,7 @@ public function testGetRebuiltUrl($url) 'request' => $requestMock, 'sidResolver' => $this->sidResolverMock, 'scopeResolver' => $this->scopeResolverMock, - 'routeParamsResolver' => $this->getRouteParamsResolver(), + 'routeParamsResolver' => $this->getRouteParamsResolver(false), 'queryParamsResolver' => $this->queryParamsResolverMock, ]); @@ -396,7 +399,7 @@ public function testGetRedirectUrl() public function testGetRedirectUrlWithSessionId() { $model = $this->getUrlModel( - ['routeParamsResolver' => $this->getRouteParamsResolver(), 'session' => $this->sessionMock, + ['routeParamsResolver' => $this->getRouteParamsResolver(false), 'session' => $this->sessionMock, 'sidResolver' => $this->sidResolverMock, 'queryParamsResolver' => $this->queryParamsResolverMock, ] ); @@ -422,7 +425,7 @@ public function getRebuiltUrlDataProvider() public function testGetRouteUrlWithValidUrl() { - $model = $this->getUrlModel(['routeParamsResolver' => $this->getRouteParamsResolver()]); + $model = $this->getUrlModel(['routeParamsResolver' => $this->getRouteParamsResolver(false)]); $this->routeParamsResolverMock->expects($this->never())->method('unsetData'); $this->assertEquals('http://example.com', $model->getRouteUrl('http://example.com')); diff --git a/lib/internal/Magento/Framework/Url.php b/lib/internal/Magento/Framework/Url.php index efffc744e3fe4..ac1fae2d5467b 100644 --- a/lib/internal/Magento/Framework/Url.php +++ b/lib/internal/Magento/Framework/Url.php @@ -135,6 +135,10 @@ class Url extends \Magento\Framework\Object implements \Magento\Framework\UrlInt */ protected $_routeParamsResolver; + /** + * @var \Magento\Framework\Url\RouteParamsResolverFactory + */ + protected $_routeParamsResolverFactory; /** * @var \Magento\Framework\Url\ScopeResolverInterface */ @@ -183,7 +187,7 @@ public function __construct( $this->_scopeResolver = $scopeResolver; $this->_session = $session; $this->_sidResolver = $sidResolver; - $this->_routeParamsResolver = $routeParamsResolver->create(); + $this->_routeParamsResolverFactory = $routeParamsResolver; $this->_queryParamsResolver = $queryParamsResolver; $this->_scopeConfig = $scopeConfig; $this->_scopeType = $scopeType; @@ -322,10 +326,10 @@ protected function _getRequest() */ protected function _getType() { - if (!$this->_routeParamsResolver->hasData('type')) { - $this->_routeParamsResolver->setData('type', self::DEFAULT_URL_TYPE); + if (!$this->getRouteParamsResolver()->hasData('type')) { + $this->getRouteParamsResolver()->setData('type', self::DEFAULT_URL_TYPE); } - return $this->_routeParamsResolver->getType(); + return $this->getRouteParamsResolver()->getType(); } /** @@ -335,27 +339,27 @@ protected function _getType() */ protected function _isSecure() { - if ($this->_routeParamsResolver->hasData('secure_is_forced')) { - return (bool) $this->_routeParamsResolver->getData('secure'); + if ($this->getRouteParamsResolver()->hasData('secure_is_forced')) { + return (bool) $this->getRouteParamsResolver()->getData('secure'); } if (!$this->_getScope()->isUrlSecure()) { return false; } - if (!$this->_routeParamsResolver->hasData('secure')) { + if (!$this->getRouteParamsResolver()->hasData('secure')) { if ($this->_getType() == UrlInterface::URL_TYPE_LINK) { $pathSecure = $this->_urlSecurityInfo->isSecure('/' . $this->_getActionPath()); - $this->_routeParamsResolver->setData('secure', $pathSecure); + $this->getRouteParamsResolver()->setData('secure', $pathSecure); } elseif ($this->_getType() == UrlInterface::URL_TYPE_STATIC) { $isRequestSecure = $this->_getRequest()->isSecure(); - $this->_routeParamsResolver->setData('secure', $isRequestSecure); + $this->getRouteParamsResolver()->setData('secure', $isRequestSecure); } else { - $this->_routeParamsResolver->setData('secure', true); + $this->getRouteParamsResolver()->setData('secure', true); } } - return $this->_routeParamsResolver->getData('secure'); + return $this->getRouteParamsResolver()->getData('secure'); } /** @@ -367,7 +371,7 @@ protected function _isSecure() public function setScope($params) { $this->setData('scope', $this->_scopeResolver->getScope($params)); - $this->_routeParamsResolver->setScope($this->_scopeResolver->getScope($params)); + $this->getRouteParamsResolver()->setScope($this->_scopeResolver->getScope($params)); return $this; } @@ -401,11 +405,11 @@ public function getBaseUrl($params = []) $this->setScope($params['_scope']); } if (isset($params['_type'])) { - $this->_routeParamsResolver->setType($params['_type']); + $this->getRouteParamsResolver()->setType($params['_type']); } if (isset($params['_secure'])) { - $this->_routeParamsResolver->setSecure($params['_secure']); + $this->getRouteParamsResolver()->setSecure($params['_secure']); } /** @@ -416,13 +420,13 @@ public function getBaseUrl($params = []) $this->_getRouteFrontName() ) ) { - $this->_routeParamsResolver->setType(UrlInterface::URL_TYPE_DIRECT_LINK); + $this->getRouteParamsResolver()->setType(UrlInterface::URL_TYPE_DIRECT_LINK); } $result = $this->_getScope()->getBaseUrl($this->_getType(), $this->_isSecure()); // setting back the original scope $this->setScope($origScope); - $this->_routeParamsResolver->setType(self::DEFAULT_URL_TYPE); + $this->getRouteParamsResolver()->setType(self::DEFAULT_URL_TYPE); return $result; } @@ -471,7 +475,7 @@ protected function _setRoutePath($data) $key = array_shift($routePieces); if (!empty($routePieces)) { $value = array_shift($routePieces); - $this->_routeParamsResolver->setRouteParam($key, $value); + $this->getRouteParamsResolver()->setRouteParam($key, $value); } } } @@ -650,7 +654,7 @@ protected function _getActionName($default = null) */ protected function _setRouteParams(array $data, $unsetOldParams = true) { - $this->_routeParamsResolver->setRouteParams($data, $unsetOldParams); + $this->getRouteParamsResolver()->setRouteParams($data, $unsetOldParams); return $this; } @@ -661,7 +665,7 @@ protected function _setRouteParams(array $data, $unsetOldParams = true) */ protected function _getRouteParams() { - return $this->_routeParamsResolver->getRouteParams(); + return $this->getRouteParamsResolver()->getRouteParams(); } /** @@ -677,7 +681,7 @@ public function getRouteUrl($routePath = null, $routeParams = null) return $routePath; } - $this->_routeParamsResolver->unsetData('route_params'); + $this->getRouteParamsResolver()->unsetData('route_params'); if (isset($routeParams['_direct'])) { if (is_array($routeParams)) { @@ -786,7 +790,7 @@ public function getUrl($routePath = null, $routeParams = null) * this method has condition for adding default controller and action names * in case when we have params */ - $this->_routeParamsResolver->unsetData('secure'); + $this->getRouteParamsResolver()->unsetData('secure'); $fragment = null; if (isset($routeParams['_fragment'])) { $fragment = $routeParams['_fragment']; @@ -840,7 +844,7 @@ public function getUrl($routePath = null, $routeParams = null) if (!is_null($fragment)) { $url .= '#' . $fragment; } - $this->_routeParamsResolver->unsetData('secure'); + $this->getRouteParamsResolver()->unsetData('secure'); return $this->escape($url); } @@ -1038,4 +1042,17 @@ public function getCurrentUrl() $url = $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . $port . $requestUri; return $url; } + + /** + * Get Route Params Resolver + * + * @return Url\RouteParamsResolverInterface + */ + protected function getRouteParamsResolver() + { + if (!$this->_routeParamsResolver) { + $this->_routeParamsResolver = $this->_routeParamsResolverFactory->create(); + } + return $this->_routeParamsResolver; + } } diff --git a/lib/internal/Magento/Framework/View/Result/Page.php b/lib/internal/Magento/Framework/View/Result/Page.php index 2fab155de5668..5002c736895f6 100644 --- a/lib/internal/Magento/Framework/View/Result/Page.php +++ b/lib/internal/Magento/Framework/View/Result/Page.php @@ -134,7 +134,6 @@ public function __construct( $generatorPool, $isIsolated ); - $this->initPageConfigReader(); } /** @@ -222,6 +221,9 @@ public function addPageLayoutHandles(array $parameters = [], $defaultHandle = nu */ protected function render(ResponseInterface $response) { + if (!$this->pageConfigRenderer) { + $this->initPageConfigReader(); + } $this->pageConfig->publicBuild(); if ($this->getPageLayout()) { $config = $this->getConfig(); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php index a01d21d07df7e..3c3aa2d36794d 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php @@ -52,6 +52,11 @@ class PageTest extends \PHPUnit_Framework_TestCase */ protected $pageConfigRenderer; + /** + * @var \Magento\Framework\View\Page\Config\RendererFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $pageConfigRendererFactory; + /** * @var \Magento\Framework\View\FileSystem|\PHPUnit_Framework_MockObject_MockObject */ @@ -107,14 +112,10 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $pageConfigRendererFactory = $this->getMockBuilder('Magento\Framework\View\Page\Config\RendererFactory') + $this->pageConfigRendererFactory = $this->getMockBuilder('Magento\Framework\View\Page\Config\RendererFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $pageConfigRendererFactory->expects($this->once()) - ->method('create') - ->with(['pageConfig' => $this->pageConfig]) - ->willReturn($this->pageConfigRenderer); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->page = $objectManagerHelper->getObject( @@ -124,7 +125,7 @@ protected function setUp() 'layoutFactory' => $this->layoutFactory, 'context' => $this->context, 'translateInline' => $this->translateInline, - 'pageConfigRendererFactory' => $pageConfigRendererFactory, + 'pageConfigRendererFactory' => $this->pageConfigRendererFactory, ] ); } @@ -243,4 +244,19 @@ public function testAddPageLayoutHandlesWithDefaultHandle() $this->page->addPageLayoutHandles($parameters, $defaultHandle); } + + public function testRenderResult() + { + /** @var $response \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */ + $response = $this->getMockBuilder('Magento\Framework\App\Response\Http') + ->disableOriginalConstructor() + ->getMock(); + + $this->pageConfigRendererFactory->expects($this->once()) + ->method('create') + ->with(['pageConfig' => $this->pageConfig]) + ->willReturn($this->pageConfigRenderer); + + $this->assertEquals($this->page->renderResult($response), $this->page); + } } From b16bac77ede19514ff0624386fbe895fe542e53b Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Wed, 22 Apr 2015 16:07:36 -0500 Subject: [PATCH 30/68] MAGETWO-21160: CLONE - Checking for functions which are disabled in php.ini in cron.php works wrong --- lib/internal/Magento/Framework/Shell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Shell.php b/lib/internal/Magento/Framework/Shell.php index 0652d49d039e0..2372ba4088571 100644 --- a/lib/internal/Magento/Framework/Shell.php +++ b/lib/internal/Magento/Framework/Shell.php @@ -49,7 +49,7 @@ public function execute($command, array $arguments = []) $command = $this->commandRenderer->render($command, $arguments); $this->log($command); - $disabled = explode(',', ini_get('disable_functions')); + $disabled = explode(',', str_replace(' ', ',', ini_get('disable_functions'))); if (in_array('exec', $disabled)) { throw new Exception\LocalizedException(new \Magento\Framework\Phrase("exec function is disabled.")); } From 083188268e8f9e96b6e1165597f95e00c412b4b8 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Thu, 23 Apr 2015 07:22:21 -0500 Subject: [PATCH 31/68] MAGETWO-35833: [GitHub] Magento\Framework\Data\Collection\Filesystem filter issue #1160 --- app/code/Magento/Backup/README.md | 2 +- .../Magento/Backup/view/adminhtml/layout/backup_index_block.xml | 1 - lib/internal/Magento/Framework/Data/Collection/Filesystem.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Backup/README.md b/app/code/Magento/Backup/README.md index 661f8a5d6ddd8..59688ea3e716e 100644 --- a/app/code/Magento/Backup/README.md +++ b/app/code/Magento/Backup/README.md @@ -1,3 +1,3 @@ The Backup module allows administrators to perform backups and rollbacks. Types of backups include system, database and media backups. This module relies on the Cron module to schedule backups. -This module does not effect the storefront. \ No newline at end of file +This module does not affect the storefront. diff --git a/app/code/Magento/Backup/view/adminhtml/layout/backup_index_block.xml b/app/code/Magento/Backup/view/adminhtml/layout/backup_index_block.xml index 861bc2050e44a..1553a783f6356 100644 --- a/app/code/Magento/Backup/view/adminhtml/layout/backup_index_block.xml +++ b/app/code/Magento/Backup/view/adminhtml/layout/backup_index_block.xml @@ -46,7 +46,6 @@ Name display_name - 0 1 col-name col-name diff --git a/lib/internal/Magento/Framework/Data/Collection/Filesystem.php b/lib/internal/Magento/Framework/Data/Collection/Filesystem.php index 817c4b4205196..e637f4e4b89da 100644 --- a/lib/internal/Magento/Framework/Data/Collection/Filesystem.php +++ b/lib/internal/Magento/Framework/Data/Collection/Filesystem.php @@ -696,7 +696,7 @@ public function getAllIds() */ public function filterCallbackLike($field, $filterValue, $row) { - $filterValueRegex = str_replace('%', '(.*?)', preg_quote($filterValue, '/')); + $filterValueRegex = str_replace('%', '(.*?)', str_replace('\'', '', preg_quote($filterValue, '/'))); return (bool)preg_match("/^{$filterValueRegex}\$/i", $row[$field]); } From b52f9d5ec405edb6514c06ffe8f33b3c2ff2bf18 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Thu, 23 Apr 2015 07:27:54 -0500 Subject: [PATCH 32/68] MAGETWO-35882: Front-end development workflow settings should have Global Scope instead of Store View in configuration --- app/code/Magento/Developer/etc/adminhtml/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Developer/etc/adminhtml/system.xml b/app/code/Magento/Developer/etc/adminhtml/system.xml index f858f6b51bc27..13ec5c3a13106 100644 --- a/app/code/Magento/Developer/etc/adminhtml/system.xml +++ b/app/code/Magento/Developer/etc/adminhtml/system.xml @@ -9,7 +9,7 @@
- + Not available in production mode Magento\Developer\Model\Config\Source\WorkflowType From 6d2a7b7aed3c0d9101097380ecde43917bfca03e Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Thu, 23 Apr 2015 09:46:53 -0500 Subject: [PATCH 33/68] MAGETWO-36179: Elimination of functional logic in constructors --- .../Magento/Framework/Search/Request/Mapper.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Search/Request/Mapper.php b/lib/internal/Magento/Framework/Search/Request/Mapper.php index 286fcd4244122..d69d5e4e6d668 100644 --- a/lib/internal/Magento/Framework/Search/Request/Mapper.php +++ b/lib/internal/Magento/Framework/Search/Request/Mapper.php @@ -14,6 +14,11 @@ */ class Mapper { + /** + * @var QueryInterface + */ + private $rootQuery; + /** * @var array */ @@ -83,11 +88,13 @@ public function __construct( */ public function getRootQuery() { - $this->mappedQueries = []; - $this->mappedFilters = []; - $query = $this->mapQuery($this->rootQueryName); - $this->validate(); - return $query; + if (!$this->rootQuery) { + $this->mappedQueries = []; + $this->mappedFilters = []; + $this->rootQuery = $this->mapQuery($this->rootQueryName); + $this->validate(); + } + return $this->rootQuery; } /** From 1d5fdb284d7ba99ca9465eb4126d7758df568da3 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Thu, 23 Apr 2015 11:20:17 -0500 Subject: [PATCH 34/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 --- .../Magento/Framework/View/Result/Page.php | 22 +++++----- .../View/Test/Unit/Result/PageTest.php | 42 ++++++++++++++++++- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Result/Page.php b/lib/internal/Magento/Framework/View/Result/Page.php index 5002c736895f6..d2184499960c5 100644 --- a/lib/internal/Magento/Framework/View/Result/Page.php +++ b/lib/internal/Magento/Framework/View/Result/Page.php @@ -137,13 +137,16 @@ public function __construct( } /** - * Initialize page config reader + * Page config renderer getter * - * @return void + * @return View\Page\Config\Renderer|View\Page\Config\RendererInterface */ - protected function initPageConfigReader() + protected function getPageConfigRenderer() { - $this->pageConfigRenderer = $this->pageConfigRendererFactory->create(['pageConfig' => $this->pageConfig]); + if (!$this->pageConfigRenderer) { + $this->pageConfigRenderer = $this->pageConfigRendererFactory->create(['pageConfig' => $this->pageConfig]); + } + return $this->pageConfigRenderer; } /** @@ -221,9 +224,6 @@ public function addPageLayoutHandles(array $parameters = [], $defaultHandle = nu */ protected function render(ResponseInterface $response) { - if (!$this->pageConfigRenderer) { - $this->initPageConfigReader(); - } $this->pageConfig->publicBuild(); if ($this->getPageLayout()) { $config = $this->getConfig(); @@ -232,11 +232,11 @@ protected function render(ResponseInterface $response) $requireJs = $this->getLayout()->getBlock('require.js'); $this->assign([ 'requireJs' => $requireJs ? $requireJs->toHtml() : null, - 'headContent' => $this->pageConfigRenderer->renderHeadContent(), + 'headContent' => $this->getPageConfigRenderer()->renderHeadContent(), 'headAdditional' => $addBlock ? $addBlock->toHtml() : null, - 'htmlAttributes' => $this->pageConfigRenderer->renderElementAttributes($config::ELEMENT_TYPE_HTML), - 'headAttributes' => $this->pageConfigRenderer->renderElementAttributes($config::ELEMENT_TYPE_HEAD), - 'bodyAttributes' => $this->pageConfigRenderer->renderElementAttributes($config::ELEMENT_TYPE_BODY), + 'htmlAttributes' => $this->getPageConfigRenderer()->renderElementAttributes($config::ELEMENT_TYPE_HTML), + 'headAttributes' => $this->getPageConfigRenderer()->renderElementAttributes($config::ELEMENT_TYPE_HEAD), + 'bodyAttributes' => $this->getPageConfigRenderer()->renderElementAttributes($config::ELEMENT_TYPE_BODY), 'loaderIcon' => $this->getViewFileUrl('images/loader-2.gif'), ]); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php index 3c3aa2d36794d..08176d8088c8c 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php @@ -247,6 +247,42 @@ public function testAddPageLayoutHandlesWithDefaultHandle() public function testRenderResult() { + $layoutReaderPool = $this->getMockBuilder('Magento\Framework\View\Layout\ReaderPool') + ->disableOriginalConstructor() + ->getMock(); + $layoutBuilderFactory = $this->getMockBuilder('Magento\Framework\View\Layout\BuilderFactory') + ->disableOriginalConstructor() + ->getMock(); + $generatorPool = $this->getMockBuilder('Magento\Framework\View\Layout\GeneratorPool') + ->disableOriginalConstructor() + ->getMock(); + $pageLayoutReader = $this->getMockBuilder('Magento\Framework\View\Page\Layout\Reader') + ->disableOriginalConstructor() + ->getMock(); + + /** @var $page \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject*/ + $page = $this->getMockBuilder('Magento\Framework\View\Result\Page') + ->setConstructorArgs( + [ + $this->context, + $this->layoutFactory, + $layoutReaderPool, + $this->translateInline, + $layoutBuilderFactory, + $generatorPool, + $this->pageConfigRendererFactory, + $pageLayoutReader, + 'template', + false + ] + ) + ->setMethods(['renderPage']) + ->getMock(); + + $page->expects($this->any()) + ->method('renderPage') + ->will($this->returnValue('output')); + /** @var $response \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */ $response = $this->getMockBuilder('Magento\Framework\App\Response\Http') ->disableOriginalConstructor() @@ -257,6 +293,10 @@ public function testRenderResult() ->with(['pageConfig' => $this->pageConfig]) ->willReturn($this->pageConfigRenderer); - $this->assertEquals($this->page->renderResult($response), $this->page); + $this->pageConfig->expects($this->any()) + ->method('getPageLayout') + ->will($this->returnValue('layout')); + + $this->assertEquals($page->renderResult($response), $page); } } From 7ab1c1c052cadbd86b79a9bfa54bba2b81289220 Mon Sep 17 00:00:00 2001 From: Joan He Date: Thu, 23 Apr 2015 13:16:51 -0500 Subject: [PATCH 35/68] MAGETWO-36178: Update constructor - Magento\Catalog\Block\Product\ProductList\Toolbar --- .../Block/Product/ProductList/Toolbar.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php index 13a595aae164d..1f0b4b6bd9389 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php @@ -282,7 +282,7 @@ public function getCurrentDirection() */ public function setDefaultOrder($field) { - $this->getAvailableOrders(); + $this->loadAvailableOrders(); if (isset($this->_availableOrder[$field])) { $this->_orderField = $field; } @@ -310,9 +310,7 @@ public function setDefaultDirection($dir) */ public function getAvailableOrders() { - if ($this->_availableOrder === null) { - $this->_availableOrder = $this->_catalogConfig->getAttributeUsedForSortByArray(); - } + $this->loadAvailableOrders(); return $this->_availableOrder; } @@ -337,7 +335,7 @@ public function setAvailableOrders($orders) */ public function addOrderToAvailableOrders($order, $value) { - $this->getAvailableOrders(); + $this->loadAvailableOrders(); $this->_availableOrder[$order] = $value; return $this; } @@ -350,7 +348,7 @@ public function addOrderToAvailableOrders($order, $value) */ public function removeOrderFromAvailableOrders($order) { - $this->getAvailableOrders(); + $this->loadAvailableOrders(); if (isset($this->_availableOrder[$order])) { unset($this->_availableOrder[$order]); } @@ -701,4 +699,11 @@ protected function getOrderField() } return $this->_orderField; } + + private function loadAvailableOrders() + { + if ($this->_availableOrder === null) { + $this->_availableOrder = $this->_catalogConfig->getAttributeUsedForSortByArray(); + } + } } From 63c1763acbc29302c4c7e63dbe3f7003f8943fe3 Mon Sep 17 00:00:00 2001 From: Joan He Date: Thu, 23 Apr 2015 13:18:20 -0500 Subject: [PATCH 36/68] MAGETWO-36178: Update constructor - Magento\Search\Model\SearchEngine --- app/code/Magento/Search/Model/SearchEngine.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Search/Model/SearchEngine.php b/app/code/Magento/Search/Model/SearchEngine.php index 8f9334034d5b8..f80e6bfd8796f 100644 --- a/app/code/Magento/Search/Model/SearchEngine.php +++ b/app/code/Magento/Search/Model/SearchEngine.php @@ -49,6 +49,9 @@ public function search(RequestInterface $request) */ protected function getAdapter() { - return ($this->adapter === null) ? $this->adapterFactory->create() : $this->adapter; + if ($this->adapter === null) { + $this->adapter = $this->adapterFactory->create(); + } + return $this->adapter; } } From bb893575d51dfeb8678637ed1d4457ae1338ddc4 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Thu, 23 Apr 2015 13:57:07 -0500 Subject: [PATCH 37/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 --- app/code/Magento/Catalog/etc/di.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index acd741fdbbe66..4de602edd4b6d 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -464,4 +464,9 @@ + + + Magento\Catalog\Model\Resource\Category\Collection\Proxy + + From a076f1ed7953d7f88a2f71d788cf843849b4e34f Mon Sep 17 00:00:00 2001 From: Joan He Date: Thu, 23 Apr 2015 13:44:30 -0500 Subject: [PATCH 38/68] MAGETWO-36178: Update constructor - \Magento\Review\Model\Resource\Review\Collection --- .../Model/Resource/Review/Collection.php | 95 +++++++-- .../Model/Resource/Review/CollectionTest.php | 188 ++++++++++++++++++ 2 files changed, 266 insertions(+), 17 deletions(-) create mode 100644 app/code/Magento/Review/Test/Unit/Model/Resource/Review/CollectionTest.php diff --git a/app/code/Magento/Review/Model/Resource/Review/Collection.php b/app/code/Magento/Review/Model/Resource/Review/Collection.php index 7bd2de244b7ad..d32a6b04ac030 100644 --- a/app/code/Magento/Review/Model/Resource/Review/Collection.php +++ b/app/code/Magento/Review/Model/Resource/Review/Collection.php @@ -17,35 +17,35 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac * * @var string */ - protected $_reviewTable; + protected $_reviewTable = null; /** * Review detail table * * @var string */ - protected $_reviewDetailTable; + protected $_reviewDetailTable = null; /** * Review status table * * @var string */ - protected $_reviewStatusTable; + protected $_reviewStatusTable = null; /** * Review entity table * * @var string */ - protected $_reviewEntityTable; + protected $_reviewEntityTable = null; /** * Review store table * * @var string */ - protected $_reviewStoreTable; + protected $_reviewStoreTable = null; /** * Add store data flag @@ -111,11 +111,6 @@ public function __construct( protected function _construct() { $this->_init('Magento\Review\Model\Review', 'Magento\Review\Model\Resource\Review'); - $this->_reviewTable = $this->getTable('review'); - $this->_reviewDetailTable = $this->getTable('review_detail'); - $this->_reviewStatusTable = $this->getTable('review_status'); - $this->_reviewEntityTable = $this->getTable('review_entity'); - $this->_reviewStoreTable = $this->getTable('review_store'); } /** @@ -127,7 +122,7 @@ protected function _initSelect() { parent::_initSelect(); $this->getSelect()->join( - ['detail' => $this->_reviewDetailTable], + ['detail' => $this->getReviewDetailTable()], 'main_table.review_id = detail.review_id', ['detail_id', 'title', 'detail', 'nickname', 'customer_id'] ); @@ -156,7 +151,7 @@ public function addStoreFilter($storeId) { $inCond = $this->getConnection()->prepareSqlCondition('store.store_id', ['in' => $storeId]); $this->getSelect()->join( - ['store' => $this->_reviewStoreTable], + ['store' => $this->getReviewStoreTable()], 'main_table.review_id=store.review_id', [] ); @@ -184,18 +179,19 @@ public function addStoreData() */ public function addEntityFilter($entity, $pkValue) { + $reviewEntityTable = $this->getReviewEntityTable(); if (is_numeric($entity)) { $this->addFilter('entity', $this->getConnection()->quoteInto('main_table.entity_id=?', $entity), 'string'); } elseif (is_string($entity)) { $this->_select->join( - $this->_reviewEntityTable, - 'main_table.entity_id=' . $this->_reviewEntityTable . '.entity_id', + $reviewEntityTable, + 'main_table.entity_id=' . $reviewEntityTable . '.entity_id', ['entity_code'] ); $this->addFilter( 'entity', - $this->getConnection()->quoteInto($this->_reviewEntityTable . '.entity_code=?', $entity), + $this->getConnection()->quoteInto($reviewEntityTable . '.entity_code=?', $entity), 'string' ); } @@ -268,7 +264,7 @@ public function addRateVotes() public function addReviewsTotalCount() { $this->_select->joinLeft( - ['r' => $this->_reviewTable], + ['r' => $this->getReviewTable()], 'main_table.entity_pk_value = r.entity_pk_value', ['total_reviews' => new \Zend_Db_Expr('COUNT(r.review_id)')] )->group( @@ -311,7 +307,7 @@ protected function _addStoreData() $storesToReviews = []; if (count($reviewsIds) > 0) { $inCond = $adapter->prepareSqlCondition('review_id', ['in' => $reviewsIds]); - $select = $adapter->select()->from($this->_reviewStoreTable)->where($inCond); + $select = $adapter->select()->from($this->getReviewStoreTable())->where($inCond); $result = $adapter->fetchAll($select); foreach ($result as $row) { if (!isset($storesToReviews[$row['review_id']])) { @@ -329,4 +325,69 @@ protected function _addStoreData() } } } + + /** + * Get review table + * + * @return string + */ + protected function getReviewTable() + { + if ($this->_reviewTable === null) { + $this->_reviewTable = $this->getTable('review'); + } + return $this->_reviewTable; + } + + /** + * Get review detail table + * + * @return string + */ + protected function getReviewDetailTable() + { + if ($this->_reviewDetailTable === null) { + $this->_reviewDetailTable = $this->getTable('review_detail'); + } + return $this->_reviewDetailTable; + } + + /** + * Get review status table + * + * @return string + */ + protected function getReviewStatusTable() + { + if ($this->_reviewStatusTable === null) { + $this->_reviewStatusTable = $this->getTable('review_status'); + } + return $this->_reviewStatusTable; + } + + /** + * Get review entity table + * + * @return string + */ + protected function getReviewEntityTable() + { + if ($this->_reviewEntityTable === null) { + $this->_reviewEntityTable = $this->getTable('review_entity'); + } + return $this->_reviewEntityTable; + } + + /** + * Get review store table + * + * @return string + */ + protected function getReviewStoreTable() + { + if ($this->_reviewStoreTable === null) { + $this->_reviewStoreTable = $this->getTable('review_store'); + } + return $this->_reviewStoreTable; + } } diff --git a/app/code/Magento/Review/Test/Unit/Model/Resource/Review/CollectionTest.php b/app/code/Magento/Review/Test/Unit/Model/Resource/Review/CollectionTest.php new file mode 100644 index 0000000000000..e1dce20116c16 --- /dev/null +++ b/app/code/Magento/Review/Test/Unit/Model/Resource/Review/CollectionTest.php @@ -0,0 +1,188 @@ +getMock('\Magento\Store\Model\Store', ['getId'], [], '', false); + $store->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface'); + $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); + $this->objectManager = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)); + $this->resourceMock = $this->getMockBuilder('Magento\Framework\Model\Resource\Db\AbstractDb') + ->disableOriginalConstructor() + ->setMethods(['getReadConnection', 'getMainTable', 'getTable']) + ->getMockForAbstractClass(); + $this->readerAdapterMock = $this->getMockBuilder('\Zend_Db_Adapter_Abstract') + ->disableOriginalConstructor() + ->setMethods(['select', 'prepareSqlCondition', 'quoteInto']) + ->getMockForAbstractClass(); + $this->selectMock = $this->getMockBuilder('\Zend_Db_Select') + ->disableOriginalConstructor() + ->getMock(); + $this->readerAdapterMock->expects($this->any()) + ->method('select') + ->willReturn($this->selectMock); + $this->resourceMock->expects($this->any()) + ->method('getReadConnection') + ->willReturn($this->readerAdapterMock); + $this->resourceMock->expects($this->any()) + ->method('getMainTable') + ->willReturn('maintable'); + $this->resourceMock->expects($this->any()) + ->method('getTable') + ->willReturnCallback(function ($table) { + return $table; + }); + $this->model = $this->objectManager->getObject( + '\Magento\Review\Model\Resource\Review\Collection', + [ + 'storeManager' => $this->storeManagerMock, + 'resource' => $this->resourceMock, + ] + ); + + } + + public function testInitSelect() + { + $this->selectMock->expects($this->once()) + ->method('join') + ->with( + ['detail' => 'review_detail'], + 'main_table.review_id = detail.review_id', + ['detail_id', 'title', 'detail', 'nickname', 'customer_id'] + ); + $this->objectManager->getObject( + '\Magento\Review\Model\Resource\Review\Collection', + [ + 'storeManager' => $this->storeManagerMock, + 'resource' => $this->resourceMock, + ] + ); + } + + public function testAddStoreFilter() + { + $this->readerAdapterMock->expects($this->once()) + ->method('prepareSqlCondition'); + $this->selectMock->expects($this->once()) + ->method('join') + ->with( + ['store' => 'review_store'], + 'main_table.review_id=store.review_id', + [] + ); + $this->model->addStoreFilter(1); + } + + /** + * @param int|string $entity + * @param int $pkValue + * @param string $quoteIntoArguments1 + * @param string $quoteIntoArguments2 + * @param string $quoteIntoReturn1 + * @param string $quoteIntoReturn2 + * @param int $callNum + * @dataProvider addEntityFilterDataProvider + */ + public function testAddEntityFilter( + $entity, + $pkValue, + $quoteIntoArguments1, + $quoteIntoArguments2, + $quoteIntoReturn1, + $quoteIntoReturn2, + $callNum + ) { + $this->readerAdapterMock->expects($this->at(0)) + ->method('quoteInto') + ->with($quoteIntoArguments1[0], $quoteIntoArguments1[1]) + ->willReturn($quoteIntoReturn1); + $this->readerAdapterMock->expects($this->at(1)) + ->method('quoteInto') + ->with($quoteIntoArguments2[0], $quoteIntoArguments2[1]) + ->willReturn($quoteIntoReturn2); + $this->selectMock->expects($this->exactly($callNum)) + ->method('join') + ->with( + 'review_entity', + 'main_table.entity_id=' . 'review_entity' . '.entity_id', + ['entity_code'] + ); + $this->model->addEntityFilter($entity, $pkValue); + } + + public function addEntityFilterDataProvider() + { + return [ + [ + 1, + 2, + ['main_table.entity_id=?', 1], + ['main_table.entity_pk_value=?', 2], + 'quoteIntoReturn1', + 'quoteIntoReturn2', + 0 + ], + [ + 'entity', + 2, + ['review_entity.entity_code=?', 'entity'], + ['main_table.entity_pk_value=?', 2], + 'quoteIntoReturn1', + 'quoteIntoReturn2', + 1 + ] + ]; + } + + public function testAddReviewsTotalCount() + { + $this->selectMock->expects($this->once()) + ->method('joinLeft') + ->with( + ['r' => 'review'], + 'main_table.entity_pk_value = r.entity_pk_value', + ['total_reviews' => new \Zend_Db_Expr('COUNT(r.review_id)')] + )->willReturnSelf(); + $this->selectMock->expects($this->once()) + ->method('group'); + $this->model->addReviewsTotalCount(); + } +} From 5650820cd8032adae99b9459d2a34417cbde2f41 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Thu, 23 Apr 2015 15:48:28 -0500 Subject: [PATCH 39/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 --- .../Catalog/Model/Resource/Category.php | 45 ++++++++++++---- .../Catalog/Model/Resource/Product.php | 51 ++++++++++++++++--- .../Model/Import/Proxy/Product/Resource.php | 4 +- app/code/Magento/Store/etc/di.xml | 2 +- app/etc/di.xml | 10 ++++ 5 files changed, 92 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Resource/Category.php b/app/code/Magento/Catalog/Model/Resource/Category.php index f99d1b9ee9d2c..27d7f8b801df5 100644 --- a/app/code/Magento/Catalog/Model/Resource/Category.php +++ b/app/code/Magento/Catalog/Model/Resource/Category.php @@ -92,13 +92,36 @@ public function __construct( $this->_categoryTreeFactory = $categoryTreeFactory; $this->_categoryCollectionFactory = $categoryCollectionFactory; $this->_eventManager = $eventManager; - $this->setType( - \Magento\Catalog\Model\Category::ENTITY - )->setConnection( - $this->_resource->getConnection('catalog_read'), - $this->_resource->getConnection('catalog_write') - ); - $this->_categoryProductTable = $this->getTable('catalog_category_product'); + + $this->_read = 'catalog_read'; + $this->_write = 'catalog_write'; + } + + /** + * Entity type getter and lazy loader + * + * @return \Magento\Eav\Model\Entity\Type + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function getEntityType() + { + if (empty($this->_type)) { + $this->setType(\Magento\Catalog\Model\Category::ENTITY); + } + return parent::getEntityType(); + } + + /** + * Category product table name getter + * + * @return string + */ + public function getCategoryProductTable() + { + if (!$this->_categoryProductTable) { + $this->_categoryProductTable = $this->getTable('catalog_category_product'); + } + return $this->_categoryProductTable; } /** @@ -359,7 +382,7 @@ protected function _saveCategoryProducts($category) */ if (!empty($delete)) { $cond = ['product_id IN(?)' => array_keys($delete), 'category_id=?' => $id]; - $adapter->delete($this->_categoryProductTable, $cond); + $adapter->delete($this->getCategoryProductTable(), $cond); } /** @@ -374,7 +397,7 @@ protected function _saveCategoryProducts($category) 'position' => (int)$position, ]; } - $adapter->insertMultiple($this->_categoryProductTable, $data); + $adapter->insertMultiple($this->getCategoryProductTable(), $data); } /** @@ -384,7 +407,7 @@ protected function _saveCategoryProducts($category) foreach ($update as $productId => $position) { $where = ['category_id = ?' => (int)$id, 'product_id = ?' => (int)$productId]; $bind = ['position' => (int)$position]; - $adapter->update($this->_categoryProductTable, $bind, $where); + $adapter->update($this->getCategoryProductTable(), $bind, $where); } } @@ -417,7 +440,7 @@ protected function _saveCategoryProducts($category) public function getProductsPosition($category) { $select = $this->_getWriteAdapter()->select()->from( - $this->_categoryProductTable, + $this->getCategoryProductTable(), ['product_id', 'position'] )->where( 'category_id = :category_id' diff --git a/app/code/Magento/Catalog/Model/Resource/Product.php b/app/code/Magento/Catalog/Model/Resource/Product.php index 336d8f796577e..6e3bbecb9c360 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product.php +++ b/app/code/Magento/Catalog/Model/Resource/Product.php @@ -91,9 +91,48 @@ public function __construct( $modelFactory, $data ); - $this->setType(\Magento\Catalog\Model\Product::ENTITY)->setConnection('catalog_read', 'catalog_write'); - $this->_productWebsiteTable = $this->getTable('catalog_product_website'); - $this->_productCategoryTable = $this->getTable('catalog_category_product'); + $this->_read = 'catalog_read'; + $this->_write = 'catalog_write'; + } + + /** + * Entity type getter and lazy loader + * + * @return \Magento\Eav\Model\Entity\Type + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function getEntityType() + { + if (empty($this->_type)) { + $this->setType(\Magento\Catalog\Model\Product::ENTITY); + } + return parent::getEntityType(); + } + + /** + * Product Website table name getter + * + * @return string + */ + public function getProductWebsiteTable() + { + if (!$this->_productWebsiteTable) { + $this->_productWebsiteTable = $this->getTable('catalog_product_website'); + } + return $this->_productWebsiteTable; + } + + /** + * Product Category table name getter + * + * @return string + */ + public function getProductCategoryTable() + { + if (!$this->_productCategoryTable) { + $this->_productCategoryTable = $this->getTable('catalog_category_product'); + } + return $this->_productCategoryTable; } /** @@ -171,7 +210,7 @@ public function getCategoryIds($product) $adapter = $this->_getReadAdapter(); $select = $adapter->select()->from( - $this->_productCategoryTable, + $this->getProductCategoryTable(), 'category_id' )->where( 'product_id = ?', @@ -329,7 +368,7 @@ protected function _saveCategories(\Magento\Framework\Object $object) ]; } if ($data) { - $write->insertMultiple($this->_productCategoryTable, $data); + $write->insertMultiple($this->getProductCategoryTable(), $data); } } @@ -337,7 +376,7 @@ protected function _saveCategories(\Magento\Framework\Object $object) foreach ($delete as $categoryId) { $where = ['product_id = ?' => (int)$object->getId(), 'category_id = ?' => (int)$categoryId]; - $write->delete($this->_productCategoryTable, $where); + $write->delete($this->getProductCategoryTable(), $where); } } diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Proxy/Product/Resource.php b/app/code/Magento/CatalogImportExport/Model/Import/Proxy/Product/Resource.php index a71fe9dcc4962..7a10bd844673d 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Proxy/Product/Resource.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Proxy/Product/Resource.php @@ -20,7 +20,7 @@ class Resource extends \Magento\Catalog\Model\Resource\Product */ public function getProductCategoryTable() { - return $this->_productCategoryTable; + return parent::getProductCategoryTable(); } /** @@ -30,6 +30,6 @@ public function getProductCategoryTable() */ public function getProductWebsiteTable() { - return $this->_productWebsiteTable; + return parent::getProductWebsiteTable(); } } diff --git a/app/code/Magento/Store/etc/di.xml b/app/code/Magento/Store/etc/di.xml index ebbc61f6036c8..c1584145c2d3d 100644 --- a/app/code/Magento/Store/etc/di.xml +++ b/app/code/Magento/Store/etc/di.xml @@ -79,7 +79,7 @@ Magento\Framework\Session\Generic\Proxy Magento\Store\Model\Store::CUSTOM_ENTRY_POINT_PARAM - Magento\Framework\UrlInterface + Magento\Framework\UrlInterface\Proxy diff --git a/app/etc/di.xml b/app/etc/di.xml index 10095a200e3bc..c82023fe68ef2 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1101,4 +1101,14 @@ + + + Magento\Framework\UrlInterface\Proxy + + + + + Magento\Framework\App\ViewInterface\Proxy + + From 54a19e9eb155cb9dc5ff766ec20d120cb831b95f Mon Sep 17 00:00:00 2001 From: Joan He Date: Thu, 23 Apr 2015 15:51:47 -0500 Subject: [PATCH 40/68] MAGETWO-36178: Update constructor - \Magento\Ui\DataProvider\Config\Data --- app/code/Magento/Ui/etc/di.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Ui/etc/di.xml b/app/code/Magento/Ui/etc/di.xml index 55a44cd9d4df7..809703e8fe6e5 100644 --- a/app/code/Magento/Ui/etc/di.xml +++ b/app/code/Magento/Ui/etc/di.xml @@ -22,4 +22,9 @@ + + + Magento\Ui\DataProvider\Config\Data\Proxy + + From 3b41c1bf58bda1d7cd73ab3a44d02b6ebae7acb9 Mon Sep 17 00:00:00 2001 From: Joan He Date: Thu, 23 Apr 2015 15:57:41 -0500 Subject: [PATCH 41/68] MAGETWO-36178: Update constructor - \Magento\Sales\Model\Resource\Order\Collection --- app/code/Magento/GoogleAdwords/etc/di.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app/code/Magento/GoogleAdwords/etc/di.xml diff --git a/app/code/Magento/GoogleAdwords/etc/di.xml b/app/code/Magento/GoogleAdwords/etc/di.xml new file mode 100644 index 0000000000000..293db157d7c38 --- /dev/null +++ b/app/code/Magento/GoogleAdwords/etc/di.xml @@ -0,0 +1,14 @@ + + + + + + Magento\Sales\Model\Resource\Order\Collection\Proxy + + + From 3f60d540afd90d112a03b1cd4175c13a95a48425 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Thu, 23 Apr 2015 16:10:59 -0500 Subject: [PATCH 42/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - reverted previous constructor logic --- .../Magento/Framework/View/Result/Page.php | 20 +++--- .../View/Test/Unit/Result/PageTest.php | 68 ++----------------- 2 files changed, 15 insertions(+), 73 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Result/Page.php b/lib/internal/Magento/Framework/View/Result/Page.php index d2184499960c5..2fab155de5668 100644 --- a/lib/internal/Magento/Framework/View/Result/Page.php +++ b/lib/internal/Magento/Framework/View/Result/Page.php @@ -134,19 +134,17 @@ public function __construct( $generatorPool, $isIsolated ); + $this->initPageConfigReader(); } /** - * Page config renderer getter + * Initialize page config reader * - * @return View\Page\Config\Renderer|View\Page\Config\RendererInterface + * @return void */ - protected function getPageConfigRenderer() + protected function initPageConfigReader() { - if (!$this->pageConfigRenderer) { - $this->pageConfigRenderer = $this->pageConfigRendererFactory->create(['pageConfig' => $this->pageConfig]); - } - return $this->pageConfigRenderer; + $this->pageConfigRenderer = $this->pageConfigRendererFactory->create(['pageConfig' => $this->pageConfig]); } /** @@ -232,11 +230,11 @@ protected function render(ResponseInterface $response) $requireJs = $this->getLayout()->getBlock('require.js'); $this->assign([ 'requireJs' => $requireJs ? $requireJs->toHtml() : null, - 'headContent' => $this->getPageConfigRenderer()->renderHeadContent(), + 'headContent' => $this->pageConfigRenderer->renderHeadContent(), 'headAdditional' => $addBlock ? $addBlock->toHtml() : null, - 'htmlAttributes' => $this->getPageConfigRenderer()->renderElementAttributes($config::ELEMENT_TYPE_HTML), - 'headAttributes' => $this->getPageConfigRenderer()->renderElementAttributes($config::ELEMENT_TYPE_HEAD), - 'bodyAttributes' => $this->getPageConfigRenderer()->renderElementAttributes($config::ELEMENT_TYPE_BODY), + 'htmlAttributes' => $this->pageConfigRenderer->renderElementAttributes($config::ELEMENT_TYPE_HTML), + 'headAttributes' => $this->pageConfigRenderer->renderElementAttributes($config::ELEMENT_TYPE_HEAD), + 'bodyAttributes' => $this->pageConfigRenderer->renderElementAttributes($config::ELEMENT_TYPE_BODY), 'loaderIcon' => $this->getViewFileUrl('images/loader-2.gif'), ]); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php index 08176d8088c8c..a01d21d07df7e 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Result/PageTest.php @@ -52,11 +52,6 @@ class PageTest extends \PHPUnit_Framework_TestCase */ protected $pageConfigRenderer; - /** - * @var \Magento\Framework\View\Page\Config\RendererFactory|\PHPUnit_Framework_MockObject_MockObject - */ - protected $pageConfigRendererFactory; - /** * @var \Magento\Framework\View\FileSystem|\PHPUnit_Framework_MockObject_MockObject */ @@ -112,10 +107,14 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $this->pageConfigRendererFactory = $this->getMockBuilder('Magento\Framework\View\Page\Config\RendererFactory') + $pageConfigRendererFactory = $this->getMockBuilder('Magento\Framework\View\Page\Config\RendererFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); + $pageConfigRendererFactory->expects($this->once()) + ->method('create') + ->with(['pageConfig' => $this->pageConfig]) + ->willReturn($this->pageConfigRenderer); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->page = $objectManagerHelper->getObject( @@ -125,7 +124,7 @@ protected function setUp() 'layoutFactory' => $this->layoutFactory, 'context' => $this->context, 'translateInline' => $this->translateInline, - 'pageConfigRendererFactory' => $this->pageConfigRendererFactory, + 'pageConfigRendererFactory' => $pageConfigRendererFactory, ] ); } @@ -244,59 +243,4 @@ public function testAddPageLayoutHandlesWithDefaultHandle() $this->page->addPageLayoutHandles($parameters, $defaultHandle); } - - public function testRenderResult() - { - $layoutReaderPool = $this->getMockBuilder('Magento\Framework\View\Layout\ReaderPool') - ->disableOriginalConstructor() - ->getMock(); - $layoutBuilderFactory = $this->getMockBuilder('Magento\Framework\View\Layout\BuilderFactory') - ->disableOriginalConstructor() - ->getMock(); - $generatorPool = $this->getMockBuilder('Magento\Framework\View\Layout\GeneratorPool') - ->disableOriginalConstructor() - ->getMock(); - $pageLayoutReader = $this->getMockBuilder('Magento\Framework\View\Page\Layout\Reader') - ->disableOriginalConstructor() - ->getMock(); - - /** @var $page \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject*/ - $page = $this->getMockBuilder('Magento\Framework\View\Result\Page') - ->setConstructorArgs( - [ - $this->context, - $this->layoutFactory, - $layoutReaderPool, - $this->translateInline, - $layoutBuilderFactory, - $generatorPool, - $this->pageConfigRendererFactory, - $pageLayoutReader, - 'template', - false - ] - ) - ->setMethods(['renderPage']) - ->getMock(); - - $page->expects($this->any()) - ->method('renderPage') - ->will($this->returnValue('output')); - - /** @var $response \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */ - $response = $this->getMockBuilder('Magento\Framework\App\Response\Http') - ->disableOriginalConstructor() - ->getMock(); - - $this->pageConfigRendererFactory->expects($this->once()) - ->method('create') - ->with(['pageConfig' => $this->pageConfig]) - ->willReturn($this->pageConfigRenderer); - - $this->pageConfig->expects($this->any()) - ->method('getPageLayout') - ->will($this->returnValue('layout')); - - $this->assertEquals($page->renderResult($response), $page); - } } From e507f8275bfaaa9f9f1342d77484c671b948c248 Mon Sep 17 00:00:00 2001 From: Joan He Date: Fri, 24 Apr 2015 08:19:47 -0500 Subject: [PATCH 43/68] MAGETWO-36178: Update constructor - Fixed static test failures --- .../Catalog/Block/Product/ProductList/Toolbar.php | 6 ++++++ .../Unit/Model/Resource/Review/CollectionTest.php | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php index 1f0b4b6bd9389..29be0868558ee 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php @@ -700,10 +700,16 @@ protected function getOrderField() return $this->_orderField; } + /** + * Load Available Orders + * + * @return $this + */ private function loadAvailableOrders() { if ($this->_availableOrder === null) { $this->_availableOrder = $this->_catalogConfig->getAttributeUsedForSortByArray(); } + return $this; } } diff --git a/app/code/Magento/Review/Test/Unit/Model/Resource/Review/CollectionTest.php b/app/code/Magento/Review/Test/Unit/Model/Resource/Review/CollectionTest.php index e1dce20116c16..67e67cdf83817 100644 --- a/app/code/Magento/Review/Test/Unit/Model/Resource/Review/CollectionTest.php +++ b/app/code/Magento/Review/Test/Unit/Model/Resource/Review/CollectionTest.php @@ -70,12 +70,12 @@ public function setUp() return $table; }); $this->model = $this->objectManager->getObject( - '\Magento\Review\Model\Resource\Review\Collection', - [ - 'storeManager' => $this->storeManagerMock, - 'resource' => $this->resourceMock, - ] - ); + '\Magento\Review\Model\Resource\Review\Collection', + [ + 'storeManager' => $this->storeManagerMock, + 'resource' => $this->resourceMock, + ] + ); } From a3a6b02a613709d3d460b777aa034299a8ec9d42 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Fri, 24 Apr 2015 10:07:32 -0500 Subject: [PATCH 44/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - CR fixes --- .../Model/Import/Proxy/Product/Resource.php | 19 ------------------- lib/internal/Magento/Framework/Url.php | 6 +++--- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Proxy/Product/Resource.php b/app/code/Magento/CatalogImportExport/Model/Import/Proxy/Product/Resource.php index 7a10bd844673d..0f68ad9e99503 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Proxy/Product/Resource.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Proxy/Product/Resource.php @@ -13,23 +13,4 @@ class Resource extends \Magento\Catalog\Model\Resource\Product { - /** - * Product to category table. - * - * @return string - */ - public function getProductCategoryTable() - { - return parent::getProductCategoryTable(); - } - - /** - * Product to website table. - * - * @return string - */ - public function getProductWebsiteTable() - { - return parent::getProductWebsiteTable(); - } } diff --git a/lib/internal/Magento/Framework/Url.php b/lib/internal/Magento/Framework/Url.php index ac1fae2d5467b..be9a82a7676f6 100644 --- a/lib/internal/Magento/Framework/Url.php +++ b/lib/internal/Magento/Framework/Url.php @@ -161,7 +161,7 @@ class Url extends \Magento\Framework\Object implements \Magento\Framework\UrlInt * @param \Magento\Framework\Url\ScopeResolverInterface $scopeResolver * @param \Magento\Framework\Session\Generic $session * @param \Magento\Framework\Session\SidResolverInterface $sidResolver - * @param \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver + * @param \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolverFactory * @param \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param string $scopeType @@ -175,7 +175,7 @@ public function __construct( \Magento\Framework\Url\ScopeResolverInterface $scopeResolver, \Magento\Framework\Session\Generic $session, \Magento\Framework\Session\SidResolverInterface $sidResolver, - \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver, + \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolverFactory, \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, $scopeType, @@ -187,7 +187,7 @@ public function __construct( $this->_scopeResolver = $scopeResolver; $this->_session = $session; $this->_sidResolver = $sidResolver; - $this->_routeParamsResolverFactory = $routeParamsResolver; + $this->_routeParamsResolverFactory = $routeParamsResolverFactory; $this->_queryParamsResolver = $queryParamsResolver; $this->_scopeConfig = $scopeConfig; $this->_scopeType = $scopeType; From c005532ce80622fb23ae68c6cbcdabcb0bac8493 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Fri, 24 Apr 2015 10:55:05 -0500 Subject: [PATCH 45/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - CR fixes --- app/code/Magento/Catalog/Model/Resource/Product.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Resource/Product.php b/app/code/Magento/Catalog/Model/Resource/Product.php index 6e3bbecb9c360..6f02829d2bc2a 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product.php +++ b/app/code/Magento/Catalog/Model/Resource/Product.php @@ -162,7 +162,7 @@ public function getWebsiteIds($product) } $select = $adapter->select()->from( - $this->_productWebsiteTable, + $this->getProductWebsiteTable(), 'website_id' )->where( 'product_id = ?', @@ -181,7 +181,7 @@ public function getWebsiteIds($product) public function getWebsiteIdsByProductIds($productIds) { $select = $this->_getWriteAdapter()->select()->from( - $this->_productWebsiteTable, + $this->getProductWebsiteTable(), ['product_id', 'website_id'] )->where( 'product_id IN (?)', @@ -313,14 +313,14 @@ protected function _saveWebsiteIds($product) foreach ($insert as $websiteId) { $data[] = ['product_id' => (int)$product->getId(), 'website_id' => (int)$websiteId]; } - $adapter->insertMultiple($this->_productWebsiteTable, $data); + $adapter->insertMultiple($this->getProductWebsiteTable(), $data); } if (!empty($delete)) { foreach ($delete as $websiteId) { $condition = ['product_id = ?' => (int)$product->getId(), 'website_id = ?' => (int)$websiteId]; - $adapter->delete($this->_productWebsiteTable, $condition); + $adapter->delete($this->getProductWebsiteTable(), $condition); } } From eb0581a7b8c019b295c6b41eb109a57f7c48f3b5 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Fri, 24 Apr 2015 13:28:34 -0500 Subject: [PATCH 46/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - CR fixes --- app/code/Magento/Catalog/etc/di.xml | 2 +- app/etc/di.xml | 2 +- .../Magento/Framework/Test/Unit/UrlTest.php | 78 +++++++++++++------ 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 2d6c9f14934a3..8a4efe5a2b862 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -472,7 +472,7 @@ - Magento\Catalog\Model\Resource\Category\Collection\Proxy + Magento\Catalog\Model\Resource\Category\Proxy diff --git a/app/etc/di.xml b/app/etc/di.xml index c82023fe68ef2..0903447d18185 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1108,7 +1108,7 @@ - Magento\Framework\App\ViewInterface\Proxy + Magento\Framework\App\ViewInterface\Proxy diff --git a/lib/internal/Magento/Framework/Test/Unit/UrlTest.php b/lib/internal/Magento/Framework/Test/Unit/UrlTest.php index 3393f621fcd1d..69e2260002ce0 100644 --- a/lib/internal/Magento/Framework/Test/Unit/UrlTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/UrlTest.php @@ -76,7 +76,7 @@ protected function setUp() * @param bool $resolve * @return \Magento\Framework\Url\RouteParamsResolverFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected function getRouteParamsResolver($resolve = true) + protected function getRouteParamsResolverFactory($resolve = true) { $routeParamsResolverFactoryMock = $this->getMock( 'Magento\Framework\Url\RouteParamsResolverFactory', @@ -155,7 +155,10 @@ public function testGetUseSession() public function testGetBaseUrlNotLinkType() { $model = $this->getUrlModel( - ['scopeResolver' => $this->scopeResolverMock, 'routeParamsResolver' => $this->getRouteParamsResolver()] + [ + 'scopeResolver' => $this->scopeResolverMock, + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory() + ] ); $baseUrl = 'base-url'; @@ -187,9 +190,12 @@ public function testGetUrl($query, $queryResult, $returnUri) $requestMock = $this->getRequestMock(); $routeConfigMock = $this->getMock('Magento\Framework\App\Route\ConfigInterface'); $model = $this->getUrlModel( - ['scopeResolver' => $this->scopeResolverMock, 'routeParamsResolver' => $this->getRouteParamsResolver(), + [ + 'scopeResolver' => $this->scopeResolverMock, + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), 'queryParamsResolver' => $this->queryParamsResolverMock, - 'request' => $requestMock, 'routeConfig' => $routeConfigMock, ] + 'request' => $requestMock, 'routeConfig' => $routeConfigMock, + ] ); $baseUrl = 'http://localhost/index.php/'; @@ -221,7 +227,7 @@ public function testGetUrlIdempotentSetRoutePath() { $model = $this->getUrlModel([ 'scopeResolver' => $this->scopeResolverMock, - 'routeParamsResolver' => $this->getRouteParamsResolver(), + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), ]); $model->setData('route_path', 'catalog/product/view'); @@ -236,7 +242,7 @@ public function testGetUrlIdempotentSetRouteName() { $model = $this->getUrlModel([ 'scopeResolver' => $this->scopeResolverMock, - 'routeParamsResolver' => $this->getRouteParamsResolver(), + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), 'request' => $this->getRequestMock() ]); $model->setData('route_name', 'catalog'); @@ -254,7 +260,7 @@ public function testGetUrlRouteHasParams() ->will($this->returnValue(['foo' => 'bar', 'true' => false])); $model = $this->getUrlModel([ 'scopeResolver' => $this->scopeResolverMock, - 'routeParamsResolver' => $this->getRouteParamsResolver(), + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), 'request' => $this->getRequestMock() ]); @@ -273,7 +279,7 @@ public function testGetUrlRouteUseRewrite() $request->expects($this->once())->method('getAlias')->will($this->returnValue('/catalog/product/view/')); $model = $this->getUrlModel([ 'scopeResolver' => $this->scopeResolverMock, - 'routeParamsResolver' => $this->getRouteParamsResolver(), + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), 'request' => $request, ]); @@ -302,9 +308,12 @@ public function testGetUrlWithAsterisksPath() $requestMock = $this->getRequestMock(); $routeConfigMock = $this->getMock('Magento\Framework\App\Route\ConfigInterface'); $model = $this->getUrlModel( - ['scopeResolver' => $this->scopeResolverMock, 'routeParamsResolver' => $this->getRouteParamsResolver(), + [ + 'scopeResolver' => $this->scopeResolverMock, + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), 'queryParamsResolver' => $this->queryParamsResolverMock, - 'request' => $requestMock, 'routeConfig' => $routeConfigMock, ] + 'request' => $requestMock, 'routeConfig' => $routeConfigMock, + ] ); $baseUrl = 'http://localhost/index.php/'; @@ -335,9 +344,12 @@ public function testGetDirectUrl() $requestMock = $this->getRequestMock(); $routeConfigMock = $this->getMock('Magento\Framework\App\Route\ConfigInterface'); $model = $this->getUrlModel( - ['scopeResolver' => $this->scopeResolverMock, 'routeParamsResolver' => $this->getRouteParamsResolver(), + [ + 'scopeResolver' => $this->scopeResolverMock, + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), 'queryParamsResolver' => $this->queryParamsResolverMock, - 'request' => $requestMock, 'routeConfig' => $routeConfigMock, ] + 'request' => $requestMock, 'routeConfig' => $routeConfigMock, + ] ); $baseUrl = 'http://localhost/index.php/'; @@ -366,7 +378,7 @@ public function testGetRebuiltUrl($url) 'request' => $requestMock, 'sidResolver' => $this->sidResolverMock, 'scopeResolver' => $this->scopeResolverMock, - 'routeParamsResolver' => $this->getRouteParamsResolver(false), + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(false), 'queryParamsResolver' => $this->queryParamsResolverMock, ]); @@ -379,8 +391,12 @@ public function testGetRebuiltUrl($url) public function testGetRedirectUrl() { $model = $this->getUrlModel( - ['routeParamsResolver' => $this->getRouteParamsResolver(), 'session' => $this->sessionMock, - 'sidResolver' => $this->sidResolverMock, 'queryParamsResolver' => $this->queryParamsResolverMock, ] + [ + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), + 'session' => $this->sessionMock, + 'sidResolver' => $this->sidResolverMock, + 'queryParamsResolver' => $this->queryParamsResolverMock, + ] ); $this->sidResolverMock->expects($this->once())->method('getUseSessionInUrl')->will($this->returnValue(true)); @@ -399,8 +415,12 @@ public function testGetRedirectUrl() public function testGetRedirectUrlWithSessionId() { $model = $this->getUrlModel( - ['routeParamsResolver' => $this->getRouteParamsResolver(false), 'session' => $this->sessionMock, - 'sidResolver' => $this->sidResolverMock, 'queryParamsResolver' => $this->queryParamsResolverMock, ] + [ + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(false), + 'session' => $this->sessionMock, + 'sidResolver' => $this->sidResolverMock, + 'queryParamsResolver' => $this->queryParamsResolverMock, + ] ); $this->sidResolverMock->expects($this->once())->method('getUseSessionInUrl')->will($this->returnValue(true)); @@ -425,7 +445,7 @@ public function getRebuiltUrlDataProvider() public function testGetRouteUrlWithValidUrl() { - $model = $this->getUrlModel(['routeParamsResolver' => $this->getRouteParamsResolver(false)]); + $model = $this->getUrlModel(['routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(false)]); $this->routeParamsResolverMock->expects($this->never())->method('unsetData'); $this->assertEquals('http://example.com', $model->getRouteUrl('http://example.com')); @@ -488,7 +508,7 @@ public function testGetConfigData($urlType, $configPath, $isSecure, $isSecureCal $urlSecurityInfoMock = $this->getMock('Magento\Framework\Url\SecurityInfoInterface'); $model = $this->getUrlModel([ 'urlSecurityInfo' => $urlSecurityInfoMock, - 'routeParamsResolver' => $this->getRouteParamsResolver(), + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), 'scopeResolver' => $this->scopeResolverMock, 'scopeConfig' => $this->scopeConfig, ]); @@ -533,7 +553,7 @@ public function getConfigDataDataProvider() public function testGetConfigDataWithSecureIsForcedParam() { $model = $this->getUrlModel([ - 'routeParamsResolver' => $this->getRouteParamsResolver(), + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), 'scopeResolver' => $this->scopeResolverMock, 'scopeConfig' => $this->scopeConfig, ]); @@ -565,8 +585,13 @@ public function testSessionUrlVarWithMatchedHostsAndBaseUrl($html, $result) { $requestMock = $this->getRequestMock(); $model = $this->getUrlModel( - ['session' => $this->sessionMock, 'request' => $requestMock, 'sidResolver' => $this->sidResolverMock, - 'scopeResolver' => $this->scopeResolverMock, 'routeParamsResolver' => $this->getRouteParamsResolver(), ] + [ + 'session' => $this->sessionMock, + 'request' => $requestMock, + 'sidResolver' => $this->sidResolverMock, + 'scopeResolver' => $this->scopeResolverMock, + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), + ] ); $requestMock->expects($this->once()) @@ -588,8 +613,13 @@ public function testSessionUrlVarWithoutMatchedHostsAndBaseUrl() { $requestMock = $this->getRequestMock(); $model = $this->getUrlModel( - ['session' => $this->sessionMock, 'request' => $requestMock, 'sidResolver' => $this->sidResolverMock, - 'scopeResolver' => $this->scopeResolverMock, 'routeParamsResolver' => $this->getRouteParamsResolver(), ] + [ + 'session' => $this->sessionMock, + 'request' => $requestMock, + 'sidResolver' => $this->sidResolverMock, + 'scopeResolver' => $this->scopeResolverMock, + 'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(), + ] ); $requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue('localhost')); From 1dad6e4b73b2b5d22551021bcbd12c38228d18ea Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Fri, 24 Apr 2015 15:22:10 -0500 Subject: [PATCH 47/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - CR fixes --- lib/internal/Magento/Framework/Url.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Url.php b/lib/internal/Magento/Framework/Url.php index be9a82a7676f6..202df3a2516db 100644 --- a/lib/internal/Magento/Framework/Url.php +++ b/lib/internal/Magento/Framework/Url.php @@ -133,12 +133,12 @@ class Url extends \Magento\Framework\Object implements \Magento\Framework\UrlInt /** * @var \Magento\Framework\Url\RouteParamsResolverInterface */ - protected $_routeParamsResolver; + private $_routeParamsResolver; /** * @var \Magento\Framework\Url\RouteParamsResolverFactory */ - protected $_routeParamsResolverFactory; + private $_routeParamsResolverFactory; /** * @var \Magento\Framework\Url\ScopeResolverInterface */ From ae81595c7b497988121da7849ade4ac7eefcc76e Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Fri, 24 Apr 2015 15:24:34 -0500 Subject: [PATCH 48/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - CR fixes --- app/code/Magento/CatalogSearch/etc/di.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/code/Magento/CatalogSearch/etc/di.xml b/app/code/Magento/CatalogSearch/etc/di.xml index 6a4cb5594965b..6e20a71762142 100644 --- a/app/code/Magento/CatalogSearch/etc/di.xml +++ b/app/code/Magento/CatalogSearch/etc/di.xml @@ -230,9 +230,4 @@ - - - Magento\CatalogSearch\Model\Fulltext\Proxy - - From 3c6322d68ce83c8a47ac01ba8b115f8493ab17e5 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Fri, 24 Apr 2015 15:25:14 -0500 Subject: [PATCH 49/68] MAGETWO-36179: Elimination of functional logic in constructors - generate an updated Proxy for layout --- .../Magento/Framework/View/Layout/Proxy.php | 639 ++++++------------ 1 file changed, 222 insertions(+), 417 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Layout/Proxy.php b/lib/internal/Magento/Framework/View/Layout/Proxy.php index 8c399f4e4161a..c794c39d4b5dd 100644 --- a/lib/internal/Magento/Framework/View/Layout/Proxy.php +++ b/lib/internal/Magento/Framework/View/Layout/Proxy.php @@ -1,14 +1,8 @@ objectManager = $objectManager; - $this->instanceName = $instanceName; - $this->isShared = $shared; + public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = '\\Magento\\Framework\\View\\Layout', $shared = true) + { + $this->_objectManager = $objectManager; + $this->_instanceName = $instanceName; + $this->_isShared = $shared; } /** @@ -60,27 +53,23 @@ public function __construct( */ public function __sleep() { - return ['_subject', '_isShared']; + return array('_subject', '_isShared'); } /** * Retrieve ObjectManager from global scope - * - * @return void */ public function __wakeup() { - $this->objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); } /** * Clone proxied instance - * - * @return void */ public function __clone() { - $this->subject = clone $this->getSubject(); + $this->_subject = clone $this->_getSubject(); } /** @@ -88,813 +77,629 @@ public function __clone() * * @return \Magento\Framework\View\Layout */ - protected function getSubject() + protected function _getSubject() { - if (!$this->subject) { - $this->subject = true === $this->isShared - ? $this->objectManager->get($this->instanceName) - : $this->objectManager->create($this->instanceName); + if (!$this->_subject) { + $this->_subject = true === $this->_isShared + ? $this->_objectManager->get($this->_instanceName) + : $this->_objectManager->create($this->_instanceName); } - return $this->subject; + return $this->_subject; } /** - * Retrieve the layout update instance - * - * @return \Magento\Framework\View\Layout\ProcessorInterface + * {@inheritdoc} + */ + public function setGeneratorPool(\Magento\Framework\View\Layout\GeneratorPool $generatorPool) + { + return $this->_getSubject()->setGeneratorPool($generatorPool); + } + + /** + * {@inheritdoc} + */ + public function setBuilder(\Magento\Framework\View\Layout\BuilderInterface $builder) + { + return $this->_getSubject()->setBuilder($builder); + } + + /** + * {@inheritdoc} + */ + public function publicBuild() + { + $this->_getSubject()->publicBuild(); + } + + /** + * {@inheritdoc} */ public function getUpdate() { - return $this->getSubject()->getUpdate(); + return $this->_getSubject()->getUpdate(); } /** - * Layout xml generation - * - * @return $this + * {@inheritdoc} */ public function generateXml() { - return $this->getSubject()->generateXml(); + return $this->_getSubject()->generateXml(); } /** - * Create structure of elements from the loaded XML configuration - * - * @return void + * {@inheritdoc} */ public function generateElements() { - $this->getSubject()->generateElements(); + $this->_getSubject()->generateElements(); } /** - * Get child block if exists - * - * @param string $parentName - * @param string $alias - * @return bool|\Magento\Framework\View\Element\AbstractBlock + * {@inheritdoc} */ public function getChildBlock($parentName, $alias) { - return $this->getSubject()->getChildBlock($parentName, $alias); + return $this->_getSubject()->getChildBlock($parentName, $alias); } /** - * Set child element into layout structure - * - * @param string $parentName - * @param string $elementName - * @param string $alias - * @return $this + * {@inheritdoc} */ public function setChild($parentName, $elementName, $alias) { - return $this->getSubject()->setChild($parentName, $elementName, $alias); + return $this->_getSubject()->setChild($parentName, $elementName, $alias); } /** - * Reorder a child of a specified element - * - * If $offsetOrSibling is null, it will put the element to the end - * If $offsetOrSibling is numeric (integer) value, it will put the element after/before specified position - * Otherwise -- after/before specified sibling - * - * @param string $parentName - * @param string $childName - * @param string|int|null $offsetOrSibling - * @param bool $after - * @return void + * {@inheritdoc} */ public function reorderChild($parentName, $childName, $offsetOrSibling, $after = true) { - $this->getSubject()->reorderChild($parentName, $childName, $offsetOrSibling, $after); + $this->_getSubject()->reorderChild($parentName, $childName, $offsetOrSibling, $after); } /** - * Remove child element from parent - * - * @param string $parentName - * @param string $alias - * @return $this + * {@inheritdoc} */ public function unsetChild($parentName, $alias) { - return $this->getSubject()->unsetChild($parentName, $alias); + return $this->_getSubject()->unsetChild($parentName, $alias); } /** - * Get list of child names - * - * @param string $parentName - * @return array + * {@inheritdoc} */ public function getChildNames($parentName) { - return $this->getSubject()->getChildNames($parentName); + return $this->_getSubject()->getChildNames($parentName); } /** - * Get list of child blocks - * - * Returns associative array of => - * - * @param string $parentName - * @return array + * {@inheritdoc} */ public function getChildBlocks($parentName) { - return $this->getSubject()->getChildBlocks($parentName); + return $this->_getSubject()->getChildBlocks($parentName); } /** - * Get child name by alias - * - * @param string $parentName - * @param string $alias - * @return bool|string + * {@inheritdoc} */ public function getChildName($parentName, $alias) { - return $this->getSubject()->getChildName($parentName, $alias); + return $this->_getSubject()->getChildName($parentName, $alias); } /** - * Find an element in layout, render it and return string with its output - * - * @param string $name - * @param bool $useCache - * @return string + * {@inheritdoc} */ public function renderElement($name, $useCache = true) { - return $this->getSubject()->renderElement($name, $useCache); + return $this->_getSubject()->renderElement($name, $useCache); } /** - * Add element to parent group - * - * @param string $blockName - * @param string $parentGroupName - * @return bool + * {@inheritdoc} + */ + public function renderNonCachedElement($name) + { + return $this->_getSubject()->renderNonCachedElement($name); + } + + /** + * {@inheritdoc} */ public function addToParentGroup($blockName, $parentGroupName) { - return $this->getSubject()->addToParentGroup($blockName, $parentGroupName); + return $this->_getSubject()->addToParentGroup($blockName, $parentGroupName); } /** - * Get element names for specified group - * - * @param string $blockName - * @param string $groupName - * @return array + * {@inheritdoc} */ public function getGroupChildNames($blockName, $groupName) { - return $this->getSubject()->getGroupChildNames($blockName, $groupName); + return $this->_getSubject()->getGroupChildNames($blockName, $groupName); } /** - * Check if element exists in layout structure - * - * @param string $name - * @return bool + * {@inheritdoc} */ public function hasElement($name) { - return $this->getSubject()->hasElement($name); + return $this->_getSubject()->hasElement($name); } /** - * Get property value of an element - * - * @param string $name - * @param string $attribute - * @return mixed + * {@inheritdoc} */ public function getElementProperty($name, $attribute) { - return $this->getSubject()->getElementProperty($name, $attribute); + return $this->_getSubject()->getElementProperty($name, $attribute); } /** - * Whether specified element is a block - * - * @param string $name - * @return bool + * {@inheritdoc} */ public function isBlock($name) { - return $this->getSubject()->isBlock($name); + return $this->_getSubject()->isBlock($name); } /** - * Checks if element with specified name is container - * - * @param string $name - * @return bool + * {@inheritdoc} + */ + public function isUiComponent($name) + { + return $this->_getSubject()->isUiComponent($name); + } + + /** + * {@inheritdoc} */ public function isContainer($name) { - return $this->getSubject()->isContainer($name); + return $this->_getSubject()->isContainer($name); } /** - * Whether the specified element may be manipulated externally - * - * @param string $name - * @return bool + * {@inheritdoc} */ public function isManipulationAllowed($name) { - return $this->getSubject()->isManipulationAllowed($name); + return $this->_getSubject()->isManipulationAllowed($name); } /** - * Save block in blocks registry - * - * @param string $name - * @param \Magento\Framework\View\Element\AbstractBlock $block - * @return $this + * {@inheritdoc} */ public function setBlock($name, $block) { - return $this->getSubject()->setBlock($name, $block); + return $this->_getSubject()->setBlock($name, $block); } /** - * Remove block from registry - * - * @param string $name - * @return $this + * {@inheritdoc} */ public function unsetElement($name) { - return $this->getSubject()->unsetElement($name); + return $this->_getSubject()->unsetElement($name); } /** - * Block Factory - * - * @param string $type - * @param string $name - * @param array $attributes - * @return \Magento\Framework\View\Element\AbstractBlock + * {@inheritdoc} */ - public function createBlock($type, $name = '', array $attributes = []) + public function createBlock($type, $name = '', array $arguments = array()) { - return $this->getSubject()->createBlock($type, $name, $attributes); + return $this->_getSubject()->createBlock($type, $name, $arguments); } /** - * Add a block to registry, create new object if needed - * - * @param string|\Magento\Framework\View\Element\AbstractBlock $block - * @param string $name - * @param string $parent - * @param string $alias - * @return \Magento\Framework\View\Element\AbstractBlock + * {@inheritdoc} */ public function addBlock($block, $name = '', $parent = '', $alias = '') { - return $this->getSubject()->addBlock($block, $name, $parent, $alias); + return $this->_getSubject()->addBlock($block, $name, $parent, $alias); } /** - * Insert container into layout structure - * - * @param string $name - * @param string $label - * @param array $options - * @param string $parent - * @param string $alias - * @return void + * {@inheritdoc} */ - public function addContainer($name, $label, array $options = [], $parent = '', $alias = '') + public function addContainer($name, $label, array $options = array(), $parent = '', $alias = '') { - $this->getSubject()->addContainer($name, $label, $options, $parent, $alias); + $this->_getSubject()->addContainer($name, $label, $options, $parent, $alias); } /** - * Rename element in layout and layout structure - * - * @param string $oldName - * @param string $newName - * @return bool + * {@inheritdoc} */ public function renameElement($oldName, $newName) { - return $this->getSubject()->renameElement($oldName, $newName); + return $this->_getSubject()->renameElement($oldName, $newName); } /** - * Retrieve all blocks from registry as array - * - * @return array + * {@inheritdoc} */ public function getAllBlocks() { - return $this->getSubject()->getAllBlocks(); + return $this->_getSubject()->getAllBlocks(); } /** - * Get block object by name - * - * @param string $name - * @return \Magento\Framework\View\Element\AbstractBlock|bool + * {@inheritdoc} */ public function getBlock($name) { - return $this->getSubject()->getBlock($name); + return $this->_getSubject()->getBlock($name); } /** - * Gets parent name of an element with specified name - * - * @param string $childName - * @return bool|string + * {@inheritdoc} + */ + public function getUiComponent($name) + { + return $this->_getSubject()->getUiComponent($name); + } + + /** + * {@inheritdoc} */ public function getParentName($childName) { - return $this->getSubject()->getParentName($childName); + return $this->_getSubject()->getParentName($childName); } /** - * Get element alias by name - * - * @param string $name - * @return bool|string + * {@inheritdoc} */ public function getElementAlias($name) { - return $this->getSubject()->getElementAlias($name); + return $this->_getSubject()->getElementAlias($name); } /** - * Add an element to output - * - * @param string $name - * @return $this + * {@inheritdoc} */ public function addOutputElement($name) { - return $this->getSubject()->addOutputElement($name); + return $this->_getSubject()->addOutputElement($name); } /** - * Remove an element from output - * - * @param string $name - * @return $this + * {@inheritdoc} */ public function removeOutputElement($name) { - return $this->getSubject()->removeOutputElement($name); + return $this->_getSubject()->removeOutputElement($name); } /** - * Get all blocks marked for output - * - * @return string + * {@inheritdoc} */ public function getOutput() { - return $this->getSubject()->getOutput(); + return $this->_getSubject()->getOutput(); } /** - * Retrieve messages block - * - * @return \Magento\Framework\View\Element\Messages + * {@inheritdoc} */ public function getMessagesBlock() { - return $this->getSubject()->getMessagesBlock(); + return $this->_getSubject()->getMessagesBlock(); } /** - * Get block singleton - * - * @param string $type - * @throws \Magento\Framework\Exception\LocalizedException - * @return \Magento\Framework\App\Helper\AbstractHelper + * {@inheritdoc} */ public function getBlockSingleton($type) { - return $this->getSubject()->getBlockSingleton($type); + return $this->_getSubject()->getBlockSingleton($type); } /** - * @param string $namespace - * @param string $staticType - * @param string $dynamicType - * @param string $type - * @param string $template - * @param array $data - * @return $this + * {@inheritdoc} */ - public function addAdjustableRenderer($namespace, $staticType, $dynamicType, $type, $template, $data = []) + public function addAdjustableRenderer($namespace, $staticType, $dynamicType, $type, $template, $data = array()) { - return $this->getSubject()->addAdjustableRenderer( - $namespace, - $staticType, - $dynamicType, - $type, - $template, - $data - ); + return $this->_getSubject()->addAdjustableRenderer($namespace, $staticType, $dynamicType, $type, $template, $data); } /** - * Get renderer options - * - * @param string $namespace - * @param string $staticType - * @param string $dynamicType - * @return array|null + * {@inheritdoc} */ public function getRendererOptions($namespace, $staticType, $dynamicType) { - return $this->getSubject()->getRendererOptions($namespace, $staticType, $dynamicType); + return $this->_getSubject()->getRendererOptions($namespace, $staticType, $dynamicType); } /** - * Execute renderer - * - * @param string $namespace - * @param string $staticType - * @param string $dynamicType - * @param array $data - * @return void + * {@inheritdoc} */ - public function executeRenderer($namespace, $staticType, $dynamicType, $data = []) + public function executeRenderer($namespace, $staticType, $dynamicType, $data = array()) { - $this->getSubject()->executeRenderer($namespace, $staticType, $dynamicType, $data); + $this->_getSubject()->executeRenderer($namespace, $staticType, $dynamicType, $data); } /** - * Init messages by message storage(s), loading and adding messages to layout messages block - * - * @param string|array $messageGroups - * @return void + * {@inheritdoc} */ - public function initMessages($messageGroups = []) + public function initMessages($messageGroups = array()) { - $this->getSubject()->initMessages($messageGroups); + $this->_getSubject()->initMessages($messageGroups); } /** - * Check is exists non-cacheable layout elements - * - * @return bool + * {@inheritdoc} */ public function isCacheable() { - return $this->getSubject()->isCacheable(); + return $this->_getSubject()->isCacheable(); } /** - * Check is exists non-cacheable layout elements - * - * @return bool + * {@inheritdoc} */ public function isPrivate() { - return $this->getSubject()->isPrivate(); + return $this->_getSubject()->isPrivate(); } /** - * Mark layout as private - * - * @param bool $isPrivate - * @return $this + * {@inheritdoc} */ public function setIsPrivate($isPrivate = true) { - return $this->getSubject()->setIsPrivate($isPrivate); + return $this->_getSubject()->setIsPrivate($isPrivate); } /** - * Sets xml for this configuration - * - * @param \Magento\Framework\Simplexml\Element $node - * @return $this + * {@inheritdoc} + */ + public function getReaderContext() + { + return $this->_getSubject()->getReaderContext(); + } + + /** + * {@inheritdoc} */ public function setXml(\Magento\Framework\Simplexml\Element $node) { - return $this->getSubject()->setXml($node); + return $this->_getSubject()->setXml($node); } /** - * Returns node found by the $path - * - * @param string $path - * @return \Magento\Framework\Simplexml\Element|bool - * @see \Magento\Framework\Simplexml\Element::descend + * {@inheritdoc} */ public function getNode($path = null) { - return $this->getSubject()->getNode($path); + return $this->_getSubject()->getNode($path); } /** - * Returns nodes found by xpath expression - * - * @param string $xpath - * @return \SimpleXMLElement[]|bool + * {@inheritdoc} */ public function getXpath($xpath) { - return $this->getSubject()->getXpath($xpath); + return $this->_getSubject()->getXpath($xpath); } /** - * Set cache - * - * @param \Magento\Framework\Simplexml\Config\Cache\AbstractCache $cache - * @return $this + * {@inheritdoc} */ public function setCache($cache) { - return $this->getSubject()->setCache($cache); + return $this->_getSubject()->setCache($cache); } /** - * Return cache - * - * @return \Magento\Framework\Simplexml\Config\Cache\AbstractCache + * {@inheritdoc} */ public function getCache() { - return $this->getSubject()->getCache(); + return $this->_getSubject()->getCache(); } /** - * Set whether cache is saved - * - * @param boolean $flag - * @return $this + * {@inheritdoc} */ public function setCacheSaved($flag) { - return $this->getSubject()->setCacheSaved($flag); + return $this->_getSubject()->setCacheSaved($flag); } /** - * Return whether cache is saved - * - * @return bool - * - * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * {@inheritdoc} */ public function getCacheSaved() { - return $this->getSubject()->getCacheSaved(); + return $this->_getSubject()->getCacheSaved(); } /** - * Set cache ID - * - * @param string $id - * @return $this + * {@inheritdoc} */ public function setCacheId($id) { - return $this->getSubject()->setCacheId($id); + return $this->_getSubject()->setCacheId($id); } /** - * Return cache ID - * - * @return string + * {@inheritdoc} */ public function getCacheId() { - return $this->getSubject()->getCacheId(); + return $this->_getSubject()->getCacheId(); } /** - * Set cache tags - * - * @param array $tags - * @return $this + * {@inheritdoc} */ public function setCacheTags($tags) { - return $this->getSubject()->setCacheTags($tags); + return $this->_getSubject()->setCacheTags($tags); } /** - * Return cache tags - * - * @return array + * {@inheritdoc} */ public function getCacheTags() { - return $this->getSubject()->getCacheTags(); + return $this->_getSubject()->getCacheTags(); } /** - * Set cache lifetime - * - * @param int $lifetime - * @return $this + * {@inheritdoc} */ public function setCacheLifetime($lifetime) { - return $this->getSubject()->setCacheLifetime($lifetime); + return $this->_getSubject()->setCacheLifetime($lifetime); } /** - * Return cache lifetime - * - * @return int + * {@inheritdoc} */ public function getCacheLifetime() { - return $this->getSubject()->getCacheLifetime(); + return $this->_getSubject()->getCacheLifetime(); } /** - * Set cache checksum - * - * @param string $data - * @return $this + * {@inheritdoc} */ public function setCacheChecksum($data) { - return $this->getSubject()->setCacheChecksum($data); + return $this->_getSubject()->setCacheChecksum($data); } /** - * Update cache checksum - * - * @param string $data - * @return $this + * {@inheritdoc} */ public function updateCacheChecksum($data) { - return $this->getSubject()->updateCacheChecksum($data); + return $this->_getSubject()->updateCacheChecksum($data); } /** - * Return cache checksum - * - * @return string + * {@inheritdoc} */ public function getCacheChecksum() { - return $this->getSubject()->getCacheChecksum(); + return $this->_getSubject()->getCacheChecksum(); } /** - * Get cache checksum ID - * - * @return string + * {@inheritdoc} */ public function getCacheChecksumId() { - return $this->getSubject()->getCacheChecksumId(); + return $this->_getSubject()->getCacheChecksumId(); } /** - * Fetch cache checksum - * - * @return boolean + * {@inheritdoc} */ public function fetchCacheChecksum() { - return $this->getSubject()->fetchCacheChecksum(); + return $this->_getSubject()->fetchCacheChecksum(); } /** - * Validate cache checksum - * - * @return boolean + * {@inheritdoc} */ public function validateCacheChecksum() { - return $this->getSubject()->validateCacheChecksum(); + return $this->_getSubject()->validateCacheChecksum(); } /** - * Load cache - * - * @return boolean + * {@inheritdoc} */ public function loadCache() { - return $this->getSubject()->loadCache(); + return $this->_getSubject()->loadCache(); } /** - * Save cache - * - * @param array $tags - * @return $this + * {@inheritdoc} */ public function saveCache($tags = null) { - return $this->getSubject()->saveCache($tags); + return $this->_getSubject()->saveCache($tags); } /** - * Return Xml of node as string - * - * @return string + * {@inheritdoc} */ public function getXmlString() { - return $this->getSubject()->getXmlString(); + return $this->_getSubject()->getXmlString(); } /** - * Remove cache - * - * @return $this + * {@inheritdoc} */ public function removeCache() { - return $this->getSubject()->removeCache(); + return $this->_getSubject()->removeCache(); } /** - * Imports XML file - * - * @param string $filePath - * @return boolean + * {@inheritdoc} */ public function loadFile($filePath) { - return $this->getSubject()->loadFile($filePath); + return $this->_getSubject()->loadFile($filePath); } /** - * Imports XML string - * - * @param string $string - * @return boolean + * {@inheritdoc} */ public function loadString($string) { - return $this->getSubject()->loadString($string); + return $this->_getSubject()->loadString($string); } /** - * Imports DOM node - * - * @param \DOMNode $dom - * @return bool + * {@inheritdoc} */ public function loadDom(\DOMNode $dom) { - return $this->getSubject()->loadDom($dom); + return $this->_getSubject()->loadDom($dom); } /** - * Create node by $path and set its value. - * - * @param string $path separated by slashes - * @param string $value - * @param boolean $overwrite - * @return $this + * {@inheritdoc} */ public function setNode($path, $value, $overwrite = true) { - return $this->getSubject()->setNode($path, $value, $overwrite); + return $this->_getSubject()->setNode($path, $value, $overwrite); } /** - * Process configuration xml - * - * @return $this + * {@inheritdoc} */ public function applyExtends() { - return $this->getSubject()->applyExtends(); + return $this->_getSubject()->applyExtends(); } /** - * Stub method for processing file data right after loading the file text - * - * @param string $text - * @return string + * {@inheritdoc} */ public function processFileData($text) { - return $this->getSubject()->processFileData($text); + return $this->_getSubject()->processFileData($text); } /** - * Extend configuration - * - * @param \Magento\Framework\Simplexml\Config $config - * @param boolean $overwrite - * @return $this + * {@inheritdoc} */ public function extend(\Magento\Framework\Simplexml\Config $config, $overwrite = true) { - return $this->getSubject()->extend($config, $overwrite); + return $this->_getSubject()->extend($config, $overwrite); } } From 43cd49ddee1f913e8852be8fa8b86011484e7083 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Fri, 24 Apr 2015 15:28:49 -0500 Subject: [PATCH 50/68] MAGETWO-36179: Elimination of functional logic in constructors --- .../Magento/Catalog/Model/Resource/Category/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Resource/Category/Collection.php b/app/code/Magento/Catalog/Model/Resource/Category/Collection.php index 451a76a435e75..f21ce9f363b51 100644 --- a/app/code/Magento/Catalog/Model/Resource/Category/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Category/Collection.php @@ -33,7 +33,7 @@ class Collection extends \Magento\Catalog\Model\Resource\Collection\AbstractColl * * @var string */ - protected $_productTable; + private $_productTable; /** * Store id, that we should count products on @@ -47,7 +47,7 @@ class Collection extends \Magento\Catalog\Model\Resource\Collection\AbstractColl * * @var string */ - protected $_productWebsiteTable; + private $_productWebsiteTable; /** * Load with product count flag From b6a65392d1f9807e59f04c2c632587dfd882ecae Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Fri, 24 Apr 2015 15:57:26 -0500 Subject: [PATCH 51/68] MAGETWO-36179: Elimination of functional logic in constructors - put some other classes behind proxies, commit framework proxies --- app/code/Magento/Quote/etc/di.xml | 5 + app/etc/di.xml | 5 + .../Magento/Framework/App/Action/Action.php | 1 + .../Object/Copy/Config/Data/Proxy.php | 113 ++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 lib/internal/Magento/Framework/Object/Copy/Config/Data/Proxy.php diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml index e9ec5105299af..0b46fc59fb7dc 100644 --- a/app/code/Magento/Quote/etc/di.xml +++ b/app/code/Magento/Quote/etc/di.xml @@ -46,4 +46,9 @@ Magento\Quote\Model\Resource\Quote\Collection\Proxy + + + Magento\Customer\Model\Address\Config\Proxy + + diff --git a/app/etc/di.xml b/app/etc/di.xml index 0903447d18185..7c3f8d5c90516 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -964,6 +964,11 @@ + + + Magento\Framework\Object\Copy\Config\Data\Proxy + + fieldset.xml diff --git a/lib/internal/Magento/Framework/App/Action/Action.php b/lib/internal/Magento/Framework/App/Action/Action.php index 3334b9c810db4..2a4d13a06da22 100644 --- a/lib/internal/Magento/Framework/App/Action/Action.php +++ b/lib/internal/Magento/Framework/App/Action/Action.php @@ -74,6 +74,7 @@ public function __construct(Context $context) $this->_redirect = $context->getRedirect(); $this->_view = $context->getView(); $this->messageManager = $context->getMessageManager(); + $this->_objectManager->create('Magento\Framework\Object\Copy\Config\Data\Proxy'); } /** diff --git a/lib/internal/Magento/Framework/Object/Copy/Config/Data/Proxy.php b/lib/internal/Magento/Framework/Object/Copy/Config/Data/Proxy.php new file mode 100644 index 0000000000000..932fb816e7ac0 --- /dev/null +++ b/lib/internal/Magento/Framework/Object/Copy/Config/Data/Proxy.php @@ -0,0 +1,113 @@ +_objectManager = $objectManager; + $this->_instanceName = $instanceName; + $this->_isShared = $shared; + } + + /** + * @return array + */ + public function __sleep() + { + return array('_subject', '_isShared'); + } + + /** + * Retrieve ObjectManager from global scope + */ + public function __wakeup() + { + $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + } + + /** + * Clone proxied instance + */ + public function __clone() + { + $this->_subject = clone $this->_getSubject(); + } + + /** + * Get proxied instance + * + * @return \Magento\Framework\Object\Copy\Config\Data + */ + protected function _getSubject() + { + if (!$this->_subject) { + $this->_subject = true === $this->_isShared + ? $this->_objectManager->get($this->_instanceName) + : $this->_objectManager->create($this->_instanceName); + } + return $this->_subject; + } + + /** + * {@inheritdoc} + */ + public function merge(array $config) + { + return $this->_getSubject()->merge($config); + } + + /** + * {@inheritdoc} + */ + public function get($path = null, $default = null) + { + return $this->_getSubject()->get($path, $default); + } + + /** + * {@inheritdoc} + */ + public function reset() + { + return $this->_getSubject()->reset(); + } +} From 1874c9bbb496f2b6e6fc7cc73bc2b689be706e41 Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Fri, 24 Apr 2015 16:31:18 -0500 Subject: [PATCH 52/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - CR fixes --- app/code/Magento/Backend/Model/Url.php | 6 +++--- app/code/Magento/Backend/Test/Unit/Model/UrlTest.php | 6 +++--- app/code/Magento/DesignEditor/Model/Url/NavigationMode.php | 6 +++--- .../DesignEditor/Test/Unit/Model/Url/NavigationModeTest.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Backend/Model/Url.php b/app/code/Magento/Backend/Model/Url.php index 265a7237ed37e..36fbfafe66974 100644 --- a/app/code/Magento/Backend/Model/Url.php +++ b/app/code/Magento/Backend/Model/Url.php @@ -83,7 +83,7 @@ class Url extends \Magento\Framework\Url implements \Magento\Backend\Model\UrlIn * @param \Magento\Framework\Url\ScopeResolverInterface $scopeResolver * @param \Magento\Framework\Session\Generic $session * @param \Magento\Framework\Session\SidResolverInterface $sidResolver - * @param \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver + * @param \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolverFactory * @param \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param string $scopeType @@ -105,7 +105,7 @@ public function __construct( \Magento\Framework\Url\ScopeResolverInterface $scopeResolver, \Magento\Framework\Session\Generic $session, \Magento\Framework\Session\SidResolverInterface $sidResolver, - \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver, + \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolverFactory, \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, $scopeType, @@ -126,7 +126,7 @@ public function __construct( $scopeResolver, $session, $sidResolver, - $routeParamsResolver, + $routeParamsResolverFactory, $queryParamsResolver, $scopeConfig, $scopeType, diff --git a/app/code/Magento/Backend/Test/Unit/Model/UrlTest.php b/app/code/Magento/Backend/Test/Unit/Model/UrlTest.php index a53b891a17be5..b833fe25752a0 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/UrlTest.php +++ b/app/code/Magento/Backend/Test/Unit/Model/UrlTest.php @@ -165,7 +165,7 @@ protected function setUp() 'menuConfig' => $this->_menuConfigMock, 'authSession' => $this->_authSessionMock, 'encryptor' => $this->_encryptor, - 'routeParamsResolver' => $this->_paramsResolverMock + 'routeParamsResolverFactory' => $this->_paramsResolverMock ] ); $this->_paramsResolverMock->expects( @@ -186,7 +186,7 @@ protected function setUp() 'menuConfig' => $this->_menuConfigMock, 'authSession' => $this->_authSessionMock, 'encryptor' => $this->_encryptor, - 'routeParamsResolver' => $this->_paramsResolverMock + 'routeParamsResolverFactory' => $this->_paramsResolverMock ] ); @@ -259,7 +259,7 @@ public function testGetAreaFrontName() [ 'backendHelper' => $helperMock, 'authSession' => $this->_authSessionMock, - 'routeParamsResolver' => $this->_paramsResolverMock + 'routeParamsResolverFactory' => $this->_paramsResolverMock ] ); $urlModel->getAreaFrontName(); diff --git a/app/code/Magento/DesignEditor/Model/Url/NavigationMode.php b/app/code/Magento/DesignEditor/Model/Url/NavigationMode.php index af413fcd477b0..cb54368e51939 100644 --- a/app/code/Magento/DesignEditor/Model/Url/NavigationMode.php +++ b/app/code/Magento/DesignEditor/Model/Url/NavigationMode.php @@ -38,7 +38,7 @@ class NavigationMode extends \Magento\Framework\Url * @param \Magento\Framework\Url\ScopeResolverInterface $scopeResolver * @param \Magento\Framework\Session\Generic $session * @param \Magento\Framework\Session\SidResolverInterface $sidResolver - * @param \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver + * @param \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolverFactory * @param \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param string $scopeType @@ -53,7 +53,7 @@ public function __construct( \Magento\Framework\Url\ScopeResolverInterface $scopeResolver, \Magento\Framework\Session\Generic $session, \Magento\Framework\Session\SidResolverInterface $sidResolver, - \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver, + \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolverFactory, \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, $scopeType, @@ -75,7 +75,7 @@ public function __construct( $scopeResolver, $session, $sidResolver, - $routeParamsResolver, + $routeParamsResolverFactory, $queryParamsResolver, $scopeConfig, $scopeType, diff --git a/app/code/Magento/DesignEditor/Test/Unit/Model/Url/NavigationModeTest.php b/app/code/Magento/DesignEditor/Test/Unit/Model/Url/NavigationModeTest.php index e6de82bcf54ee..e4ee8ff763659 100644 --- a/app/code/Magento/DesignEditor/Test/Unit/Model/Url/NavigationModeTest.php +++ b/app/code/Magento/DesignEditor/Test/Unit/Model/Url/NavigationModeTest.php @@ -90,7 +90,7 @@ protected function setUp() [ 'helper' => $this->_designHelperMock, 'data' => $this->_testData, - 'routeParamsResolver' => $this->_routeParamsMock, + 'routeParamsResolverFactory' => $this->_routeParamsMock, 'scopeResolver' => $this->_scopeResolverMock ] ); From 26c42d0843e552037b302e0ba5c74890be76793b Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Fri, 24 Apr 2015 16:34:29 -0500 Subject: [PATCH 53/68] MAGETWO-36179: Elimination of functional logic in constructors --- lib/internal/Magento/Framework/App/Action/Action.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Action/Action.php b/lib/internal/Magento/Framework/App/Action/Action.php index 2a4d13a06da22..3334b9c810db4 100644 --- a/lib/internal/Magento/Framework/App/Action/Action.php +++ b/lib/internal/Magento/Framework/App/Action/Action.php @@ -74,7 +74,6 @@ public function __construct(Context $context) $this->_redirect = $context->getRedirect(); $this->_view = $context->getView(); $this->messageManager = $context->getMessageManager(); - $this->_objectManager->create('Magento\Framework\Object\Copy\Config\Data\Proxy'); } /** From 2cd6ab8633aed0955db8bba0c8c08a7fb6e55eeb Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Fri, 24 Apr 2015 16:46:55 -0500 Subject: [PATCH 54/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - CR fixes --- .../Framework/App/ViewInterface/Proxy.php | 185 ++++++++++++++++ .../Magento/Framework/UrlInterface/Proxy.php | 201 ++++++++++++++++++ 2 files changed, 386 insertions(+) create mode 100644 lib/internal/Magento/Framework/App/ViewInterface/Proxy.php create mode 100644 lib/internal/Magento/Framework/UrlInterface/Proxy.php diff --git a/lib/internal/Magento/Framework/App/ViewInterface/Proxy.php b/lib/internal/Magento/Framework/App/ViewInterface/Proxy.php new file mode 100644 index 0000000000000..7a3e778950307 --- /dev/null +++ b/lib/internal/Magento/Framework/App/ViewInterface/Proxy.php @@ -0,0 +1,185 @@ +_objectManager = $objectManager; + $this->_instanceName = $instanceName; + $this->_isShared = $shared; + } + + /** + * @return array + */ + public function __sleep() + { + return array('_subject', '_isShared'); + } + + /** + * Retrieve ObjectManager from global scope + */ + public function __wakeup() + { + $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + } + + /** + * Clone proxied instance + */ + public function __clone() + { + $this->_subject = clone $this->_getSubject(); + } + + /** + * Get proxied instance + * + * @return \Magento\Framework\App\ViewInterface + */ + protected function _getSubject() + { + if (!$this->_subject) { + $this->_subject = true === $this->_isShared + ? $this->_objectManager->get($this->_instanceName) + : $this->_objectManager->create($this->_instanceName); + } + return $this->_subject; + } + + /** + * {@inheritdoc} + */ + public function loadLayoutUpdates() + { + return $this->_getSubject()->loadLayoutUpdates(); + } + + /** + * {@inheritdoc} + */ + public function renderLayout($output = '') + { + return $this->_getSubject()->renderLayout($output); + } + + /** + * {@inheritdoc} + */ + public function getDefaultLayoutHandle() + { + return $this->_getSubject()->getDefaultLayoutHandle(); + } + + /** + * {@inheritdoc} + */ + public function loadLayout($handles = null, $generateBlocks = true, $generateXml = true, $addActionHandles = true) + { + return $this->_getSubject()->loadLayout($handles, $generateBlocks, $generateXml, $addActionHandles); + } + + /** + * {@inheritdoc} + */ + public function generateLayoutXml() + { + return $this->_getSubject()->generateLayoutXml(); + } + + /** + * {@inheritdoc} + */ + public function addPageLayoutHandles(array $parameters = array(), $defaultHandle = null) + { + return $this->_getSubject()->addPageLayoutHandles($parameters, $defaultHandle); + } + + /** + * {@inheritdoc} + */ + public function generateLayoutBlocks() + { + return $this->_getSubject()->generateLayoutBlocks(); + } + + /** + * {@inheritdoc} + */ + public function getPage() + { + return $this->_getSubject()->getPage(); + } + + /** + * {@inheritdoc} + */ + public function getLayout() + { + return $this->_getSubject()->getLayout(); + } + + /** + * {@inheritdoc} + */ + public function addActionLayoutHandles() + { + return $this->_getSubject()->addActionLayoutHandles(); + } + + /** + * {@inheritdoc} + */ + public function setIsLayoutLoaded($value) + { + return $this->_getSubject()->setIsLayoutLoaded($value); + } + + /** + * {@inheritdoc} + */ + public function isLayoutLoaded() + { + return $this->_getSubject()->isLayoutLoaded(); + } +} diff --git a/lib/internal/Magento/Framework/UrlInterface/Proxy.php b/lib/internal/Magento/Framework/UrlInterface/Proxy.php new file mode 100644 index 0000000000000..16dae48577683 --- /dev/null +++ b/lib/internal/Magento/Framework/UrlInterface/Proxy.php @@ -0,0 +1,201 @@ +_objectManager = $objectManager; + $this->_instanceName = $instanceName; + $this->_isShared = $shared; + } + + /** + * @return array + */ + public function __sleep() + { + return array('_subject', '_isShared'); + } + + /** + * Retrieve ObjectManager from global scope + */ + public function __wakeup() + { + $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + } + + /** + * Clone proxied instance + */ + public function __clone() + { + $this->_subject = clone $this->_getSubject(); + } + + /** + * Get proxied instance + * + * @return \Magento\Framework\UrlInterface + */ + protected function _getSubject() + { + if (!$this->_subject) { + $this->_subject = true === $this->_isShared + ? $this->_objectManager->get($this->_instanceName) + : $this->_objectManager->create($this->_instanceName); + } + return $this->_subject; + } + + /** + * {@inheritdoc} + */ + public function getUseSession() + { + return $this->_getSubject()->getUseSession(); + } + + /** + * {@inheritdoc} + */ + public function getBaseUrl($params = array()) + { + return $this->_getSubject()->getBaseUrl($params); + } + + /** + * {@inheritdoc} + */ + public function getCurrentUrl() + { + return $this->_getSubject()->getCurrentUrl(); + } + + /** + * {@inheritdoc} + */ + public function getRouteUrl($routePath = null, $routeParams = null) + { + return $this->_getSubject()->getRouteUrl($routePath, $routeParams); + } + + /** + * {@inheritdoc} + */ + public function addSessionParam() + { + return $this->_getSubject()->addSessionParam(); + } + + /** + * {@inheritdoc} + */ + public function addQueryParams(array $data) + { + return $this->_getSubject()->addQueryParams($data); + } + + /** + * {@inheritdoc} + */ + public function setQueryParam($key, $data) + { + return $this->_getSubject()->setQueryParam($key, $data); + } + + /** + * {@inheritdoc} + */ + public function getUrl($routePath = null, $routeParams = null) + { + return $this->_getSubject()->getUrl($routePath, $routeParams); + } + + /** + * {@inheritdoc} + */ + public function escape($value) + { + return $this->_getSubject()->escape($value); + } + + /** + * {@inheritdoc} + */ + public function getDirectUrl($url, $params = array()) + { + return $this->_getSubject()->getDirectUrl($url, $params); + } + + /** + * {@inheritdoc} + */ + public function sessionUrlVar($html) + { + return $this->_getSubject()->sessionUrlVar($html); + } + + /** + * {@inheritdoc} + */ + public function isOwnOriginUrl() + { + return $this->_getSubject()->isOwnOriginUrl(); + } + + /** + * {@inheritdoc} + */ + public function getRedirectUrl($url) + { + return $this->_getSubject()->getRedirectUrl($url); + } + + /** + * {@inheritdoc} + */ + public function setScope($params) + { + return $this->_getSubject()->setScope($params); + } +} From ec6c23d8a1715315ad974fdfbc0d5c5f9e16a469 Mon Sep 17 00:00:00 2001 From: Joan He Date: Sun, 26 Apr 2015 00:23:37 -0500 Subject: [PATCH 55/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - fixed integration test failures --- app/etc/di.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/etc/di.xml b/app/etc/di.xml index 7c3f8d5c90516..0b759ff625446 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1111,9 +1111,4 @@ Magento\Framework\UrlInterface\Proxy - - - Magento\Framework\App\ViewInterface\Proxy - - From bee4cf95eac93563c5419f9beeeba3fb3f6b855c Mon Sep 17 00:00:00 2001 From: Joan He Date: Sun, 26 Apr 2015 00:42:46 -0500 Subject: [PATCH 56/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - fixed static test failures --- .../Framework/App/ViewInterface/Proxy.php | 185 ------------------ .../Object/Copy/Config/Data/Proxy.php | 17 +- lib/internal/Magento/Framework/Url.php | 1 + .../Magento/Framework/View/Layout/Proxy.php | 37 +++- 4 files changed, 43 insertions(+), 197 deletions(-) delete mode 100644 lib/internal/Magento/Framework/App/ViewInterface/Proxy.php diff --git a/lib/internal/Magento/Framework/App/ViewInterface/Proxy.php b/lib/internal/Magento/Framework/App/ViewInterface/Proxy.php deleted file mode 100644 index 7a3e778950307..0000000000000 --- a/lib/internal/Magento/Framework/App/ViewInterface/Proxy.php +++ /dev/null @@ -1,185 +0,0 @@ -_objectManager = $objectManager; - $this->_instanceName = $instanceName; - $this->_isShared = $shared; - } - - /** - * @return array - */ - public function __sleep() - { - return array('_subject', '_isShared'); - } - - /** - * Retrieve ObjectManager from global scope - */ - public function __wakeup() - { - $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - } - - /** - * Clone proxied instance - */ - public function __clone() - { - $this->_subject = clone $this->_getSubject(); - } - - /** - * Get proxied instance - * - * @return \Magento\Framework\App\ViewInterface - */ - protected function _getSubject() - { - if (!$this->_subject) { - $this->_subject = true === $this->_isShared - ? $this->_objectManager->get($this->_instanceName) - : $this->_objectManager->create($this->_instanceName); - } - return $this->_subject; - } - - /** - * {@inheritdoc} - */ - public function loadLayoutUpdates() - { - return $this->_getSubject()->loadLayoutUpdates(); - } - - /** - * {@inheritdoc} - */ - public function renderLayout($output = '') - { - return $this->_getSubject()->renderLayout($output); - } - - /** - * {@inheritdoc} - */ - public function getDefaultLayoutHandle() - { - return $this->_getSubject()->getDefaultLayoutHandle(); - } - - /** - * {@inheritdoc} - */ - public function loadLayout($handles = null, $generateBlocks = true, $generateXml = true, $addActionHandles = true) - { - return $this->_getSubject()->loadLayout($handles, $generateBlocks, $generateXml, $addActionHandles); - } - - /** - * {@inheritdoc} - */ - public function generateLayoutXml() - { - return $this->_getSubject()->generateLayoutXml(); - } - - /** - * {@inheritdoc} - */ - public function addPageLayoutHandles(array $parameters = array(), $defaultHandle = null) - { - return $this->_getSubject()->addPageLayoutHandles($parameters, $defaultHandle); - } - - /** - * {@inheritdoc} - */ - public function generateLayoutBlocks() - { - return $this->_getSubject()->generateLayoutBlocks(); - } - - /** - * {@inheritdoc} - */ - public function getPage() - { - return $this->_getSubject()->getPage(); - } - - /** - * {@inheritdoc} - */ - public function getLayout() - { - return $this->_getSubject()->getLayout(); - } - - /** - * {@inheritdoc} - */ - public function addActionLayoutHandles() - { - return $this->_getSubject()->addActionLayoutHandles(); - } - - /** - * {@inheritdoc} - */ - public function setIsLayoutLoaded($value) - { - return $this->_getSubject()->setIsLayoutLoaded($value); - } - - /** - * {@inheritdoc} - */ - public function isLayoutLoaded() - { - return $this->_getSubject()->isLayoutLoaded(); - } -} diff --git a/lib/internal/Magento/Framework/Object/Copy/Config/Data/Proxy.php b/lib/internal/Magento/Framework/Object/Copy/Config/Data/Proxy.php index 932fb816e7ac0..ea974307333d3 100644 --- a/lib/internal/Magento/Framework/Object/Copy/Config/Data/Proxy.php +++ b/lib/internal/Magento/Framework/Object/Copy/Config/Data/Proxy.php @@ -1,4 +1,8 @@ _objectManager = $objectManager; $this->_instanceName = $instanceName; $this->_isShared = $shared; @@ -53,11 +60,13 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan */ public function __sleep() { - return array('_subject', '_isShared'); + return ['_subject', '_isShared']; } /** * Retrieve ObjectManager from global scope + * + * @return void */ public function __wakeup() { @@ -66,6 +75,8 @@ public function __wakeup() /** * Clone proxied instance + * + * @return void */ public function __clone() { diff --git a/lib/internal/Magento/Framework/Url.php b/lib/internal/Magento/Framework/Url.php index 202df3a2516db..697e461df050f 100644 --- a/lib/internal/Magento/Framework/Url.php +++ b/lib/internal/Magento/Framework/Url.php @@ -56,6 +56,7 @@ * - G: route_path * - H: route_url * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Url extends \Magento\Framework\Object implements \Magento\Framework\UrlInterface { diff --git a/lib/internal/Magento/Framework/View/Layout/Proxy.php b/lib/internal/Magento/Framework/View/Layout/Proxy.php index c794c39d4b5dd..95220e34913df 100644 --- a/lib/internal/Magento/Framework/View/Layout/Proxy.php +++ b/lib/internal/Magento/Framework/View/Layout/Proxy.php @@ -1,8 +1,13 @@ _objectManager = $objectManager; $this->_instanceName = $instanceName; $this->_isShared = $shared; @@ -53,11 +61,13 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan */ public function __sleep() { - return array('_subject', '_isShared'); + return ['_subject', '_isShared']; } /** * Retrieve ObjectManager from global scope + * + * @return void */ public function __wakeup() { @@ -66,6 +76,8 @@ public function __wakeup() /** * Clone proxied instance + * + * @return void */ public function __clone() { @@ -290,7 +302,7 @@ public function unsetElement($name) /** * {@inheritdoc} */ - public function createBlock($type, $name = '', array $arguments = array()) + public function createBlock($type, $name = '', array $arguments = []) { return $this->_getSubject()->createBlock($type, $name, $arguments); } @@ -306,7 +318,7 @@ public function addBlock($block, $name = '', $parent = '', $alias = '') /** * {@inheritdoc} */ - public function addContainer($name, $label, array $options = array(), $parent = '', $alias = '') + public function addContainer($name, $label, array $options = [], $parent = '', $alias = '') { $this->_getSubject()->addContainer($name, $label, $options, $parent, $alias); } @@ -402,9 +414,16 @@ public function getBlockSingleton($type) /** * {@inheritdoc} */ - public function addAdjustableRenderer($namespace, $staticType, $dynamicType, $type, $template, $data = array()) + public function addAdjustableRenderer($namespace, $staticType, $dynamicType, $type, $template, $data = []) { - return $this->_getSubject()->addAdjustableRenderer($namespace, $staticType, $dynamicType, $type, $template, $data); + return $this->_getSubject()->addAdjustableRenderer( + $namespace, + $staticType, + $dynamicType, + $type, + $template, + $data + ); } /** @@ -418,7 +437,7 @@ public function getRendererOptions($namespace, $staticType, $dynamicType) /** * {@inheritdoc} */ - public function executeRenderer($namespace, $staticType, $dynamicType, $data = array()) + public function executeRenderer($namespace, $staticType, $dynamicType, $data = []) { $this->_getSubject()->executeRenderer($namespace, $staticType, $dynamicType, $data); } @@ -426,7 +445,7 @@ public function executeRenderer($namespace, $staticType, $dynamicType, $data = a /** * {@inheritdoc} */ - public function initMessages($messageGroups = array()) + public function initMessages($messageGroups = []) { $this->_getSubject()->initMessages($messageGroups); } From e12a3919bb7c9e30b4530978b34c936699843b68 Mon Sep 17 00:00:00 2001 From: Joan He Date: Sun, 26 Apr 2015 00:49:34 -0500 Subject: [PATCH 57/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - fixed static test failures --- .../Magento/Framework/UrlInterface/Proxy.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/UrlInterface/Proxy.php b/lib/internal/Magento/Framework/UrlInterface/Proxy.php index 16dae48577683..7ed1a1bbc7bff 100644 --- a/lib/internal/Magento/Framework/UrlInterface/Proxy.php +++ b/lib/internal/Magento/Framework/UrlInterface/Proxy.php @@ -1,4 +1,8 @@ _objectManager = $objectManager; $this->_instanceName = $instanceName; $this->_isShared = $shared; @@ -53,11 +60,13 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan */ public function __sleep() { - return array('_subject', '_isShared'); + return ['_subject', '_isShared']; } /** * Retrieve ObjectManager from global scope + * + * @return void */ public function __wakeup() { @@ -66,6 +75,8 @@ public function __wakeup() /** * Clone proxied instance + * + * @return void */ public function __clone() { @@ -98,7 +109,7 @@ public function getUseSession() /** * {@inheritdoc} */ - public function getBaseUrl($params = array()) + public function getBaseUrl($params = []) { return $this->_getSubject()->getBaseUrl($params); } @@ -162,7 +173,7 @@ public function escape($value) /** * {@inheritdoc} */ - public function getDirectUrl($url, $params = array()) + public function getDirectUrl($url, $params = []) { return $this->_getSubject()->getDirectUrl($url, $params); } From 21c746547311d65471a17fcc44e69f321dd609e8 Mon Sep 17 00:00:00 2001 From: Joan He Date: Mon, 27 Apr 2015 08:58:29 -0500 Subject: [PATCH 58/68] MAGETWO-34216: Elimination of functional logic in constructors - Part 1 - fixed static test failures --- .../Magento/Test/Integrity/Readme/_files/blacklist/ce.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Readme/_files/blacklist/ce.txt b/dev/tests/static/testsuite/Magento/Test/Integrity/Readme/_files/blacklist/ce.txt index 2fd6ad123621c..564d756255d7e 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Readme/_files/blacklist/ce.txt +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Readme/_files/blacklist/ce.txt @@ -35,5 +35,6 @@ lib/internal/Magento/Framework/System lib/internal/Magento/Framework/Test lib/internal/Magento/Framework/App/Utility lib/internal/Magento/Framework/Url +lib/internal/Magento/Framework/UrlInterface lib/internal/Magento/Framework/Xml lib/internal/Magento/Framework From d1ae42d1ae5c4482f1162f9a0061d78af8e7f72f Mon Sep 17 00:00:00 2001 From: Maksym Savich Date: Tue, 28 Apr 2015 12:14:04 -0500 Subject: [PATCH 59/68] MAGETWO-36289: Widget title not escaped properly - Bug fixed, Thests fixed/implemented. --- .../Block/Adminhtml/Block/Widget/Chooser.php | 2 +- .../Block/Adminhtml/Page/Widget/Chooser.php | 2 +- .../Adminhtml/Block/Widget/ChooserTest.php | 49 +++- .../Adminhtml/Page/Widget/ChooserTest.php | 271 ++++++++++++++++++ 4 files changed, 308 insertions(+), 16 deletions(-) create mode 100644 app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Page/Widget/ChooserTest.php diff --git a/app/code/Magento/Cms/Block/Adminhtml/Block/Widget/Chooser.php b/app/code/Magento/Cms/Block/Adminhtml/Block/Widget/Chooser.php index fed2f67da6f17..11a83c181d64f 100644 --- a/app/code/Magento/Cms/Block/Adminhtml/Block/Widget/Chooser.php +++ b/app/code/Magento/Cms/Block/Adminhtml/Block/Widget/Chooser.php @@ -81,7 +81,7 @@ public function prepareElementHtml(\Magento\Framework\Data\Form\Element\Abstract if ($element->getValue()) { $block = $this->_blockFactory->create()->load($element->getValue()); if ($block->getId()) { - $chooser->setLabel($block->getTitle()); + $chooser->setLabel($this->escapeHtml($block->getTitle())); } } diff --git a/app/code/Magento/Cms/Block/Adminhtml/Page/Widget/Chooser.php b/app/code/Magento/Cms/Block/Adminhtml/Page/Widget/Chooser.php index addaf3f4926b8..54c169c890a9b 100644 --- a/app/code/Magento/Cms/Block/Adminhtml/Page/Widget/Chooser.php +++ b/app/code/Magento/Cms/Block/Adminhtml/Page/Widget/Chooser.php @@ -98,7 +98,7 @@ public function prepareElementHtml(\Magento\Framework\Data\Form\Element\Abstract if ($element->getValue()) { $page = $this->_pageFactory->create()->load((int)$element->getValue()); if ($page->getId()) { - $chooser->setLabel($page->getTitle()); + $chooser->setLabel($this->escapeHtml($page->getTitle())); } } diff --git a/app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Block/Widget/ChooserTest.php b/app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Block/Widget/ChooserTest.php index 0c075194e3330..55761dae44ac9 100644 --- a/app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Block/Widget/ChooserTest.php +++ b/app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Block/Widget/ChooserTest.php @@ -35,6 +35,11 @@ class ChooserTest extends \PHPUnit_Framework_TestCase */ protected $urlBuilderMock; + /** + * @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject + */ + protected $escaper; + /** * @var \Magento\Cms\Model\BlockFactory|\PHPUnit_Framework_MockObject_MockObject */ @@ -66,6 +71,14 @@ protected function setUp() $this->urlBuilderMock = $this->getMockBuilder('Magento\Framework\UrlInterface') ->disableOriginalConstructor() ->getMock(); + $this->escaper = $this->getMockBuilder('Magento\Framework\Escaper') + ->disableOriginalConstructor() + ->setMethods( + [ + 'escapeHtml', + ] + ) + ->getMock(); $this->blockFactoryMock = $this->getMockBuilder('Magento\Cms\Model\BlockFactory') ->setMethods( [ @@ -90,6 +103,7 @@ protected function setUp() [ 'getTitle', 'load', + 'getId', ] ) ->getMock(); @@ -112,15 +126,16 @@ protected function setUp() $this->context = $objectManager->getObject( 'Magento\Backend\Block\Template\Context', [ - 'layout' => $this->layoutMock, + 'layout' => $this->layoutMock, 'mathRandom' => $this->mathRandomMock, - 'urlBuilder' => $this->urlBuilderMock + 'urlBuilder' => $this->urlBuilderMock, + 'escaper' => $this->escaper, ] ); $this->this = $objectManager->getObject( 'Magento\Cms\Block\Adminhtml\Block\Widget\Chooser', [ - 'context' => $this->context, + 'context' => $this->context, 'blockFactory' => $this->blockFactoryMock ] ); @@ -135,13 +150,14 @@ protected function setUp() */ public function testPrepareElementHtml($elementValue, $modelBlockId) { - $elementId = 1; - $uniqId = '126hj4h3j73hk7b347jhkl37gb34'; - $sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34'; - $config = ['key1' => 'value1']; - $fieldsetId = 2; - $html = 'some html'; - $title = 'some title'; + $elementId = 1; + $uniqId = '126hj4h3j73hk7b347jhkl37gb34'; + $sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34'; + $config = ['key1' => 'value1']; + $fieldsetId = 2; + $html = 'some html'; + $title = 'some ">; title'; + $titleEscaped = 'some "><img src=y onerror=prompt(document.domain)>; title'; $this->this->setConfig($config); $this->this->setFieldsetId($fieldsetId); @@ -197,13 +213,18 @@ public function testPrepareElementHtml($elementValue, $modelBlockId) $this->modelBlockMock->expects($this->any()) ->method('getTitle') ->willReturn($title); - $this->chooserMock->expects($this->any()) - ->method('setLabel') - ->with($title) - ->willReturnSelf(); $this->chooserMock->expects($this->atLeastOnce()) ->method('toHtml') ->willReturn($html); + if (!empty($elementValue) && !empty($modelBlockId)) { + $this->escaper->expects(($this->atLeastOnce())) + ->method('escapeHtml') + ->willReturn($titleEscaped); + $this->chooserMock->expects($this->atLeastOnce()) + ->method('setLabel') + ->with($titleEscaped) + ->willReturnSelf(); + } $this->elementMock->expects($this->atLeastOnce()) ->method('setData') ->with('after_element_html', $html) diff --git a/app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Page/Widget/ChooserTest.php b/app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Page/Widget/ChooserTest.php new file mode 100644 index 0000000000000..75107bcb42de1 --- /dev/null +++ b/app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Page/Widget/ChooserTest.php @@ -0,0 +1,271 @@ +layoutMock = $this->getMockBuilder('Magento\Framework\View\LayoutInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->mathRandomMock = $this->getMockBuilder('Magento\Framework\Math\Random') + ->disableOriginalConstructor() + ->getMock(); + $this->urlBuilderMock = $this->getMockBuilder('Magento\Framework\UrlInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->escaper = $this->getMockBuilder('Magento\Framework\Escaper') + ->disableOriginalConstructor() + ->setMethods( + [ + 'escapeHtml', + ] + ) + ->getMock(); + $this->pageFactoryMock = $this->getMockBuilder('Magento\Cms\Model\PageFactory') + ->setMethods( + [ + 'create', + ] + ) + ->disableOriginalConstructor() + ->getMock(); + $this->elementMock = $this->getMockBuilder('Magento\Framework\Data\Form\Element\AbstractElement') + ->disableOriginalConstructor() + ->setMethods( + [ + 'getId', + 'getValue', + 'setData', + ] + ) + ->getMock(); + $this->cmsPageMock = $this->getMockBuilder('Magento\Cms\Model\Page') + ->disableOriginalConstructor() + ->setMethods( + [ + 'getTitle', + 'load', + 'getId', + ] + ) + ->getMock(); + $this->chooserMock = $this->getMockBuilder('Magento\Framework\View\Element\BlockInterface') + ->disableOriginalConstructor() + ->setMethods( + [ + 'setElement', + 'setConfig', + 'setFieldsetId', + 'setSourceUrl', + 'setUniqId', + 'setLabel', + 'toHtml', + ] + ) + ->getMock(); + + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->context = $objectManager->getObject( + 'Magento\Backend\Block\Template\Context', + [ + 'layout' => $this->layoutMock, + 'mathRandom' => $this->mathRandomMock, + 'urlBuilder' => $this->urlBuilderMock, + 'escaper' => $this->escaper, + ] + ); + $this->this = $objectManager->getObject( + 'Magento\Cms\Block\Adminhtml\Page\Widget\Chooser', + [ + 'context' => $this->context, + 'pageFactory' => $this->pageFactoryMock + ] + ); + } + + /** + * @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml + * + * @param string $elementValue + * @param integer|null $cmsPageId + * + * @dataProvider prepareElementHtmlDataProvider + */ + public function testPrepareElementHtml($elementValue, $cmsPageId) + { + //$elementValue = 12345; + //$cmsPageId = 1; + $elementId = 1; + $uniqId = '126hj4h3j73hk7b347jhkl37gb34'; + $sourceUrl = 'cms/page_widget/chooser/126hj4h3j73hk7b347jhkl37gb34'; + $config = ['key1' => 'value1']; + $fieldsetId = 2; + $html = 'some html'; + $title = 'some ">; title'; + $titleEscaped = 'some "><img src=y onerror=prompt(document.domain)>; title'; + + $this->this->setConfig($config); + $this->this->setFieldsetId($fieldsetId); + + $this->elementMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn($elementId); + $this->mathRandomMock->expects($this->atLeastOnce()) + ->method('getUniqueHash') + ->with($elementId) + ->willReturn($uniqId); + $this->urlBuilderMock->expects($this->atLeastOnce()) + ->method('getUrl') + ->with('cms/page_widget/chooser', ['uniq_id' => $uniqId]) + ->willReturn($sourceUrl); + $this->layoutMock->expects($this->atLeastOnce()) + ->method('createBlock') + ->with('Magento\Widget\Block\Adminhtml\Widget\Chooser') + ->willReturn($this->chooserMock); + $this->chooserMock->expects($this->atLeastOnce()) + ->method('setElement') + ->with($this->elementMock) + ->willReturnSelf(); + $this->chooserMock->expects($this->atLeastOnce()) + ->method('setConfig') + ->with($config) + ->willReturnSelf(); + $this->chooserMock->expects($this->atLeastOnce()) + ->method('setFieldsetId') + ->with($fieldsetId) + ->willReturnSelf(); + $this->chooserMock->expects($this->atLeastOnce()) + ->method('setSourceUrl') + ->with($sourceUrl) + ->willReturnSelf(); + $this->chooserMock->expects($this->atLeastOnce()) + ->method('setUniqId') + ->with($uniqId) + ->willReturnSelf(); + $this->elementMock->expects($this->atLeastOnce()) + ->method('getValue') + ->willReturn($elementValue); + $this->pageFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->cmsPageMock); + $this->cmsPageMock->expects($this->any()) + ->method('load') + ->with((int)$elementValue) + ->willReturnSelf(); + $this->cmsPageMock->expects($this->any()) + ->method('getId') + ->willReturn($cmsPageId); + $this->cmsPageMock->expects($this->any()) + ->method('getTitle') + ->willReturn($title); + $this->chooserMock->expects($this->atLeastOnce()) + ->method('toHtml') + ->willReturn($html); + if (!empty($elementValue) && !empty($cmsPageId)) { + $this->escaper->expects(($this->atLeastOnce())) + ->method('escapeHtml') + ->willReturn($titleEscaped); + $this->chooserMock->expects($this->atLeastOnce()) + ->method('setLabel') + ->with($titleEscaped) + ->willReturnSelf(); + } + $this->elementMock->expects($this->atLeastOnce()) + ->method('setData') + ->with('after_element_html', $html) + ->willReturnSelf(); + + $this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock)); + } + + public function prepareElementHtmlDataProvider() + { + return [ + 'elementValue NOT EMPTY, modelBlockId NOT EMPTY' => [ + 'elementValue' => 'some value', + 'cmsPageId' => 1, + ], + 'elementValue NOT EMPTY, modelBlockId IS EMPTY' => [ + 'elementValue' => 'some value', + 'cmsPageId' => null, + ], + 'elementValue IS EMPTY, modelBlockId NEVER REACHED' => [ + 'elementValue' => '', + 'cmsPageId' => 1, + ] + ]; + } + + /** + * @covers \Magento\Cms\Block\Adminhtml\Page\Widget\Chooser::getGridUrl + */ + public function testGetGridUrl() + { + $url = 'some url'; + + $this->urlBuilderMock->expects($this->atLeastOnce()) + ->method('getUrl') + ->with('cms/page_widget/chooser', ['_current' => true]) + ->willReturn($url); + + $this->assertEquals($url, $this->this->getGridUrl()); + } +} From 5c5d60ccff593a83c50785cf59e15e2a0ec686ef Mon Sep 17 00:00:00 2001 From: Joan He Date: Tue, 28 Apr 2015 17:29:19 -0500 Subject: [PATCH 60/68] MAGETWO-23159: [GITHUB] Area Sessions: Magento 2 Should not Allow "area-less" Sessions During an Area Aware Request #526 --- .../Magento/Backend/Model/Auth/Session.php | 7 +- app/code/Magento/Backend/Model/Session.php | 33 -- .../Magento/Backend/Model/Session/Quote.php | 7 +- .../Test/Unit/Model/Session/QuoteTest.php | 10 +- app/code/Magento/Catalog/Model/Session.php | 2 +- app/code/Magento/Checkout/Model/Session.php | 7 +- app/code/Magento/Customer/Model/Session.php | 7 +- app/code/Magento/Newsletter/Model/Session.php | 2 +- .../Framework/Session/SessionManagerTest.php | 335 +++++++++++------- .../Magento/Framework/Message/Session.php | 2 +- .../Magento/Framework/Session/Generic.php | 34 -- .../Framework/Session/SessionManager.php | 28 +- setup/src/Magento/Setup/Model/Installer.php | 3 + .../Setup/Test/Unit/Model/InstallerTest.php | 9 + 14 files changed, 267 insertions(+), 219 deletions(-) diff --git a/app/code/Magento/Backend/Model/Auth/Session.php b/app/code/Magento/Backend/Model/Auth/Session.php index fec438f70c744..d5cf7e86c4b8a 100644 --- a/app/code/Magento/Backend/Model/Auth/Session.php +++ b/app/code/Magento/Backend/Model/Auth/Session.php @@ -61,9 +61,11 @@ class Session extends \Magento\Framework\Session\SessionManager implements \Mage * @param \Magento\Framework\Session\StorageInterface $storage * @param CookieManagerInterface $cookieManager * @param CookieMetadataFactory $cookieMetadataFactory + * @param \Magento\Framework\App\State $appState * @param \Magento\Framework\Acl\Builder $aclBuilder * @param \Magento\Backend\Model\UrlInterface $backendUrl * @param \Magento\Backend\App\ConfigInterface $config + * @throws \Magento\Framework\Exception\SessionException * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -75,6 +77,7 @@ public function __construct( \Magento\Framework\Session\StorageInterface $storage, CookieManagerInterface $cookieManager, CookieMetadataFactory $cookieMetadataFactory, + \Magento\Framework\App\State $appState, \Magento\Framework\Acl\Builder $aclBuilder, \Magento\Backend\Model\UrlInterface $backendUrl, \Magento\Backend\App\ConfigInterface $config @@ -90,9 +93,9 @@ public function __construct( $validator, $storage, $cookieManager, - $cookieMetadataFactory + $cookieMetadataFactory, + $appState ); - $this->start(); } /** diff --git a/app/code/Magento/Backend/Model/Session.php b/app/code/Magento/Backend/Model/Session.php index c0719bb2ecf9e..6dd5af4a3c548 100644 --- a/app/code/Magento/Backend/Model/Session.php +++ b/app/code/Magento/Backend/Model/Session.php @@ -9,39 +9,6 @@ class Session extends \Magento\Framework\Session\SessionManager { - /** - * @param \Magento\Framework\App\Request\Http $request - * @param \Magento\Framework\Session\SidResolverInterface $sidResolver - * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig - * @param \Magento\Framework\Session\SaveHandlerInterface $saveHandler - * @param \Magento\Framework\Session\ValidatorInterface $validator - * @param \Magento\Framework\Session\StorageInterface $storage - * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager - * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory - */ - public function __construct( - \Magento\Framework\App\Request\Http $request, - \Magento\Framework\Session\SidResolverInterface $sidResolver, - \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, - \Magento\Framework\Session\SaveHandlerInterface $saveHandler, - \Magento\Framework\Session\ValidatorInterface $validator, - \Magento\Framework\Session\StorageInterface $storage, - \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, - \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory - ) { - parent::__construct( - $request, - $sidResolver, - $sessionConfig, - $saveHandler, - $validator, - $storage, - $cookieManager, - $cookieMetadataFactory - ); - $this->start(); - } - /** * Skip path validation in backend area * diff --git a/app/code/Magento/Backend/Model/Session/Quote.php b/app/code/Magento/Backend/Model/Session/Quote.php index 2f1f75ab07e92..16d39fd25e4e1 100644 --- a/app/code/Magento/Backend/Model/Session/Quote.php +++ b/app/code/Magento/Backend/Model/Session/Quote.php @@ -83,11 +83,13 @@ class Quote extends \Magento\Framework\Session\SessionManager * @param \Magento\Framework\Session\StorageInterface $storage * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory + * @param \Magento\Framework\App\State $appState * @param CustomerRepositoryInterface $customerRepository * @param \Magento\Quote\Model\QuoteRepository $quoteRepository * @param \Magento\Sales\Model\OrderFactory $orderFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param GroupManagementInterface $groupManagement + * @throws \Magento\Framework\Exception\SessionException * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -99,6 +101,7 @@ public function __construct( \Magento\Framework\Session\StorageInterface $storage, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, + \Magento\Framework\App\State $appState, CustomerRepositoryInterface $customerRepository, \Magento\Quote\Model\QuoteRepository $quoteRepository, \Magento\Sales\Model\OrderFactory $orderFactory, @@ -118,9 +121,9 @@ public function __construct( $validator, $storage, $cookieManager, - $cookieMetadataFactory + $cookieMetadataFactory, + $appState ); - $this->start(); if ($this->_storeManager->hasSingleStore()) { $this->setStoreId($this->_storeManager->getStore(true)->getId()); } diff --git a/app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php b/app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php index 13f906bee346b..d092a33375c62 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php +++ b/app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php @@ -182,6 +182,13 @@ protected function setUp() '', false ); + $appStateMock = $this->getMock( + 'Magento\Framework\App\State', + [], + [], + '', + false + ); $this->storeManagerMock = $this->getMockForAbstractClass( 'Magento\Store\Model\StoreManagerInterface', [], @@ -201,11 +208,12 @@ protected function setUp() 'storage' => $this->storageMock, 'cookieManager' => $this->cookieManagerMock, 'cookieMetadataFactory' => $this->cookieMetadataFactoryMock, + 'appState' => $appStateMock, 'customerRepository' => $this->customerRepositoryMock, 'quoteRepository' => $this->quoteRepositoryMock, 'orderFactory' => $this->orderFactoryMock, 'storeManager' => $this->storeManagerMock, - 'groupManagement' => $this->groupManagementMock + 'groupManagement' => $this->groupManagementMock, ], '', true diff --git a/app/code/Magento/Catalog/Model/Session.php b/app/code/Magento/Catalog/Model/Session.php index b61175b11e7da..d7a3748c2810b 100644 --- a/app/code/Magento/Catalog/Model/Session.php +++ b/app/code/Magento/Catalog/Model/Session.php @@ -8,6 +8,6 @@ /** * Catalog session model */ -class Session extends \Magento\Framework\Session\Generic +class Session extends \Magento\Framework\Session\SessionManager { } diff --git a/app/code/Magento/Checkout/Model/Session.php b/app/code/Magento/Checkout/Model/Session.php index 0f7d18e41355b..da634e082756d 100644 --- a/app/code/Magento/Checkout/Model/Session.php +++ b/app/code/Magento/Checkout/Model/Session.php @@ -90,6 +90,7 @@ class Session extends \Magento\Framework\Session\SessionManager * @param \Magento\Framework\Session\StorageInterface $storage * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory + * @param \Magento\Framework\App\State $appState * @param \Magento\Sales\Model\OrderFactory $orderFactory * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Quote\Model\QuoteRepository $quoteRepository @@ -97,6 +98,7 @@ class Session extends \Magento\Framework\Session\SessionManager * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository + * @throws \Magento\Framework\Exception\SessionException * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -108,6 +110,7 @@ public function __construct( \Magento\Framework\Session\StorageInterface $storage, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, + \Magento\Framework\App\State $appState, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Customer\Model\Session $customerSession, \Magento\Quote\Model\QuoteRepository $quoteRepository, @@ -131,9 +134,9 @@ public function __construct( $validator, $storage, $cookieManager, - $cookieMetadataFactory + $cookieMetadataFactory, + $appState ); - $this->start(); } /** diff --git a/app/code/Magento/Customer/Model/Session.php b/app/code/Magento/Customer/Model/Session.php index c01cd99d642cf..4212be78b5911 100644 --- a/app/code/Magento/Customer/Model/Session.php +++ b/app/code/Magento/Customer/Model/Session.php @@ -102,6 +102,7 @@ class Session extends \Magento\Framework\Session\SessionManager * @param \Magento\Framework\Session\StorageInterface $storage * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory + * @param \Magento\Framework\App\State $appState * @param Share $configShare * @param \Magento\Framework\Url\Helper\Data $coreUrl * @param \Magento\Customer\Model\Url $customerUrl @@ -113,6 +114,7 @@ class Session extends \Magento\Framework\Session\SessionManager * @param \Magento\Framework\App\Http\Context $httpContext * @param CustomerRepositoryInterface $customerRepository * @param GroupManagementInterface $groupManagement + * @throws \Magento\Framework\Exception\SessionException * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -124,6 +126,7 @@ public function __construct( \Magento\Framework\Session\StorageInterface $storage, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, + \Magento\Framework\App\State $appState, Config\Share $configShare, \Magento\Framework\Url\Helper\Data $coreUrl, \Magento\Customer\Model\Url $customerUrl, @@ -154,9 +157,9 @@ public function __construct( $validator, $storage, $cookieManager, - $cookieMetadataFactory + $cookieMetadataFactory, + $appState ); - $this->start(); $this->groupManagement = $groupManagement; $this->_eventManager->dispatch('customer_session_init', ['customer_session' => $this]); } diff --git a/app/code/Magento/Newsletter/Model/Session.php b/app/code/Magento/Newsletter/Model/Session.php index 18d680df14260..2ffb0b2f25236 100644 --- a/app/code/Magento/Newsletter/Model/Session.php +++ b/app/code/Magento/Newsletter/Model/Session.php @@ -8,7 +8,7 @@ /** * Newsletter session model */ -class Session extends \Magento\Framework\Session\Generic +class Session extends \Magento\Framework\Session\SessionManager { /** * Set error message diff --git a/dev/tests/integration/testsuite/Magento/Framework/Session/SessionManagerTest.php b/dev/tests/integration/testsuite/Magento/Framework/Session/SessionManagerTest.php index c8379e5e9c39f..18a4314710c3d 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Session/SessionManagerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Session/SessionManagerTest.php @@ -3,153 +3,214 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Session; - -class SessionManagerTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Framework\Session\SessionManagerInterface - */ - protected $_model; - - /** - * @var \Magento\Framework\Session\SidResolverInterface - */ - protected $_sidResolver; - - /** - * @var string - */ - protected $sessionName; - - /** - * @var \Magento\Framework\App\RequestInterface - */ - protected $request; - - protected function setUp() - { - $this->sessionName = 'frontEndSession'; - - ini_set('session.use_only_cookies', '0'); - ini_set('session.name', $this->sessionName); - - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - - /** @var \Magento\Framework\Session\SidResolverInterface $sidResolver */ - $this->_sidResolver = $objectManager->get('Magento\Framework\Session\SidResolverInterface'); - - $this->request = $objectManager->get('Magento\Framework\App\RequestInterface'); - - /** @var \Magento\Framework\Session\SessionManager _model */ - $this->_model = $objectManager->create( - 'Magento\Framework\Session\SessionManager', - [ - $this->request, - $this->_sidResolver, - $objectManager->get('Magento\Framework\Session\Config\ConfigInterface'), - $objectManager->get('Magento\Framework\Session\SaveHandlerInterface'), - $objectManager->get('Magento\Framework\Session\ValidatorInterface'), - $objectManager->get('Magento\Framework\Session\StorageInterface') - ] - ); - } - - public function testSessionNameFromIni() - { - $this->_model->start(); - $this->assertSame($this->sessionName, $this->_model->getName()); - $this->_model->destroy(); - } - - public function testSessionUseOnlyCookies() - { - $expectedValue = '1'; - $sessionUseOnlyCookies = ini_get('session.use_only_cookies'); - $this->assertSame($expectedValue, $sessionUseOnlyCookies); - } - - public function testGetData() - { - $this->_model->setData(['test_key' => 'test_value']); - $this->assertEquals('test_value', $this->_model->getData('test_key', true)); - $this->assertNull($this->_model->getData('test_key')); - } - - public function testGetSessionId() - { - $this->assertEquals(session_id(), $this->_model->getSessionId()); - } - - public function testGetName() - { - $this->assertEquals(session_name(), $this->_model->getName()); - } - - public function testSetName() - { - $this->_model->setName('test'); - $this->assertEquals('test', $this->_model->getName()); - } - - public function testDestroy() - { - $data = ['key' => 'value']; - $this->_model->setData($data); - - $this->assertEquals($data, $this->_model->getData()); - $this->_model->destroy(); - - $this->assertEquals([], $this->_model->getData()); - } +// @codingStandardsIgnoreStart +namespace { + $mockPHPFunctions = false; +} - public function testSetSessionId() - { - $sessionId = $this->_model->getSessionId(); - $this->_model->setSessionId($this->_sidResolver->getSid($this->_model)); - $this->assertEquals($sessionId, $this->_model->getSessionId()); - - $this->_model->setSessionId('test'); - $this->assertEquals('test', $this->_model->getSessionId()); - } +namespace Magento\Framework\Session { + // @codingStandardsIgnoreEnd /** - * @magentoConfigFixture current_store web/session/use_frontend_sid 1 + * Mock session_status if in test mode, or continue normal execution otherwise + * + * @return int Session status code */ - public function testSetSessionIdFromParam() + function session_status() { - $this->assertNotEquals('test_id', $this->_model->getSessionId()); - $this->request->getQuery()->set($this->_sidResolver->getSessionIdQueryParam($this->_model), 'test-id'); - $this->_model->setSessionId($this->_sidResolver->getSid($this->_model)); - - $this->assertEquals('test-id', $this->_model->getSessionId()); - - /* Use not valid identifier */ - $this->request->getQuery()->set($this->_sidResolver->getSessionIdQueryParam($this->_model), 'test_id'); - $this->_model->setSessionId($this->_sidResolver->getSid($this->_model)); - $this->assertEquals('test-id', $this->_model->getSessionId()); + global $mockPHPFunctions; + if ($mockPHPFunctions) { + return PHP_SESSION_NONE; + } + return call_user_func_array('\session_status', func_get_args()); } - public function testGetSessionIdForHost() + function headers_sent() { - $this->request->getServer()->set('HTTP_HOST', 'localhost'); - $this->_model->start(); - $this->assertEmpty($this->_model->getSessionIdForHost('localhost')); - $this->assertNotEmpty($this->_model->getSessionIdForHost('test')); - $this->_model->destroy(); + global $mockPHPFunctions; + if ($mockPHPFunctions) { + return false; + } + return call_user_func_array('\headers_sent', func_get_args()); } - public function testIsValidForHost() + class SessionManagerTest extends \PHPUnit_Framework_TestCase { - $this->request->getServer()->set('HTTP_HOST', 'localhost'); - $this->_model->start(); - - $reflection = new \ReflectionMethod($this->_model, '_addHost'); - $reflection->setAccessible(true); - $reflection->invoke($this->_model); - - $this->assertFalse($this->_model->isValidForHost('test.com')); - $this->assertTrue($this->_model->isValidForHost('localhost')); - $this->_model->destroy(); + /** + * @var \Magento\Framework\Session\SessionManagerInterface + */ + protected $_model; + + /** + * @var \Magento\Framework\Session\SidResolverInterface + */ + protected $_sidResolver; + + /** + * @var string + */ + protected $sessionName; + + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + protected $objectManager; + + protected function setUp() + { + $this->sessionName = 'frontEndSession'; + + ini_set('session.use_only_cookies', '0'); + ini_set('session.name', $this->sessionName); + + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + + /** @var \Magento\Framework\Session\SidResolverInterface $sidResolver */ + $this->_sidResolver = $this->objectManager->get('Magento\Framework\Session\SidResolverInterface'); + + $this->request = $this->objectManager->get('Magento\Framework\App\RequestInterface'); + + /** @var \Magento\Framework\Session\SessionManager _model */ + $this->_model = $this->objectManager->create( + 'Magento\Framework\Session\SessionManager', + [ + $this->objectManager->get('Magento\Framework\App\Request\Http'), + $this->_sidResolver, + $this->objectManager->get('Magento\Framework\Session\Config\ConfigInterface'), + $this->objectManager->get('Magento\Framework\Session\SaveHandlerInterface'), + $this->objectManager->get('Magento\Framework\Session\ValidatorInterface'), + $this->objectManager->get('Magento\Framework\Session\StorageInterface') + ] + ); + } + + public function testSessionNameFromIni() + { + $this->_model->start(); + $this->assertSame($this->sessionName, $this->_model->getName()); + $this->_model->destroy(); + } + + public function testSessionUseOnlyCookies() + { + $expectedValue = '1'; + $sessionUseOnlyCookies = ini_get('session.use_only_cookies'); + $this->assertSame($expectedValue, $sessionUseOnlyCookies); + } + + public function testGetData() + { + $this->_model->setData(['test_key' => 'test_value']); + $this->assertEquals('test_value', $this->_model->getData('test_key', true)); + $this->assertNull($this->_model->getData('test_key')); + } + + public function testGetSessionId() + { + $this->assertEquals(session_id(), $this->_model->getSessionId()); + } + + public function testGetName() + { + $this->assertEquals(session_name(), $this->_model->getName()); + } + + public function testSetName() + { + $this->_model->setName('test'); + $this->assertEquals('test', $this->_model->getName()); + } + + public function testDestroy() + { + $data = ['key' => 'value']; + $this->_model->setData($data); + + $this->assertEquals($data, $this->_model->getData()); + $this->_model->destroy(); + + $this->assertEquals([], $this->_model->getData()); + } + + public function testSetSessionId() + { + $sessionId = $this->_model->getSessionId(); + $this->_model->setSessionId($this->_sidResolver->getSid($this->_model)); + $this->assertEquals($sessionId, $this->_model->getSessionId()); + + $this->_model->setSessionId('test'); + $this->assertEquals('test', $this->_model->getSessionId()); + } + + /** + * @magentoConfigFixture current_store web/session/use_frontend_sid 1 + */ + public function testSetSessionIdFromParam() + { + $this->assertNotEquals('test_id', $this->_model->getSessionId()); + $this->request->getQuery()->set($this->_sidResolver->getSessionIdQueryParam($this->_model), 'test-id'); + $this->_model->setSessionId($this->_sidResolver->getSid($this->_model)); + $this->assertEquals('test-id', $this->_model->getSessionId()); + /* Use not valid identifier */ + $this->request->getQuery()->set($this->_sidResolver->getSessionIdQueryParam($this->_model), 'test_id'); + $this->_model->setSessionId($this->_sidResolver->getSid($this->_model)); + $this->assertEquals('test-id', $this->_model->getSessionId()); + } + + public function testGetSessionIdForHost() + { + $_SERVER['HTTP_HOST'] = 'localhost'; + $this->_model->start(); + $this->assertEmpty($this->_model->getSessionIdForHost('localhost')); + $this->assertNotEmpty($this->_model->getSessionIdForHost('test')); + $this->_model->destroy(); + } + + public function testIsValidForHost() + { + $_SERVER['HTTP_HOST'] = 'localhost'; + $this->_model->start(); + + $reflection = new \ReflectionMethod($this->_model, '_addHost'); + $reflection->setAccessible(true); + $reflection->invoke($this->_model); + + $this->assertFalse($this->_model->isValidForHost('test.com')); + $this->assertTrue($this->_model->isValidForHost('localhost')); + $this->_model->destroy(); + } + + + /** + * @expectedException \Magento\Framework\Exception\SessionException + * @expectedExceptionMessage Area code not set: Area code must be set before starting a session. + */ + public function testStartAreaNotSet() + { + $scope = $this->objectManager->get('Magento\Framework\Config\ScopeInterface'); + $appState = new \Magento\Framework\App\State($scope); + + /** + * Must be created by "new" in order to get a real Magento\Framework\App\State object that + * is not overridden in the TestFramework + * + * @var \Magento\Framework\Session\SessionManager _model + */ + $this->_model = new \Magento\Framework\Session\SessionManager( + $this->objectManager->get('Magento\Framework\App\Request\Http'), + $this->_sidResolver, + $this->objectManager->get('Magento\Framework\Session\Config\ConfigInterface'), + $this->objectManager->get('Magento\Framework\Session\SaveHandlerInterface'), + $this->objectManager->get('Magento\Framework\Session\ValidatorInterface'), + $this->objectManager->get('Magento\Framework\Session\StorageInterface'), + $this->objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface'), + $this->objectManager->get('Magento\Framework\Stdlib\Cookie\CookieMetadataFactory'), + $appState + ); + + global $mockPHPFunctions; + $mockPHPFunctions = true; + $this->_model->start(); + } } } diff --git a/lib/internal/Magento/Framework/Message/Session.php b/lib/internal/Magento/Framework/Message/Session.php index da86d172577a4..8ceb66543e370 100644 --- a/lib/internal/Magento/Framework/Message/Session.php +++ b/lib/internal/Magento/Framework/Message/Session.php @@ -8,6 +8,6 @@ /** * Message session model */ -class Session extends \Magento\Framework\Session\Generic +class Session extends \Magento\Framework\Session\SessionManager { } diff --git a/lib/internal/Magento/Framework/Session/Generic.php b/lib/internal/Magento/Framework/Session/Generic.php index dd7da87c933a3..bfaf48d74ee9d 100644 --- a/lib/internal/Magento/Framework/Session/Generic.php +++ b/lib/internal/Magento/Framework/Session/Generic.php @@ -7,38 +7,4 @@ class Generic extends SessionManager { - /** - * Constructor - * - * @param \Magento\Framework\App\Request\Http $request - * @param SidResolverInterface $sidResolver - * @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig - * @param SaveHandlerInterface $saveHandler - * @param ValidatorInterface $validator - * @param StorageInterface $storage - * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager - * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory - */ - public function __construct( - \Magento\Framework\App\Request\Http $request, - SidResolverInterface $sidResolver, - \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, - SaveHandlerInterface $saveHandler, - ValidatorInterface $validator, - StorageInterface $storage, - \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, - \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory - ) { - parent::__construct( - $request, - $sidResolver, - $sessionConfig, - $saveHandler, - $validator, - $storage, - $cookieManager, - $cookieMetadataFactory - ); - $this->start(); - } } diff --git a/lib/internal/Magento/Framework/Session/SessionManager.php b/lib/internal/Magento/Framework/Session/SessionManager.php index 17636fa077680..c66672e87ca8f 100644 --- a/lib/internal/Magento/Framework/Session/SessionManager.php +++ b/lib/internal/Magento/Framework/Session/SessionManager.php @@ -11,6 +11,7 @@ /** * Session Manager + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class SessionManager implements SessionManagerInterface { @@ -87,8 +88,11 @@ class SessionManager implements SessionManagerInterface protected $cookieMetadataFactory; /** - * Constructor - * + * @var \Magento\Framework\App\State + */ + private $appState; + + /** * @param \Magento\Framework\App\Request\Http $request * @param SidResolverInterface $sidResolver * @param ConfigInterface $sessionConfig @@ -97,6 +101,8 @@ class SessionManager implements SessionManagerInterface * @param StorageInterface $storage * @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager * @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory + * @param \Magento\Framework\App\State $appState + * @throws \Magento\Framework\Exception\SessionException */ public function __construct( \Magento\Framework\App\Request\Http $request, @@ -106,7 +112,8 @@ public function __construct( ValidatorInterface $validator, StorageInterface $storage, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, - \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory + \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, + \Magento\Framework\App\State $appState ) { $this->request = $request; $this->sidResolver = $sidResolver; @@ -116,9 +123,11 @@ public function __construct( $this->storage = $storage; $this->cookieManager = $cookieManager; $this->cookieMetadataFactory = $cookieMetadataFactory; + $this->appState = $appState; // Enable session.use_only_cookies ini_set('session.use_only_cookies', '1'); + $this->start(); } /** @@ -152,12 +161,25 @@ public function __call($method, $args) /** * Configure session handler and start session * + * @throws \Magento\Framework\Exception\SessionException * @return $this */ public function start() { if (!$this->isSessionExists()) { \Magento\Framework\Profiler::start('session_start'); + + try { + $this->appState->getAreaCode(); + } catch (\Magento\Framework\Exception\LocalizedException $e) { + throw new \Magento\Framework\Exception\SessionException( + new \Magento\Framework\Phrase( + 'Area code not set: Area code must be set before starting a session.' + ), + $e + ); + } + // Need to apply the config options so they can be ready by session_start $this->initIniOptions(); $this->registerSaveHandler(); diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 5db3a546a6611..414ef89f37a61 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -787,6 +787,9 @@ private function handleDBSchemaData($setup, $type) public function installUserConfig($data) { $userConfig = new StoreConfigurationDataMapper(); + /** @var \Magento\Framework\App\State $appState */ + $appState = $this->objectManagerProvider->get()->get('Magento\Framework\App\State'); + $appState->setAreaCode('setup'); $configData = $userConfig->getConfigData($data); if (count($configData) === 0) { return; diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 553c5c8ed4c1e..e3e44ebd20a3b 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -234,12 +234,21 @@ public function testInstall() $cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); $cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']); + $appState = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject( + 'Magento\Framework\App\State' + ); $this->objectManager->expects($this->any()) ->method('create') ->will($this->returnValueMap([ ['Magento\Setup\Module\Setup', ['resource' => $resource], $setup], ['Magento\Setup\Module\DataSetup', [], $dataSetup], ['Magento\Framework\App\Cache\Manager', [], $cacheManager], + ['Magento\Framework\App\State', [], $appState], + ])); + $this->objectManager->expects($this->any()) + ->method('get') + ->will($this->returnValueMap([ + ['Magento\Framework\App\State', $appState], ])); $this->adminFactory->expects($this->once())->method('create')->willReturn( $this->getMock('Magento\Setup\Model\AdminAccount', [], [], '', false) From 1ae920b6b218a1c00628bc670c7b22af720b3bd0 Mon Sep 17 00:00:00 2001 From: Joan He Date: Wed, 29 Apr 2015 12:06:37 -0500 Subject: [PATCH 61/68] MAGETWO-32624: Investigate and Annotate @api to classes and/or methods - fixed unit test failures --- app/code/Magento/Config/Model/Config/ScopeDefiner.php | 2 +- .../Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php | 2 +- .../Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Config/Model/Config/ScopeDefiner.php b/app/code/Magento/Config/Model/Config/ScopeDefiner.php index f2230e2737e05..f69e9dd96d2eb 100644 --- a/app/code/Magento/Config/Model/Config/ScopeDefiner.php +++ b/app/code/Magento/Config/Model/Config/ScopeDefiner.php @@ -39,6 +39,6 @@ public function getScope() 'store' ) ? StoreScopeInterface::SCOPE_STORE : ($this->_request->getParam( 'website' - ) ? StoreScopeInterface::SCOPE_WEBSITE : StoreScopeInterface::SCOPE_DEFAULT); + ) ? StoreScopeInterface::SCOPE_WEBSITE : ScopeConfigInterface::SCOPE_TYPE_DEFAULT); } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php b/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php index 69f3f6e0df310..9359af03ee68d 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Email/AsyncSendingTest.php @@ -63,7 +63,7 @@ protected function setUp() public function testAfterSave($value, $oldValue, $eventName) { $path = 'sales_email/general/async_sending'; - $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT; + $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT; $this->object->setData(['value' => $value, 'path' => $path, 'scope' => $scope]); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php b/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php index 972cfae38e2ae..729c19940ccff 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Config/Backend/Grid/AsyncIndexingTest.php @@ -63,7 +63,7 @@ protected function setUp() public function testAfterSave($value, $oldValue, $eventName) { $path = 'dev/grid/async_indexing'; - $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT; + $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT; $this->object->setData(['value' => $value, 'path' => $path, 'scope' => $scope]); From 49d0fec1b8ddee117e264ce66344b48601888d0e Mon Sep 17 00:00:00 2001 From: Joan He Date: Wed, 29 Apr 2015 14:36:00 -0500 Subject: [PATCH 62/68] MAGETWO-32624: Investigate and Annotate @api to classes and/or methods - fixed static test failures --- app/code/Magento/Email/Model/BackendTemplate.php | 1 + app/code/Magento/Store/Model/Config/Reader/DefaultReader.php | 4 ++-- app/code/Magento/Theme/Model/View/Design.php | 1 + .../testsuite/Magento/Payment/Model/ObserverTest.php | 1 + lib/internal/Magento/Framework/App/Config/Value.php | 1 - 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Email/Model/BackendTemplate.php b/app/code/Magento/Email/Model/BackendTemplate.php index 6584fdbd21575..c8bc6b34398e0 100644 --- a/app/code/Magento/Email/Model/BackendTemplate.php +++ b/app/code/Magento/Email/Model/BackendTemplate.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Email\Model; + use Magento\Framework\App\Config\ScopeConfigInterface; /** diff --git a/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php b/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php index 911e9bd8ae155..189753ef58ad3 100644 --- a/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php +++ b/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php @@ -45,14 +45,14 @@ public function __construct( * Read configuration data * * @param null|string $scope - * @throws \Magento\Framework\Exception Exception is thrown when scope other than default is given + * @throws \Magento\Framework\Exception\LocalizedException Exception is thrown when scope other than default is given * @return array */ public function read($scope = null) { $scope = $scope === null ? ScopeConfigInterface::SCOPE_TYPE_DEFAULT : $scope; if ($scope !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { - throw new \Magento\Framework\Exception("Only default scope allowed"); + throw new \Magento\Framework\Exception\LocalizedException(__("Only default scope allowed")); } $config = $this->_initialConfig->getData($scope); diff --git a/app/code/Magento/Theme/Model/View/Design.php b/app/code/Magento/Theme/Model/View/Design.php index a158874feff56..f0cf795f6b448 100644 --- a/app/code/Magento/Theme/Model/View/Design.php +++ b/app/code/Magento/Theme/Model/View/Design.php @@ -5,6 +5,7 @@ */ namespace Magento\Theme\Model\View; + use Magento\Framework\App\Config\ScopeConfigInterface; /** diff --git a/dev/tests/integration/testsuite/Magento/Payment/Model/ObserverTest.php b/dev/tests/integration/testsuite/Magento/Payment/Model/ObserverTest.php index fd30d5b492fc7..f83337a307eb2 100644 --- a/dev/tests/integration/testsuite/Magento/Payment/Model/ObserverTest.php +++ b/dev/tests/integration/testsuite/Magento/Payment/Model/ObserverTest.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Payment\Model; + use Magento\Framework\App\Config\ScopeConfigInterface; /** diff --git a/lib/internal/Magento/Framework/App/Config/Value.php b/lib/internal/Magento/Framework/App/Config/Value.php index 64263bc7b69e8..92ee527a9c48e 100644 --- a/lib/internal/Magento/Framework/App/Config/Value.php +++ b/lib/internal/Magento/Framework/App/Config/Value.php @@ -4,7 +4,6 @@ * See COPYING.txt for license details. */ namespace Magento\Framework\App\Config; -use Magento\Framework\App\Config\ScopeConfigInterface; /** * Config data model From a1622330dda0a41cf808b66438f0c52cf5aca26a Mon Sep 17 00:00:00 2001 From: Joan He Date: Wed, 29 Apr 2015 15:03:20 -0500 Subject: [PATCH 63/68] MAGETWO-32624: Investigate and Annotate @api to classes and/or methods - fixed static test failures --- app/code/Magento/Store/Model/Config/Reader/DefaultReader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php b/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php index 189753ef58ad3..7bb9981369440 100644 --- a/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php +++ b/app/code/Magento/Store/Model/Config/Reader/DefaultReader.php @@ -8,6 +8,7 @@ namespace Magento\Store\Model\Config\Reader; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Exception\LocalizedException; class DefaultReader implements \Magento\Framework\App\Config\Scope\ReaderInterface { @@ -45,7 +46,7 @@ public function __construct( * Read configuration data * * @param null|string $scope - * @throws \Magento\Framework\Exception\LocalizedException Exception is thrown when scope other than default is given + * @throws LocalizedException Exception is thrown when scope other than default is given * @return array */ public function read($scope = null) From 3823b63f71d38ae3327498810c040c0159328b13 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Wed, 29 Apr 2015 16:09:07 -0500 Subject: [PATCH 64/68] MAGETWO-35991: Profiling option #2 is broken --- .htaccess | 1 + .../Profiler/FactoryDecorator.php | 16 +++- .../Unit/Profiler/FactoryDecoratorTest.php | 75 +++++++++++++++++++ .../Test/Unit/_files/logger_classes.php | 21 ++++++ 4 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 lib/internal/Magento/Framework/ObjectManager/Test/Unit/Profiler/FactoryDecoratorTest.php create mode 100644 lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/logger_classes.php diff --git a/.htaccess b/.htaccess index 404488eb7ff0e..8df703b468970 100644 --- a/.htaccess +++ b/.htaccess @@ -189,3 +189,4 @@ ## http://developer.yahoo.com/performance/rules.html#etags #FileETag none +SetEnv MAGE_PROFILER 2 diff --git a/lib/internal/Magento/Framework/ObjectManager/Profiler/FactoryDecorator.php b/lib/internal/Magento/Framework/ObjectManager/Profiler/FactoryDecorator.php index ad3864500bbc9..895377327281b 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Profiler/FactoryDecorator.php +++ b/lib/internal/Magento/Framework/ObjectManager/Profiler/FactoryDecorator.php @@ -8,6 +8,11 @@ class FactoryDecorator implements \Magento\Framework\ObjectManager\FactoryInterface { + /** + * Name of the class that generates logging wrappers + */ + const GENERATOR_NAME = 'Magento\Framework\ObjectManager\Profiler\Code\Generator\Logger'; + /** * @var \Magento\Framework\ObjectManager\FactoryInterface */ @@ -45,9 +50,12 @@ public function create($requestedType, array $arguments = []) { $this->log->startCreating($requestedType); $result = $this->subject->create($requestedType, $arguments); - $loggerClassName = get_class($result) . "\\Logger"; - $wrappedResult = new $loggerClassName($result, $this->log); - $this->log->stopCreating($result); - return $wrappedResult; + if ($requestedType !== self::GENERATOR_NAME) { + $loggerClassName = get_class($result) . "\\Logger"; + $wrappedResult = new $loggerClassName($result, $this->log); + $this->log->stopCreating($result); + $result = $wrappedResult; + } + return $result; } } diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Profiler/FactoryDecoratorTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Profiler/FactoryDecoratorTest.php new file mode 100644 index 0000000000000..1d0fa91e42286 --- /dev/null +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Profiler/FactoryDecoratorTest.php @@ -0,0 +1,75 @@ +objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManager\FactoryInterface') + ->disableOriginalConstructor() + ->getMock(); + + // Instantiate SUT + $this->model = $objectManager->getObject( + 'Magento\Framework\ObjectManager\Profiler\FactoryDecorator', + ['subject' => $this->objectManagerMock] + ); + } + + public function testCreate() + { + $baseObjectName = self::CLASS_NAME; + $baseObject = new $baseObjectName(); + + $arguments = [1, 2, 3]; + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with(self::CLASS_NAME, $arguments) + ->willReturn($baseObject); + + $this->assertInstanceOf(self::LOGGER_NAME, $this->model->create(self::CLASS_NAME, $arguments)); + } + + public function testCreateNeglectGenerator() + { + $arguments = [1, 2, 3]; + $loggerMock = $this->getMockBuilder(self::GENERATOR_NAME)->disableOriginalConstructor()->getMock(); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with(self::GENERATOR_NAME, $arguments) + ->willReturn($loggerMock); + + $this->assertSame($loggerMock, $this->model->create(self::GENERATOR_NAME, $arguments)); + } +} diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/logger_classes.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/logger_classes.php new file mode 100644 index 0000000000000..e55641a0a272a --- /dev/null +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/logger_classes.php @@ -0,0 +1,21 @@ + Date: Wed, 29 Apr 2015 16:12:56 -0500 Subject: [PATCH 65/68] MAGETWO-35991: Profiling option #2 is broken --- .htaccess | 1 - 1 file changed, 1 deletion(-) diff --git a/.htaccess b/.htaccess index 8df703b468970..404488eb7ff0e 100644 --- a/.htaccess +++ b/.htaccess @@ -189,4 +189,3 @@ ## http://developer.yahoo.com/performance/rules.html#etags #FileETag none -SetEnv MAGE_PROFILER 2 From f372d1337e289455ec3cb3b0cc27fd7cc07cddc5 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Wed, 29 Apr 2015 16:30:55 -0500 Subject: [PATCH 66/68] MAGETWO-35833: [GitHub] Magento\Framework\Data\Collection\Filesystem filter issue #1160 --- .../Test/Unit/Collection/FilesystemTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/internal/Magento/Framework/Data/Test/Unit/Collection/FilesystemTest.php diff --git a/lib/internal/Magento/Framework/Data/Test/Unit/Collection/FilesystemTest.php b/lib/internal/Magento/Framework/Data/Test/Unit/Collection/FilesystemTest.php new file mode 100644 index 0000000000000..b764079a841b7 --- /dev/null +++ b/lib/internal/Magento/Framework/Data/Test/Unit/Collection/FilesystemTest.php @@ -0,0 +1,30 @@ +model = $objectManager->getObject('Magento\Framework\Data\Collection\Filesystem'); + } + + public function testFilterCallbackLike() + { + $field = 'field'; + $row = [$field => 'beginning_filter_target_end',]; + $filterValueSuccess = new \Zend_Db_Expr('%filter_target%'); + $filterValueFailure = new \Zend_Db_Expr('%not_found_in_the_row%'); + + $this->assertTrue($this->model->filterCallbackLike($field, $filterValueSuccess, $row)); + $this->assertFalse($this->model->filterCallbackLike($field, $filterValueFailure, $row)); + } +} From 9ba83d1d5b713e2741e78ec7d2c217d6c307620b Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Wed, 6 May 2015 15:34:22 -0400 Subject: [PATCH 67/68] MAGETWO-34787: Process pull request --- .../Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php | 1 - app/code/Magento/Ui/etc/di.xml | 5 ----- .../Magento/Framework/Data/Collection/Filesystem.php | 1 + .../ObjectManager/Test/Unit/_files/logger_classes.php | 5 +++++ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php b/app/code/Magento/Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php index 1eb9f23050582..9fede0b023878 100644 --- a/app/code/Magento/Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php +++ b/app/code/Magento/Tax/Controller/Adminhtml/Tax/IgnoreTaxNotification.php @@ -9,7 +9,6 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Controller\ResultFactory; - class IgnoreTaxNotification extends \Magento\Tax\Controller\Adminhtml\Tax { /** diff --git a/app/code/Magento/Ui/etc/di.xml b/app/code/Magento/Ui/etc/di.xml index 6042d3eaa23e5..b5684f5734d9b 100644 --- a/app/code/Magento/Ui/etc/di.xml +++ b/app/code/Magento/Ui/etc/di.xml @@ -252,9 +252,4 @@ uiComponentAggregatedSourceOverrideThemeFiltered - - - Magento\Ui\DataProvider\Config\Data\Proxy - - diff --git a/lib/internal/Magento/Framework/Data/Collection/Filesystem.php b/lib/internal/Magento/Framework/Data/Collection/Filesystem.php index e637f4e4b89da..dc0e3cf501f6e 100644 --- a/lib/internal/Magento/Framework/Data/Collection/Filesystem.php +++ b/lib/internal/Magento/Framework/Data/Collection/Filesystem.php @@ -284,6 +284,7 @@ protected function _collectRecursive($dir) * @param bool $printQuery * @param bool $logQuery * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @throws \Exception */ public function loadData($printQuery = false, $logQuery = false) diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/logger_classes.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/logger_classes.php index e55641a0a272a..da593225f2079 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/logger_classes.php +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/_files/logger_classes.php @@ -4,7 +4,9 @@ * See COPYING.txt for license details. */ +//@codingStandardsIgnoreStart namespace Magento\Test\Di { + /** * Test classes used for \Magento\Framework\ObjectManager\Test\Unit\Profiler\FactoryDecoratorTest */ @@ -13,9 +15,12 @@ class WrappedClass } } + namespace Magento\Test\Di\WrappedClass { + class Logger { } } +//@codingStandardsIgnoreEnd From fa7c1fcdeb64a08e2c0ba901e3edee8fd4ea9755 Mon Sep 17 00:00:00 2001 From: Dale Sikkema Date: Wed, 6 May 2015 16:11:41 -0400 Subject: [PATCH 68/68] MAGETWO-34787: Process pull request --- lib/internal/Magento/Framework/Data/Collection/Filesystem.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/Magento/Framework/Data/Collection/Filesystem.php b/lib/internal/Magento/Framework/Data/Collection/Filesystem.php index dc0e3cf501f6e..cec62bc94a82b 100644 --- a/lib/internal/Magento/Framework/Data/Collection/Filesystem.php +++ b/lib/internal/Magento/Framework/Data/Collection/Filesystem.php @@ -669,6 +669,7 @@ protected function _renderConditionBeforeFilterElement($increment, $isAnd) * @param string $value * @param string $type * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function addFilter($field, $value, $type = 'and') {