diff --git a/README.md b/README.md index 5ece86f880b60febb9f605232f351835ae8b28cf..a1f4a848d6cd7772805466cc1cbc4e117583acb5 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Use the following table to verify you have the correct prerequisites to install </tr> <tr> <td>Apache 2.2 or 2.4</td> - <td>Ubuntu: <code>apache -v</code><br> + <td>Ubuntu: <code>apache2 -v</code><br> CentOS: <code>httpd -v</code></td> <td><a href="http://devdocs.magento.com/guides/v1.0/install-gde/prereq/apache.html">Apache</a></td> </tr> @@ -57,3 +57,17 @@ After verifying your prerequisites, perform the following tasks in order to prep * <a href="http://devdocs.magento.com/guides/v1.0/install-gde/install/install-web.html">Install Magento software using the web interface</a> * <a href="http://devdocs.magento.com/guides/v1.0/install-gde/install/install-cli.html">Install Magento software using the command line</a> 2. <a href="http://devdocs.magento.com/guides/v1.0/install-gde/install/verify.html">Verify the installation</a> + +<h2>Contributing to the Magento 2 code base</h2> +Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes, optimizations, or just good suggestions. + +To make learn about how to make a contribution, click [here][1]. + +To learn about issues, click [here][2]. To open an issue, click [here][3]. + +To suggest documentation improvements, click [here][4]. + +[1]: <http://devdocs.magento.com/guides/v1.0/contributor-guide/CONTRIBUTING.html> +[2]: <http://devdocs.magento.com/guides/v1.0/contributor-guide/CONTRIBUTING.html#report> +[3]: <https://github.com/magento/magento2/issues> +[4]: <http://devdocs.magento.com> diff --git a/app/code/Magento/Backend/App/Action/Context.php b/app/code/Magento/Backend/App/Action/Context.php index 0630d8213d2413e7ab3f9f75cd711206a47bc9ae..e6618170e4d6b72683ed960679575649e307dec4 100644 --- a/app/code/Magento/Backend/App/Action/Context.php +++ b/app/code/Magento/Backend/App/Action/Context.php @@ -61,6 +61,7 @@ class Context extends \Magento\Framework\App\Action\Context * @param \Magento\Framework\App\ActionFlag $actionFlag * @param \Magento\Framework\App\ViewInterface $view * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\Session $session * @param \Magento\Framework\AuthorizationInterface $authorization * @param \Magento\Backend\Model\Auth $auth @@ -81,6 +82,7 @@ class Context extends \Magento\Framework\App\Action\Context \Magento\Framework\App\ActionFlag $actionFlag, \Magento\Framework\App\ViewInterface $view, \Magento\Framework\Message\ManagerInterface $messageManager, + \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\Session $session, \Magento\Framework\AuthorizationInterface $authorization, \Magento\Backend\Model\Auth $auth, @@ -99,7 +101,8 @@ class Context extends \Magento\Framework\App\Action\Context $redirect, $actionFlag, $view, - $messageManager + $messageManager, + $resultRedirectFactory ); $this->_session = $session; diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php b/app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php index b8e22be3ef59bd4a00529670c2e8fc31d5a7f345..6aed5e22c5282ed4e72790170da1323c3fbce78d 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Auth/Login.php @@ -13,25 +13,17 @@ class Login extends \Magento\Backend\Controller\Adminhtml\Auth */ protected $resultPageFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * Constructor * * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Auth/Logout.php b/app/code/Magento/Backend/Controller/Adminhtml/Auth/Logout.php index 0f632337827b1084a95a806dc6b79554a00a1962..098022bed0a8d7c764c9cf5fc66409f222bc6369 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Auth/Logout.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Auth/Logout.php @@ -8,23 +8,6 @@ namespace Magento\Backend\Controller\Adminhtml\Auth; class Logout extends \Magento\Backend\Controller\Adminhtml\Auth { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * Administrator logout action * diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache.php index f200ef062d37f9ef991f581fb20636b8677919b7..f7d1548519d70fdac4560ff7fcd3a399cf6a0db0 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache.php @@ -25,11 +25,6 @@ class Cache extends Action */ protected $_cacheFrontendPool; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\View\Result\PageFactory */ @@ -40,7 +35,6 @@ class Cache extends Action * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Framework\App\Cache\StateInterface $cacheState * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( @@ -48,14 +42,12 @@ class Cache extends Action \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Cache\StateInterface $cacheState, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context); $this->_cacheTypeList = $cacheTypeList; $this->_cacheState = $cacheState; $this->_cacheFrontendPool = $cacheFrontendPool; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultPageFactory = $resultPageFactory; } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php index 95c03bc8ccdc5605b06d11d871314712bbaf2907..23d056c9a208ade817db72fe6706ede3a2c0dfec 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanImages.php @@ -14,19 +14,24 @@ class CleanImages extends \Magento\Backend\Controller\Adminhtml\Cache * Clean JS/css files cache * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws LocalizedException */ public function execute() { - try { - $this->_objectManager->create('Magento\Catalog\Model\Product\Image')->clearCache(); - $this->_eventManager->dispatch('clean_catalog_images_cache_after'); - $this->messageManager->addSuccess(__('The image cache was cleaned.')); - } catch (LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('An error occurred while clearing the image cache.')); - } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $this->_objectManager->create('Magento\Catalog\Model\Product\Image')->clearCache(); + $this->_eventManager->dispatch('clean_catalog_images_cache_after'); + $this->messageManager->addSuccess(__('The image cache was cleaned.')); + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('adminhtml/*'); } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php index 8133c1f530bb18d4f0a9eb428b549cd6756faf26..95af905952ce66e4c8cfc98e3979d241b6bc678e 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/CleanMedia.php @@ -14,19 +14,24 @@ class CleanMedia extends \Magento\Backend\Controller\Adminhtml\Cache * Clean JS/css files cache * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws LocalizedException */ public function execute() { - try { - $this->_objectManager->get('Magento\Framework\View\Asset\MergeService')->cleanMergedJsCss(); - $this->_eventManager->dispatch('clean_media_cache_after'); - $this->messageManager->addSuccess(__('The JavaScript/CSS cache has been cleaned.')); - } catch (LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('An error occurred while clearing the JavaScript/CSS cache.')); - } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $this->_objectManager->get('Magento\Framework\View\Asset\MergeService')->cleanMergedJsCss(); + $this->_eventManager->dispatch('clean_media_cache_after'); + $this->messageManager->addSuccess(__('The JavaScript/CSS cache has been cleaned.')); + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('adminhtml/*'); } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php index 503637b67520dbd64329d97a5878390b87d7a220..a5f0d8d38ed8803e8c524b4025656f8e37ab88d4 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php @@ -14,33 +14,38 @@ class MassDisable extends \Magento\Backend\Controller\Adminhtml\Cache * Mass action for cache disabling * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { - try { - $types = $this->getRequest()->getParam('types'); - $updatedTypes = 0; - if (!is_array($types)) { - $types = []; - } - $this->_validateTypes($types); - foreach ($types as $code) { - if ($this->_cacheState->isEnabled($code)) { - $this->_cacheState->setEnabled($code, false); - $updatedTypes++; - } - $this->_cacheTypeList->cleanType($code); - } - if ($updatedTypes > 0) { - $this->_cacheState->persist(); - $this->messageManager->addSuccess(__("%1 cache type(s) disabled.", $updatedTypes)); + $types = $this->getRequest()->getParam('types'); + $updatedTypes = 0; + if (!is_array($types)) { + $types = []; + } + $this->_validateTypes($types); + foreach ($types as $code) { + if ($this->_cacheState->isEnabled($code)) { + $this->_cacheState->setEnabled($code, false); + $updatedTypes++; } - } catch (LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('An error occurred while disabling cache.')); + $this->_cacheTypeList->cleanType($code); } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + if ($updatedTypes > 0) { + $this->_cacheState->persist(); + $this->messageManager->addSuccess(__("%1 cache type(s) disabled.", $updatedTypes)); + } + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('adminhtml/*'); } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassEnable.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassEnable.php index 0125bdfd6aea8589f4ee98a2b82f3c4f08ff260a..597f6f13e0a70e1ae37f8f294b3e555126af9dcd 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassEnable.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassEnable.php @@ -14,32 +14,37 @@ class MassEnable extends \Magento\Backend\Controller\Adminhtml\Cache * Mass action for cache enabling * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { - try { - $types = $this->getRequest()->getParam('types'); - $updatedTypes = 0; - if (!is_array($types)) { - $types = []; - } - $this->_validateTypes($types); - foreach ($types as $code) { - if (!$this->_cacheState->isEnabled($code)) { - $this->_cacheState->setEnabled($code, true); - $updatedTypes++; - } - } - if ($updatedTypes > 0) { - $this->_cacheState->persist(); - $this->messageManager->addSuccess(__("%1 cache type(s) enabled.", $updatedTypes)); + $types = $this->getRequest()->getParam('types'); + $updatedTypes = 0; + if (!is_array($types)) { + $types = []; + } + $this->_validateTypes($types); + foreach ($types as $code) { + if (!$this->_cacheState->isEnabled($code)) { + $this->_cacheState->setEnabled($code, true); + $updatedTypes++; } - } catch (LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('An error occurred while enabling cache.')); } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + if ($updatedTypes > 0) { + $this->_cacheState->persist(); + $this->messageManager->addSuccess(__("%1 cache type(s) enabled.", $updatedTypes)); + } + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('adminhtml/*'); } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php index 7f9c0b2d3050deb3c2d18cb8f8638f5a2aabf590..78db76ec2d82d8029d2f8441cbb61661a367df13 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php @@ -6,38 +6,41 @@ */ namespace Magento\Backend\Controller\Adminhtml\Cache; -use Magento\Framework\Exception\LocalizedException; - class MassRefresh extends \Magento\Backend\Controller\Adminhtml\Cache { /** * Mass action for cache refresh * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { - try { - $types = $this->getRequest()->getParam('types'); - $updatedTypes = 0; - if (!is_array($types)) { - $types = []; - } - $this->_validateTypes($types); - foreach ($types as $type) { - $this->_cacheTypeList->cleanType($type); - $this->_eventManager->dispatch('adminhtml_cache_refresh_type', ['type' => $type]); - $updatedTypes++; - } - if ($updatedTypes > 0) { - $this->messageManager->addSuccess(__("%1 cache type(s) refreshed.", $updatedTypes)); - } - } catch (LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('An error occurred while refreshing cache.')); + $types = $this->getRequest()->getParam('types'); + $updatedTypes = 0; + if (!is_array($types)) { + $types = []; + } + $this->_validateTypes($types); + foreach ($types as $type) { + $this->_cacheTypeList->cleanType($type); + $this->_eventManager->dispatch('adminhtml_cache_refresh_type', ['type' => $type]); + $updatedTypes++; + } + if ($updatedTypes > 0) { + $this->messageManager->addSuccess(__("%1 cache type(s) refreshed.", $updatedTypes)); } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('adminhtml/*'); } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Dashboard/RefreshStatistics.php b/app/code/Magento/Backend/Controller/Adminhtml/Dashboard/RefreshStatistics.php index 5172f791b6d021decee43a64baa44430b84acf94..7f4b2d919f3c06c82afbfab05a5e0a2af635dbdf 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Dashboard/RefreshStatistics.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Dashboard/RefreshStatistics.php @@ -11,36 +11,42 @@ class RefreshStatistics extends \Magento\Reports\Controller\Adminhtml\Report\Sta /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param array $reportTypes * @param \Psr\Log\LoggerInterface $logger */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, array $reportTypes, \Psr\Log\LoggerInterface $logger ) { - parent::__construct($context, $dateFilter, $resultRedirectFactory, $reportTypes); + parent::__construct($context, $dateFilter, $reportTypes); $this->logger = $logger; } /** * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { - try { - $collectionsNames = array_values($this->reportTypes); - foreach ($collectionsNames as $collectionName) { - $this->_objectManager->create($collectionName)->aggregate(); - } - $this->messageManager->addSuccess(__('We updated lifetime statistic.')); - } catch (\Exception $e) { - $this->messageManager->addError(__('We can\'t refresh lifetime statistics.')); - $this->logger->critical($e); + $collectionsNames = array_values($this->reportTypes); + foreach ($collectionsNames as $collectionName) { + $this->_objectManager->create($collectionName)->aggregate(); } - return $this->resultRedirectFactory->create()->setPath('*/*'); + $this->messageManager->addSuccess(__('We updated lifetime statistic.')); + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('*/*'); } } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Denied.php b/app/code/Magento/Backend/Controller/Adminhtml/Denied.php index 04c0cdf98cd4033cc2e607fa696750196d8837f2..c77bb09fb00548f52a0ad58f72c62acdb16d520b 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Denied.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Denied.php @@ -8,11 +8,6 @@ namespace Magento\Backend\Controller\Adminhtml; class Denied extends \Magento\Backend\App\Action { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\View\Result\PageFactory */ @@ -20,16 +15,13 @@ class Denied extends \Magento\Backend\App\Action /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultPageFactory = $resultPageFactory; } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Index/ChangeLocale.php b/app/code/Magento/Backend/Controller/Adminhtml/Index/ChangeLocale.php index 4fca603999c5af054a81c89b413f9c0f8f1bbc9d..9505f4b1d6d2f33094558dfc448f664b201a3046 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Index/ChangeLocale.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Index/ChangeLocale.php @@ -8,25 +8,6 @@ namespace Magento\Backend\Controller\Adminhtml\Index; class ChangeLocale extends \Magento\Backend\Controller\Adminhtml\Index { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * Constructor - * - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context); - } - /** * Change locale action * diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Index/Index.php b/app/code/Magento/Backend/Controller/Adminhtml/Index/Index.php index da57138a8b57b15421e757e8741df0468f089b6c..0298a2b9d36b7c8dd7110cb24b34a8b71c17abfc 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Index/Index.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Index/Index.php @@ -8,23 +8,6 @@ namespace Magento\Backend\Controller\Adminhtml\Index; class Index extends \Magento\Backend\Controller\Adminhtml\Index { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * Admin area entry point * Always redirects to the startup page url diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index 86ec95f344e19d2fade1d60582365ffa98bfedf3..06ade97d1e905424aba18f85c14b7a94db210ebd 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -6,30 +6,15 @@ namespace Magento\Backend\Controller\Adminhtml\System\Account; use Magento\Framework\Exception\AuthenticationException; +use Magento\Framework\Exception\LocalizedException; class Save extends \Magento\Backend\Controller\Adminhtml\System\Account { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * Saving edited user information * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() @@ -42,17 +27,11 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account /** @var $user \Magento\User\Model\User */ $user = $this->_objectManager->create('Magento\User\Model\User')->load($userId); - $user->setId( - $userId - )->setUsername( - $this->getRequest()->getParam('username', false) - )->setFirstname( - $this->getRequest()->getParam('firstname', false) - )->setLastname( - $this->getRequest()->getParam('lastname', false) - )->setEmail( - strtolower($this->getRequest()->getParam('email', false)) - ); + $user->setId($userId) + ->setUsername($this->getRequest()->getParam('username', false)) + ->setFirstname($this->getRequest()->getParam('firstname', false)) + ->setLastname($this->getRequest()->getParam('lastname', false)) + ->setEmail(strtolower($this->getRequest()->getParam('email', false))); if ($this->_objectManager->get('Magento\Framework\Locale\Validator')->isValid($interfaceLocale)) { $user->setInterfaceLocale($interfaceLocale); @@ -83,13 +62,19 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account if ($e->getMessage()) { $this->messageManager->addError($e->getMessage()); } - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('An error occurred while saving account.')); } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { $resultRedirect = $this->resultRedirectFactory->create(); - return $resultRedirect->setPath("*/*/"); + return $resultRedirect->setPath('*/*'); } } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Design.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Design.php index 66e2b5739f6157d3da37d3ce4212b9d3956df2ff..fb5725b74bbf800d933b2e35f8cf8d4089c7ff08 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Design.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Design.php @@ -21,11 +21,6 @@ class Design extends Action */ protected $dateFilter; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Backend\Model\View\Result\ForwardFactory */ @@ -45,7 +40,6 @@ class Design extends Action * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory @@ -54,7 +48,6 @@ class Design extends Action \Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory @@ -62,7 +55,6 @@ class Design extends Action $this->_coreRegistry = $coreRegistry; $this->dateFilter = $dateFilter; parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; $this->resultPageFactory = $resultPageFactory; $this->resultLayoutFactory = $resultLayoutFactory; diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Design/Delete.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Design/Delete.php index e9b7e2d6b7a0c11ddd96249a21da096fce97b32d..869f8af7923470767c96804afbd59e84266ffda8 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Design/Delete.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Design/Delete.php @@ -20,7 +20,7 @@ class Delete extends \Magento\Backend\Controller\Adminhtml\System\Design try { $design->delete(); $this->messageManager->addSuccess(__('You deleted the design change.')); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __("Cannot delete the design change.")); diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store.php index f17843629a420285506e3bd721979120809f8823..a6efb535ec2658ac32c0ef66f1a3472bcdeb322a 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store.php @@ -36,11 +36,6 @@ class Store extends Action */ protected $resultForwardFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\View\Result\PageFactory */ @@ -51,7 +46,6 @@ class Store extends Action * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\Filter\FilterManager $filterManager * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( @@ -59,14 +53,12 @@ class Store extends Action \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { $this->_coreRegistry = $coreRegistry; $this->filterManager = $filterManager; parent::__construct($context); $this->resultForwardFactory = $resultForwardFactory; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultPageFactory = $resultPageFactory; } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteGroupPost.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteGroupPost.php index 4450de457669c7765dfd427fa61eca73453bb2d4..aa771ac2ec80ff9e92c92b5cba1ce30618387d44 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteGroupPost.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteGroupPost.php @@ -10,6 +10,7 @@ class DeleteGroupPost extends \Magento\Backend\Controller\Adminhtml\System\Store { /** * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { @@ -31,15 +32,8 @@ class DeleteGroupPost extends \Magento\Backend\Controller\Adminhtml\System\Store return $redirectResult->setPath('*/*/editGroup', ['group_id' => $itemId]); } - try { - $model->delete(); - $this->messageManager->addSuccess(__('The store has been deleted.')); - return $redirectResult->setPath('adminhtml/*/'); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('Unable to delete store. Please, try again later.')); - } - return $redirectResult->setPath('adminhtml/*/editGroup', ['group_id' => $itemId]); + $model->delete(); + $this->messageManager->addSuccess(__('The store has been deleted.')); + return $redirectResult->setPath('adminhtml/*/'); } } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteStorePost.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteStorePost.php index 0d325541d82df7d453f4fb3d3aa1b40dc673d5ef..1eca177ae08e90305c494f62845778be4a944af6 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteStorePost.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteStorePost.php @@ -12,6 +12,7 @@ class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store * Delete store view post action * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { @@ -32,18 +33,11 @@ class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store return $redirectResult->setPath('*/*/editStore', ['store_id' => $itemId]); } - try { - $model->delete(); + $model->delete(); - $this->_eventManager->dispatch('store_delete', ['store' => $model]); + $this->_eventManager->dispatch('store_delete', ['store' => $model]); - $this->messageManager->addSuccess(__('The store view has been deleted.')); - return $redirectResult->setPath('adminhtml/*/'); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('Unable to delete store view. Please, try again later.')); - } - return $redirectResult->setPath('adminhtml/*/editStore', ['store_id' => $itemId]); + $this->messageManager->addSuccess(__('The store view has been deleted.')); + return $redirectResult->setPath('adminhtml/*/'); } } diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php index c1d1c98779e8e9cce5c8a3a369a375585a8bd943..09c9f363b8b54c0f76d6510069ef9c1e56607eab 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php @@ -10,6 +10,7 @@ class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Sto { /** * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { @@ -33,15 +34,8 @@ class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Sto return $redirectResult->setPath('*/*/editWebsite', ['website_id' => $itemId]); } - try { - $model->delete(); - $this->messageManager->addSuccess(__('The website has been deleted.')); - return $redirectResult->setPath('adminhtml/*/'); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('Unable to delete website. Please, try again later.')); - } - return $redirectResult->setPath('*/*/editWebsite', ['website_id' => $itemId]); + $model->delete(); + $this->messageManager->addSuccess(__('The website has been deleted.')); + return $redirectResult->setPath('adminhtml/*/'); } } diff --git a/app/code/Magento/Backend/Model/Menu/Config/Menu/Dom.php b/app/code/Magento/Backend/Model/Menu/Config/Menu/Dom.php index 2b06e285b559f1f0a26680f79d05dfdb23c215dd..7dc805fa57f2d181e3ce715f16668e5acb3dda07 100644 --- a/app/code/Magento/Backend/Model/Menu/Config/Menu/Dom.php +++ b/app/code/Magento/Backend/Model/Menu/Config/Menu/Dom.php @@ -15,7 +15,8 @@ class Dom extends \Magento\Framework\Config\Dom * * @param string $nodePath * @return \DOMElement|null - * @throws \Magento\Framework\Exception an exception is possible if original document contains multiple fixed nodes + * @throws \Magento\Framework\Exception\LocalizedException an exception is possible if original document contains + * multiple fixed nodes */ protected function _getMatchedNode($nodePath) { diff --git a/app/code/Magento/Backend/Model/View/Result/Redirect.php b/app/code/Magento/Backend/Model/View/Result/Redirect.php index f8717a0b3e1fae060c0813ecb2ba8b1c09e314cc..2545f7e084a6a0e899db82068ea4dc4c3778e796 100644 --- a/app/code/Magento/Backend/Model/View/Result/Redirect.php +++ b/app/code/Magento/Backend/Model/View/Result/Redirect.php @@ -42,6 +42,17 @@ class Redirect extends \Magento\Framework\Controller\Result\Redirect parent::__construct($redirect, $urlBuilder); } + /** + * Set referer url or dashboard if referer does not exist + * + * @return $this + */ + public function setRefererOrBaseUrl() + { + $this->url = $this->redirect->getRedirectUrl($this->urlBuilder->getUrl($this->urlBuilder->getStartupPageUrl())); + return $this; + } + /** * {@inheritdoc} */ diff --git a/app/code/Magento/Backend/Model/View/Result/RedirectFactory.php b/app/code/Magento/Backend/Model/View/Result/RedirectFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..a848ed6ea46facb4e55f3b51be6040c550524a45 --- /dev/null +++ b/app/code/Magento/Backend/Model/View/Result/RedirectFactory.php @@ -0,0 +1,51 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Backend\Model\View\Result; + +use Magento\Framework\ObjectManagerInterface; + +/** + * Factory class for \Magento\Backend\Model\View\Result\Redirect + */ +class RedirectFactory extends \Magento\Framework\Controller\Result\RedirectFactory +{ + /** + * Object Manager instance + * + * @var ObjectManagerInterface + */ + protected $objectManager; + + /** + * Instance name to create + * + * @var string + */ + protected $instanceName; + + /** + * @param ObjectManagerInterface $objectManager + * @param string $instanceName + */ + public function __construct( + ObjectManagerInterface $objectManager, + $instanceName = 'Magento\Backend\Model\View\Result\Redirect' + ) { + $this->objectManager = $objectManager; + $this->instanceName = $instanceName; + } + + /** + * Create class instance with specified parameters + * + * @param array $data + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function create(array $data = []) + { + return $this->objectManager->create($this->instanceName, $data); + } +} diff --git a/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Cache/CleanMediaTest.php b/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Cache/CleanMediaTest.php index 7fba92c348bdf0e006a3b52aed3313a3cc18b478..a61bd01156c9d81ba8d8684abcc433bbdd37e500 100644 --- a/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Cache/CleanMediaTest.php +++ b/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Cache/CleanMediaTest.php @@ -32,7 +32,7 @@ class CleanMediaTest extends \PHPUnit_Framework_TestCase ); $context = $this->getMock( 'Magento\Backend\App\Action\Context', - ['getRequest', 'getResponse', 'getMessageManager', 'getSession'], + ['getRequest', 'getResponse', 'getMessageManager', 'getSession', 'getResultRedirectFactory'], $helper->getConstructArguments( 'Magento\Backend\App\Action\Context', [ @@ -45,28 +45,26 @@ class CleanMediaTest extends \PHPUnit_Framework_TestCase ] ) ); - $context->expects($this->once())->method('getRequest')->will($this->returnValue($request)); - $context->expects($this->once())->method('getResponse')->will($this->returnValue($response)); - $context->expects($this->once())->method('getSession')->will($this->returnValue($session)); - $context->expects($this->once())->method('getMessageManager')->will($this->returnValue($messageManager)); - - $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') - ->disableOriginalConstructor() - ->getMock(); - $resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); $resultRedirectFactory->expects($this->atLeastOnce()) ->method('create') ->willReturn($resultRedirect); + $context->expects($this->once())->method('getRequest')->willReturn($request); + $context->expects($this->once())->method('getResponse')->willReturn($response); + $context->expects($this->once())->method('getSession')->willReturn($session); + $context->expects($this->once())->method('getMessageManager')->willReturn($messageManager); + $context->expects($this->once())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory); $controller = $helper->getObject( 'Magento\Backend\Controller\Adminhtml\Cache\CleanMedia', [ - 'context' => $context, - 'resultRedirectFactory' => $resultRedirectFactory + 'context' => $context ] ); diff --git a/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Dashboard/RefreshStatisticsTest.php b/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Dashboard/RefreshStatisticsTest.php index f13a680af4a3b0e8172a5f63ddbd1ce871d1ec9b..e1ac51552586ab6edf311aa3d8d4bd2750ef143b 100644 --- a/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Dashboard/RefreshStatisticsTest.php +++ b/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Dashboard/RefreshStatisticsTest.php @@ -93,12 +93,14 @@ class RefreshStatisticsTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once())->method('getResponse')->willReturn($this->response); $this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager); $this->context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManager); + $this->context->expects($this->once()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactory); $this->refreshStatisticsController = $objectManagerHelper->getObject( 'Magento\Backend\Controller\Adminhtml\Dashboard\RefreshStatistics', [ 'context' => $this->context, - 'resultRedirectFactory' => $this->resultRedirectFactory, 'reportTypes' => $reportTypes ] ); diff --git a/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/System/Account/SaveTest.php b/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/System/Account/SaveTest.php index 49a1f4a21b24e25e45a50cb6efc9b509e989278c..012d90382443ebf785069ac2f8890267c72fd56d 100644 --- a/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/System/Account/SaveTest.php +++ b/app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/System/Account/SaveTest.php @@ -94,35 +94,26 @@ class SaveTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $contextMock = $this->getMock('Magento\Backend\App\Action\Context', [], [], '', false); - $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->_requestMock)); - $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->_responseMock)); - $contextMock->expects($this->any()) - ->method('getObjectManager') - ->will($this->returnValue($this->_objectManagerMock)); - $contextMock->expects($this->any()) - ->method('getFrontController') - ->will($this->returnValue($frontControllerMock)); - - $contextMock->expects($this->any())->method('getHelper')->will($this->returnValue($this->_helperMock)); - $contextMock->expects($this->any()) - ->method('getMessageManager') - ->will($this->returnValue($this->_messagesMock)); - $contextMock->expects($this->any())->method('getTranslator')->will($this->returnValue($this->_translatorMock)); - - $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') - ->disableOriginalConstructor() - ->getMock(); - $resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $resultRedirectFactory->expects($this->atLeastOnce()) - ->method('create') - ->willReturn($resultRedirect); + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $resultRedirectFactory->expects($this->atLeastOnce())->method('create')->willReturn($resultRedirect); - $args = ['context' => $contextMock, 'resultRedirectFactory' => $resultRedirectFactory]; + $contextMock = $this->getMock('Magento\Backend\App\Action\Context', [], [], '', false); + $contextMock->expects($this->any())->method('getRequest')->willReturn($this->_requestMock); + $contextMock->expects($this->any())->method('getResponse')->willReturn($this->_responseMock); + $contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->_objectManagerMock); + $contextMock->expects($this->any())->method('getFrontController')->willReturn($frontControllerMock); + $contextMock->expects($this->any())->method('getHelper')->willReturn($this->_helperMock); + $contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->_messagesMock); + $contextMock->expects($this->any())->method('getTranslator')->willReturn($this->_translatorMock); + $contextMock->expects($this->once())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory); + + $args = ['context' => $contextMock]; $testHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->_controller = $testHelper->getObject('Magento\Backend\Controller\Adminhtml\System\Account\Save', $args); diff --git a/app/code/Magento/Backend/Test/Unit/Model/Menu/ItemTest.php b/app/code/Magento/Backend/Test/Unit/Model/Menu/ItemTest.php index 6b90cdc5f8248c21e7f775eb229f91776eebbc5a..2b450fd1a3bef37e8a2be372066869a5720525d5 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/Menu/ItemTest.php +++ b/app/code/Magento/Backend/Test/Unit/Model/Menu/ItemTest.php @@ -208,7 +208,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase )->with( 'Magento_Config::config' )->will( - $this->throwException(new \Magento\Framework\Exception()) + $this->throwException(new \Magento\Framework\Exception\LocalizedException(__('Error'))) ); $this->assertFalse($this->_model->isAllowed()); } diff --git a/app/code/Magento/Backend/Test/Unit/Model/View/Result/RedirectTest.php b/app/code/Magento/Backend/Test/Unit/Model/View/Result/RedirectTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ca51c9d8a2e288ddd0ff56ff1204b14483f8cfa2 --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Model/View/Result/RedirectTest.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Backend\Test\Unit\Model\View\Result; + +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; + +class RedirectTest extends \PHPUnit_Framework_TestCase +{ + /** @var \Magento\Backend\Model\View\Result\Redirect */ + protected $action; + + /** @var ObjectManagerHelper */ + protected $objectManagerHelper; + + /** @var \Magento\Backend\Model\Session|\PHPUnit_Framework_MockObject_MockObject */ + protected $session; + + /** @var \Magento\Framework\App\ActionFlag|\PHPUnit_Framework_MockObject_MockObject */ + protected $actionFlag; + + /** @var \Magento\Backend\Model\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $urlBuilder; + + /** @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $redirect; + + protected $url = 'adminhtml/index'; + + protected function setUp() + { + $this->session = $this->getMock('Magento\Backend\Model\Session', [], [], '', false); + $this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false); + $this->urlBuilder = $this->getMock('Magento\Backend\Model\UrlInterface', [], [], '', false); + $this->redirect = $this->getMock( + 'Magento\Framework\App\Response\RedirectInterface', + [], + [], + '', + false + ); + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->action = $this->objectManagerHelper->getObject( + 'Magento\Backend\Model\View\Result\Redirect', + [ + 'session' => $this->session, + 'actionFlag' => $this->actionFlag, + 'redirect' => $this->redirect, + 'urlBuilder' =>$this->urlBuilder, + ] + ); + } + + public function testSetRefererOrBaseUrl() + { + $this->urlBuilder->expects($this->once())->method('getUrl')->willReturn($this->url); + $this->redirect->expects($this->once())->method('getRedirectUrl')->with($this->url)->willReturn('test string'); + $this->action->setRefererOrBaseUrl(); + } +} diff --git a/app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php b/app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php index 52ad8d4ac6e96d985e5acc9658e6e524a9e98aec..c9fe2c5758624b59d19f5a8ec8deba05bcb6c11a 100755 --- a/app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php +++ b/app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php @@ -15,11 +15,6 @@ class Download extends \Magento\Backup\Controller\Adminhtml\Index */ protected $resultRawFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry @@ -28,7 +23,6 @@ class Download extends \Magento\Backup\Controller\Adminhtml\Index * @param \Magento\Backup\Model\BackupFactory $backupModelFactory * @param \Magento\Framework\App\MaintenanceMode $maintenanceMode * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, @@ -37,8 +31,7 @@ class Download extends \Magento\Backup\Controller\Adminhtml\Index \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Backup\Model\BackupFactory $backupModelFactory, \Magento\Framework\App\MaintenanceMode $maintenanceMode, - \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\Controller\Result\RawFactory $resultRawFactory ) { parent::__construct( $context, @@ -49,7 +42,6 @@ class Download extends \Magento\Backup\Controller\Adminhtml\Index $maintenanceMode ); $this->resultRawFactory = $resultRawFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php b/app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php index ef03c35226aef73091e954a9e38aac1f0d16ef3a..d797caeebfb4d9ca9f2f93a1a1cf93d22b79798c 100644 --- a/app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php +++ b/app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php @@ -44,7 +44,7 @@ class Rollback extends \Magento\Backup\Controller\Adminhtml\Index } if (!$backup->getTime()) { - throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot(); + throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot(__('Can\'t load snapshot archive')); } $type = $backup->getType(); diff --git a/app/code/Magento/Backup/Exception.php b/app/code/Magento/Backup/Exception.php deleted file mode 100644 index 2f783199aa4a33488e755e10ca6a8c54efbac964..0000000000000000000000000000000000000000 --- a/app/code/Magento/Backup/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Backup; - -class Exception extends \Zend_Exception -{ -} diff --git a/app/code/Magento/Backup/Model/Backup.php b/app/code/Magento/Backup/Model/Backup.php index be790f48ef99aefbd11467d8b6ce65b7bb5ab910..a19cf7091903b12ebf12db04d5919bbf84d4f8dc 100755 --- a/app/code/Magento/Backup/Model/Backup.php +++ b/app/code/Magento/Backup/Model/Backup.php @@ -273,20 +273,22 @@ class Backup extends \Magento\Framework\Object implements \Magento\Framework\Bac * * @param bool $write * @return $this - * @throws \Magento\Backup\Exception + * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Backup\Exception\NotEnoughPermissions */ public function open($write = false) { if ($this->getPath() === null) { - throw new \Magento\Backup\Exception(__('The backup file path was not specified.')); + throw new \Magento\Framework\Exception\InputException(__('The backup file path was not specified.')); } if ($write && $this->varDirectory->isFile($this->_getFilePath())) { $this->varDirectory->delete($this->_getFilePath()); } if (!$write && !$this->varDirectory->isFile($this->_getFilePath())) { - throw new \Magento\Backup\Exception(__('The backup file "%1" does not exist.', $this->getFileName())); + throw new \Magento\Framework\Exception\InputException( + __('The backup file "%1" does not exist.', $this->getFileName()) + ); } $mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb'; @@ -298,7 +300,7 @@ class Backup extends \Magento\Framework\Object implements \Magento\Framework\Bac $this->_getFilePath(), $mode ); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( __('Sorry, but we cannot read from or write to backup file "%1".', $this->getFileName()) ); @@ -311,12 +313,12 @@ class Backup extends \Magento\Framework\Object implements \Magento\Framework\Bac * Get zlib handler * * @return \Magento\Framework\Filesystem\File\WriteInterface - * @throws \Magento\Backup\Exception + * @throws \Magento\Framework\Exception\InputException */ protected function _getStream() { if ($this->_stream === null) { - throw new \Magento\Backup\Exception(__('The backup file handler was unspecified.')); + throw new \Magento\Framework\Exception\InputException(__('The backup file handler was unspecified.')); } return $this->_stream; } @@ -347,14 +349,14 @@ class Backup extends \Magento\Framework\Object implements \Magento\Framework\Bac * * @param string $string * @return $this - * @throws \Magento\Backup\Exception + * @throws \Magento\Framework\Exception\InputException */ public function write($string) { try { $this->_getStream()->write($string); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { - throw new \Magento\Backup\Exception( + } catch (\Magento\Framework\Exception\FileSystemException $e) { + throw new \Magento\Framework\Exception\InputException( __('Something went wrong writing to the backup file "%1".', $this->getFileName()) ); } diff --git a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php index bba764fa20551565dd69ab8eee775f287af82d35..4aaebd08b4addfa6e68ce88a044185dbbe09a7bb 100755 --- a/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php +++ b/app/code/Magento/Backup/Test/Unit/Controller/Adminhtml/Index/DownloadTest.php @@ -126,7 +126,8 @@ class DownloadTest extends \PHPUnit_Framework_TestCase [ 'objectManager' => $this->objectManagerMock, 'request' => $this->requestMock, - 'response' => $this->responseMock + 'response' => $this->responseMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock ] ); $this->downloadController = $this->objectManager->getObject( @@ -136,7 +137,6 @@ class DownloadTest extends \PHPUnit_Framework_TestCase 'backupModelFactory' => $this->backupModelFactoryMock, 'fileFactory' => $this->fileFactoryMock, 'resultRawFactory' => $this->resultRawFactoryMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock ] ); } diff --git a/app/code/Magento/Captcha/Model/DefaultModel.php b/app/code/Magento/Captcha/Model/DefaultModel.php old mode 100644 new mode 100755 diff --git a/app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php b/app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php old mode 100644 new mode 100755 index d195bd29bf24fd141af8b1ab3fa2fe4f1578c80d..2e82417babb2a1fa1f1132ca0b87c8b017ec3ad7 --- a/app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php +++ b/app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php @@ -7,6 +7,11 @@ namespace Magento\Captcha\Test\Unit\Model; class DefaultTest extends \PHPUnit_Framework_TestCase { + /** + * Expiration frame + */ + const EXPIRE_FRAME = 86400; + /** * Captcha default config data * @var array @@ -67,7 +72,7 @@ class DefaultTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $_session; + protected $session; /** * @var \PHPUnit_Framework_MockObject_MockObject @@ -186,7 +191,7 @@ class DefaultTest extends \PHPUnit_Framework_TestCase { self::$_defaultConfig['case_sensitive'] = '1'; $this->assertFalse($this->_object->isCorrect('abcdef5')); - $sessionData = ['user_create_word' => ['data' => 'AbCdEf5', 'expires' => time() + 600]]; + $sessionData = ['user_create_word' => ['data' => 'AbCdEf5', 'expires' => time() + self::EXPIRE_FRAME]]; $this->_object->getSession()->setData($sessionData); self::$_defaultConfig['case_sensitive'] = '0'; $this->assertTrue($this->_object->isCorrect('abcdef5')); @@ -251,7 +256,7 @@ class DefaultTest extends \PHPUnit_Framework_TestCase ); $session->expects($this->any())->method('isLoggedIn')->will($this->returnValue(false)); - $session->setData(['user_create_word' => ['data' => 'AbCdEf5', 'expires' => time() + 600]]); + $session->setData(['user_create_word' => ['data' => 'AbCdEf5', 'expires' => time() + self::EXPIRE_FRAME]]); return $session; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category.php index 048739d49b1dd0bc5f951492798bd95c7ff6061e..718bf23d4965f0315c00c29a00f9baf11731bae0 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category.php @@ -10,23 +10,6 @@ namespace Magento\Catalog\Controller\Adminhtml; */ class Category extends \Magento\Backend\App\Action { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * Initialize requested category and put it into registry. * Root category can be returned, if inappropriate store/category is specified diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Add.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Add.php index 06bb17ec517b6aa3e872053720986f0acd6d4a5b..5cd9fffd001c469ca9276a706a71105206b70d1d 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Add.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Add.php @@ -15,15 +15,13 @@ class Add extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultForwardFactory = $resultForwardFactory; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php index 5fec84fb27a853f3eccfccab7abd20425672dd7f..6f9cf5cc6e551509bb3eb6c33dbb55f90032761d 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php @@ -20,17 +20,15 @@ class CategoriesJson extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\LayoutFactory $layoutFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\LayoutFactory $layoutFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->layoutFactory = $layoutFactory; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php index e0a7db83c41fc61373fce8a2197f1d7549c4418c..cc0e60a82a3918825367c4a4b166c0bb0477c216 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php @@ -13,15 +13,13 @@ class Delete extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->categoryRepository = $categoryRepository; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php index 0d0b763cfec6bc93832e2ebd25fff308328a3030..8834b03f6a8952c745c6459838f172e8dafbf53f 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php @@ -20,17 +20,15 @@ class Edit extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultPageFactory = $resultPageFactory; $this->resultJsonFactory = $resultJsonFactory; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Grid.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Grid.php index aa775168229db30f2971a603d59576850b34952a..fdecd7c3922901e0a4288d146219eeaadbd76e12 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Grid.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Grid.php @@ -20,17 +20,15 @@ class Grid extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory * @param \Magento\Framework\View\LayoutFactory $layoutFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, \Magento\Framework\View\LayoutFactory $layoutFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultRawFactory = $resultRawFactory; $this->layoutFactory = $layoutFactory; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Index.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Index.php index 3c395c8ff251409d285f615dd39846313a587f0e..1b0bbf347f509d852ee2ee713513a58de1e185a3 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Index.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Index.php @@ -15,15 +15,13 @@ class Index extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultForwardFactory = $resultForwardFactory; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php index c35247eaacf7946444fb1fa0d89f1a47ff8a8a86..fb0d48aacc43c37800cf9f4745a777909eb6e44d 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php @@ -25,19 +25,17 @@ class Move extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\LayoutFactory $layoutFactory, * @param \Psr\Log\LoggerInterface $logger, */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\LayoutFactory $layoutFactory, \Psr\Log\LoggerInterface $logger ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->layoutFactory = $layoutFactory; $this->logger = $logger; @@ -72,7 +70,7 @@ class Move extends \Magento\Catalog\Controller\Adminhtml\Category } catch (\Magento\Framework\Exception\LocalizedException $e) { $error = true; $this->messageManager->addError(__('There was a category move error.')); - } catch (\Magento\UrlRewrite\Model\Storage\DuplicateEntryException $e) { + } catch (\Magento\Framework\Exception\AlreadyExistsException $e) { $error = true; $this->messageManager->addError(__('There was a category move error. %1', $e->getMessage())); } catch (\Exception $e) { diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php index 8b19840c3c083f0b8ec8554d7f48eb2133849583..150b0194664890a4de8f33bd33c82eaa9eddeb2e 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/RefreshPath.php @@ -15,15 +15,13 @@ class RefreshPath extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php index 01f622f6996f39a791fa04ebc25eb16c4bce79a9..9949ffe5699e9f3d93a317a16b564d48cb191e74 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php @@ -29,19 +29,17 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category * Constructor * * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\LayoutFactory $layoutFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\LayoutFactory $layoutFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultRawFactory = $resultRawFactory; $this->resultJsonFactory = $resultJsonFactory; $this->layoutFactory = $layoutFactory; diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/SuggestCategories.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/SuggestCategories.php index 14d7bf780c053563758b86b5e8cd39a8fa3b519c..94c8010cc39809e7383ca98384e3c019a93304b0 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/SuggestCategories.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/SuggestCategories.php @@ -20,17 +20,15 @@ class SuggestCategories extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\LayoutFactory $layoutFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\LayoutFactory $layoutFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->layoutFactory = $layoutFactory; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Tree.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Tree.php index 6604d3fc116a0b06793eece09e869076c6a663b6..9acd075bc827602e5839bfbf30ba2f1a1e00ab3c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Tree.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Tree.php @@ -20,17 +20,15 @@ class Tree extends \Magento\Catalog\Controller\Adminhtml\Category /** * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\LayoutFactory $layoutFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\LayoutFactory $layoutFactory ) { - parent::__construct($context, $resultRedirectFactory); + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->layoutFactory = $layoutFactory; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php index 4e114334b66f781f4a6c6c54fa7bc4fe271d7043..0b6377c4b470212590216a46f004a325a6e20653 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Edit.php @@ -13,26 +13,18 @@ class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut */ protected $resultPageFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Catalog\Helper\Product\Edit\Action\Attribute $attributeHelper * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Catalog\Helper\Product\Edit\Action\Attribute $attributeHelper, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context, $attributeHelper); $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php index ef791cd838cdac322244ddead979da27b69c4f27..3661567d5fa0001cc9a0a051145f1c0b69e3f100 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php @@ -43,11 +43,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut */ protected $_stockIndexerProcessor; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\Api\DataObjectHelper */ @@ -61,7 +56,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut * @param \Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexerProcessor * @param \Magento\Catalog\Helper\Product $catalogProduct * @param \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper */ public function __construct( @@ -72,7 +66,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut \Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexerProcessor, \Magento\Catalog\Helper\Product $catalogProduct, \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory $stockItemFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper ) { $this->_productFlatIndexerProcessor = $productFlatIndexerProcessor; @@ -81,7 +74,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut $this->_catalogProduct = $catalogProduct; $this->stockItemFactory = $stockItemFactory; parent::__construct($context, $attributeHelper); - $this->resultRedirectFactory = $resultRedirectFactory; $this->dataObjectHelper = $dataObjectHelper; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php index bcc311e379449f12037798963ab9a0a3febfff50..3fbda63630e30573e0c3e38dde53d8cf3b1d0a01 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Delete.php @@ -8,31 +8,6 @@ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; class Delete extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * Constructor - * - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Cache\FrontendInterface $attributeLabelCache - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Cache\FrontendInterface $attributeLabelCache, - \Magento\Framework\Registry $coreRegistry, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * @return \Magento\Backend\Model\View\Result\Redirect */ diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php index 7eee03d9f842eef0d0b3c1c3475644509c13c008..f149ff2506a6cdb51ecadac9f049774d645ad4da 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php @@ -6,37 +6,8 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; -use Magento\Backend\App\Action; -use Magento\Backend\Model\View\Result\RedirectFactory; -use Magento\Framework\View\Result\PageFactory; - class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * Constructor - * - * @param Action\Context $context - * @param \Magento\Framework\Cache\FrontendInterface $attributeLabelCache - * @param \Magento\Framework\Registry $coreRegistry - * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Cache\FrontendInterface $attributeLabelCache, - \Magento\Framework\Registry $coreRegistry, - PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory); - } - /** * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.NPathComplexity) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index c78d3aea2e0e6d512ad411c45a6dacc970088536..4faadeba7d39f5b3e5c5d5899ad8142f221d5681 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -46,11 +46,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute */ protected $groupCollectionFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Cache\FrontendInterface $attributeLabelCache @@ -62,7 +57,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute * @param \Magento\Framework\Filter\FilterManager $filterManager * @param \Magento\Catalog\Helper\Product $productHelper * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -75,8 +69,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory, \Magento\Eav\Model\Resource\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory, \Magento\Framework\Filter\FilterManager $filterManager, - \Magento\Catalog\Helper\Product $productHelper, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Catalog\Helper\Product $productHelper ) { parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory); $this->buildFactory = $buildFactory; @@ -85,7 +78,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute $this->attributeFactory = $attributeFactory; $this->validatorFactory = $validatorFactory; $this->groupCollectionFactory = $groupCollectionFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Duplicate.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Duplicate.php index 4e5ba91e5939287413890eaed444829fd0590f8e..d335b898f71ce1b455608d81f85f186f9d7af435 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Duplicate.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Duplicate.php @@ -16,26 +16,18 @@ class Duplicate extends \Magento\Catalog\Controller\Adminhtml\Product */ protected $productCopier; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Action\Context $context * @param Builder $productBuilder * @param \Magento\Catalog\Model\Product\Copier $productCopier - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, Product\Builder $productBuilder, - \Magento\Catalog\Model\Product\Copier $productCopier, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Catalog\Model\Product\Copier $productCopier ) { $this->productCopier = $productCopier; parent::__construct($context, $productBuilder); - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php index 34d74da1fa0c07362963ab4a59a3505bee21af92..30e1299ca1749c93a6274425d0e2a3a1f3343637 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Edit.php @@ -20,26 +20,18 @@ class Edit extends \Magento\Catalog\Controller\Adminhtml\Product */ protected $resultPageFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Catalog\Controller\Adminhtml\Product\Builder $productBuilder * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Catalog\Controller\Adminhtml\Product\Builder $productBuilder, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context, $productBuilder); $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index bab900046dc23df9d6d3db911d8e058e3d42f3f2..19a6a11743b626fa0e6d079a8a0762de201bc37f 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -8,25 +8,6 @@ namespace Magento\Catalog\Controller\Adminhtml\Product; class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Catalog\Controller\Adminhtml\Product\Builder $productBuilder - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Catalog\Controller\Adminhtml\Product\Builder $productBuilder, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $productBuilder); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * @return \Magento\Backend\Model\View\Result\Redirect */ diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php index 26665c88a5f2fef3e5f49a91dee577a14a0e6415..749b55d0ee127eff2573c555d035eda82d7cf8ad 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php @@ -16,26 +16,18 @@ class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product */ protected $_productPriceIndexerProcessor; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Action\Context $context * @param Builder $productBuilder * @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, Product\Builder $productBuilder, - \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Catalog\Model\Indexer\Product\Price\Processor $productPriceIndexerProcessor ) { $this->_productPriceIndexerProcessor = $productPriceIndexerProcessor; parent::__construct($context, $productBuilder); - $this->resultRedirectFactory = $resultRedirectFactory; } /** @@ -61,6 +53,7 @@ class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product * Update product(s) status action * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { @@ -68,20 +61,26 @@ class MassStatus extends \Magento\Catalog\Controller\Adminhtml\Product $storeId = (int) $this->getRequest()->getParam('store', 0); $status = (int) $this->getRequest()->getParam('status'); - try { - $this->_validateMassStatus($productIds, $status); - $this->_objectManager->get('Magento\Catalog\Model\Product\Action') - ->updateAttributes($productIds, ['status' => $status], $storeId); - $this->messageManager->addSuccess(__('A total of %1 record(s) have been updated.', count($productIds))); - $this->_productPriceIndexerProcessor->reindexList($productIds); - } catch (\Magento\Framework\Exception $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->_getSession()->addException($e, __('Something went wrong while updating the product(s) status.')); - } + $this->_validateMassStatus($productIds, $status); + $this->_objectManager->get('Magento\Catalog\Model\Product\Action') + ->updateAttributes($productIds, ['status' => $status], $storeId); + $this->messageManager->addSuccess(__('A total of %1 record(s) have been updated.', count($productIds))); + $this->_productPriceIndexerProcessor->reindexList($productIds); + + return $this->getDefaultResult(); + } - return $this->resultRedirectFactory->create()->setPath('catalog/*/', ['store' => $storeId]); + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath( + 'catalog/*/', + ['store' => $this->getRequest()->getParam('store', 0)] + ); } } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php index 9a28b53da56483ae0f48a70bad0a39961b085800..1ef2d92da33a5b2fc44c7b49927f77be245a3737 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php @@ -26,32 +26,24 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product */ protected $productTypeManager; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Action\Context $context * @param Builder $productBuilder * @param Initialization\Helper $initializationHelper * @param \Magento\Catalog\Model\Product\Copier $productCopier * @param \Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, Product\Builder $productBuilder, Initialization\Helper $initializationHelper, \Magento\Catalog\Model\Product\Copier $productCopier, - \Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Catalog\Model\Product\TypeTransitionManager $productTypeManager ) { $this->initializationHelper = $initializationHelper; $this->productCopier = $productCopier; $this->productTypeManager = $productTypeManager; parent::__construct($context, $productBuilder); - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php index 506552221c95b7f88973ebcc5076235f56bc7e1d..110cb1a5f752db557f1ee4e6d1c843714b6dc741 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Delete.php @@ -8,11 +8,6 @@ namespace Magento\Catalog\Controller\Adminhtml\Product\Set; class Delete extends \Magento\Catalog\Controller\Adminhtml\Product\Set { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Eav\Api\AttributeSetRepositoryInterface */ @@ -21,17 +16,14 @@ class Delete extends \Magento\Catalog\Controller\Adminhtml\Product\Set /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSetRepository */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSetRepository ) { parent::__construct($context, $coreRegistry); - $this->resultRedirectFactory = $resultRedirectFactory; $this->attributeSetRepository = $attributeSetRepository; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php index 1d124a7cd04c04cd0f9c1e85b69c0f7fb2773b9c..d40982a5d5641e8d2c3a3099015686f5435e52b8 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php @@ -13,26 +13,18 @@ class Edit extends \Magento\Catalog\Controller\Adminhtml\Product\Set */ protected $resultPageFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context, $coreRegistry); $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php index fc228f2cf35d1670366467e4875aa21f4155a3ec..09e77fbdec769cacb87a69678ed41a40eeda0a5a 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Save.php @@ -13,11 +13,6 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set */ protected $layoutFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\Controller\Result\JsonFactory */ @@ -27,19 +22,16 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\View\LayoutFactory $layoutFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\View\LayoutFactory $layoutFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory ) { parent::__construct($context, $coreRegistry); $this->layoutFactory = $layoutFactory; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultJsonFactory = $resultJsonFactory; } diff --git a/app/code/Magento/Catalog/Controller/Category/View.php b/app/code/Magento/Catalog/Controller/Category/View.php index 50c79ade7e64e44418d63e241a6497cbba49cd89..2941bf03189cd9b0e5c82ceed3f7355f220acf76 100644 --- a/app/code/Magento/Catalog/Controller/Category/View.php +++ b/app/code/Magento/Catalog/Controller/Category/View.php @@ -57,11 +57,6 @@ class View extends \Magento\Framework\App\Action\Action */ protected $resultForwardFactory; - /** - * @var \Magento\Framework\Controller\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * Catalog Layer Resolver * @@ -85,7 +80,6 @@ class View extends \Magento\Framework\App\Action\Action * @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param Resolver $layerResolver * @param CategoryRepositoryInterface $categoryRepository * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -99,7 +93,6 @@ class View extends \Magento\Framework\App\Action\Action \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository ) { @@ -111,7 +104,6 @@ class View extends \Magento\Framework\App\Action\Action $this->categoryUrlPathGenerator = $categoryUrlPathGenerator; $this->resultPageFactory = $resultPageFactory; $this->resultForwardFactory = $resultForwardFactory; - $this->resultRedirectFactory = $resultRedirectFactory; $this->layerResolver = $layerResolver; $this->categoryRepository = $categoryRepository; } diff --git a/app/code/Magento/Catalog/Controller/Index/Index.php b/app/code/Magento/Catalog/Controller/Index/Index.php index f90d14005efc69954d055e69750973b7d8a84fe7..5ea3a57caf483b4ad09f26d56ec28602a7c292fd 100644 --- a/app/code/Magento/Catalog/Controller/Index/Index.php +++ b/app/code/Magento/Catalog/Controller/Index/Index.php @@ -1,35 +1,12 @@ <?php /** - * * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Catalog\Controller\Index; -use Magento\Framework\App\Action\Context; -use Magento\Framework\Controller\Result; - class Index extends \Magento\Framework\App\Action\Action { - /** - * @var Result\Redirect - */ - protected $resultRedirectFactory; - - /** - * Constructor - * - * @param Context $context - * @param Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - Context $context, - Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context); - } - /** * Index action * diff --git a/app/code/Magento/Catalog/Controller/Product/Compare.php b/app/code/Magento/Catalog/Controller/Product/Compare.php index 441646f6e71e181c1559ed9c751d39356f556123..89952430169bfb8f11be751843e8e318dfff7e02 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare.php @@ -7,7 +7,6 @@ namespace Magento\Catalog\Controller\Product; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\Data\Form\FormKey\Validator; -use Magento\Framework\Controller\Result; use Magento\Framework\View\Result\PageFactory; /** @@ -77,11 +76,6 @@ class Compare extends \Magento\Framework\App\Action\Action */ protected $_formKeyValidator; - /** - * @var Result\Redirect - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\View\Result\PageFactory */ @@ -104,7 +98,6 @@ class Compare extends \Magento\Framework\App\Action\Action * @param \Magento\Catalog\Model\Session $catalogSession * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param Validator $formKeyValidator - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @param ProductRepositoryInterface $productRepository * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -119,7 +112,6 @@ class Compare extends \Magento\Framework\App\Action\Action \Magento\Catalog\Model\Session $catalogSession, \Magento\Store\Model\StoreManagerInterface $storeManager, Validator $formKeyValidator, - Result\RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, ProductRepositoryInterface $productRepository ) { @@ -131,7 +123,6 @@ class Compare extends \Magento\Framework\App\Action\Action $this->_catalogProductCompareList = $catalogProductCompareList; $this->_catalogSession = $catalogSession; $this->_formKeyValidator = $formKeyValidator; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultPageFactory = $resultPageFactory; $this->productRepository = $productRepository; parent::__construct($context); diff --git a/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php b/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php index 0a27a74c35267ec620232da8c1514640ed8f2da8..8c25b8c0e5d59ada33d8144155e6425358b0e64c 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare/Clear.php @@ -26,17 +26,10 @@ class Clear extends \Magento\Catalog\Controller\Product\Compare $items->setVisitorId($this->_customerVisitor->getId()); } - try { - $items->clear(); - $this->messageManager->addSuccess(__('You cleared the comparison list.')); - $this->_objectManager->get('Magento\Catalog\Helper\Product\Compare')->calculate(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('Something went wrong clearing the comparison list.')); - } + $items->clear(); + $this->messageManager->addSuccess(__('You cleared the comparison list.')); + $this->_objectManager->get('Magento\Catalog\Helper\Product\Compare')->calculate(); - $resultRedirect = $this->resultRedirectFactory->create(); - return $resultRedirect->setRefererOrBaseUrl(); + return $this->getDefaultResult(); } } diff --git a/app/code/Magento/Catalog/Controller/Product/Compare/Index.php b/app/code/Magento/Catalog/Controller/Product/Compare/Index.php index 93b985ec094a5bc6906255d46e6e4c8ebfaaba9d..954437bf09576e67e3029cac1ef059f25814b083 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare/Index.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare/Index.php @@ -8,7 +8,6 @@ namespace Magento\Catalog\Controller\Product\Compare; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\Data\Form\FormKey\Validator; -use Magento\Framework\Controller\Result; use Magento\Framework\View\Result\PageFactory; /** @@ -31,7 +30,6 @@ class Index extends \Magento\Catalog\Controller\Product\Compare * @param \Magento\Catalog\Model\Session $catalogSession * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param Validator $formKeyValidator - * @param Result\RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param ProductRepositoryInterface $productRepository * @param \Magento\Framework\Url\DecoderInterface $urlDecoder @@ -48,7 +46,6 @@ class Index extends \Magento\Catalog\Controller\Product\Compare \Magento\Catalog\Model\Session $catalogSession, \Magento\Store\Model\StoreManagerInterface $storeManager, Validator $formKeyValidator, - Result\RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, ProductRepositoryInterface $productRepository, \Magento\Framework\Url\DecoderInterface $urlDecoder @@ -63,7 +60,6 @@ class Index extends \Magento\Catalog\Controller\Product\Compare $catalogSession, $storeManager, $formKeyValidator, - $resultRedirectFactory, $resultPageFactory, $productRepository ); diff --git a/app/code/Magento/Catalog/Controller/Product/Gallery.php b/app/code/Magento/Catalog/Controller/Product/Gallery.php index f5dcaa74f8a73a6ca0bdf5c8485b91d515873e44..b4e9c7480ba1de468cf4eb08f11d8478d91eb1a1 100644 --- a/app/code/Magento/Catalog/Controller/Product/Gallery.php +++ b/app/code/Magento/Catalog/Controller/Product/Gallery.php @@ -12,11 +12,6 @@ use Magento\Framework\View\Result\PageFactory; class Gallery extends \Magento\Catalog\Controller\Product { - /** - * @var Result\Redirect - */ - protected $resultRedirectFactory; - /** * @var Result\ForwardFactory */ @@ -31,17 +26,14 @@ class Gallery extends \Magento\Catalog\Controller\Product * Constructor * * @param Context $context - * @param Result\RedirectFactory $resultRedirectFactory * @param Result\ForwardFactory $resultForwardFactory * @param PageFactory $resultPageFactory */ public function __construct( Context $context, - Result\RedirectFactory $resultRedirectFactory, Result\ForwardFactory $resultForwardFactory, PageFactory $resultPageFactory ) { - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; $this->resultPageFactory = $resultPageFactory; parent::__construct($context); diff --git a/app/code/Magento/Catalog/Controller/Product/View.php b/app/code/Magento/Catalog/Controller/Product/View.php index c9a9957da33c1cef4dc39d5788af1620da07f44d..9cdee4fc826f82591b0d48a87f118523312c6466 100644 --- a/app/code/Magento/Catalog/Controller/Product/View.php +++ b/app/code/Magento/Catalog/Controller/Product/View.php @@ -7,7 +7,6 @@ namespace Magento\Catalog\Controller\Product; use Magento\Framework\App\Action\Context; -use Magento\Framework\Controller\Result; use Magento\Framework\View\Result\PageFactory; class View extends \Magento\Catalog\Controller\Product @@ -17,11 +16,6 @@ class View extends \Magento\Catalog\Controller\Product */ protected $viewHelper; - /** - * @var \Magento\Framework\Controller\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\Controller\Result\ForwardFactory */ @@ -37,19 +31,16 @@ class View extends \Magento\Catalog\Controller\Product * * @param Context $context * @param \Magento\Catalog\Helper\Product\View $viewHelper - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory * @param PageFactory $resultPageFactory */ public function __construct( Context $context, \Magento\Catalog\Helper\Product\View $viewHelper, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, PageFactory $resultPageFactory ) { $this->viewHelper = $viewHelper; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; $this->resultPageFactory = $resultPageFactory; parent::__construct($context); diff --git a/app/code/Magento/Catalog/Exception.php b/app/code/Magento/Catalog/Exception.php deleted file mode 100644 index e6beec63ca73960892bca6a8a39aea63acb3cc93..0000000000000000000000000000000000000000 --- a/app/code/Magento/Catalog/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Catalog; - -class Exception extends \Zend_Exception -{ -} diff --git a/app/code/Magento/Catalog/Model/Attribute/Backend/Customlayoutupdate.php b/app/code/Magento/Catalog/Model/Attribute/Backend/Customlayoutupdate.php index cc6329800747bf920e016b132540dded47129af0..575afc4b97c2d1b5500fe26e173a2b9df4b7c7d8 100644 --- a/app/code/Magento/Catalog/Model/Attribute/Backend/Customlayoutupdate.php +++ b/app/code/Magento/Catalog/Model/Attribute/Backend/Customlayoutupdate.php @@ -53,8 +53,8 @@ class Customlayoutupdate extends \Magento\Eav\Model\Entity\Attribute\Backend\Abs if (!$validator->isValid($xml)) { $messages = $validator->getMessages(); //Add first message to exception - $massage = array_shift($messages); - $eavExc = new Exception($massage); + $message = array_shift($messages); + $eavExc = new Exception(__($message)); $eavExc->setAttributeCode($attributeName); throw $eavExc; } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php old mode 100644 new mode 100755 index 8c74ca3126cb3ba93bd2d0056eb595f6c590bd84..09733d3b8a0cbace2a1eb0b0f22ddb68af67eb7c --- a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php @@ -15,14 +15,15 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction * * @param array|int|null $ids * @return void - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\LocalizedException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($ids = null) { try { $this->reindex(); } catch (\Exception $e) { - throw new \Magento\Catalog\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); } } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Row.php b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Row.php old mode 100644 new mode 100755 index 2aad332960bc66caa53b7cf3d5cff722a409a250..cd367f0682f6e3b8f5ce09e95fd17b9b434e133d --- a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Row.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Row.php @@ -15,17 +15,18 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction * * @param int|null $id * @return void - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\LocalizedException */ public function execute($id = null) { if (!isset($id) || empty($id)) { - throw new \Magento\Catalog\Exception(__('Could not rebuild index for undefined product')); + throw new \Magento\Framework\Exception\InputException(__('Could not rebuild index for undefined product')); } try { $this->reindex($id); } catch (\Exception $e) { - throw new \Magento\Catalog\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); } } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Rows.php b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Rows.php old mode 100644 new mode 100755 index e05aa311a0f13041855fd900adb08bc32d1ed261..9414f898aeda4f603b852dfc08f5c3cc05296f17 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Rows.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Rows.php @@ -15,17 +15,18 @@ class Rows extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction * * @param array $ids * @return void - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\LocalizedException */ public function execute($ids) { if (empty($ids)) { - throw new \Magento\Catalog\Exception(__('Bad value was supplied.')); + throw new \Magento\Framework\Exception\InputException(__('Bad value was supplied.')); } try { $this->reindex($ids); } catch (\Exception $e) { - throw new \Magento\Catalog\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); } } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Full.php index 9860c748d27cdb5fd662e9c76bf7ef120186fc41..7a7f81a1091780070909de54e6cf61d89bb7530d 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Full.php @@ -17,7 +17,7 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction * @param null|array $ids * * @return \Magento\Catalog\Model\Indexer\Product\Flat\Action\Full - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Exception * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php old mode 100644 new mode 100755 index 2f408c71ea765bc0e8567c8ca067173a0d8f009e..6e43b0666791cf26a65df23d3dbd6809bbc48b2f --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php @@ -365,13 +365,13 @@ abstract class AbstractAction * * @param string $productTypeId * @return \Magento\Catalog\Model\Resource\Product\Indexer\Price\PriceInterface - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\InputException */ protected function _getIndexer($productTypeId) { $this->getTypeIndexers(); if (!isset($this->_indexers[$productTypeId])) { - throw new \Magento\Catalog\Exception(__('Unsupported product type "%1".', $productTypeId)); + throw new \Magento\Framework\Exception\InputException(__('Unsupported product type "%1".', $productTypeId)); } return $this->_indexers[$productTypeId]; } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php old mode 100644 new mode 100755 index 835c7f3e15463295f41a37c2a02947d3bb19a06c..61700737da9d279d805533bc4421db2bbfb18182 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php @@ -16,7 +16,7 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction * * @param array|int|null $ids * @return void - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function execute($ids = null) { @@ -32,7 +32,7 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction } $this->_syncData(); } catch (\Exception $e) { - throw new \Magento\Catalog\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); } } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Row.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Row.php old mode 100644 new mode 100755 index a5a629823c5894bf8dd14fe649b7d9015c66787b..8ba3086616817d0170aac3638e87eb4de5dd3005 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Row.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Row.php @@ -16,17 +16,18 @@ class Row extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction * * @param int|null $id * @return void - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\LocalizedException */ public function execute($id = null) { if (!isset($id) || empty($id)) { - throw new \Magento\Catalog\Exception(__('Could not rebuild index for undefined product')); + throw new \Magento\Framework\Exception\InputException(__('Could not rebuild index for undefined product')); } try { $this->_reindexRows([$id]); } catch (\Exception $e) { - throw new \Magento\Catalog\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); } } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Rows.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Rows.php old mode 100644 new mode 100755 index 962435d557d834a4fa33fedb598a8a0a4f550508..9a7daacc654d227e8f54bd75196a318e2cdd52a6 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Rows.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Rows.php @@ -16,17 +16,18 @@ class Rows extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction * * @param array $ids * @return void - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\LocalizedException */ public function execute($ids) { if (empty($ids)) { - throw new \Magento\Catalog\Exception(__('Bad value was supplied.')); + throw new \Magento\Framework\Exception\InputException(__('Bad value was supplied.')); } try { $this->_reindexRows($ids); } catch (\Exception $e) { - throw new \Magento\Catalog\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); } } } diff --git a/app/code/Magento/Catalog/Model/Product/Copier.php b/app/code/Magento/Catalog/Model/Product/Copier.php index a066164bd7aebfbef1cb91a7fc5f2f884a75d971..9e54f0e78ddab88f5c2a040d8720730cf014fb83 100644 --- a/app/code/Magento/Catalog/Model/Product/Copier.php +++ b/app/code/Magento/Catalog/Model/Product/Copier.php @@ -7,8 +7,6 @@ */ namespace Magento\Catalog\Model\Product; -use Magento\UrlRewrite\Model\Storage\DuplicateEntryException; - class Copier { /** @@ -65,7 +63,7 @@ class Copier try { $duplicate->save(); $isDuplicateSaved = true; - } catch (DuplicateEntryException $e) { + } catch (\Magento\Framework\Exception\AlreadyExistsException $e) { } } while (!$isDuplicateSaved); diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index b68f8f1bec8e78078d3e9601d11139dd15fcb1d9..f1f80f7701c0cf8e260892361e90110616656a31 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -79,7 +79,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param File\ValidatorInfo $validatorInfo * @param File\ValidatorFile $validatorFile * @param array $data - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php index a8f61ba1e36335355c227c77d6fd107f0d57984b..beb1b3d2f8da1b5421b751aab1ee24d36de49c63 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php @@ -61,7 +61,7 @@ class ValidatorFile extends Validator * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\File\Size $fileSize * @param \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, diff --git a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php index 2a59073ff7f5fb5cca087f9a331c2fd48c7fa013..94612dbf200a5f95fc003342e0c114d273366be1 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php +++ b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php @@ -488,7 +488,7 @@ abstract class AbstractType DirectoryList::ROOT ); $rootDir->create($rootDir->getRelativePath($path)); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \Magento\Framework\Exception\LocalizedException( __('We can\'t create writeable directory "%1".', $path) ); diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/DefaultPrice.php b/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/DefaultPrice.php old mode 100644 new mode 100755 index b0185bcf1397171d73550b750766a591ba08487b..7c488ecf2ec36d3bc050d1726df25a72d6d365fb --- a/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/DefaultPrice.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/DefaultPrice.php @@ -86,12 +86,14 @@ class DefaultPrice extends \Magento\Catalog\Model\Resource\Product\Indexer\Abstr * Retrieve Product Type Code * * @return string - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getTypeId() { if ($this->_typeId === null) { - throw new \Magento\Catalog\Exception(__('A product type is not defined for the indexer.')); + throw new \Magento\Framework\Exception\LocalizedException( + __('A product type is not defined for the indexer.') + ); } return $this->_typeId; } diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/Factory.php b/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/Factory.php old mode 100644 new mode 100755 index d28536b4ebb77f11763951262c68f047f2ecf400..517b00635c2a532022e8f6a941bf721a0c719931 --- a/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/Factory.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Price/Factory.php @@ -34,15 +34,15 @@ class Factory * @param string $className * @param array $data * @return \Magento\Catalog\Model\Resource\Product\Indexer\Price\DefaultPrice - * @throws \Magento\Catalog\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create($className, array $data = []) { $indexerPrice = $this->_objectManager->create($className, $data); if (!$indexerPrice instanceof \Magento\Catalog\Model\Resource\Product\Indexer\Price\DefaultPrice) { - throw new \Magento\Catalog\Exception( - $className . ' doesn\'t extends \Magento\Catalog\Model\Resource\Product\Indexer\Price\DefaultPrice' + throw new \Magento\Framework\Exception\LocalizedException( + __('%1 doesn\'t extend \Magento\Catalog\Model\Resource\Product\Indexer\Price\DefaultPrice', $className) ); } return $indexerPrice; diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/DeleteTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/DeleteTest.php index f360e3a6c3ffd883b37310d6e20c7f7acf4d79ab..bec5548f8bbc374a6b7631d984f6517da430bcbc 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/DeleteTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/DeleteTest.php @@ -98,6 +98,7 @@ class DeleteTest extends \PHPUnit_Framework_TestCase $context->expects($this->any()) ->method('getAuth') ->will($this->returnValue($auth)); + $context->expects($this->once())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory); $auth->expects($this->any()) ->method('getAuthStorage') ->will($this->returnValue($this->authStorage)); @@ -109,7 +110,6 @@ class DeleteTest extends \PHPUnit_Framework_TestCase 'Magento\Catalog\Controller\Adminhtml\Category\Delete', [ 'context' => $context, - 'resultRedirectFactory' => $resultRedirectFactory, 'categoryRepository' => $this->categoryRepository ] ); diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php index 9b5bb8d759b6b78396f9bf4db5792c1259e3d56f..e903fbbfacebc9f8ace5301969167b4db8b01a14 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php @@ -94,7 +94,8 @@ class SaveTest extends \PHPUnit_Framework_TestCase 'getObjectManager', 'getEventManager', 'getResponse', - 'getMessageManager' + 'getMessageManager', + 'getResultRedirectFactory' ], [], '', @@ -165,30 +166,20 @@ class SaveTest extends \PHPUnit_Framework_TestCase ['addSuccess', 'getMessages'] ); + $this->contextMock->expects($this->any())->method('getTitle')->willReturn($this->titleMock); + $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); + $this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock); + $this->contextMock->expects($this->any())->method('getEventManager')->willReturn($this->eventManagerMock); + $this->contextMock->expects($this->any())->method('getResponse')->willReturn($this->responseMock); + $this->contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->contextMock->expects($this->any()) - ->method('getTitle') - ->will($this->returnValue($this->titleMock)); - $this->contextMock->expects($this->any()) - ->method('getRequest') - ->will($this->returnValue($this->requestMock)); - $this->contextMock->expects($this->any()) - ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); - $this->contextMock->expects($this->any()) - ->method('getEventManager') - ->will($this->returnValue($this->eventManagerMock)); - $this->contextMock->expects($this->any()) - ->method('getResponse') - ->will($this->returnValue($this->responseMock)); - $this->contextMock->expects($this->any()) - ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $this->save = $this->objectManager->getObject( 'Magento\Catalog\Controller\Adminhtml\Category\Save', [ 'context' => $this->contextMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock, 'resultRawFactory' => $this->resultRawFactoryMock, 'resultJsonFactory' => $this->resultJsonFactoryMock, 'layoutFactory' => $this->layoutFactoryMock diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/SaveTest.php index dbe1bd83b11df585fdb5c48e939283d5699f8e8f..b83afa0e6361f9fbad7576e272ebfb75477391f7 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Action/Attribute/SaveTest.php @@ -93,10 +93,13 @@ class SaveTest extends \PHPUnit_Framework_TestCase /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $stockItemRepository; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactory; + protected function setUp() { - $this->prepareContext(); - $this->attributeHelper = $this->getMock( 'Magento\Catalog\Helper\Product\Edit\Action\Attribute', ['getProductIds', 'getSelectedStoreId', 'getStoreWebsiteId'], @@ -121,14 +124,16 @@ class SaveTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + $this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $resultRedirectFactory->expects($this->atLeastOnce()) + $this->resultRedirectFactory->expects($this->atLeastOnce()) ->method('create') ->willReturn($resultRedirect); + $this->prepareContext(); + $this->object = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject( 'Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save', [ @@ -136,7 +141,6 @@ class SaveTest extends \PHPUnit_Framework_TestCase 'attributeHelper' => $this->attributeHelper, 'stockIndexerProcessor' => $this->stockIndexerProcessor, 'dataObjectHelper' => $this->dataObjectHelperMock, - 'resultRedirectFactory' => $resultRedirectFactory ] ); } @@ -189,33 +193,32 @@ class SaveTest extends \PHPUnit_Framework_TestCase 'getFormKeyValidator', 'getTitle', 'getLocaleResolver', + 'getResultRedirectFactory' ], [], '', false ); - $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); - $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($this->response)); - $this->context->expects($this->any())->method('getObjectManager') - ->will($this->returnValue($this->objectManager)); - $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($this->eventManager)); - $this->context->expects($this->any())->method('getUrl')->will($this->returnValue($this->url)); - $this->context->expects($this->any())->method('getRedirect')->will($this->returnValue($this->redirect)); - $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->actionFlag)); - $this->context->expects($this->any())->method('getView')->will($this->returnValue($this->view)); - $this->context->expects($this->any())->method('getMessageManager') - ->will($this->returnValue($this->messageManager)); - $this->context->expects($this->any())->method('getSession')->will($this->returnValue($this->session)); - $this->context->expects($this->any())->method('getAuthorization') - ->will($this->returnValue($this->authorization)); - $this->context->expects($this->any())->method('getAuth')->will($this->returnValue($this->auth)); - $this->context->expects($this->any())->method('getHelper')->will($this->returnValue($this->helper)); - $this->context->expects($this->any())->method('getBackendUrl')->will($this->returnValue($this->backendUrl)); - $this->context->expects($this->any())->method('getFormKeyValidator') - ->will($this->returnValue($this->formKeyValidator)); - $this->context->expects($this->any())->method('getTitle')->will($this->returnValue($this->title)); - $this->context->expects($this->any())->method('getLocaleResolver') - ->will($this->returnValue($this->localeResolver)); + $this->context->expects($this->any())->method('getRequest')->willReturn($this->request); + $this->context->expects($this->any())->method('getResponse')->willReturn($this->response); + $this->context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManager); + $this->context->expects($this->any())->method('getEventManager')->willReturn($this->eventManager); + $this->context->expects($this->any())->method('getUrl')->willReturn($this->url); + $this->context->expects($this->any())->method('getRedirect')->willReturn($this->redirect); + $this->context->expects($this->any())->method('getActionFlag')->willReturn($this->actionFlag); + $this->context->expects($this->any())->method('getView')->willReturn($this->view); + $this->context->expects($this->any())->method('getMessageManager')->willReturn($this->messageManager); + $this->context->expects($this->any())->method('getSession')->willReturn($this->session); + $this->context->expects($this->any())->method('getAuthorization')->willReturn($this->authorization); + $this->context->expects($this->any())->method('getAuth')->willReturn($this->auth); + $this->context->expects($this->any())->method('getHelper')->willReturn($this->helper); + $this->context->expects($this->any())->method('getBackendUrl')->willReturn($this->backendUrl); + $this->context->expects($this->any())->method('getFormKeyValidator')->willReturn($this->formKeyValidator); + $this->context->expects($this->any())->method('getTitle')->willReturn($this->title); + $this->context->expects($this->any())->method('getLocaleResolver')->willReturn($this->localeResolver); + $this->context->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactory); $this->product = $this->getMock( 'Magento\Catalog\Model\Product', diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php index 0627241e28305cd00763e8d7fa03d5c079109ad4..438cec2b2d7cbf0297ee602172ab3eab3969a7b4 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php @@ -42,11 +42,11 @@ class MassStatusTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\Pro ->method('create') ->willReturn($this->resultRedirect); + $additionalParams = ['resultRedirectFactory' => $resultRedirectFactory]; $this->action = new \Magento\Catalog\Controller\Adminhtml\Product\MassStatus( - $this->initContext(), + $this->initContext($additionalParams), $productBuilder, - $this->priceProcessor, - $resultRedirectFactory + $this->priceProcessor ); } diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/SaveTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/SaveTest.php index 77f31ab47a4f6636792d227686854e328e0ac3a2..17a99b3ab8f5210ca601190541b362d510372123 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/SaveTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/SaveTest.php @@ -90,14 +90,14 @@ class SaveTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\ProductTe false ); + $additionalParams = ['resultRedirectFactory' => $this->resultRedirectFactory]; $this->action = (new ObjectManagerHelper($this))->getObject( 'Magento\Catalog\Controller\Adminhtml\Product\Save', [ - 'context' => $this->initContext(), + 'context' => $this->initContext($additionalParams), 'productBuilder' => $this->productBuilder, 'resultPageFactory' => $resultPageFactory, 'resultForwardFactory' => $resultForwardFactory, - 'resultRedirectFactory' => $this->resultRedirectFactory, 'initializationHelper' => $this->initializationHelper, ] ); diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/ValidateTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/ValidateTest.php index 9c6a309197f2e790a373f98aea95fdd9b7ead69e..9c58d09dfe4434cef1a398214de2a3fb6082dc06 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/ValidateTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/ValidateTest.php @@ -111,14 +111,14 @@ class ValidateTest extends \Magento\Catalog\Test\Unit\Controller\Adminhtml\Produ ->getMock(); $this->resultJsonFactory->expects($this->any())->method('create')->willReturn($this->resultJson); + $additionalParams = ['resultRedirectFactory' => $this->resultRedirectFactory]; $this->action = (new ObjectManagerHelper($this))->getObject( 'Magento\Catalog\Controller\Adminhtml\Product\Validate', [ - 'context' => $this->initContext(), + 'context' => $this->initContext($additionalParams), 'productBuilder' => $this->productBuilder, 'resultPageFactory' => $resultPageFactory, 'resultForwardFactory' => $resultForwardFactory, - 'resultRedirectFactory' => $this->resultRedirectFactory, 'initializationHelper' => $this->initializationHelper, 'resultJsonFactory' => $this->resultJsonFactory, 'productFactory' => $this->productFactory, diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/ProductTest.php index 3e04c8a0c27f345cb2ef5892098f65a04f61b667..84ba97726acdfbf23f9f0835170cdc9f5b4ddc64 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/ProductTest.php @@ -19,9 +19,12 @@ abstract class ProductTest extends \PHPUnit_Framework_TestCase protected $request; /** - * Init context object + * Init context object + * + * @param array $additionalParams + * @return \PHPUnit_Framework_MockObject_MockObject */ - protected function initContext() + protected function initContext(array $additionalParams = []) { $productActionMock = $this->getMock('Magento\Catalog\Model\Product\Action', [], [], '', false); $objectManagerMock = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); @@ -70,7 +73,8 @@ abstract class ProductTest extends \PHPUnit_Framework_TestCase 'getActionFlag', 'getHelper', 'getTitle', - 'getView' + 'getView', + 'getResultRedirectFactory' ], [], '', @@ -89,6 +93,10 @@ abstract class ProductTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock)); $this->context->expects($this->any())->method('getHelper')->will($this->returnValue($helperDataMock)); + foreach ($additionalParams as $property => $object) { + $this->context->expects($this->any())->method('get' . ucfirst($property))->willReturn($object); + } + $this->session = $sessionMock; $this->request = $requestInterfaceMock; diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Product/Compare/IndexTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Product/Compare/IndexTest.php index 1ee181ccdaec8a270fd21f1790bfad7d637518ac..81633cf019cbd49c1d607b432d63795f34631c38 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Product/Compare/IndexTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Product/Compare/IndexTest.php @@ -70,19 +70,25 @@ class IndexTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->contextMock = $this->getMock('Magento\Framework\App\Action\Context', - ['getRequest', 'getResponse'], + ['getRequest', 'getResponse', 'getResultRedirectFactory'], [], '', false ); $this->request = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false); $this->response = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false); + $this->redirectFactoryMock = $this->getMock( + 'Magento\Framework\Controller\Result\RedirectFactory', + ['create'], + [], + '', + false + ); + $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->request); + $this->contextMock->expects($this->any())->method('getResponse')->willReturn($this->response); $this->contextMock->expects($this->any()) - ->method('getRequest') - ->willReturn($this->request); - $this->contextMock->expects($this->any()) - ->method('getResponse') - ->willReturn($this->response); + ->method('getResultRedirectFactory') + ->willReturn($this->redirectFactoryMock); $this->itemFactoryMock = $this->getMock('Magento\Catalog\Model\Product\Compare\ItemFactory', [], [], '', false); $this->collectionFactoryMock = $this->getMock( @@ -100,13 +106,6 @@ class IndexTest extends \PHPUnit_Framework_TestCase $this->formKeyValidatorMock = $this->getMockBuilder('Magento\Framework\Data\Form\FormKey\Validator') ->disableOriginalConstructor() ->getMock(); - $this->redirectFactoryMock = $this->getMock( - 'Magento\Framework\Controller\Result\RedirectFactory', - ['create'], - [], - '', - false - ); $this->pageFactoryMock = $this->getMock('Magento\Framework\View\Result\PageFactory', [], [], '', false); $this->productRepositoryMock = $this->getMock('Magento\Catalog\Api\ProductRepositoryInterface'); $this->decoderMock = $this->getMock('Magento\Framework\Url\DecoderInterface'); @@ -121,7 +120,6 @@ class IndexTest extends \PHPUnit_Framework_TestCase $this->catalogSession, $this->storeManagerMock, $this->formKeyValidatorMock, - $this->redirectFactoryMock, $this->pageFactoryMock, $this->productRepositoryMock, $this->decoderMock diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php old mode 100644 new mode 100755 index 15ff5136c76caeb641f66081ebccee0ce0be471f..fc1a0758eecb9584031f95aa4c2d2248789496a8 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php @@ -36,7 +36,7 @@ class FullTest extends \PHPUnit_Framework_TestCase $eavSourceFactory ); - $this->setExpectedException('\Magento\Catalog\Exception', $exceptionMessage); + $this->setExpectedException('Magento\Framework\Exception\LocalizedException', $exceptionMessage); $model->execute(); } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/RowTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/RowTest.php old mode 100644 new mode 100755 index 80a1f2ea8c5e1d1a4494360bf2064e368bdc6c4e..b40ffc2e186c9746725e9999c8be987c8731371c --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/RowTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/RowTest.php @@ -21,7 +21,7 @@ class RowTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Catalog\Exception + * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Could not rebuild index for undefined product */ public function testEmptyId() diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/RowsTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/RowsTest.php old mode 100644 new mode 100755 index 994e561ade36f356935889eb59b33c3dbe7204dd..95577b9fcf1890402d9801427137d4f43705e756 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/RowsTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/RowsTest.php @@ -21,7 +21,7 @@ class RowsTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Catalog\Exception + * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Bad value was supplied. */ public function testEmptyIds() diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowTest.php old mode 100644 new mode 100755 index 0910824ecfe79052605601449db89ac599d4452a..27369edc624560bcd61ad2d9d6d85dbcf9e71f74 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowTest.php @@ -21,7 +21,7 @@ class RowTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Catalog\Exception + * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Could not rebuild index for undefined product */ public function testEmptyId() diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowsTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowsTest.php old mode 100644 new mode 100755 index 5ab73e71e45932a1de40c93b59221e3750054b29..36814e3bf8df90407a95466a55a77948b01f7a7f --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowsTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowsTest.php @@ -21,7 +21,7 @@ class RowsTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Catalog\Exception + * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Bad value was supplied. */ public function testEmptyIds() diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php index 8a7930bb0f6d7243e66fc68fcbc51751d517f6d5..bf60494dae2505f08654308ae2e512d75e277081 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php @@ -334,7 +334,7 @@ class ProductRepositoryTest extends \PHPUnit_Framework_TestCase $this->resourceModelMock->expects($this->once())->method('validate')->with($this->productMock) ->willReturn(true); $this->resourceModelMock->expects($this->once())->method('save')->with($this->productMock) - ->willThrowException(new \Magento\Eav\Model\Entity\Attribute\Exception('123')); + ->willThrowException(new \Magento\Eav\Model\Entity\Attribute\Exception(__('123'))); $this->productMock->expects($this->never())->method('getId'); $this->extensibleDataObjectConverterMock ->expects($this->once()) diff --git a/app/code/Magento/CatalogInventory/Exception.php b/app/code/Magento/CatalogInventory/Exception.php deleted file mode 100644 index 61edb1d7f44a003e21bcd8bcafb719190cc79cce..0000000000000000000000000000000000000000 --- a/app/code/Magento/CatalogInventory/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\CatalogInventory; - -class Exception extends \Exception -{ -} diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php index ff2cafbdcbd422cda438238fac8d4b5662689703..070fc994c48fa940f3c341130652fc5a14e2295b 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php @@ -19,16 +19,18 @@ class Full extends \Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction * Execute Full reindex * * @param null|array $ids - * @throws \Magento\CatalogInventory\Exception + * @throws \Magento\Framework\Exception\LocalizedException * * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($ids = null) { try { $this->reindexAll(); } catch (\Exception $e) { - throw new \Magento\CatalogInventory\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); } } } diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Row.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Row.php index 2ddf25ac201eb6aa6bd452635b66420d1d1c87f3..0103d0849f897fa8ca31ce6d9071de6d167d9e1f 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Row.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Row.php @@ -19,19 +19,21 @@ class Row extends \Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction * Execute Row reindex * * @param int|null $id - * @throws \Magento\CatalogInventory\Exception + * @throws \Magento\Framework\Exception\LocalizedException * * @return void */ public function execute($id = null) { if (!isset($id) || empty($id)) { - throw new \Magento\CatalogInventory\Exception(__('Could not rebuild index for undefined product')); + throw new \Magento\Framework\Exception\LocalizedException( + __('Could not rebuild index for undefined product') + ); } try { $this->_reindexRows([$id]); } catch (\Exception $e) { - throw new \Magento\CatalogInventory\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException($e->getMessage(), $e->getCode(), $e); } } } diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Rows.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Rows.php index 5e6a31a6b70d7c642827053fac8fd9b20f16a272..ed9b5827e8c3d417caaaf839cb68280060c06a5e 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Rows.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Rows.php @@ -19,19 +19,21 @@ class Rows extends \Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction * Execute Rows reindex * * @param array $ids - * @throws \Magento\CatalogInventory\Exception + * @throws \Magento\Framework\Exception\LocalizedException * * @return void */ public function execute($ids) { if (empty($ids)) { - throw new \Magento\CatalogInventory\Exception(__('Could not rebuild index for empty products array')); + throw new \Magento\Framework\Exception\LocalizedException( + __('Could not rebuild index for empty products array') + ); } try { $this->_reindexRows($ids); } catch (\Exception $e) { - throw new \Magento\CatalogInventory\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException($e->getMessage(), $e->getCode(), $e); } } } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/FullTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/FullTest.php index 664492933324e1f041138647743990f824e5cdac..a096f71925e83c08696139a9d64d5abed10ec239 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/FullTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/FullTest.php @@ -41,7 +41,7 @@ class FullTest extends \PHPUnit_Framework_TestCase $productTypeMock ); - $this->setExpectedException('\Magento\CatalogInventory\Exception', $exceptionMessage); + $this->setExpectedException('\Magento\Framework\Exception\LocalizedException', $exceptionMessage); $model->execute(); } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/RowTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/RowTest.php index a6071c6213c71f97e833e5c8518538e9687b3cb2..9a2bb4ec376b3c01d2a7c1862f4b7f802c39d5e1 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/RowTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/RowTest.php @@ -25,7 +25,7 @@ class RowTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\CatalogInventory\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Could not rebuild index for undefined product */ public function testEmptyId() diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/RowsTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/RowsTest.php index 70d917aa59e80a72428e42210c1ef9d441cf6e9b..460f300c153a7072423465ef3685d691be6d3634 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/RowsTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/Action/RowsTest.php @@ -25,7 +25,7 @@ class RowsTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\CatalogInventory\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Could not rebuild index for empty products array */ public function testEmptyIds() diff --git a/app/code/Magento/CatalogRule/CatalogRuleException.php b/app/code/Magento/CatalogRule/CatalogRuleException.php deleted file mode 100644 index 0b93d3c00f4e46554e9eff6a1ba22aed24ea4824..0000000000000000000000000000000000000000 --- a/app/code/Magento/CatalogRule/CatalogRuleException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\CatalogRule; - -class CatalogRuleException extends \Exception -{ -} diff --git a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/ApplyRules.php b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/ApplyRules.php index b3a28507fd6b35cb2c2fa144b95d79bde403e934..56438a823ee13a151c2b4d10d11cf5d7cac53e80 100644 --- a/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/ApplyRules.php +++ b/app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/ApplyRules.php @@ -13,26 +13,33 @@ class ApplyRules extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog /** * Apply all active catalog price rules * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Exception */ public function execute() { $errorMessage = __('Unable to apply rules.'); - try { - /** @var Job $ruleJob */ - $ruleJob = $this->_objectManager->get('Magento\CatalogRule\Model\Rule\Job'); - $ruleJob->applyAll(); + /** @var Job $ruleJob */ + $ruleJob = $this->_objectManager->get('Magento\CatalogRule\Model\Rule\Job'); + $ruleJob->applyAll(); - if ($ruleJob->hasSuccess()) { - $this->messageManager->addSuccess($ruleJob->getSuccess()); - $this->_objectManager->create('Magento\CatalogRule\Model\Flag')->loadSelf()->setState(0)->save(); - } elseif ($ruleJob->hasError()) { - $this->messageManager->addError($errorMessage . ' ' . $ruleJob->getError()); - } - } catch (\Exception $e) { - $this->_objectManager->create('Psr\Log\LoggerInterface')->critical($e); - $this->messageManager->addError($errorMessage); + if ($ruleJob->hasSuccess()) { + $this->messageManager->addSuccess($ruleJob->getSuccess()); + $this->_objectManager->create('Magento\CatalogRule\Model\Flag')->loadSelf()->setState(0)->save(); + } elseif ($ruleJob->hasError()) { + $this->messageManager->addError($errorMessage . ' ' . $ruleJob->getError()); } - $this->_redirect('catalog_rule/*'); + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('catalog_rule/*'); } } diff --git a/app/code/Magento/CatalogRule/Model/Indexer/AbstractIndexer.php b/app/code/Magento/CatalogRule/Model/Indexer/AbstractIndexer.php index a4d8b53934937cd2342f00bfd5505f6d59953ecc..13dc23422a50c60ace7d5f0ed87376fba998f04f 100644 --- a/app/code/Magento/CatalogRule/Model/Indexer/AbstractIndexer.php +++ b/app/code/Magento/CatalogRule/Model/Indexer/AbstractIndexer.php @@ -5,7 +5,6 @@ */ namespace Magento\CatalogRule\Model\Indexer; -use Magento\CatalogRule\CatalogRuleException; use Magento\Framework\Mview\ActionInterface as MviewActionInterface; use Magento\Indexer\Model\ActionInterface as IndexerActionInterface; @@ -74,13 +73,15 @@ abstract class AbstractIndexer implements IndexerActionInterface, MviewActionInt * Execute partial indexation by ID list * * @param int[] $ids - * @throws CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ public function executeList(array $ids) { if (!$ids) { - throw new CatalogRuleException(__('Could not rebuild index for empty products array')); + throw new \Magento\Framework\Exception\LocalizedException( + __('Could not rebuild index for empty products array') + ); } $this->doExecuteList($ids); } @@ -97,13 +98,15 @@ abstract class AbstractIndexer implements IndexerActionInterface, MviewActionInt * Execute partial indexation by ID * * @param int $id - * @throws CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ public function executeRow($id) { if (!$id) { - throw new CatalogRuleException(__('Could not rebuild index for undefined product')); + throw new \Magento\Framework\Exception\LocalizedException( + __('Could not rebuild index for undefined product') + ); } $this->doExecuteRow($id); } @@ -112,7 +115,7 @@ abstract class AbstractIndexer implements IndexerActionInterface, MviewActionInt * Execute partial indexation by ID. Template method * * @param int $id - * @throws \Magento\CatalogRule\CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ abstract protected function doExecuteRow($id); diff --git a/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php b/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php index 2394d6afaae2be230798bb620492f6d98fb08b23..a2cfaba45a1e0ccdf826cce274ad17864eb00ca7 100644 --- a/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php +++ b/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php @@ -7,7 +7,6 @@ namespace Magento\CatalogRule\Model\Indexer; use Magento\Catalog\Model\Product; -use Magento\CatalogRule\CatalogRuleException; use Magento\CatalogRule\Model\Resource\Rule\CollectionFactory as RuleCollectionFactory; use Magento\CatalogRule\Model\Rule; use Magento\Framework\Pricing\PriceCurrencyInterface; @@ -126,7 +125,7 @@ class IndexBuilder * Reindex by ids * * @param array $ids - * @throws \Magento\CatalogRule\CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ public function reindexByIds(array $ids) @@ -135,7 +134,7 @@ class IndexBuilder $this->doReindexByIds($ids); } catch (\Exception $e) { $this->critical($e); - throw new CatalogRuleException($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException($e->getMessage(), $e->getCode(), $e); } } @@ -159,7 +158,7 @@ class IndexBuilder /** * Full reindex * - * @throws CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ public function reindexFull() @@ -168,7 +167,7 @@ class IndexBuilder $this->doReindexFull(); } catch (\Exception $e) { $this->critical($e); - throw new CatalogRuleException($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException($e->getMessage(), $e->getCode(), $e); } } diff --git a/app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/AbstractIndexerTest.php b/app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/AbstractIndexerTest.php index b9a21020e4120a7218a7af66fc9ba0d833a2ebc8..dfec1c047ab09db3763e463ff16d120f3d4c50ad 100644 --- a/app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/AbstractIndexerTest.php +++ b/app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/AbstractIndexerTest.php @@ -74,7 +74,7 @@ class AbstractIndexerTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\CatalogRule\CatalogRuleException + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Could not rebuild index for empty products array * * @return void @@ -85,7 +85,7 @@ class AbstractIndexerTest extends \PHPUnit_Framework_TestCase } /** - * @throws \Magento\CatalogRule\CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * * @return void */ @@ -98,7 +98,7 @@ class AbstractIndexerTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\CatalogRule\CatalogRuleException + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Could not rebuild index for undefined product * * @return void @@ -109,7 +109,7 @@ class AbstractIndexerTest extends \PHPUnit_Framework_TestCase } /** - * @throws \Magento\CatalogRule\CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * * @return void */ diff --git a/app/code/Magento/Checkout/Controller/Action.php b/app/code/Magento/Checkout/Controller/Action.php index daa22d34d16b57cdf0af041d28743e7276dc4d88..0306ebf24acd733a12192f6fccbf2766405352c8 100644 --- a/app/code/Magento/Checkout/Controller/Action.php +++ b/app/code/Magento/Checkout/Controller/Action.php @@ -29,29 +29,21 @@ abstract class Action extends \Magento\Framework\App\Action\Action */ protected $accountManagement; - /** - * @var \Magento\Framework\Controller\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession * @param CustomerRepositoryInterface $customerRepository * @param AccountManagementInterface $accountManagement - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, CustomerRepositoryInterface $customerRepository, - AccountManagementInterface $accountManagement, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory + AccountManagementInterface $accountManagement ) { $this->_customerSession = $customerSession; $this->customerRepository = $customerRepository; $this->accountManagement = $accountManagement; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Checkout/Controller/Cart.php b/app/code/Magento/Checkout/Controller/Cart.php index 2b056aeac07fab9f177311dcd9c0b9d764fe0763..9aa93f99d03528ac3cb292debd7f03ff01f542aa 100644 --- a/app/code/Magento/Checkout/Controller/Cart.php +++ b/app/code/Magento/Checkout/Controller/Cart.php @@ -39,11 +39,6 @@ class Cart extends \Magento\Framework\App\Action\Action implements ViewInterface */ protected $cart; - /** - * @var \Magento\Framework\Controller\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig @@ -51,7 +46,6 @@ class Cart extends \Magento\Framework\App\Action\Action implements ViewInterface * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator * @param CustomerCart $cart - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Framework\App\Action\Context $context, @@ -59,15 +53,13 @@ class Cart extends \Magento\Framework\App\Action\Action implements ViewInterface \Magento\Checkout\Model\Session $checkoutSession, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, - CustomerCart $cart, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory + CustomerCart $cart ) { $this->_formKeyValidator = $formKeyValidator; $this->_scopeConfig = $scopeConfig; $this->_checkoutSession = $checkoutSession; $this->_storeManager = $storeManager; $this->cart = $cart; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Checkout/Controller/Cart/Add.php b/app/code/Magento/Checkout/Controller/Cart/Add.php index 69aa88b0b3dc81e75993c2e7fb99689b175b71a4..c26c171daea13b95cde9c7ac654c5e30094e4ff3 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Add.php +++ b/app/code/Magento/Checkout/Controller/Cart/Add.php @@ -30,7 +30,6 @@ class Add extends \Magento\Checkout\Controller\Cart * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator * @param CustomerCart $cart - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param ProductRepositoryInterface $productRepository */ public function __construct( @@ -40,7 +39,6 @@ class Add extends \Magento\Checkout\Controller\Cart \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, CustomerCart $cart, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, ProductRepositoryInterface $productRepository ) { parent::__construct( @@ -49,8 +47,7 @@ class Add extends \Magento\Checkout\Controller\Cart $checkoutSession, $storeManager, $formKeyValidator, - $cart, - $resultRedirectFactory + $cart ); $this->productRepository = $productRepository; } diff --git a/app/code/Magento/Checkout/Controller/Cart/Configure.php b/app/code/Magento/Checkout/Controller/Cart/Configure.php index eebb127c786c5dc5e73264393b19a8aa3480c40d..cedc400e20b9f56245f3b90261cf0e01d4357b32 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Configure.php +++ b/app/code/Magento/Checkout/Controller/Cart/Configure.php @@ -22,7 +22,6 @@ class Configure extends \Magento\Checkout\Controller\Cart * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator * @param \Magento\Checkout\Model\Cart $cart - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( @@ -32,7 +31,6 @@ class Configure extends \Magento\Checkout\Controller\Cart \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\Checkout\Model\Cart $cart, - Framework\Controller\Result\RedirectFactory $resultRedirectFactory, Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct( @@ -41,8 +39,7 @@ class Configure extends \Magento\Checkout\Controller\Cart $checkoutSession, $storeManager, $formKeyValidator, - $cart, - $resultRedirectFactory + $cart ); $this->resultPageFactory = $resultPageFactory; } @@ -51,6 +48,7 @@ class Configure extends \Magento\Checkout\Controller\Cart * Action to reconfigure cart item * * @return \Magento\Framework\View\Result\Page|\Magento\Framework\Controller\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { @@ -62,30 +60,34 @@ class Configure extends \Magento\Checkout\Controller\Cart $quoteItem = $this->cart->getQuote()->getItemById($id); } - try { - if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) { - $this->messageManager->addError(__("We can't find the quote item.")); - return $this->resultRedirectFactory->create()->setPath('checkout/cart'); - } + if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) { + $this->messageManager->addError(__("We can't find the quote item.")); + return $this->resultRedirectFactory->create()->setPath('checkout/cart'); + } - $params = new \Magento\Framework\Object(); - $params->setCategoryId(false); - $params->setConfigureMode(true); - $params->setBuyRequest($quoteItem->getBuyRequest()); + $params = new \Magento\Framework\Object(); + $params->setCategoryId(false); + $params->setConfigureMode(true); + $params->setBuyRequest($quoteItem->getBuyRequest()); - $resultPage = $this->resultPageFactory->create(); - $this->_objectManager->get('Magento\Catalog\Helper\Product\View') - ->prepareAndRender( - $resultPage, - $quoteItem->getProduct()->getId(), - $this, - $params - ); - return $resultPage; - } catch (\Exception $e) { - $this->messageManager->addError(__('We cannot configure the product.')); - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); - return $this->_goBack(); - } + $resultPage = $this->resultPageFactory->create(); + $this->_objectManager->get('Magento\Catalog\Helper\Product\View') + ->prepareAndRender( + $resultPage, + $quoteItem->getProduct()->getId(), + $this, + $params + ); + return $resultPage; + } + + /** + * {@inheritdoc} + * + * @return \Magento\Framework\Controller\Result\Redirect + */ + public function getDefaultResult() + { + return $this->_goBack(); } } diff --git a/app/code/Magento/Checkout/Controller/Cart/CouponPost.php b/app/code/Magento/Checkout/Controller/Cart/CouponPost.php index 26225b39fa6f9732cb5562c4ffda4d28c0f7eacd..2b93e3d1cb1840c16b5db2dfe59a4c531a7aeae8 100644 --- a/app/code/Magento/Checkout/Controller/Cart/CouponPost.php +++ b/app/code/Magento/Checkout/Controller/Cart/CouponPost.php @@ -21,7 +21,6 @@ class CouponPost extends \Magento\Checkout\Controller\Cart * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator * @param \Magento\Checkout\Model\Cart $cart - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Quote\Model\QuoteRepository $quoteRepository */ public function __construct( @@ -31,7 +30,6 @@ class CouponPost extends \Magento\Checkout\Controller\Cart \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\Checkout\Model\Cart $cart, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Quote\Model\QuoteRepository $quoteRepository ) { parent::__construct( @@ -40,8 +38,7 @@ class CouponPost extends \Magento\Checkout\Controller\Cart $checkoutSession, $storeManager, $formKeyValidator, - $cart, - $resultRedirectFactory + $cart ); $this->quoteRepository = $quoteRepository; } @@ -50,6 +47,7 @@ class CouponPost extends \Magento\Checkout\Controller\Cart * Initialize coupon * * @return \Magento\Framework\Controller\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -71,41 +69,44 @@ class CouponPost extends \Magento\Checkout\Controller\Cart return $this->_goBack(); } - try { - $codeLength = strlen($couponCode); - $isCodeLengthValid = $codeLength && $codeLength <= \Magento\Checkout\Helper\Cart::COUPON_CODE_MAX_LENGTH; + $codeLength = strlen($couponCode); + $isCodeLengthValid = $codeLength && $codeLength <= \Magento\Checkout\Helper\Cart::COUPON_CODE_MAX_LENGTH; - $this->cart->getQuote()->getShippingAddress()->setCollectShippingRates(true); - $this->cart->getQuote()->setCouponCode($isCodeLengthValid ? $couponCode : '')->collectTotals(); - $this->quoteRepository->save($this->cart->getQuote()); + $this->cart->getQuote()->getShippingAddress()->setCollectShippingRates(true); + $this->cart->getQuote()->setCouponCode($isCodeLengthValid ? $couponCode : '')->collectTotals(); + $this->quoteRepository->save($this->cart->getQuote()); - if ($codeLength) { - if ($isCodeLengthValid && $couponCode == $this->cart->getQuote()->getCouponCode()) { - $this->messageManager->addSuccess( - __( - 'The coupon code "%1" was applied.', - $this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($couponCode) - ) - ); - } else { - $this->messageManager->addError( - __( - 'The coupon code "%1" is not valid.', - $this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($couponCode) - ) - ); - $this->cart->save(); - } + if ($codeLength) { + if ($isCodeLengthValid && $couponCode == $this->cart->getQuote()->getCouponCode()) { + $this->messageManager->addSuccess( + __( + 'The coupon code "%1" was applied.', + $this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($couponCode) + ) + ); } else { - $this->messageManager->addSuccess(__('The coupon code was canceled.')); + $this->messageManager->addError( + __( + 'The coupon code "%1" is not valid.', + $this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($couponCode) + ) + ); + $this->cart->save(); } - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('We cannot apply the coupon code.')); - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); + } else { + $this->messageManager->addSuccess(__('The coupon code was canceled.')); } return $this->_goBack(); } + + /** + * {@inheritdoc} + * + * @return \Magento\Framework\Controller\Result\Redirect + */ + public function getDefaultResult() + { + return $this->_goBack(); + } } diff --git a/app/code/Magento/Checkout/Controller/Cart/EstimatePost.php b/app/code/Magento/Checkout/Controller/Cart/EstimatePost.php index 88a1d46d971e69146a4b0f40ff2fb4fe19c3d9d3..ce6bbc95511f5980e8ddb76bad03ca61f0817f80 100644 --- a/app/code/Magento/Checkout/Controller/Cart/EstimatePost.php +++ b/app/code/Magento/Checkout/Controller/Cart/EstimatePost.php @@ -22,7 +22,6 @@ class EstimatePost extends \Magento\Checkout\Controller\Cart * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator * @param CustomerCart $cart - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Quote\Model\QuoteRepository $quoteRepository */ public function __construct( @@ -32,7 +31,6 @@ class EstimatePost extends \Magento\Checkout\Controller\Cart \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, CustomerCart $cart, - Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Quote\Model\QuoteRepository $quoteRepository ) { $this->quoteRepository = $quoteRepository; @@ -42,8 +40,7 @@ class EstimatePost extends \Magento\Checkout\Controller\Cart $checkoutSession, $storeManager, $formKeyValidator, - $cart, - $resultRedirectFactory + $cart ); } diff --git a/app/code/Magento/Checkout/Controller/Cart/Index.php b/app/code/Magento/Checkout/Controller/Cart/Index.php index 8a29029fd18365c618a3c0f5fede9a0edfd7a0d1..de1a954f86ae22765ed4d4f4426e9c4b1dbf541b 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Index.php +++ b/app/code/Magento/Checkout/Controller/Cart/Index.php @@ -21,7 +21,6 @@ class Index extends \Magento\Checkout\Controller\Cart * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator * @param \Magento\Checkout\Model\Cart $cart - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( @@ -31,7 +30,6 @@ class Index extends \Magento\Checkout\Controller\Cart \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\Checkout\Model\Cart $cart, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct( @@ -40,8 +38,7 @@ class Index extends \Magento\Checkout\Controller\Cart $checkoutSession, $storeManager, $formKeyValidator, - $cart, - $resultRedirectFactory + $cart ); $this->resultPageFactory = $resultPageFactory; } diff --git a/app/code/Magento/Checkout/Controller/Index/Index.php b/app/code/Magento/Checkout/Controller/Index/Index.php index 7e34b412e338311a0ac66aaeb53a45867572ee29..de5f3dea47424538422c9d06218df3f790f04ace 100644 --- a/app/code/Magento/Checkout/Controller/Index/Index.php +++ b/app/code/Magento/Checkout/Controller/Index/Index.php @@ -8,23 +8,6 @@ namespace Magento\Checkout\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { - /** - * @var \Magento\Framework\Controller\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Framework\App\Action\Context $context, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * @return \Magento\Framework\Controller\Result\Redirect */ diff --git a/app/code/Magento/Checkout/Controller/Onepage.php b/app/code/Magento/Checkout/Controller/Onepage.php index 3a47eca2e4f86807ed665c56deed717b2b89319a..2257347e9150ba0993f4b04e12a59019744152c1 100644 --- a/app/code/Magento/Checkout/Controller/Onepage.php +++ b/app/code/Magento/Checkout/Controller/Onepage.php @@ -7,7 +7,7 @@ namespace Magento\Checkout\Controller; use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\CustomerRepositoryInterface; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\App\RequestInterface; /** @@ -86,7 +86,6 @@ class Onepage extends Action * @param \Magento\Customer\Model\Session $customerSession * @param CustomerRepositoryInterface $customerRepository * @param AccountManagementInterface $accountManagement - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\Translate\InlineInterface $translateInline * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator @@ -105,7 +104,6 @@ class Onepage extends Action \Magento\Customer\Model\Session $customerSession, CustomerRepositoryInterface $customerRepository, AccountManagementInterface $accountManagement, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Translate\InlineInterface $translateInline, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, @@ -131,8 +129,7 @@ class Onepage extends Action $context, $customerSession, $customerRepository, - $accountManagement, - $resultRedirectFactory + $accountManagement ); } @@ -141,7 +138,7 @@ class Onepage extends Action * * @param RequestInterface $request * @return \Magento\Framework\App\ResponseInterface - * @throws \Magento\Framework\App\Action\NotFoundException + * @throws \Magento\Framework\Exception\NotFoundException */ public function dispatch(RequestInterface $request) { @@ -158,7 +155,7 @@ class Onepage extends Action } if (!$this->_canShowForUnregisteredUsers()) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } return parent::dispatch($request); } diff --git a/app/code/Magento/Checkout/Controller/Onepage/SavePayment.php b/app/code/Magento/Checkout/Controller/Onepage/SavePayment.php index 18a3f1524908e9107e4e561e8e6a0afc7a99cbf4..19e17acf91ee53299f14c092916153888c2766fc 100644 --- a/app/code/Magento/Checkout/Controller/Onepage/SavePayment.php +++ b/app/code/Magento/Checkout/Controller/Onepage/SavePayment.php @@ -45,11 +45,6 @@ class SavePayment extends \Magento\Checkout\Controller\Onepage if ($redirectUrl) { $result['redirect'] = $redirectUrl; } - } catch (\Magento\Payment\Exception $e) { - if ($e->getFields()) { - $result['fields'] = $e->getFields(); - } - $result['error'] = $e->getMessage(); } catch (\Magento\Framework\Exception\LocalizedException $e) { $result['error'] = $e->getMessage(); } catch (\Exception $e) { diff --git a/app/code/Magento/Checkout/Exception.php b/app/code/Magento/Checkout/Exception.php old mode 100644 new mode 100755 index 2ee13bca5009cc52e51d7942639bd3f92d852cce..f0e271627daea344cfd4209a99199121797433af --- a/app/code/Magento/Checkout/Exception.php +++ b/app/code/Magento/Checkout/Exception.php @@ -5,6 +5,6 @@ */ namespace Magento\Checkout; -class Exception extends \Zend_Exception +class Exception extends \Magento\Framework\Exception\LocalizedException { } diff --git a/app/code/Magento/Checkout/Test/Unit/Controller/Onepage/IndexTest.php b/app/code/Magento/Checkout/Test/Unit/Controller/Onepage/IndexTest.php index 67669a198a926cdb5490c2fbb1c88e3df1aa91a8..e5142f4ef2e3c096ff3a47a15745df0014b04599 100644 --- a/app/code/Magento/Checkout/Test/Unit/Controller/Onepage/IndexTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Controller/Onepage/IndexTest.php @@ -167,6 +167,7 @@ class IndexTest extends \PHPUnit_Framework_TestCase ->willReturn($this->basicMock('\Magento\Framework\Message\ManagerInterface')); $this->basicStub($this->contextMock, 'getRedirect')->willReturn($this->redirectMock); $this->basicStub($this->contextMock, 'getUrl')->willReturn($this->url); + $this->basicStub($this->contextMock, 'getResultRedirectFactory')->willReturn($resultRedirectFactoryMock); // SUT $this->model = $this->objectManager->getObject( diff --git a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Delete.php b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Delete.php index fba6b572166c142a4e8f6a58275809f295705db8..9be4d20c91f2fbfe151aef2ceb50e7999b2ec4a2 100644 --- a/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Delete.php +++ b/app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Delete.php @@ -10,6 +10,7 @@ class Delete extends \Magento\CheckoutAgreements\Controller\Adminhtml\Agreement { /** * @return void + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { @@ -21,17 +22,8 @@ class Delete extends \Magento\CheckoutAgreements\Controller\Adminhtml\Agreement return; } - try { - $model->delete(); - $this->messageManager->addSuccess(__('The condition has been deleted.')); - $this->_redirect('checkout/*/'); - return; - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('Something went wrong while deleting this condition.')); - } - - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*'))); + $model->delete(); + $this->messageManager->addSuccess(__('The condition has been deleted.')); + $this->_redirect('checkout/*/'); } } diff --git a/app/code/Magento/Cms/Block/Page.php b/app/code/Magento/Cms/Block/Page.php index 6788811a85054149231104adabc78b647ee92b38..9b28ef8015ea158ea8ea6df080efbc5813db22e8 100644 --- a/app/code/Magento/Cms/Block/Page.php +++ b/app/code/Magento/Cms/Block/Page.php @@ -118,7 +118,7 @@ class Page extends \Magento\Framework\View\Element\AbstractBlock implements * Prepare breadcrumbs * * @param \Magento\Cms\Model\Page $page - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ protected function _addBreadcrumbs(\Magento\Cms\Model\Page $page) diff --git a/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php b/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php index c3a871112593f687b23ce20d719fc279b008d394..defddb18779229876ae60ca59e9b40491885aedf 100755 --- a/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php @@ -37,50 +37,40 @@ class AbstractMassDelete extends \Magento\Backend\App\Action */ protected $model = 'Magento\Framework\Model\AbstractModel'; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context); - } - /** * Execute action * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { $data = $this->getRequest()->getParam('massaction', '[]'); $data = json_decode($data, true); - $resultRedirect = $this->resultRedirectFactory->create(); - try { - if (isset($data['all_selected']) && $data['all_selected'] === true) { - if (!empty($data['excluded'])) { - $this->excludedDelete($data['excluded']); - } else { - $this->deleteAll(); - } - } elseif (!empty($data['selected'])) { - $this->selectedDelete($data['selected']); + if (isset($data['all_selected']) && $data['all_selected'] === true) { + if (!empty($data['excluded'])) { + $this->excludedDelete($data['excluded']); } else { - $this->messageManager->addError(__('Please select item(s).')); + $this->deleteAll(); } - } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); + } elseif (!empty($data['selected'])) { + $this->selectedDelete($data['selected']); + } else { + $this->messageManager->addError(__('Please select item(s).')); } + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath(static::REDIRECT_URL); } diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/Delete.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/Delete.php index df5ed33ff756e2279854f7387bb4e8c00911be94..c5bf68c00e127f199bc23d04f165a333db937035 100755 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/Delete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/Delete.php @@ -8,25 +8,6 @@ namespace Magento\Cms\Controller\Adminhtml\Block; class Delete extends \Magento\Cms\Controller\Adminhtml\Block { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context, $coreRegistry); - } - /** * Delete action * diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php index d042bb4fc351e7aece51e943a70351b75718fd8b..bc8f586567c58fc68aec8d3fcc351ee98fcf9d73 100755 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php @@ -8,11 +8,6 @@ namespace Magento\Cms\Controller\Adminhtml\Block; class Edit extends \Magento\Cms\Controller\Adminhtml\Block { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\View\Result\PageFactory */ @@ -21,16 +16,13 @@ class Edit extends \Magento\Cms\Controller\Adminhtml\Block /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultPageFactory = $resultPageFactory; parent::__construct($context, $coreRegistry); } diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php index 7fa41aace2be14b9c92f95797c30019a5e7dba62..1fe7e266c91be3609d217d825d2b1a5b5a943881 100755 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/Save.php @@ -8,25 +8,6 @@ namespace Magento\Cms\Controller\Adminhtml\Block; class Save extends \Magento\Cms\Controller\Adminhtml\Block { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context, $coreRegistry); - } - /** * Save action * diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/Delete.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/Delete.php index 306668ffe6ac4ef2b1b87559a87ff11fb7df1f6d..278515e3f101773c5ba196e9e77dfc8896ac4d0a 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/Delete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/Delete.php @@ -6,27 +6,8 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page; -use Magento\Backend\App\Action; - class Delete extends \Magento\Backend\App\Action { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context); - } - /** * {@inheritdoc} */ diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php index 36e68c281a54aa5fa5226af889678e9907bf601a..c53641376c471c985556de4e84792749fdf8ca42 100755 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php @@ -22,25 +22,17 @@ class Edit extends \Magento\Backend\App\Action */ protected $resultPageFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Action\Context $context * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Registry $registry */ public function __construct( Action\Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Registry $registry ) { $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; $this->_coreRegistry = $registry; parent::__construct($context); } diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php index fc89acb6d7d72e127b8947bd40e5671d11df66a5..46b0998de61fd481386bfe840506b715a4d9b692 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php @@ -7,15 +7,9 @@ namespace Magento\Cms\Controller\Adminhtml\Page; use Magento\Backend\App\Action; -use Magento\Backend\Model\View\Result\RedirectFactory; class Save extends \Magento\Backend\App\Action { - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var PostDataProcessor */ @@ -24,15 +18,10 @@ class Save extends \Magento\Backend\App\Action /** * @param Action\Context $context * @param PostDataProcessor $dataProcessor - * @param RedirectFactory $resultRedirectFactory */ - public function __construct( - Action\Context $context, - PostDataProcessor $dataProcessor, - RedirectFactory $resultRedirectFactory - ) { + public function __construct(Action\Context $context, PostDataProcessor $dataProcessor) + { $this->dataProcessor = $dataProcessor; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php index 72fab43cf7fb46d9c31182d65db6cd56bc35f7c7..9728519a5e2101446790e491bd5b6fd3429132ac 100644 --- a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php +++ b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php @@ -206,7 +206,7 @@ class Images extends \Magento\Framework\App\Helper\AbstractHelper if (!$this->_directory->isExist($currentDir)) { $this->_directory->create($currentDir); } - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { $message = __('The directory %1 is not writable by server.', $currentPath); throw new \Magento\Framework\Exception\LocalizedException($message); } diff --git a/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php b/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php index 683506fc7b36f44c810048e2610f170c0b88b0bf..2adc979aacac0827c5211b171a53ba3d4945a2ef 100644 --- a/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php +++ b/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php @@ -375,7 +375,7 @@ class Storage extends \Magento\Framework\Object 'id' => $this->_cmsWysiwygImages->convertPathToId($newPath), ]; return $result; - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a new directory.')); } } @@ -396,7 +396,7 @@ class Storage extends \Magento\Framework\Object $this->_deleteByPath($path); $path = $this->getThumbnailRoot() . $this->_getRelativePathToRoot($path); $this->_deleteByPath($path); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \Magento\Framework\Exception\LocalizedException(__('We cannot delete directory %1.', $path)); } } diff --git a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Edit.php b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Edit.php index 71d3b9146c48f89ca62d1cbb8f63c745e91e39a3..9f8bf3a73f1778c792403d964c4ab4f0a7e20d1f 100644 --- a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Edit.php +++ b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Edit.php @@ -8,11 +8,6 @@ namespace Magento\Config\Controller\Adminhtml\System\Config; class Edit extends AbstractScopeConfig { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\View\Result\PageFactory */ @@ -23,7 +18,6 @@ class Edit extends AbstractScopeConfig * @param \Magento\Config\Model\Config\Structure $configStructure * @param \Magento\Config\Controller\Adminhtml\System\ConfigSectionChecker $sectionChecker * @param \Magento\Config\Model\Config $backendConfig - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ public function __construct( @@ -31,11 +25,9 @@ class Edit extends AbstractScopeConfig \Magento\Config\Model\Config\Structure $configStructure, \Magento\Config\Controller\Adminhtml\System\ConfigSectionChecker $sectionChecker, \Magento\Config\Model\Config $backendConfig, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context, $configStructure, $sectionChecker, $backendConfig); - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultPageFactory = $resultPageFactory; } diff --git a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php index 8cc81e08d40092507e5abdada866ff6ccf175a94..f5969841a7db1d5653e6f19cdb0765973d1b8310 100644 --- a/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php +++ b/app/code/Magento/Config/Controller/Adminhtml/System/Config/Save.php @@ -32,11 +32,6 @@ class Save extends AbstractConfig */ protected $string; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Config\Model\Config\Structure $configStructure @@ -44,7 +39,6 @@ class Save extends AbstractConfig * @param \Magento\Config\Model\Config\Factory $configFactory * @param \Magento\Framework\Cache\FrontendInterface $cache * @param \Magento\Framework\Stdlib\String $string - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, @@ -52,14 +46,12 @@ class Save extends AbstractConfig \Magento\Config\Controller\Adminhtml\System\ConfigSectionChecker $sectionChecker, \Magento\Config\Model\Config\Factory $configFactory, \Magento\Framework\Cache\FrontendInterface $cache, - \Magento\Framework\Stdlib\String $string, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\Stdlib\String $string ) { parent::__construct($context, $configStructure, $sectionChecker); $this->_configFactory = $configFactory; $this->_cache = $cache; $this->string = $string; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Config/Controller/Adminhtml/System/ConfigSectionChecker.php b/app/code/Magento/Config/Controller/Adminhtml/System/ConfigSectionChecker.php index f143741ec2c78aca48f74ca897eee90c99755dd5..bbce2b525d4e645f61ea4c8c7f3d87abb39c5678 100644 --- a/app/code/Magento/Config/Controller/Adminhtml/System/ConfigSectionChecker.php +++ b/app/code/Magento/Config/Controller/Adminhtml/System/ConfigSectionChecker.php @@ -6,7 +6,7 @@ namespace Magento\Config\Controller\Adminhtml\System; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; class ConfigSectionChecker { @@ -41,7 +41,7 @@ class ConfigSectionChecker } return true; } catch (\Zend_Acl_Exception $e) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } catch (\Exception $e) { return false; } diff --git a/app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/SaveTest.php b/app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/SaveTest.php index 060672c505204f81cb57ce75c31c5348821cecc7..23d788e710f5b601a702d9dbd0669363442431a1 100644 --- a/app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/SaveTest.php +++ b/app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/SaveTest.php @@ -123,12 +123,27 @@ class SaveTest extends \PHPUnit_Framework_TestCase $this->_cacheMock = $this->getMock('Magento\Framework\App\Cache\Type\Layout', [], [], '', false); - $configStructureMock->expects($this->any())->method('getElement') - ->will($this->returnValue($this->_sectionMock)); + $configStructureMock->expects($this->any())->method('getElement')->willReturn($this->_sectionMock); - $helperMock->expects($this->any())->method('getUrl')->will($this->returnArgument(0)); + $helperMock->expects($this->any())->method('getUrl')->willReturnArgument(0); $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirect->expects($this->atLeastOnce()) + ->method('setPath') + ->with('adminhtml/system_config/edit') + ->willReturnSelf(); + $resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $resultRedirectFactory->expects($this->atLeastOnce()) + ->method('create') + ->willReturn($this->resultRedirect); + $arguments = [ 'request' => $this->_requestMock, 'response' => $this->_responseMock, @@ -136,6 +151,7 @@ class SaveTest extends \PHPUnit_Framework_TestCase 'eventManager' => $this->_eventManagerMock, 'auth' => $this->_authMock, 'messageManager' => $this->messageManagerMock, + 'resultRedirectFactory' => $resultRedirectFactory ]; $this->_sectionCheckerMock = $this->getMock( @@ -146,21 +162,6 @@ class SaveTest extends \PHPUnit_Framework_TestCase false ); - $this->resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') - ->disableOriginalConstructor() - ->getMock(); - $this->resultRedirect->expects($this->atLeastOnce()) - ->method('setPath') - ->with('adminhtml/system_config/edit') - ->willReturnSelf(); - $resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $resultRedirectFactory->expects($this->atLeastOnce()) - ->method('create') - ->willReturn($this->resultRedirect); - $context = $helper->getObject('Magento\Backend\App\Action\Context', $arguments); $this->_controller = $this->getMock( 'Magento\Config\Controller\Adminhtml\System\Config\Save', @@ -172,7 +173,6 @@ class SaveTest extends \PHPUnit_Framework_TestCase $this->_configFactoryMock, $this->_cacheMock, new \Magento\Framework\Stdlib\String(), - $resultRedirectFactory ] ); } diff --git a/app/code/Magento/Contact/Controller/Index.php b/app/code/Magento/Contact/Controller/Index.php index d144b198916e8b7574756dbf347297986572591c..df15306308938be825471943e34c0274a7edfc55 100644 --- a/app/code/Magento/Contact/Controller/Index.php +++ b/app/code/Magento/Contact/Controller/Index.php @@ -5,7 +5,7 @@ */ namespace Magento\Contact\Controller; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\App\RequestInterface; use Magento\Store\Model\ScopeInterface; @@ -80,12 +80,12 @@ class Index extends \Magento\Framework\App\Action\Action * * @param RequestInterface $request * @return \Magento\Framework\App\ResponseInterface - * @throws \Magento\Framework\App\Action\NotFoundException + * @throws \Magento\Framework\Exception\NotFoundException */ public function dispatch(RequestInterface $request) { if (!$this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED, ScopeInterface::SCOPE_STORE)) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } return parent::dispatch($request); } diff --git a/app/code/Magento/Contact/Test/Unit/Controller/IndexTest.php b/app/code/Magento/Contact/Test/Unit/Controller/IndexTest.php index 4cd4d71f5b74678f909390a67867814534cadb4e..9db82a0300c8dfcc1fb590aa2f7bf329596dd736 100644 --- a/app/code/Magento/Contact/Test/Unit/Controller/IndexTest.php +++ b/app/code/Magento/Contact/Test/Unit/Controller/IndexTest.php @@ -61,7 +61,7 @@ class IndexTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\App\Action\NotFoundException + * @expectedException \Magento\Framework\Exception\NotFoundException */ public function testDispatch() { diff --git a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php index d860910e844bd7030cafdd90c7269468a40b201d..a99c5d696096d3acb8c36937e2e78b4553a1ec8c 100644 --- a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php +++ b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php @@ -11,46 +11,51 @@ class FetchRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Cur /** * Fetch rates action * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect * @throws \Exception|\Magento\Framework\Exception\LocalizedException */ public function execute() { /** @var \Magento\Backend\Model\Session $backendSession */ $backendSession = $this->_objectManager->get('Magento\Backend\Model\Session'); - try { - $service = $this->getRequest()->getParam('rate_services'); - $this->_getSession()->setCurrencyRateService($service); - if (!$service) { - throw new \Exception(__('Please specify a correct Import Service.')); - } - try { - /** @var \Magento\Directory\Model\Currency\Import\ImportInterface $importModel */ - $importModel = $this->_objectManager->get( - 'Magento\Directory\Model\Currency\Import\Factory' - )->create( - $service - ); - } catch (\Exception $e) { - throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t initialize the import model.')); - } - $rates = $importModel->fetchRates(); - $errors = $importModel->getMessages(); - if (sizeof($errors) > 0) { - foreach ($errors as $error) { - $this->messageManager->addWarning($error); - } - $this->messageManager->addWarning( - __('All possible rates were fetched, please click on "Save" to apply') - ); - } else { - $this->messageManager->addSuccess(__('All rates were fetched, please click on "Save" to apply')); - } - $backendSession->setRates($rates); + $service = $this->getRequest()->getParam('rate_services'); + $this->_getSession()->setCurrencyRateService($service); + if (!$service) { + throw new \Exception(__('Please specify a correct Import Service.')); + } + try { + /** @var \Magento\Directory\Model\Currency\Import\ImportInterface $importModel */ + $importModel = $this->_objectManager->get('Magento\Directory\Model\Currency\Import\Factory') + ->create($service); } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); + throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t initialize the import model.')); + } + $rates = $importModel->fetchRates(); + $errors = $importModel->getMessages(); + if (sizeof($errors) > 0) { + foreach ($errors as $error) { + $this->messageManager->addWarning($error); + } + $this->messageManager->addWarning( + __('All possible rates were fetched, please click on "Save" to apply') + ); + } else { + $this->messageManager->addSuccess(__('All rates were fetched, please click on "Save" to apply')); } - $this->_redirect('adminhtml/*/'); + + $backendSession->setRates($rates); + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('adminhtml/*/'); } } diff --git a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php index e89ab91b3aab4382e9690247272e05bd954440d6..01940a5bee4c225946b1475263f3b96e921295ce 100644 --- a/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php +++ b/app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php @@ -12,6 +12,7 @@ class Save extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencys * Save custom Currency symbol * * @return void + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { @@ -24,16 +25,9 @@ class Save extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencys } } - try { - $this->_objectManager->create( - 'Magento\CurrencySymbol\Model\System\Currencysymbol' - )->setCurrencySymbolsData( - $symbolsDataArray - ); - $this->messageManager->addSuccess(__('The custom currency symbols were applied.')); - } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); - } + $this->_objectManager->create('Magento\CurrencySymbol\Model\System\Currencysymbol') + ->setCurrencySymbolsData($symbolsDataArray); + $this->messageManager->addSuccess(__('The custom currency symbols were applied.')); $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*'))); } diff --git a/app/code/Magento/Customer/Controller/Account.php b/app/code/Magento/Customer/Controller/Account.php index 15b3136eb542707d5105b12885d5a118a011be90..286f3f4cd6c554a122d312cc1a58d729f784dee7 100644 --- a/app/code/Magento/Customer/Controller/Account.php +++ b/app/code/Magento/Customer/Controller/Account.php @@ -8,7 +8,6 @@ namespace Magento\Customer\Controller; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\Context; use Magento\Framework\App\RequestInterface; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; /** @@ -42,11 +41,6 @@ class Account extends \Magento\Framework\App\Action\Action /** @var Session */ protected $session; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var PageFactory */ @@ -55,17 +49,14 @@ class Account extends \Magento\Framework\App\Action\Action /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory */ public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory ) { $this->session = $customerSession; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } diff --git a/app/code/Magento/Customer/Controller/Account/Confirm.php b/app/code/Magento/Customer/Controller/Account/Confirm.php index a42a81c43f8589f176884e88e35786399456f71b..04e84dd7ceebcb448933731e3fe41813b6d47991 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirm.php +++ b/app/code/Magento/Customer/Controller/Account/Confirm.php @@ -10,7 +10,6 @@ use Magento\Customer\Model\Url; use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; @@ -48,7 +47,6 @@ class Confirm extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param ScopeConfigInterface $scopeConfig * @param StoreManagerInterface $storeManager @@ -62,7 +60,6 @@ class Confirm extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, @@ -77,13 +74,14 @@ class Confirm extends \Magento\Customer\Controller\Account $this->customerRepository = $customerRepository; $this->addressHelper = $addressHelper; $this->urlModel = $urlFactory->create(); - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** * Confirm customer account by id and confirmation key * * @return \Magento\Framework\Controller\Result\Redirect + * @throws \Exception */ public function execute() { @@ -94,32 +92,35 @@ class Confirm extends \Magento\Customer\Controller\Account $resultRedirect->setPath('*/*/'); return $resultRedirect; } - try { - $customerId = $this->getRequest()->getParam('id', false); - $key = $this->getRequest()->getParam('key', false); - if (empty($customerId) || empty($key)) { - throw new \Exception(__('Bad request.')); - } - - // log in and send greeting email - $customerEmail = $this->customerRepository->getById($customerId)->getEmail(); - $customer = $this->customerAccountManagement->activate($customerEmail, $key); - $this->_getSession()->setCustomerDataAsLoggedIn($customer); - $this->messageManager->addSuccess($this->getSuccessMessage()); - $resultRedirect->setUrl($this->getSuccessRedirect()); - return $resultRedirect; - } catch (StateException $e) { - $this->messageManager->addException($e, __('This confirmation key is invalid or has expired.')); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('There was an error confirming the account')); + $customerId = $this->getRequest()->getParam('id', false); + $key = $this->getRequest()->getParam('key', false); + if (empty($customerId) || empty($key)) { + throw new \Exception(__('Bad request.')); } - // die unhappy - $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); - $resultRedirect->setUrl($this->_redirect->error($url)); + + // log in and send greeting email + $customerEmail = $this->customerRepository->getById($customerId)->getEmail(); + $customer = $this->customerAccountManagement->activate($customerEmail, $key); + $this->_getSession()->setCustomerDataAsLoggedIn($customer); + + $this->messageManager->addSuccess($this->getSuccessMessage()); + $resultRedirect->setUrl($this->getSuccessRedirect()); return $resultRedirect; } + /** + * {@inheritdoc} + * + * @return \Magento\Framework\Controller\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); + return $resultRedirect->setUrl($this->_redirect->error($url)); + } + /** * Retrieve success message * diff --git a/app/code/Magento/Customer/Controller/Account/Confirmation.php b/app/code/Magento/Customer/Controller/Account/Confirmation.php index ba7ee81e3eaf8e199059bf50f728e5ef58bc5e51..0eea2052db37fb847aa1ab75f262930256181f71 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirmation.php +++ b/app/code/Magento/Customer/Controller/Account/Confirmation.php @@ -8,7 +8,6 @@ namespace Magento\Customer\Controller\Account; use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; @@ -25,7 +24,6 @@ class Confirmation extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param StoreManagerInterface $storeManager * @param AccountManagementInterface $customerAccountManagement @@ -33,14 +31,13 @@ class Confirmation extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, StoreManagerInterface $storeManager, AccountManagementInterface $customerAccountManagement ) { $this->storeManager = $storeManager; $this->customerAccountManagement = $customerAccountManagement; - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** diff --git a/app/code/Magento/Customer/Controller/Account/Create.php b/app/code/Magento/Customer/Controller/Account/Create.php index 215f1a0198d18b245c3bd22d4fd76933a7373452..887ec8d996a35bfc2fc3207bd182cca2eefc1596 100644 --- a/app/code/Magento/Customer/Controller/Account/Create.php +++ b/app/code/Magento/Customer/Controller/Account/Create.php @@ -8,7 +8,6 @@ namespace Magento\Customer\Controller\Account; use Magento\Customer\Model\Registration; use Magento\Customer\Model\Session; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; @@ -20,19 +19,17 @@ class Create extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param Registration $registration */ public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, Registration $registration ) { $this->registration = $registration; - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** diff --git a/app/code/Magento/Customer/Controller/Account/CreatePassword.php b/app/code/Magento/Customer/Controller/Account/CreatePassword.php index 69f5eb09d510084ad0fd55a38bf0fe2bb9f23f8a..22ef71e47e3cf2e1b4dbd71144536fa78e7b1b17 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePassword.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePassword.php @@ -8,7 +8,6 @@ namespace Magento\Customer\Controller\Account; use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Model\Session; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; @@ -20,19 +19,17 @@ class CreatePassword extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param AccountManagementInterface $customerAccountManagement */ public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, AccountManagementInterface $customerAccountManagement ) { $this->customerAccountManagement = $customerAccountManagement; - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** diff --git a/app/code/Magento/Customer/Controller/Account/CreatePost.php b/app/code/Magento/Customer/Controller/Account/CreatePost.php index 420139f171cfabb1925d5b9f0d86265cf8c67384..c132eb904d1446ff1bc8d49c4068e1675963e968 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePost.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePost.php @@ -11,7 +11,6 @@ use Magento\Customer\Model\Url; use Magento\Framework\Api\DataObjectHelper; use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\StoreManagerInterface; @@ -82,7 +81,6 @@ class CreatePost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param ScopeConfigInterface $scopeConfig * @param StoreManagerInterface $storeManager @@ -106,7 +104,6 @@ class CreatePost extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, @@ -144,7 +141,6 @@ class CreatePost extends \Magento\Customer\Controller\Account parent::__construct( $context, $customerSession, - $resultRedirectFactory, $resultPageFactory ); } diff --git a/app/code/Magento/Customer/Controller/Account/Edit.php b/app/code/Magento/Customer/Controller/Account/Edit.php index b4de05f17140b8be1acb91b7fc070fe38400c0e7..df4dde04fc35ca50a1f14ddffa439a8223bb0252 100644 --- a/app/code/Magento/Customer/Controller/Account/Edit.php +++ b/app/code/Magento/Customer/Controller/Account/Edit.php @@ -9,7 +9,6 @@ namespace Magento\Customer\Controller\Account; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\Api\DataObjectHelper; use Magento\Customer\Model\Session; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; @@ -24,7 +23,6 @@ class Edit extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param CustomerRepositoryInterface $customerRepository * @param DataObjectHelper $dataObjectHelper @@ -32,14 +30,13 @@ class Edit extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, CustomerRepositoryInterface $customerRepository, DataObjectHelper $dataObjectHelper ) { $this->customerRepository = $customerRepository; $this->dataObjectHelper = $dataObjectHelper; - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** diff --git a/app/code/Magento/Customer/Controller/Account/EditPost.php b/app/code/Magento/Customer/Controller/Account/EditPost.php index a3df334fbf83560dc676ee96e415ff842a88ac30..c61860f64004def6eb8bc8a72a04d0ea02a2eaf9 100644 --- a/app/code/Magento/Customer/Controller/Account/EditPost.php +++ b/app/code/Magento/Customer/Controller/Account/EditPost.php @@ -11,7 +11,6 @@ use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Model\CustomerExtractor; use Magento\Customer\Model\Session; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; use Magento\Framework\Exception\AuthenticationException; @@ -37,7 +36,6 @@ class EditPost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param AccountManagementInterface $customerAccountManagement * @param CustomerRepositoryInterface $customerRepository @@ -48,7 +46,6 @@ class EditPost extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, AccountManagementInterface $customerAccountManagement, CustomerRepositoryInterface $customerRepository, @@ -59,7 +56,7 @@ class EditPost extends \Magento\Customer\Controller\Account $this->customerRepository = $customerRepository; $this->formKeyValidator = $formKeyValidator; $this->customerExtractor = $customerExtractor; - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** diff --git a/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php b/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php index 3b82507dc7f45d9f7c079bb2679539e1ed915be3..fc391f4143525b23d8e88590fa2c5065eeeed664 100644 --- a/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php +++ b/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php @@ -9,7 +9,6 @@ namespace Magento\Customer\Controller\Account; use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Model\AccountManagement; use Magento\Customer\Model\Session; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; use Magento\Framework\Escaper; @@ -26,7 +25,6 @@ class ForgotPasswordPost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param AccountManagementInterface $customerAccountManagement * @param Escaper $escaper @@ -34,14 +32,13 @@ class ForgotPasswordPost extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, AccountManagementInterface $customerAccountManagement, Escaper $escaper ) { $this->customerAccountManagement = $customerAccountManagement; $this->escaper = $escaper; - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** diff --git a/app/code/Magento/Customer/Controller/Account/LoginPost.php b/app/code/Magento/Customer/Controller/Account/LoginPost.php index 1f05dff29314ebeca53856b305565dca6619aeb1..500a2f7b68302ee573f84a0ac597b551c899e36b 100644 --- a/app/code/Magento/Customer/Controller/Account/LoginPost.php +++ b/app/code/Magento/Customer/Controller/Account/LoginPost.php @@ -8,7 +8,6 @@ namespace Magento\Customer\Controller\Account; use Magento\Customer\Model\Account\Redirect as AccountRedirect; use Magento\Framework\App\Action\Context; use Magento\Customer\Model\Session; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Model\Url as CustomerUrl; @@ -35,7 +34,6 @@ class LoginPost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param AccountManagementInterface $customerAccountManagement * @param CustomerUrl $customerHelperData @@ -47,7 +45,6 @@ class LoginPost extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, AccountManagementInterface $customerAccountManagement, CustomerUrl $customerHelperData, @@ -61,7 +58,6 @@ class LoginPost extends \Magento\Customer\Controller\Account parent::__construct( $context, $customerSession, - $resultRedirectFactory, $resultPageFactory ); } diff --git a/app/code/Magento/Customer/Controller/Account/ResetPassword.php b/app/code/Magento/Customer/Controller/Account/ResetPassword.php index 32735a80177b4323b0a7784a539f85a56de3c7dc..d8486b21549a9161b12ce30c36d798976273b319 100644 --- a/app/code/Magento/Customer/Controller/Account/ResetPassword.php +++ b/app/code/Magento/Customer/Controller/Account/ResetPassword.php @@ -8,7 +8,6 @@ namespace Magento\Customer\Controller\Account; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\Context; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\Controller\Result\ForwardFactory; @@ -22,19 +21,17 @@ class ResetPassword extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param ForwardFactory $resultForwardFactory */ public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, ForwardFactory $resultForwardFactory ) { $this->resultForwardFactory = $resultForwardFactory; - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** diff --git a/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php b/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php index b8055dc7354e7a34a16dd876f05611bd28f6c3a3..2d53034cb6897e21849bed76fdb2a9e80a02ab33 100644 --- a/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php +++ b/app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php @@ -10,7 +10,6 @@ use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Model\Session; use Magento\Framework\App\Action\Context; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; class ResetPasswordPost extends \Magento\Customer\Controller\Account @@ -24,7 +23,6 @@ class ResetPasswordPost extends \Magento\Customer\Controller\Account /** * @param Context $context * @param Session $customerSession - * @param RedirectFactory $resultRedirectFactory * @param PageFactory $resultPageFactory * @param AccountManagementInterface $accountManagement * @param CustomerRepositoryInterface $customerRepository @@ -32,14 +30,13 @@ class ResetPasswordPost extends \Magento\Customer\Controller\Account public function __construct( Context $context, Session $customerSession, - RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, AccountManagementInterface $accountManagement, CustomerRepositoryInterface $customerRepository ) { $this->accountManagement = $accountManagement; $this->customerRepository = $customerRepository; - parent::__construct($context, $customerSession, $resultRedirectFactory, $resultPageFactory); + parent::__construct($context, $customerSession, $resultPageFactory); } /** diff --git a/app/code/Magento/Customer/Controller/Address.php b/app/code/Magento/Customer/Controller/Address.php index 60b2c38fd2676c8e5c1cbece3323dd6f5a959b6b..27f6b54271ee3b7f80037bb335922642c124eb04 100644 --- a/app/code/Magento/Customer/Controller/Address.php +++ b/app/code/Magento/Customer/Controller/Address.php @@ -54,11 +54,6 @@ class Address extends \Magento\Framework\App\Action\Action */ protected $dataObjectHelper; - /** - * @var \Magento\Framework\Controller\Result\Redirect - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\Controller\Result\ForwardFactory */ @@ -79,7 +74,6 @@ class Address extends \Magento\Framework\App\Action\Action * @param \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory * @param \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -94,7 +88,6 @@ class Address extends \Magento\Framework\App\Action\Action \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { @@ -106,7 +99,6 @@ class Address extends \Magento\Framework\App\Action\Action $this->regionDataFactory = $regionDataFactory; $this->_dataProcessor = $dataProcessor; $this->dataObjectHelper = $dataObjectHelper; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; $this->resultPageFactory = $resultPageFactory; parent::__construct($context); diff --git a/app/code/Magento/Customer/Controller/Address/Index.php b/app/code/Magento/Customer/Controller/Address/Index.php index cfb5fc0580777b96c93db111efc4d35560be671b..bf2975bb3b054738f7b215445af73ead7563163e 100644 --- a/app/code/Magento/Customer/Controller/Address/Index.php +++ b/app/code/Magento/Customer/Controller/Address/Index.php @@ -29,7 +29,6 @@ class Index extends \Magento\Customer\Controller\Address * @param \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper * @param CustomerRepositoryInterface $customerRepository - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -44,7 +43,6 @@ class Index extends \Magento\Customer\Controller\Address \Magento\Customer\Api\Data\RegionInterfaceFactory $regionDataFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, CustomerRepositoryInterface $customerRepository @@ -60,7 +58,6 @@ class Index extends \Magento\Customer\Controller\Address $regionDataFactory, $dataProcessor, $dataObjectHelper, - $resultRedirectFactory, $resultForwardFactory, $resultPageFactory ); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Update.php b/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Update.php index 099e121b9de5d88ba311359e3f0177122564ae27..a77e904edbea387aa1674bb62d535ac2806e67fe 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Update.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/Update.php @@ -8,25 +8,6 @@ namespace Magento\Customer\Controller\Adminhtml\Cart\Product\Composite\Cart; class Update extends \Magento\Customer\Controller\Adminhtml\Cart\Product\Composite\Cart { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Quote\Model\QuoteRepository $quoteRepository - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Quote\Model\QuoteRepository $quoteRepository, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $quoteRepository); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * IFrame handler for submitted configuration for quote item * diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group.php b/app/code/Magento/Customer/Controller/Adminhtml/Group.php index 47e6c1c04309b409e6cb9fe2f5cb659ab1e09a18..cfbca15cae3615922702eba5fa522179ca45480b 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group.php @@ -30,11 +30,6 @@ class Group extends \Magento\Backend\App\Action */ protected $groupDataFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Backend\Model\View\Result\ForwardFactory */ @@ -52,7 +47,6 @@ class Group extends \Magento\Backend\App\Action * @param \Magento\Framework\Registry $coreRegistry * @param GroupRepositoryInterface $groupRepository * @param GroupInterfaceFactory $groupDataFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ @@ -61,7 +55,6 @@ class Group extends \Magento\Backend\App\Action \Magento\Framework\Registry $coreRegistry, GroupRepositoryInterface $groupRepository, GroupInterfaceFactory $groupDataFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { @@ -69,7 +62,6 @@ class Group extends \Magento\Backend\App\Action $this->groupRepository = $groupRepository; $this->groupDataFactory = $groupDataFactory; parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; $this->resultPageFactory = $resultPageFactory; } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php index 94581d7783830f3c3bbc5f10f20bdaa3dff3130a..614abdb1c686cccd324c4f44c5dfa8ddf2679e2a 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Group/Save.php @@ -23,7 +23,6 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Group * @param \Magento\Framework\Registry $coreRegistry * @param GroupRepositoryInterface $groupRepository * @param GroupInterfaceFactory $groupDataFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory * @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor @@ -33,7 +32,6 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Group \Magento\Framework\Registry $coreRegistry, GroupRepositoryInterface $groupRepository, GroupInterfaceFactory $groupDataFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor @@ -44,7 +42,6 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Group $coreRegistry, $groupRepository, $groupDataFactory, - $resultRedirectFactory, $resultForwardFactory, $resultPageFactory ); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index.php b/app/code/Magento/Customer/Controller/Adminhtml/Index.php index eec31225f83eaf86c8d9ea536e45fd82c558e60f..2d84f59c80f84d81d66000c07bb485f694816b39 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index.php @@ -133,11 +133,6 @@ class Index extends \Magento\Backend\App\Action */ protected $resultPageFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Backend\Model\View\Result\ForwardFactory */ @@ -172,7 +167,6 @@ class Index extends \Magento\Backend\App\Action * @param \Magento\Framework\View\LayoutFactory $layoutFactory * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @@ -202,7 +196,6 @@ class Index extends \Magento\Backend\App\Action \Magento\Framework\View\LayoutFactory $layoutFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory ) { @@ -228,7 +221,6 @@ class Index extends \Magento\Backend\App\Action $this->layoutFactory = $layoutFactory; $this->resultLayoutFactory = $resultLayoutFactory; $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; $this->resultJsonFactory = $resultJsonFactory; parent::__construct($context); diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php index d6d46cb468d66b4c8e9bf218f397bbf9a382a848..9ca36cab18553645f184045ea47a657ac6dd9ca6 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Delete.php @@ -13,21 +13,27 @@ class Delete extends \Magento\Customer\Controller\Adminhtml\Index * Delete customer action * * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Exception */ public function execute() { $this->_initCustomer(); $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID); if (!empty($customerId)) { - try { - $this->_customerRepository->deleteById($customerId); - $this->messageManager->addSuccess(__('You deleted the customer.')); - } catch (\Exception $exception) { - $this->messageManager->addError($exception->getMessage()); - } + $this->_customerRepository->deleteById($customerId); + $this->messageManager->addSuccess(__('You deleted the customer.')); } + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { $resultRedirect = $this->resultRedirectFactory->create(); - $resultRedirect->setPath('customer/index'); - return $resultRedirect; + return $resultRedirect->setPath('customer/index'); } } diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php index 86f937f8981a7fc110e63a31aee8e6ae0f40f1c6..aeb28057de13b555d37c18b0881d446bc345695a 100755 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php @@ -11,7 +11,7 @@ use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Api\Data\AddressInterfaceFactory; use Magento\Customer\Api\Data\CustomerInterfaceFactory; use Magento\Customer\Model\Address\Mapper; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\ObjectFactory; @@ -54,7 +54,6 @@ class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index * @param \Magento\Framework\View\LayoutFactory $layoutFactory * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory @@ -86,7 +85,6 @@ class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index \Magento\Framework\View\LayoutFactory $layoutFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, @@ -116,7 +114,6 @@ class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index $layoutFactory, $resultLayoutFactory, $resultPageFactory, - $resultRedirectFactory, $resultForwardFactory, $resultJsonFactory ); @@ -148,7 +145,7 @@ class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index ); $plain = true; } else { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } /** @var \Magento\Framework\Filesystem $filesystem */ @@ -159,7 +156,7 @@ class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index if (!$directory->isFile($fileName) && !$this->_objectManager->get('Magento\MediaStorage\Helper\File\Storage')->processStorageFile($path) ) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } if ($plain) { diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Update.php b/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Update.php index 4a9028ee2968d2312ebe3f5115dae04ef34bf7d4..c1e7e8307c8344d914cf725acd704bcfe6d2acf5 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Update.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Wishlist/Product/Composite/Wishlist/Update.php @@ -10,23 +10,6 @@ use Exception; class Update extends \Magento\Customer\Controller\Adminhtml\Wishlist\Product\Composite\Wishlist { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * IFrame handler for submitted configuration for wishlist item. * diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 4d0ca1e9efbedea3be686e2bff50b42a97055013..d4b541e090af24cd638e03cc0e04e80c9c34413a 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -31,7 +31,7 @@ use Magento\Framework\Exception\State\ExpiredException; use Magento\Framework\Exception\State\InputMismatchException; use Magento\Framework\Exception\State\InvalidTransitionException; use Psr\Log\LoggerInterface as PsrLogger; -use Magento\Framework\Mail\Exception as MailException; +use Magento\Framework\Exception\MailException; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Framework\Math\Random; use Magento\Framework\Reflection\DataObjectProcessor; diff --git a/app/code/Magento/Customer/Model/GroupManagement.php b/app/code/Magento/Customer/Model/GroupManagement.php index 0e6792f095f42e6805e5fdec1b7bb767546cd387..fb05d732285d7e4d4e45a23fa952ac76020dc9ec 100644 --- a/app/code/Magento/Customer/Model/GroupManagement.php +++ b/app/code/Magento/Customer/Model/GroupManagement.php @@ -120,7 +120,7 @@ class GroupManagement implements \Magento\Customer\Api\GroupManagementInterface \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId ); - } catch (\Magento\Framework\App\InitException $e) { + } catch (\Magento\Framework\Exception\State\InitException $e) { throw NoSuchEntityException::singleField('storeId', $storeId); } try { diff --git a/app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php b/app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php index c356f2f352c2907446d85ba4efc67372640b8879..f5404347c8c841a24ca630175235b6348fea6a95 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php @@ -166,7 +166,7 @@ class EditTest extends \PHPUnit_Framework_TestCase } /** - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testSetLayoutWithAlienAddress() diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php index a4fe4832056411b7453b2eaa2b8b01ea04d3b010..bbcbfe8192d33cad464578de3b2b488284b3aea3 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php @@ -144,19 +144,22 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase $this->contextMock = $this->getMock('Magento\Framework\App\Action\Context', [], [], '', false); $this->contextMock->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->requestMock)); + ->willReturn($this->requestMock); $this->contextMock->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->responseMock)); + ->willReturn($this->responseMock); $this->contextMock->expects($this->any()) ->method('getRedirect') - ->will($this->returnValue($this->redirectMock)); + ->willReturn($this->redirectMock); $this->contextMock->expects($this->any()) ->method('getView') - ->will($this->returnValue($viewMock)); + ->willReturn($viewMock); $this->contextMock->expects($this->any()) ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); + ->willReturn($this->messageManagerMock); + $this->contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($redirectFactoryMock); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -171,7 +174,6 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase 'customerRepository' => $this->customerRepositoryMock, 'addressHelper' => $this->addressHelperMock, 'urlFactory' => $urlFactoryMock, - 'resultRedirectFactory' => $redirectFactoryMock, ] ); } @@ -190,7 +192,30 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Magento\Framework\Controller\Result\Redirect', $this->model->execute()); } + public function testGetDefaultRedirect() + { + $testUrl = 'http://example.com'; + $this->urlMock->expects($this->once()) + ->method('getUrl') + ->with('*/*/index', ['_secure' => true]) + ->willReturn($testUrl); + + $this->redirectMock->expects($this->once()) + ->method('error') + ->with($testUrl) + ->willReturn($testUrl); + + $this->redirectResultMock->expects($this->once()) + ->method('setUrl') + ->with($testUrl) + ->willReturnSelf(); + + $this->model->getDefaultResult(); + } + /** + * @expectedException \Exception + * @expectedExceptionMessage Bad request. * @dataProvider getParametersDataProvider */ public function testNoCustomerIdInRequest($customerId, $key) @@ -208,27 +233,6 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo('key'), false) ->will($this->returnValue($key)); - $exception = new \Exception('Bad request.'); - $this->messageManagerMock->expects($this->once()) - ->method('addException') - ->with($this->equalTo($exception), $this->equalTo('There was an error confirming the account')); - - $testUrl = 'http://example.com'; - $this->urlMock->expects($this->once()) - ->method('getUrl') - ->with($this->equalTo('*/*/index'), ['_secure' => true]) - ->will($this->returnValue($testUrl)); - - $this->redirectMock->expects($this->once()) - ->method('error') - ->with($this->equalTo($testUrl)) - ->will($this->returnValue($testUrl)); - - $this->redirectResultMock->expects($this->once()) - ->method('setUrl') - ->with($this->equalTo($testUrl)) - ->willReturnSelf(); - $this->assertInstanceOf('Magento\Framework\Controller\Result\Redirect', $this->model->execute()); } @@ -313,9 +317,9 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase public function getSuccessMessageDataProvider() { return [ - [1, 1, false, null, __('Thank you for registering with')], - [1, 1, true, Address::TYPE_BILLING, __('enter you billing address for proper VAT calculation')], - [1, 1, true, Address::TYPE_SHIPPING, __('enter you shipping address for proper VAT calculation')], + [1, 1, false, null, 'Thank you for registering with'], + [1, 1, true, Address::TYPE_BILLING, 'enter you billing address for proper VAT calculation'], + [1, 1, true, Address::TYPE_SHIPPING, 'enter you shipping address for proper VAT calculation'], ]; } @@ -388,18 +392,18 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo('*/*/index'), ['_secure' => true]) ->will($this->returnValue($successUrl)); - $this->redirectMock->expects($this->never()) + $this->redirectMock->expects($this->once()) ->method('success') ->with($this->equalTo($resultUrl)) - ->will($this->returnValue($resultUrl)); + ->willReturn($resultUrl); - $this->scopeConfigMock->expects($this->never()) + $this->scopeConfigMock->expects($this->once()) ->method('isSetFlag') ->with( - $this->equalTo(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD), - $this->equalTo(ScopeInterface::SCOPE_STORE) + Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD, + ScopeInterface::SCOPE_STORE ) - ->will($this->returnValue($isSetFlag)); + ->willReturn($isSetFlag); $this->model->execute(); } @@ -417,7 +421,7 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase null, 'http://example.com/back', true, - __('Thank you for registering with'), + 'Thank you for registering with', ], [ 1, @@ -426,7 +430,7 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase 'http://example.com/success', 'http://example.com/success', true, - __('Thank you for registering with'), + 'Thank you for registering with', ], [ 1, @@ -435,7 +439,7 @@ class ConfirmTest extends \PHPUnit_Framework_TestCase 'http://example.com/success', 'http://example.com/success', false, - __('Thank you for registering with'), + 'Thank you for registering with', ], ]; } diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php index 46bd9cbf68c9c93fa72277f057bb28972f056251..41115e5ac8649409c8c6f1bb8499955edbd5b7b1 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/CreatePostTest.php @@ -198,30 +198,32 @@ class CreatePostTest extends \PHPUnit_Framework_TestCase $eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\Result\RedirectFactory') + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->redirectMock); + $contextMock = $this->getMock('Magento\Framework\App\Action\Context', [], [], '', false); $contextMock->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->requestMock)); + ->willReturn($this->requestMock); $contextMock->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->responseMock)); + ->willReturn($this->responseMock); $contextMock->expects($this->any()) ->method('getRedirect') - ->will($this->returnValue($this->redirectMock)); + ->willReturn($this->redirectMock); $contextMock->expects($this->any()) ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); + ->willReturn($this->messageManagerMock); $contextMock->expects($this->any()) ->method('getEventManager') - ->will($this->returnValue($eventManagerMock)); - - $this->resultRedirectFactoryMock = $this->getMockBuilder( - 'Magento\Framework\Controller\Result\RedirectFactory' - )->setMethods(['create']) - ->getMock(); - $this->resultRedirectFactoryMock->expects($this->any()) - ->method('create') - ->willReturn($this->redirectMock); + ->willReturn($eventManagerMock); + $contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $this->model = $objectManager->getObject( 'Magento\Customer\Controller\Account\CreatePost', @@ -243,7 +245,6 @@ class CreatePostTest extends \PHPUnit_Framework_TestCase 'escape' => $escaperMock, 'customerExtractor' => $this->customerExtractorMock, 'dataObjectHelper' => $this->dataObjectHelperMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock, ] ); } diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Account/EditPostTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Account/EditPostTest.php index 86113cef969df40aa3c6f1f1f1603acca0f148b2..eabe54ae5d46deb4fca77f3c0a8ebb8f7c06a3e4 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Account/EditPostTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Account/EditPostTest.php @@ -90,24 +90,26 @@ class EditPostTest extends \PHPUnit_Framework_TestCase $this->messageManager = $this->getMock('Magento\Framework\Message\Manager', [], [], '', false); + $this->resultRedirectFactory = $this->getMock( + 'Magento\Framework\Controller\Result\RedirectFactory', + ['create'], + [], + '', + false + ); + $this->context = $this->objectManager->getObject( 'Magento\Framework\App\Action\Context', [ 'request' => $this->request, 'response' => $this->response, - 'messageManager' => $this->messageManager + 'messageManager' => $this->messageManager, + 'resultRedirectFactory' => $this->resultRedirectFactory ] ); $this->redirectResultMock = $this->getMock('Magento\Framework\Controller\Result\Redirect', [], [], '', false); $this->customerSession = $this->getMock('Magento\Customer\Model\Session', [], [], '', false); - $this->resultRedirectFactory = $this->getMock( - 'Magento\Framework\Controller\Result\RedirectFactory', - ['create'], - [], - '', - false - ); $this->resultPageFactory = $this->getMock('Magento\Framework\View\Result\PageFactory', [], [], '', false); $this->customerAccountManagement = $this->getMockForAbstractClass( 'Magento\Customer\Api\AccountManagementInterface', diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php index 53ffa02b353e2fdb921a19e0b1f52063359ac365..336877afcab7e52e0061276a6014abf672a8b9bf 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ResetPasswordTest.php @@ -171,44 +171,29 @@ class ResetPasswordTest extends \PHPUnit_Framework_TestCase 'getResponse', 'getTitle', 'getView', + 'getResultRedirectFactory' ]; $contextMock = $this->getMockBuilder( '\Magento\Backend\App\Action\Context' )->disableOriginalConstructor()->setMethods( $contextArgs )->getMock(); - $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->_request)); - $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->_response)); - $contextMock->expects( - $this->any() - )->method( - 'getObjectManager' - )->will( - $this->returnValue($this->_objectManager) - ); - $contextMock->expects( - $this->any() - )->method( - 'getFrontController' - )->will( - $this->returnValue($frontControllerMock) - ); - $contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock)); - - $contextMock->expects($this->any())->method('getHelper')->will($this->returnValue($this->_helper)); - $contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->_session)); - $contextMock->expects( - $this->any() - )->method( - 'getMessageManager' - )->will( - $this->returnValue($this->messageManager) - ); + $contextMock->expects($this->any())->method('getRequest')->willReturn($this->_request); + $contextMock->expects($this->any())->method('getResponse')->willReturn($this->_response); + $contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->_objectManager); + $contextMock->expects($this->any())->method('getFrontController')->willReturn($frontControllerMock); + $contextMock->expects($this->any())->method('getActionFlag')->willReturn($actionFlagMock); + $contextMock->expects($this->any())->method('getHelper')->willReturn($this->_helper); + $contextMock->expects($this->any())->method('getSession')->willReturn($this->_session); + $contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->messageManager); $titleMock = $this->getMockBuilder('\Magento\Framework\App\Action\Title')->getMock(); - $contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($titleMock)); + $contextMock->expects($this->any())->method('getTitle')->willReturn($titleMock); $viewMock = $this->getMockBuilder('\Magento\Framework\App\ViewInterface')->getMock(); - $viewMock->expects($this->any())->method('loadLayout')->will($this->returnSelf()); - $contextMock->expects($this->any())->method('getView')->will($this->returnValue($viewMock)); + $viewMock->expects($this->any())->method('loadLayout')->willReturnSelf(); + $contextMock->expects($this->any())->method('getView')->willReturn($viewMock); + $contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $this->_customerAccountManagementMock = $this->getMockBuilder( 'Magento\Customer\Api\AccountManagementInterface' @@ -222,7 +207,6 @@ class ResetPasswordTest extends \PHPUnit_Framework_TestCase 'context' => $contextMock, 'customerAccountManagement' => $this->_customerAccountManagementMock, 'customerRepository' => $this->_customerRepositoryMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock ]; $helperObjectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ViewfileTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ViewfileTest.php index 0d38fb9a0ee18fc41c8c65bbf5e316f6dd661b1d..3021161364bf164c63eabb3e53aa0e30b2df77a2 100755 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ViewfileTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/ViewfileTest.php @@ -94,8 +94,8 @@ class ViewfileTest extends \PHPUnit_Framework_TestCase } /** - * @throws \Magento\Framework\App\Action\NotFoundException - * @expectedException \Magento\Framework\App\Action\NotFoundException + * @throws \Magento\Framework\Exception\NotFoundException + * @expectedException \Magento\Framework\Exception\NotFoundException */ public function testExecuteNoParamsShouldThrowException() { diff --git a/app/code/Magento/Customer/Test/Unit/Model/Resource/Group/Grid/ServiceCollectionTest.php b/app/code/Magento/Customer/Test/Unit/Model/Resource/Group/Grid/ServiceCollectionTest.php index 5d9f67f24e56e09a51f142380ce5e27363b064ca..1094b73194e5b3a75ac84cb57c8b6c85ecac26b3 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Resource/Group/Grid/ServiceCollectionTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Resource/Group/Grid/ServiceCollectionTest.php @@ -217,7 +217,7 @@ class ServiceCollectionTest extends \PHPUnit_Framework_TestCase * @param string[] $fields * @param array $conditions * - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage When passing in a field array there must be a matching condition array * @dataProvider addFieldToFilterInconsistentArraysDataProvider */ diff --git a/app/code/Magento/DesignEditor/Block/Adminhtml/Editor/Tools/Code/ImageSizing.php b/app/code/Magento/DesignEditor/Block/Adminhtml/Editor/Tools/Code/ImageSizing.php index 3a7213c67e7adeb629d04d229770adaf2a25a0fa..918f008e68065098e467a4a88061ffa616b2a78a 100644 --- a/app/code/Magento/DesignEditor/Block/Adminhtml/Editor/Tools/Code/ImageSizing.php +++ b/app/code/Magento/DesignEditor/Block/Adminhtml/Editor/Tools/Code/ImageSizing.php @@ -89,7 +89,7 @@ class ImageSizing extends \Magento\Backend\Block\Widget\Form\Generic \Magento\DesignEditor\Model\Editor\Tools\Controls\Factory::TYPE_IMAGE_SIZING, $this->_themeContext->getStagingTheme() ); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $isFilePresent = false; } diff --git a/app/code/Magento/DesignEditor/Controller/Adminhtml/System/Design/Editor/Revert.php b/app/code/Magento/DesignEditor/Controller/Adminhtml/System/Design/Editor/Revert.php index 70fd186f3cc70726c24a3ec1a878ce79af927ea1..d2b47b2815926c1955a90897ca4e075f86c3873f 100644 --- a/app/code/Magento/DesignEditor/Controller/Adminhtml/System/Design/Editor/Revert.php +++ b/app/code/Magento/DesignEditor/Controller/Adminhtml/System/Design/Editor/Revert.php @@ -44,7 +44,9 @@ class Revert extends \Magento\DesignEditor\Controller\Adminhtml\System\Design\Ed break; default: - throw new \Magento\Framework\Exception('Invalid revert mode "%s"', $revertTo); + throw new \Magento\Framework\Exception\LocalizedException( + __('Invalid revert mode "%1"', $revertTo) + ); } $response = ['message' => $message]; } catch (\Exception $e) { diff --git a/app/code/Magento/DesignEditor/Model/Config/Control/AbstractControl.php b/app/code/Magento/DesignEditor/Model/Config/Control/AbstractControl.php index 78dc2dfe98ce03ebca729184785dd6c625504a93..363d73270fa898198e4b21750a36de95d0a7eb94 100644 --- a/app/code/Magento/DesignEditor/Model/Config/Control/AbstractControl.php +++ b/app/code/Magento/DesignEditor/Model/Config/Control/AbstractControl.php @@ -112,12 +112,12 @@ abstract class AbstractControl extends \Magento\Framework\Config\AbstractXml * * @param string $controlName * @return array - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getControlData($controlName) { if (!isset($this->_data[$controlName])) { - throw new \Magento\Framework\Exception("Unknown control: \"{$controlName}\""); + throw new \Magento\Framework\Exception\LocalizedException(__('Unknown control: "%1', $controlName)); } return $this->_data[$controlName]; } diff --git a/app/code/Magento/DesignEditor/Model/Editor/Tools/Controls/Factory.php b/app/code/Magento/DesignEditor/Model/Editor/Tools/Controls/Factory.php index 8819a67da581f515090705bfb100c975ea64d23a..9799b2c78974eef96ff5d565558ecd833737bc2f 100644 --- a/app/code/Magento/DesignEditor/Model/Editor/Tools/Controls/Factory.php +++ b/app/code/Magento/DesignEditor/Model/Editor/Tools/Controls/Factory.php @@ -75,12 +75,14 @@ class Factory * @param string $type * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getFilePathByType($type, $theme) { if (!isset($this->_fileNames[$type])) { - throw new \Magento\Framework\Exception("Unknown control configuration type: \"{$type}\""); + throw new \Magento\Framework\Exception\LocalizedException( + __('Unknown control configuration type: "%1"', $type) + ); } return $this->assetRepo->createAsset( $this->_fileNames[$type], @@ -97,7 +99,7 @@ class Factory * @param \Magento\Framework\View\Design\ThemeInterface $parentTheme * @param string[] $files * @return \Magento\DesignEditor\Model\Editor\Tools\Controls\Configuration - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create( $type, @@ -114,7 +116,9 @@ class Factory $class = 'Magento\DesignEditor\Model\Config\Control\ImageSizing'; break; default: - throw new \Magento\Framework\Exception("Unknown control configuration type: \"{$type}\""); + throw new \Magento\Framework\Exception\LocalizedException( + __('Unknown control configuration type: "%1"', $type) + ); } $rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::ROOT); $paths = []; diff --git a/app/code/Magento/DesignEditor/Model/Editor/Tools/QuickStyles/Form/Builder.php b/app/code/Magento/DesignEditor/Model/Editor/Tools/QuickStyles/Form/Builder.php index f92754bacf369d605c012223ee81e037d3d6a31a..efbea06e7104493fe78457d5a1ea0edb8d7d7856 100644 --- a/app/code/Magento/DesignEditor/Model/Editor/Tools/QuickStyles/Form/Builder.php +++ b/app/code/Magento/DesignEditor/Model/Editor/Tools/QuickStyles/Form/Builder.php @@ -73,7 +73,7 @@ class Builder $data['theme'], $data['parent_theme'] ); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $isFilePresent = false; } diff --git a/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php b/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php index 59e3441a782e30214138e7bcc872c02e737961f3..eaf588a27cc671b76d66a0d74169fe4043b14317 100644 --- a/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php +++ b/app/code/Magento/Developer/Model/View/Page/Config/ClientSideLessCompilation/Renderer.php @@ -125,7 +125,7 @@ class Renderer extends Config\Renderer $result .= sprintf($template, $asset->getUrl()); } } - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->logger->critical($e); $result .= sprintf($template, $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound'])); } diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php index 6c2dcc71ed12a164f6a8675b18aef512523a97d0..cc3d3950d01b2d66fe48129d35506daa3a967a91 100644 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -733,7 +733,7 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract /** @var \Magento\Eav\Model\Entity\Attribute\Exception $e */ $e = $this->_universalFactory->create( 'Magento\Eav\Model\Entity\Attribute\Exception', - ['message' => $e->getMessage()] + ['phrase' => __($e->getMessage())] ); $e->setAttributeCode($attrCode)->setPart($part); throw $e; diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Exception.php b/app/code/Magento/Eav/Model/Entity/Attribute/Exception.php index b74c562458caa827cd330684f549a37c1e5fcd27..423c51fb6554bbb4dffcefd32caf68827c074504 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Exception.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Exception.php @@ -10,7 +10,7 @@ namespace Magento\Eav\Model\Entity\Attribute; * * @author Magento Core Team <core@magentocommerce.com> */ -class Exception extends \Exception +class Exception extends \Magento\Framework\Exception\LocalizedException { /** * Eav entity attribute diff --git a/app/code/Magento/Email/Model/AbstractTemplate.php b/app/code/Magento/Email/Model/AbstractTemplate.php index 94cf7b362fa7261538f396ca165bd8f0318eef63..4eba984b8fcfa243c684cce9019a51444cad3283 100644 --- a/app/code/Magento/Email/Model/AbstractTemplate.php +++ b/app/code/Magento/Email/Model/AbstractTemplate.php @@ -143,12 +143,12 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn * * @param array $config * @return $this - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function setDesignConfig(array $config) { if (!isset($config['area']) || !isset($config['store'])) { - throw new \Magento\Framework\Exception('Design config must have area and store.'); + throw new \Magento\Framework\Exception\LocalizedException(__('Design config must have area and store.')); } $this->getDesignConfig()->setData($config); return $this; diff --git a/app/code/Magento/Email/Model/Template.php b/app/code/Magento/Email/Model/Template.php index 8287fa82aca1e61954395a4611c788bc18c9410b..577393b498924af0885edb1affd4f97c6feec9bb 100644 --- a/app/code/Magento/Email/Model/Template.php +++ b/app/code/Magento/Email/Model/Template.php @@ -410,7 +410,7 @@ class Template extends \Magento\Email\Model\AbstractTemplate implements \Magento * * @param array $variables * @return string - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function getProcessedTemplate(array $variables = []) { @@ -440,7 +440,7 @@ class Template extends \Magento\Email\Model\AbstractTemplate implements \Magento $processedResult = $processor->setStoreId($storeId)->filter($this->getPreparedTemplateText()); } catch (\Exception $e) { $this->_cancelDesignConfig(); - throw new \Magento\Framework\Mail\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\MailException(__($e->getMessage()), $e); } return $processedResult; } @@ -493,7 +493,7 @@ class Template extends \Magento\Email\Model\AbstractTemplate implements \Magento * * @param array $variables * @return string - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function getProcessedTemplateSubject(array $variables) { @@ -511,7 +511,7 @@ class Template extends \Magento\Email\Model\AbstractTemplate implements \Magento $processedResult = $processor->setStoreId($storeId)->filter($this->getTemplateSubject()); } catch (\Exception $e) { $this->_cancelDesignConfig(); - throw new \Magento\Framework\Mail\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\MailException(__($e->getMessage()), $e); } $this->_cancelDesignConfig(); return $processedResult; @@ -596,17 +596,17 @@ class Template extends \Magento\Email\Model\AbstractTemplate implements \Magento /** * Validate email template code * - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException * @return $this */ public function beforeSave() { $code = $this->getTemplateCode(); if (empty($code)) { - throw new \Magento\Framework\Mail\Exception(__('The template Name must not be empty.')); + throw new \Magento\Framework\Exception\MailException(__('The template Name must not be empty.')); } if ($this->_getResource()->checkCodeUsage($this)) { - throw new \Magento\Framework\Mail\Exception(__('Duplicate Of Template Name')); + throw new \Magento\Framework\Exception\MailException(__('Duplicate Of Template Name')); } return parent::beforeSave(); } @@ -615,7 +615,7 @@ class Template extends \Magento\Email\Model\AbstractTemplate implements \Magento * Get processed template * * @return string - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function processTemplate() { @@ -627,7 +627,9 @@ class Template extends \Magento\Email\Model\AbstractTemplate implements \Magento } if (!$this->getId()) { - throw new \Magento\Framework\Mail\Exception(__('Invalid transactional email code: %1', $templateId)); + throw new \Magento\Framework\Exception\MailException( + __('Invalid transactional email code: %1', $templateId) + ); } $this->setUseAbsoluteLinks(true); diff --git a/app/code/Magento/Email/Model/Template/Filter.php b/app/code/Magento/Email/Model/Template/Filter.php index 3c152b34f5a339fb71c7d23b1756c0974cddaafa..c95b3f4e21572e16f38fdb967abf3ccc25a582e8 100644 --- a/app/code/Magento/Email/Model/Template/Filter.php +++ b/app/code/Magento/Email/Model/Template/Filter.php @@ -526,7 +526,7 @@ class Filter extends \Magento\Framework\Filter\Template * also allow additional parameter "store" * * @param string[] $construction - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException * @return string */ public function protocolDirective($construction) @@ -537,7 +537,9 @@ class Filter extends \Magento\Framework\Filter\Template try { $store = $this->_storeManager->getStore($params['store']); } catch (\Exception $e) { - throw new \Magento\Framework\Mail\Exception(__('Requested invalid store "%1"', $params['store'])); + throw new \Magento\Framework\Exception\MailException( + __('Requested invalid store "%1"', $params['store']) + ); } } $isSecure = $this->_storeManager->getStore($store)->isCurrentlySecure(); diff --git a/app/code/Magento/Email/Model/Template/SenderResolver.php b/app/code/Magento/Email/Model/Template/SenderResolver.php index f1e1a4b659883e8b36323e63c62abd2f530adf54..761aaffd756df505e460a8582f3a3da338199ee0 100644 --- a/app/code/Magento/Email/Model/Template/SenderResolver.php +++ b/app/code/Magento/Email/Model/Template/SenderResolver.php @@ -45,7 +45,7 @@ class SenderResolver implements \Magento\Framework\Mail\Template\SenderResolverI } if (!isset($result['name']) || !isset($result['email'])) { - throw new \Magento\Framework\Mail\Exception(__('Invalid sender data')); + throw new \Magento\Framework\Exception\MailException(__('Invalid sender data')); } return $result; diff --git a/app/code/Magento/Email/Test/Unit/Block/Adminhtml/Template/PreviewTest.php b/app/code/Magento/Email/Test/Unit/Block/Adminhtml/Template/PreviewTest.php index 42ecbba29562e2becee389badd395f8c3f9b3683..29f65b1f795ad795faeffd1855b24675910ea6fa 100644 --- a/app/code/Magento/Email/Test/Unit/Block/Adminhtml/Template/PreviewTest.php +++ b/app/code/Magento/Email/Test/Unit/Block/Adminhtml/Template/PreviewTest.php @@ -118,7 +118,7 @@ class PreviewTest extends \PHPUnit_Framework_TestCase /** * Test exception with no store found * - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Design config must have area and store. */ public function testToHtmlWithException() diff --git a/app/code/Magento/Email/Test/Unit/Model/AbstractTemplateTest.php b/app/code/Magento/Email/Test/Unit/Model/AbstractTemplateTest.php index bfdd32f7e55421599563f7da80f170a757111b31..d0bd4041ac324bf41e9d5a93fe45b62d07b6a7b6 100644 --- a/app/code/Magento/Email/Test/Unit/Model/AbstractTemplateTest.php +++ b/app/code/Magento/Email/Test/Unit/Model/AbstractTemplateTest.php @@ -39,7 +39,7 @@ class AbstractTemplateTest extends \PHPUnit_Framework_TestCase /** * @param array $config - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @dataProvider invalidInputParametersDataProvider */ public function testSetDesignConfigWithInvalidInputParametersThrowsException($config) diff --git a/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/Delete.php b/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/Delete.php index a2abe73a45fca38f0279e99110f5049a4ef6b147..b9098d3c1e48004b5c20c439506874eb46e0230b 100644 --- a/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/Delete.php +++ b/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/Delete.php @@ -11,22 +11,30 @@ class Delete extends \Magento\GoogleShopping\Controller\Adminhtml\Googleshopping /** * Delete attribute set mapping * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Exception */ public function execute() { - try { - $id = $this->getRequest()->getParam('id'); - $model = $this->_objectManager->create('Magento\GoogleShopping\Model\Type'); - $model->load($id); - if ($model->getTypeId()) { - $model->delete(); - } - $this->messageManager->addSuccess(__('Attribute set mapping was deleted')); - } catch (\Exception $e) { - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); - $this->messageManager->addError(__("We can't delete Attribute Set Mapping.")); + $id = $this->getRequest()->getParam('id'); + $model = $this->_objectManager->create('Magento\GoogleShopping\Model\Type'); + $model->load($id); + if ($model->getTypeId()) { + $model->delete(); } - $this->_redirect('adminhtml/*/index', ['store' => $this->_getStore()->getId()]); + $this->messageManager->addSuccess(__('Attribute set mapping was deleted')); + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('adminhtml/*/index', ['store' => $this->_getStore()->getId()]); } } diff --git a/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/LoadAttributeSets.php b/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/LoadAttributeSets.php index 40f937d29059c5d3988ea145d273fd78ed9e47d0..6cb5d6885d1355e0049abc808c63bc297ea878c4 100644 --- a/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/LoadAttributeSets.php +++ b/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/LoadAttributeSets.php @@ -12,21 +12,14 @@ class LoadAttributeSets extends \Magento\GoogleShopping\Controller\Adminhtml\Goo * Get available attribute sets * * @return void + * @throws \Exception */ public function execute() { - try { - $this->getResponse()->setBody( - $this->_view->getLayout()->getBlockSingleton( - 'Magento\GoogleShopping\Block\Adminhtml\Types\Edit\Form' - )->getAttributeSetsSelectElement( - $this->getRequest()->getParam('target_country') - )->toHtml() - ); - } catch (\Exception $e) { - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); - // just need to output text with error - $this->messageManager->addError(__("We can't load attribute sets.")); - } + $this->getResponse()->setBody( + $this->_view->getLayout()->getBlockSingleton('Magento\GoogleShopping\Block\Adminhtml\Types\Edit\Form') + ->getAttributeSetsSelectElement($this->getRequest()->getParam('target_country')) + ->toHtml() + ); } } diff --git a/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/Save.php b/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/Save.php index 43f836ddb771c13e6c0304702dde50c4eb8081ff..f8e4e7a1a7cd32c59ad2b9adab55dd06b403fac6 100644 --- a/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/Save.php +++ b/app/code/Magento/GoogleShopping/Controller/Adminhtml/Googleshopping/Types/Save.php @@ -11,7 +11,8 @@ class Save extends \Magento\GoogleShopping\Controller\Adminhtml\Googleshopping\T /** * Save attribute set mapping * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() @@ -23,59 +24,56 @@ class Save extends \Magento\GoogleShopping\Controller\Adminhtml\Googleshopping\T $typeModel->load($id); } - try { - $typeModel->setCategory($this->getRequest()->getParam('category')); - if ($typeModel->getId()) { - $collection = $this->_objectManager->create( - 'Magento\GoogleShopping\Model\Resource\Attribute\Collection' - )->addTypeFilter( - $typeModel->getId() - )->load(); - foreach ($collection as $attribute) { - $attribute->delete(); - } - } else { - $typeModel->setAttributeSetId( - $this->getRequest()->getParam('attribute_set_id') - )->setTargetCountry( - $this->getRequest()->getParam('target_country') - ); + $typeModel->setCategory($this->getRequest()->getParam('category')); + if ($typeModel->getId()) { + $collection = $this->_objectManager->create('Magento\GoogleShopping\Model\Resource\Attribute\Collection') + ->addTypeFilter($typeModel->getId()) + ->load(); + foreach ($collection as $attribute) { + $attribute->delete(); } - $typeModel->save(); + } else { + $typeModel->setAttributeSetId($this->getRequest()->getParam('attribute_set_id')) + ->setTargetCountry($this->getRequest()->getParam('target_country')); + } + $typeModel->save(); - $attributes = $this->getRequest()->getParam('attributes'); - $requiredAttributes = $this->_objectManager->get( - 'Magento\GoogleShopping\Model\Config' - )->getRequiredAttributes(); - if (is_array($attributes)) { - $typeId = $typeModel->getId(); - foreach ($attributes as $attrInfo) { - if (isset($attrInfo['delete']) && $attrInfo['delete'] == 1) { - continue; - } - $this->_objectManager->create( - 'Magento\GoogleShopping\Model\Attribute' - )->setAttributeId( - $attrInfo['attribute_id'] - )->setGcontentAttribute( - $attrInfo['gcontent_attribute'] - )->setTypeId( - $typeId - )->save(); - unset($requiredAttributes[$attrInfo['gcontent_attribute']]); + $attributes = $this->getRequest()->getParam('attributes'); + $requiredAttributes = $this->_objectManager->get('Magento\GoogleShopping\Model\Config') + ->getRequiredAttributes(); + if (is_array($attributes)) { + $typeId = $typeModel->getId(); + foreach ($attributes as $attrInfo) { + if (isset($attrInfo['delete']) && $attrInfo['delete'] == 1) { + continue; } + $this->_objectManager->create('Magento\GoogleShopping\Model\Attribute') + ->setAttributeId($attrInfo['attribute_id']) + ->setGcontentAttribute($attrInfo['gcontent_attribute']) + ->setTypeId($typeId) + ->save(); + unset($requiredAttributes[$attrInfo['gcontent_attribute']]); } + } - $this->messageManager->addSuccess(__('The attribute mapping has been saved.')); - if (!empty($requiredAttributes)) { - $this->messageManager->addSuccess( - $this->_objectManager->get('Magento\GoogleShopping\Helper\Category')->getMessage() - ); - } - } catch (\Exception $e) { - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); - $this->messageManager->addError(__("We can't save Attribute Set Mapping.")); + $this->messageManager->addSuccess(__('The attribute mapping has been saved.')); + if (!empty($requiredAttributes)) { + $this->messageManager->addSuccess( + $this->_objectManager->get('Magento\GoogleShopping\Helper\Category')->getMessage() + ); } - $this->_redirect('adminhtml/*/index', ['store' => $this->_getStore()->getId()]); + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('adminhtml/*/index', ['store' => $this->_getStore()->getId()]); } } diff --git a/app/code/Magento/ImportExport/Model/Import.php b/app/code/Magento/ImportExport/Model/Import.php index c09a012798e1d6f3fc9075440cedf77aa8277c38..b3aaeec836d2a737056bfc2029f1952dbc81bf8a 100644 --- a/app/code/Magento/ImportExport/Model/Import.php +++ b/app/code/Magento/ImportExport/Model/Import.php @@ -494,7 +494,7 @@ class Import extends \Magento\ImportExport\Model\AbstractModel $this->_varDirectory->getRelativePath($uploadedFile), $sourceFileRelative ); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \Magento\Framework\Exception\LocalizedException(__('Source file moving failed')); } } diff --git a/app/code/Magento/ImportExport/Model/Import/Source/Csv.php b/app/code/Magento/ImportExport/Model/Import/Source/Csv.php index 8941368a8f061b5e67c692b14bb61b405be0f296..386f4aea620f1bbf7b80bf0b236725958e502337 100644 --- a/app/code/Magento/ImportExport/Model/Import/Source/Csv.php +++ b/app/code/Magento/ImportExport/Model/Import/Source/Csv.php @@ -44,7 +44,7 @@ class Csv extends \Magento\ImportExport\Model\Import\AbstractSource ) { try { $this->_file = $directory->openFile($directory->getRelativePath($file), 'r'); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \LogicException("Unable to open file: '{$file}'"); } $this->_delimiter = $delimiter; diff --git a/app/code/Magento/ImportExport/Test/Unit/Model/Import/Source/CsvTest.php b/app/code/Magento/ImportExport/Test/Unit/Model/Import/Source/CsvTest.php index 2cea74eb72dd28d15b9fc4e072b61604df1d0b2d..25e6e1a441c0835a90a111262eb08b1cc675838e 100644 --- a/app/code/Magento/ImportExport/Test/Unit/Model/Import/Source/CsvTest.php +++ b/app/code/Magento/ImportExport/Test/Unit/Model/Import/Source/CsvTest.php @@ -37,13 +37,9 @@ class CsvTest extends \PHPUnit_Framework_TestCase */ public function testConstructException() { - $this->_directoryMock->expects( - $this->any() - )->method( - 'openFile' - )->will( - $this->throwException(new \Magento\Framework\Filesystem\FilesystemException()) - ); + $this->_directoryMock->expects($this->any()) + ->method('openFile') + ->willThrowException(new \Magento\Framework\Exception\FileSystemException(__('Error message'))); new \Magento\ImportExport\Model\Import\Source\Csv(__DIR__ . '/invalid_file', $this->_directoryMock); } diff --git a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php index 141784d46b976d27ebeee62c4d3187c33353d74c..89a575dac808014fc1ab9375ad19bade912b82d2 100644 --- a/app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php +++ b/app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php @@ -7,55 +7,61 @@ namespace Magento\Integration\Controller\Adminhtml\Integration; use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info; -use Magento\Framework\Exception\IntegrationException; class Delete extends \Magento\Integration\Controller\Adminhtml\Integration { /** * Delete the integration. * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Exception */ public function execute() { $integrationId = (int)$this->getRequest()->getParam(self::PARAM_INTEGRATION_ID); - try { - if ($integrationId) { - $integrationData = $this->_integrationService->get($integrationId); - if ($this->_integrationData->isConfigType($integrationData)) { - $this->messageManager->addError( - __( - "Uninstall the extension to remove integration '%1'.", - $this->escaper->escapeHtml($integrationData[Info::DATA_NAME]) - ) - ); - $this->_redirect('*/*/'); - return; - } - $integrationData = $this->_integrationService->delete($integrationId); - if (!$integrationData[Info::DATA_ID]) { - $this->messageManager->addError(__('This integration no longer exists.')); - } else { - //Integration deleted successfully, now safe to delete the associated consumer data - if (isset($integrationData[Info::DATA_CONSUMER_ID])) { - $this->_oauthService->deleteConsumer($integrationData[Info::DATA_CONSUMER_ID]); - } - $this->_registry->register(self::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData); - $this->messageManager->addSuccess( - __( - "The integration '%1' has been deleted.", - $this->escaper->escapeHtml($integrationData[Info::DATA_NAME]) - ) - ); - } + + if ($integrationId) { + $integrationData = $this->_integrationService->get($integrationId); + if ($this->_integrationData->isConfigType($integrationData)) { + $this->messageManager->addError( + __( + "Uninstall the extension to remove integration '%1'.", + $this->escaper->escapeHtml($integrationData[Info::DATA_NAME]) + ) + ); + return $this->getDefaultResult(); + } + $integrationData = $this->_integrationService->delete($integrationId); + if (!$integrationData[Info::DATA_ID]) { + $this->messageManager->addError(__('This integration no longer exists.')); } else { - $this->messageManager->addError(__('Integration ID is not specified or is invalid.')); + //Integration deleted successfully, now safe to delete the associated consumer data + if (isset($integrationData[Info::DATA_CONSUMER_ID])) { + $this->_oauthService->deleteConsumer($integrationData[Info::DATA_CONSUMER_ID]); + } + $this->_registry->register(self::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData); + $this->messageManager->addSuccess( + __( + "The integration '%1' has been deleted.", + $this->escaper->escapeHtml($integrationData[Info::DATA_NAME]) + ) + ); } - } catch (IntegrationException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->_logger->critical($e); + } else { + $this->messageManager->addError(__('Integration ID is not specified or is invalid.')); } - $this->_redirect('*/*/'); + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('*/*/'); } } diff --git a/app/code/Magento/Integration/Test/Unit/Controller/Adminhtml/Integration/DeleteTest.php b/app/code/Magento/Integration/Test/Unit/Controller/Adminhtml/Integration/DeleteTest.php index aebe506f736a3cd0c1b365267a1dfb1a0f72a5f3..f2b69c6a65751dc5e7181c70fad2635baf90f3a5 100644 --- a/app/code/Magento/Integration/Test/Unit/Controller/Adminhtml/Integration/DeleteTest.php +++ b/app/code/Magento/Integration/Test/Unit/Controller/Adminhtml/Integration/DeleteTest.php @@ -14,144 +14,109 @@ use Magento\Framework\Exception\IntegrationException; class DeleteTest extends \Magento\Integration\Test\Unit\Controller\Adminhtml\IntegrationTest { + /** + * @var \Magento\Integration\Controller\Adminhtml\Integration\Delete + */ + protected $integrationController; + + protected function setUp() + { + parent::setUp(); + + $this->integrationController = $this->_createIntegrationController('Delete'); + + $resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $resultRedirect->expects($this->any()) + ->method('setPath') + ->with('*/*/') + ->willReturnSelf(); + + $this->resultRedirectFactory->expects($this->any()) + ->method('create') + ->willReturn($resultRedirect); + } + public function testDeleteAction() { $intData = $this->_getSampleIntegrationData(); - $this->_requestMock->expects( - $this->once() - )->method( - 'getParam' - )->will( - $this->returnValue(self::INTEGRATION_ID) - ); - $this->_integrationSvcMock->expects( - $this->any() - )->method( - 'get' - )->with( - $this->anything() - )->will( - $this->returnValue($intData) - ); - $this->_integrationSvcMock->expects( - $this->any() - )->method( - 'delete' - )->with( - $this->anything() - )->will( - $this->returnValue($intData) - ); + $this->_requestMock->expects($this->once()) + ->method('getParam') + ->willReturn(self::INTEGRATION_ID); + $this->_integrationSvcMock->expects($this->any()) + ->method('get') + ->with($this->anything()) + ->willReturn($intData); + $this->_integrationSvcMock->expects($this->any()) + ->method('delete') + ->with($this->anything()) + ->willReturn($intData); // Use real translate model $this->_translateModelMock = null; // verify success message - $this->_messageManager->expects( - $this->once() - )->method( - 'addSuccess' - )->with( - __('The integration \'%1\' has been deleted.', $intData[Info::DATA_NAME]) - ); - $integrationContr = $this->_createIntegrationController('Delete'); - $integrationContr->execute(); + $this->_messageManager->expects($this->once()) + ->method('addSuccess') + ->with(__('The integration \'%1\' has been deleted.', $intData[Info::DATA_NAME])); + + $this->integrationController->execute(); } public function testDeleteActionWithConsumer() { $intData = $this->_getSampleIntegrationData(); $intData[Info::DATA_CONSUMER_ID] = 1; - $this->_requestMock->expects( - $this->once() - )->method( - 'getParam' - )->will( - $this->returnValue(self::INTEGRATION_ID) - ); - $this->_integrationSvcMock->expects( - $this->any() - )->method( - 'get' - )->with( - $this->anything() - )->will( - $this->returnValue($intData) - ); - $this->_integrationSvcMock->expects( - $this->once() - )->method( - 'delete' - )->with( - $this->anything() - )->will( - $this->returnValue($intData) - ); - $this->_oauthSvcMock->expects( - $this->once() - )->method( - 'deleteConsumer' - )->with( - $this->anything() - )->will( - $this->returnValue($intData) - ); + $this->_requestMock->expects($this->once()) + ->method('getParam') + ->willReturn(self::INTEGRATION_ID); + $this->_integrationSvcMock->expects($this->any()) + ->method('get') + ->with($this->anything()) + ->willReturn($intData); + $this->_integrationSvcMock->expects($this->once()) + ->method('delete') + ->with($this->anything()) + ->willReturn($intData); + $this->_oauthSvcMock->expects($this->once()) + ->method('deleteConsumer') + ->with($this->anything()) + ->willReturn($intData); // Use real translate model $this->_translateModelMock = null; // verify success message - $this->_messageManager->expects( - $this->once() - )->method( - 'addSuccess' - )->with( - __('The integration \'%1\' has been deleted.', $intData[Info::DATA_NAME]) - ); - $integrationContr = $this->_createIntegrationController('Delete'); - $integrationContr->execute(); + $this->_messageManager->expects($this->once()) + ->method('addSuccess') + ->with(__('The integration \'%1\' has been deleted.', $intData[Info::DATA_NAME])); + + $this->integrationController->execute(); } public function testDeleteActionConfigSetUp() { $intData = $this->_getSampleIntegrationData(); $intData[Info::DATA_SETUP_TYPE] = IntegrationModel::TYPE_CONFIG; - $this->_requestMock->expects( - $this->once() - )->method( - 'getParam' - )->will( - $this->returnValue(self::INTEGRATION_ID) - ); - $this->_integrationSvcMock->expects( - $this->any() - )->method( - 'get' - )->with( - $this->anything() - )->will( - $this->returnValue($intData) - ); - $this->_integrationHelperMock->expects( - $this->once() - )->method( - 'isConfigType' - )->with( - $intData - )->will( - $this->returnValue(true) - ); + $this->_requestMock->expects($this->once()) + ->method('getParam') + ->willReturn(self::INTEGRATION_ID); + $this->_integrationSvcMock->expects($this->any()) + ->method('get') + ->with($this->anything()) + ->willReturn($intData); + $this->_integrationHelperMock->expects($this->once()) + ->method('isConfigType') + ->with($intData) + ->willReturn(true); // verify error message - $this->_messageManager->expects( - $this->once() - )->method( - 'addError' - )->with( - __('Uninstall the extension to remove integration \'%1\'.', $intData[Info::DATA_NAME]) - ); + $this->_messageManager->expects($this->once()) + ->method('addError') + ->with(__('Uninstall the extension to remove integration \'%1\'.', $intData[Info::DATA_NAME])); $this->_integrationSvcMock->expects($this->never())->method('delete'); // Use real translate model $this->_translateModelMock = null; // verify success message $this->_messageManager->expects($this->never())->method('addSuccess'); - $integrationContr = $this->_createIntegrationController('Delete'); - $integrationContr->execute(); + + $this->integrationController->execute(); } public function testDeleteActionMissingId() @@ -161,85 +126,62 @@ class DeleteTest extends \Magento\Integration\Test\Unit\Controller\Adminhtml\Int // Use real translate model $this->_translateModelMock = null; // verify error message - $this->_messageManager->expects( - $this->once() - )->method( - 'addError' - )->with( - __('Integration ID is not specified or is invalid.') - ); - $integrationContr = $this->_createIntegrationController('Delete'); - $integrationContr->execute(); + $this->_messageManager->expects($this->once()) + ->method('addError') + ->with(__('Integration ID is not specified or is invalid.')); + + $this->integrationController->execute(); } + /** + * @expectedException \Exception + * @expectedExceptionMessage Integration with ID '1' doesn't exist. + */ public function testDeleteActionForServiceIntegrationException() { $intData = $this->_getSampleIntegrationData(); - $this->_integrationSvcMock->expects( - $this->any() - )->method( - 'get' - )->with( - $this->anything() - )->will( - $this->returnValue($intData) - ); - $this->_requestMock->expects( - $this->once() - )->method( - 'getParam' - )->will( - $this->returnValue(self::INTEGRATION_ID) - ); + $this->_integrationSvcMock->expects($this->any()) + ->method('get') + ->with($this->anything()) + ->willReturn($intData); + $this->_requestMock->expects($this->once()) + ->method('getParam') + ->willReturn(self::INTEGRATION_ID); // Use real translate model $this->_translateModelMock = null; $exceptionMessage = __("Integration with ID '%1' doesn't exist.", $intData[Info::DATA_ID]); $invalidIdException = new IntegrationException($exceptionMessage); - $this->_integrationSvcMock->expects( - $this->once() - )->method( - 'delete' - )->will( - $this->throwException($invalidIdException) - ); - $this->_messageManager->expects($this->once())->method('addError')->with($exceptionMessage); - $integrationContr = $this->_createIntegrationController('Delete'); - $integrationContr->execute(); + $this->_integrationSvcMock->expects($this->once()) + ->method('delete') + ->willThrowException($invalidIdException); + $this->_messageManager->expects($this->never())->method('addError'); + + $this->integrationController->execute(); } + /** + * @expectedException \Exception + * @expectedExceptionMessage Integration with ID '1' doesn't exist. + */ public function testDeleteActionForServiceGenericException() { $intData = $this->_getSampleIntegrationData(); - $this->_integrationSvcMock->expects( - $this->any() - )->method( - 'get' - )->with( - $this->anything() - )->will( - $this->returnValue($intData) - ); - $this->_requestMock->expects( - $this->once() - )->method( - 'getParam' - )->will( - $this->returnValue(self::INTEGRATION_ID) - ); + $this->_integrationSvcMock->expects($this->any()) + ->method('get') + ->with($this->anything()) + ->willReturn($intData); + $this->_requestMock->expects($this->once()) + ->method('getParam') + ->willReturn(self::INTEGRATION_ID); // Use real translate model $this->_translateModelMock = null; $exceptionMessage = __("Integration with ID '%1' doesn't exist.", $intData[Info::DATA_ID]); $invalidIdException = new \Exception($exceptionMessage); - $this->_integrationSvcMock->expects( - $this->once() - )->method( - 'delete' - )->will( - $this->throwException($invalidIdException) - ); - //Generic Exception(non-Service) should never add the message in session for user display + $this->_integrationSvcMock->expects($this->once()) + ->method('delete') + ->willThrowException($invalidIdException); $this->_messageManager->expects($this->never())->method('addError'); - $integrationContr = $this->_createIntegrationController('Delete'); - $integrationContr->execute(); + + $this->integrationController->execute(); } } diff --git a/app/code/Magento/Integration/Test/Unit/Controller/Adminhtml/IntegrationTest.php b/app/code/Magento/Integration/Test/Unit/Controller/Adminhtml/IntegrationTest.php index 0e3fdb67644ddf7496919e9b5180bf9b096893b4..d3fd636940bacea0caaecbccc8fde7f3de6b4694 100644 --- a/app/code/Magento/Integration/Test/Unit/Controller/Adminhtml/IntegrationTest.php +++ b/app/code/Magento/Integration/Test/Unit/Controller/Adminhtml/IntegrationTest.php @@ -96,6 +96,11 @@ abstract class IntegrationTest extends \PHPUnit_Framework_TestCase */ protected $_escaper; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactory; + /** Sample integration ID */ const INTEGRATION_ID = 1; @@ -210,6 +215,11 @@ abstract class IntegrationTest extends \PHPUnit_Framework_TestCase ->willReturn($this->pageTitleMock); $this->_escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0)); + $this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $contextParameters = [ 'view' => $this->_viewMock, 'objectManager' => $this->_objectManagerMock, @@ -218,6 +228,7 @@ abstract class IntegrationTest extends \PHPUnit_Framework_TestCase 'request' => $this->_requestMock, 'response' => $this->_responseMock, 'messageManager' => $this->_messageManager, + 'resultRedirectFactory' => $this->resultRedirectFactory ]; $this->_backendActionCtxMock = $this->_objectManagerHelper->getObject( diff --git a/app/code/Magento/MediaStorage/Controller/Adminhtml/System/Config/System/Storage/Status.php b/app/code/Magento/MediaStorage/Controller/Adminhtml/System/Config/System/Storage/Status.php index 527a932ee63ea47bb473fb4cd48c21dd84eaaa11..3d2b755575ad00c7391ba92af82e10b33b958cec 100644 --- a/app/code/Magento/MediaStorage/Controller/Adminhtml/System/Config/System/Storage/Status.php +++ b/app/code/Magento/MediaStorage/Controller/Adminhtml/System/Config/System/Storage/Status.php @@ -83,7 +83,7 @@ class Status extends \Magento\MediaStorage\Controller\Adminhtml\System\Config\Sy $this->_objectManager->get( 'Psr\Log\LoggerInterface' )->critical( - new \Magento\Framework\Exception( + new \Magento\Framework\Exception\LocalizedException( __('The timeout limit for response from synchronize process was reached.') ) ); diff --git a/app/code/Magento/MediaStorage/Model/File/Storage/Config.php b/app/code/Magento/MediaStorage/Model/File/Storage/Config.php index e56b7af11f1b5632d0b7efa781f40cc83f67beec..404434584903b317a9d6d6958e6449b0ade8e8b0 100644 --- a/app/code/Magento/MediaStorage/Model/File/Storage/Config.php +++ b/app/code/Magento/MediaStorage/Model/File/Storage/Config.php @@ -8,7 +8,7 @@ namespace Magento\MediaStorage\Model\File\Storage; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\Directory\WriteInterface as DirectoryWrite; use Magento\Framework\Filesystem\File\Write; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; class Config { @@ -82,7 +82,7 @@ class Config $file->write(json_encode($this->config)); $file->unlock(); $file->close(); - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { $file->close(); } } diff --git a/app/code/Magento/MediaStorage/Model/File/Storage/Synchronization.php b/app/code/Magento/MediaStorage/Model/File/Storage/Synchronization.php index decccfd2ba0d5089739c10cba3165a36060a8923..88a72ad5c6e6bfb12f5d9165fa7860ff283b4e44 100644 --- a/app/code/Magento/MediaStorage/Model/File/Storage/Synchronization.php +++ b/app/code/Magento/MediaStorage/Model/File/Storage/Synchronization.php @@ -8,7 +8,7 @@ namespace Magento\MediaStorage\Model\File\Storage; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\Directory\WriteInterface as DirectoryWrite; use Magento\Framework\Filesystem\File\Write; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; /** * Class Synchronization @@ -65,7 +65,7 @@ class Synchronization $file->write($storage->getContent()); $file->unlock(); $file->close(); - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { $file->close(); } } diff --git a/app/code/Magento/MediaStorage/Model/Resource/File/Storage/File.php b/app/code/Magento/MediaStorage/Model/Resource/File/Storage/File.php index 511ae4dad60e4d24663c16dc3a12d857d15e52d8..2682dd691a46d839efa2e223b46a8653a9402ed1 100644 --- a/app/code/Magento/MediaStorage/Model/Resource/File/Storage/File.php +++ b/app/code/Magento/MediaStorage/Model/Resource/File/Storage/File.php @@ -125,7 +125,7 @@ class File $directoryInstance->writeFile($filePath, $content); return true; } - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { $this->_logger->info($e->getMessage()); throw new \Magento\Framework\Exception\LocalizedException(__('Unable to save file: %1', $filePath)); } diff --git a/app/code/Magento/Multishipping/Controller/Checkout.php b/app/code/Magento/Multishipping/Controller/Checkout.php index 5482e8239be1f985f541198cc99423e83782cd06..ded1bf1b308214a55c3c401abe74b7deaae2c029 100644 --- a/app/code/Magento/Multishipping/Controller/Checkout.php +++ b/app/code/Magento/Multishipping/Controller/Checkout.php @@ -23,21 +23,18 @@ class Checkout extends \Magento\Checkout\Controller\Action implements * @param \Magento\Customer\Model\Session $customerSession * @param CustomerRepositoryInterface $customerRepository * @param AccountManagementInterface $accountManagement - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, CustomerRepositoryInterface $customerRepository, - AccountManagementInterface $accountManagement, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory + AccountManagementInterface $accountManagement ) { parent::__construct( $context, $customerSession, $customerRepository, - $accountManagement, - $resultRedirectFactory + $accountManagement ); } diff --git a/app/code/Magento/Multishipping/Controller/Checkout/OverviewPost.php b/app/code/Magento/Multishipping/Controller/Checkout/OverviewPost.php index 5dd2f85ddefe6190cb9e975ff88df667612cb984..a782a26e6bfa1bf4d851ab1a55a6ac93f389d8bc 100644 --- a/app/code/Magento/Multishipping/Controller/Checkout/OverviewPost.php +++ b/app/code/Magento/Multishipping/Controller/Checkout/OverviewPost.php @@ -27,7 +27,6 @@ class OverviewPost extends \Magento\Multishipping\Controller\Checkout * @param \Magento\Customer\Model\Session $customerSession * @param CustomerRepositoryInterface $customerRepository * @param AccountManagementInterface $accountManagement - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator */ public function __construct( @@ -35,7 +34,6 @@ class OverviewPost extends \Magento\Multishipping\Controller\Checkout \Magento\Customer\Model\Session $customerSession, CustomerRepositoryInterface $customerRepository, AccountManagementInterface $accountManagement, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator ) { $this->formKeyValidator = $formKeyValidator; @@ -43,8 +41,7 @@ class OverviewPost extends \Magento\Multishipping\Controller\Checkout $context, $customerSession, $customerRepository, - $accountManagement, - $resultRedirectFactory + $accountManagement ); } diff --git a/app/code/Magento/Newsletter/Model/Queue.php b/app/code/Magento/Newsletter/Model/Queue.php index 33becad798415fa853a4962fdd3a3e79f7e6c43e..4c34f3419f10ad6f41717fd31d5b656d2d849ffb 100644 --- a/app/code/Magento/Newsletter/Model/Queue.php +++ b/app/code/Magento/Newsletter/Model/Queue.php @@ -239,7 +239,7 @@ class Queue extends \Magento\Email\Model\AbstractTemplate try { $transport->sendMessage(); - } catch (\Magento\Framework\Mail\Exception $e) { + } catch (\Magento\Framework\Exception\MailException $e) { /** @var \Magento\Newsletter\Model\Problem $problem */ $problem = $this->_problemFactory->create(); $problem->addSubscriberData($item); diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index a1cb1547bda898f223e0b5980b11cad2d09f17c3..f2885610281947d30f55abdccb526e6a270c6ac4 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -8,7 +8,7 @@ namespace Magento\Newsletter\Model; use Magento\Customer\Api\AccountManagementInterface; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Framework\Mail\Exception as MailException; +use Magento\Framework\Exception\MailException; /** * Subscriber model diff --git a/app/code/Magento/Payment/Exception.php b/app/code/Magento/Payment/Exception.php deleted file mode 100644 index 5ca752b37e3e71e220d7e8eb5db3c940b50ccf25..0000000000000000000000000000000000000000 --- a/app/code/Magento/Payment/Exception.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Payment; - -/** - * Payment exception - * - * @author Magento Core Team <core@magentocommerce.com> - */ -class Exception extends \Exception -{ - /** - * @var int|null - */ - protected $_code = null; - - /** - * @param string|null $message - * @param int $code - */ - public function __construct($message = null, $code = 0) - { - $this->_code = $code; - parent::__construct($message, 0); - } - - /** - * @return int|null - */ - public function getFields() - { - return $this->_code; - } -} diff --git a/app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php b/app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php index cbaca7b85a3d74acea510f7bfd3028de205a942a..72deb26aefc070d473031645749bf9e49249fb77 100644 --- a/app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php +++ b/app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php @@ -157,7 +157,7 @@ class CcTest extends \PHPUnit_Framework_TestCase public function getCcExpDateDataProvider() { return [ - [2, 2015], + [3, 2015], [12, 2011], [01, 2036] ]; diff --git a/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php b/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php index aacabec010c730287e8263e2cc45ab7cfc7ad840..e2b9bf759f64bb701f704d10cc1a9d4557cc73cb 100644 --- a/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php +++ b/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php @@ -9,21 +9,29 @@ namespace Magento\ProductAlert\Controller\Unsubscribe; class PriceAll extends \Magento\ProductAlert\Controller\Unsubscribe { /** - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { - try { - $this->_objectManager->create( - 'Magento\ProductAlert\Model\Price' - )->deleteCustomer( - $this->_customerSession->getCustomerId(), - $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() - ); - $this->messageManager->addSuccess(__('You will no longer receive price alerts for this product.')); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('Unable to update the alert subscription.')); - } - $this->_redirect('customer/account/'); + $this->_objectManager->create( + 'Magento\ProductAlert\Model\Price' + )->deleteCustomer( + $this->_customerSession->getCustomerId(), + $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() + ); + $this->messageManager->addSuccess(__('You will no longer receive price alerts for this product.')); + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Framework\Controller\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('customer/account/'); } } diff --git a/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php b/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php index 3d9b989cdbb8c9b388469ab83629cac2b7b378c0..c8dec914e9540d5d8c21c7ad4b613807be8c7cca 100644 --- a/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php +++ b/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php @@ -9,21 +9,29 @@ namespace Magento\ProductAlert\Controller\Unsubscribe; class StockAll extends \Magento\ProductAlert\Controller\Unsubscribe { /** - * @return void + * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { - try { - $this->_objectManager->create( - 'Magento\ProductAlert\Model\Stock' - )->deleteCustomer( - $this->_customerSession->getCustomerId(), - $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() - ); - $this->messageManager->addSuccess(__('You will no longer receive stock alerts.')); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('Unable to update the alert subscription.')); - } - $this->_redirect('customer/account/'); + $this->_objectManager->create( + 'Magento\ProductAlert\Model\Stock' + )->deleteCustomer( + $this->_customerSession->getCustomerId(), + $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId() + ); + $this->messageManager->addSuccess(__('You will no longer receive stock alerts.')); + + return $this->getDefaultResult(); + } + + /** + * {@inheritdoc} + * + * @return \Magento\Framework\Controller\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('customer/account/'); } } diff --git a/app/code/Magento/Quote/Model/Quote.php b/app/code/Magento/Quote/Model/Quote.php index 1f9fb10d01a1df5eded433b519aae09a7025e7c5..5daefcfe5f7f6ea293cd8d5c55445002d6c063f7 100644 --- a/app/code/Magento/Quote/Model/Quote.php +++ b/app/code/Magento/Quote/Model/Quote.php @@ -1538,8 +1538,8 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C /** * Error message */ - if (is_string($cartCandidates)) { - return $cartCandidates; + if (is_string($cartCandidates) || $cartCandidates instanceof \Magento\Framework\Phrase) { + return strval($cartCandidates); } /** diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics.php index f0c6995732236110745edbb92a1bde4efcf7d50e..7de4649499c06a557f497abe7974e127353de17d 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics.php @@ -35,26 +35,18 @@ class Statistics extends \Magento\Backend\App\Action */ protected $reportTypes; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param [] $reportTypes */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, array $reportTypes ) { $this->_dateFilter = $dateFilter; $this->reportTypes = $reportTypes; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Reports/Exception.php b/app/code/Magento/Reports/Exception.php deleted file mode 100644 index 17966d0a21e7ebbaa5e7e1429b0ff5f4334194ec..0000000000000000000000000000000000000000 --- a/app/code/Magento/Reports/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Reports; - -class Exception extends \Zend_Exception -{ -} diff --git a/app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php b/app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php index 98537419a90f346fdf884520c90e00ace48ed54c..8e11e8f401f4f4860c1f0c67394e4a387e439128 100644 --- a/app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php +++ b/app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php @@ -425,7 +425,7 @@ abstract class AbstractReport extends \Magento\Framework\Model\Resource\Db\Abstr $tr = $transitions[$i]; try { $this->timezoneValidator->validate($tr['ts'], $to); - } catch (\Magento\Framework\Stdlib\DateTime\Timezone\ValidationException $e) { + } catch (\Magento\Framework\Exception\ValidatorException $e) { continue; } diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php b/app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php index 0edc1cc9c4c266620cacebf793b3763382cfdd9e..90818ea3d9d8c78d36c53869bfcc44ca2a681c5a 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php @@ -14,22 +14,24 @@ class Delete extends \Magento\Review\Controller\Adminhtml\Product public function execute() { $reviewId = $this->getRequest()->getParam('id', false); - try { - $this->_reviewFactory->create()->setId($reviewId)->aggregate()->delete(); + $this->_reviewFactory->create()->setId($reviewId)->aggregate()->delete(); - $this->messageManager->addSuccess(__('The review has been deleted.')); - if ($this->getRequest()->getParam('ret') == 'pending') { - $this->getResponse()->setRedirect($this->getUrl('review/*/pending')); - } else { - $this->getResponse()->setRedirect($this->getUrl('review/*/')); - } - return; - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('Something went wrong deleting this review.')); + $this->messageManager->addSuccess(__('The review has been deleted.')); + if ($this->getRequest()->getParam('ret') == 'pending') { + $this->getResponse()->setRedirect($this->getUrl('review/*/pending')); + } else { + $this->getResponse()->setRedirect($this->getUrl('review/*/')); } + } - $this->_redirect('review/*/edit/', ['id' => $reviewId]); + /** + * {@inheritdoc} + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('review/*/edit/', ['id' => $this->getRequest()->getParam('id', false)]); } } diff --git a/app/code/Magento/Rss/Controller/Adminhtml/Feed/Index.php b/app/code/Magento/Rss/Controller/Adminhtml/Feed/Index.php index ee2379d4e143c63e6af028c9eb1ba2a5ee50db36..61da0e27c2e12c99f5db440b287521c670b59fd1 100644 --- a/app/code/Magento/Rss/Controller/Adminhtml/Feed/Index.php +++ b/app/code/Magento/Rss/Controller/Adminhtml/Feed/Index.php @@ -6,7 +6,7 @@ */ namespace Magento\Rss\Controller\Adminhtml\Feed; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; /** * Class Index @@ -23,18 +23,18 @@ class Index extends \Magento\Rss\Controller\Adminhtml\Feed public function execute() { if (!$this->scopeConfig->getValue('rss/config/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $type = $this->getRequest()->getParam('type'); try { $provider = $this->rssManager->getProvider($type); } catch (\InvalidArgumentException $e) { - throw new NotFoundException($e->getMessage()); + throw new NotFoundException(__($e->getMessage())); } if (!$provider->isAllowed()) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } /** @var $rss \Magento\Rss\Model\Rss */ diff --git a/app/code/Magento/Rss/Controller/Feed/Index.php b/app/code/Magento/Rss/Controller/Feed/Index.php index e6bba8d7424c4047ed7e2c9ac5da8d01f1f9566f..e3679a100212d62f1fc86674ee13e9e4c7851881 100644 --- a/app/code/Magento/Rss/Controller/Feed/Index.php +++ b/app/code/Magento/Rss/Controller/Feed/Index.php @@ -6,7 +6,7 @@ */ namespace Magento\Rss\Controller\Feed; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; /** * Class Index @@ -23,14 +23,14 @@ class Index extends \Magento\Rss\Controller\Feed public function execute() { if (!$this->scopeConfig->getValue('rss/config/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $type = $this->getRequest()->getParam('type'); try { $provider = $this->rssManager->getProvider($type); } catch (\InvalidArgumentException $e) { - throw new NotFoundException($e->getMessage()); + throw new NotFoundException(__($e->getMessage())); } if ($provider->isAuthRequired() && !$this->auth()) { @@ -38,7 +38,7 @@ class Index extends \Magento\Rss\Controller\Feed } if (!$provider->isAllowed()) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } /** @var $rss \Magento\Rss\Model\Rss */ diff --git a/app/code/Magento/Rss/Controller/Index/Index.php b/app/code/Magento/Rss/Controller/Index/Index.php index 4df5440a1700ae0753abe724763d0637d62041c8..63575ad8e44ec3864d50c97ace7421dd2d984754 100644 --- a/app/code/Magento/Rss/Controller/Index/Index.php +++ b/app/code/Magento/Rss/Controller/Index/Index.php @@ -6,7 +6,7 @@ */ namespace Magento\Rss\Controller\Index; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; class Index extends \Magento\Rss\Controller\Index { @@ -22,7 +22,7 @@ class Index extends \Magento\Rss\Controller\Index $this->_view->loadLayout(); $this->_view->renderLayout(); } else { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } } } diff --git a/app/code/Magento/Rule/Model/Condition/Sql/Builder.php b/app/code/Magento/Rule/Model/Condition/Sql/Builder.php index 43e1ab5177159766d4d0bdf1e48ada4134dd3540..f093608f46f42568df97fb759da3a087e5e0dd30 100644 --- a/app/code/Magento/Rule/Model/Condition/Sql/Builder.php +++ b/app/code/Magento/Rule/Model/Condition/Sql/Builder.php @@ -112,7 +112,7 @@ class Builder * @param AbstractCondition $condition * @param string $value * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getMappedSqlCondition(AbstractCondition $condition, $value = '') { @@ -121,7 +121,7 @@ class Builder $conditionOperator = $condition->getOperatorForValidate(); if (!isset($this->_conditionOperatorMap[$conditionOperator])) { - throw new \Magento\Framework\Exception('Unknown condition operator'); + throw new \Magento\Framework\Exception\LocalizedException(__('Unknown condition operator')); } $sql = str_replace( diff --git a/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php b/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php index 0fe2f97dcd9b256613b5b16237c5af3df7f3ef82..567433355f3ed1a97c2959c2b2c5088e285a6e33 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php +++ b/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php @@ -9,7 +9,6 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\RequestInterface; use Magento\Framework\Registry; use Magento\Framework\Controller\Result\ForwardFactory; -use Magento\Framework\Controller\Result\RedirectFactory; class OrderLoader implements OrderLoaderInterface { @@ -38,33 +37,25 @@ class OrderLoader implements OrderLoaderInterface */ protected $resultForwardFactory; - /** - * @var Redirect - */ - protected $resultRedirectFactory; - /** * @param \Magento\Sales\Model\OrderFactory $orderFactory * @param OrderViewAuthorizationInterface $orderAuthorization * @param Registry $registry * @param \Magento\Framework\UrlInterface $url * @param ForwardFactory $resultForwardFactory - * @param RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Sales\Model\OrderFactory $orderFactory, OrderViewAuthorizationInterface $orderAuthorization, Registry $registry, \Magento\Framework\UrlInterface $url, - ForwardFactory $resultForwardFactory, - RedirectFactory $resultRedirectFactory + ForwardFactory $resultForwardFactory ) { $this->orderFactory = $orderFactory; $this->orderAuthorization = $orderAuthorization; $this->registry = $registry; $this->url = $url; $this->resultForwardFactory = $resultForwardFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php b/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php index c2ac3856a201e7c0ba89219e999f965b883872fb..4c97760450e22605a59f5879772712385211fee6 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php @@ -8,7 +8,6 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -use Magento\Framework\Controller\Result\RedirectFactory; abstract class PrintCreditmemo extends \Magento\Framework\App\Action\Action { @@ -27,29 +26,21 @@ abstract class PrintCreditmemo extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, \Magento\Framework\Registry $registry, - PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory + PageFactory $resultPageFactory ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php index 6757cdde059b195a97224dc6fc0a96f1df85c5e7..15cc2a5c2c48e5b9ce0f926e4f7f8668adf91947 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php @@ -8,7 +8,6 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -use Magento\Framework\Controller\Result\RedirectFactory; abstract class PrintInvoice extends \Magento\Framework\App\Action\Action { @@ -27,29 +26,21 @@ abstract class PrintInvoice extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, \Magento\Framework\Registry $registry, - PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory + PageFactory $resultPageFactory ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php index c912a736bf9fc571b16ee530c659a1ba7f556351..74fbb3439445d4185be0be3ec4aadb63757197cc 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -8,7 +8,6 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -use Magento\Framework\Controller\Result\RedirectFactory; abstract class PrintShipment extends \Magento\Framework\App\Action\Action { @@ -27,29 +26,21 @@ abstract class PrintShipment extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, \Magento\Framework\Registry $registry, - PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory + PageFactory $resultPageFactory ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/AbstractController/Reorder.php b/app/code/Magento/Sales/Controller/AbstractController/Reorder.php index 096e26f65c839c0b1dbe4f064bbd2d12df77ab24..7010d3bd5c04140599a3bce2c7ac35322c2d66c8 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/Reorder.php +++ b/app/code/Magento/Sales/Controller/AbstractController/Reorder.php @@ -7,7 +7,6 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\Registry; abstract class Reorder extends Action\Action @@ -22,26 +21,18 @@ abstract class Reorder extends Action\Action */ protected $_coreRegistry; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Action\Context $context * @param OrderLoaderInterface $orderLoader * @param Registry $registry - * @param RedirectFactory $resultRedirectFactory */ public function __construct( Action\Context $context, OrderLoaderInterface $orderLoader, - Registry $registry, - RedirectFactory $resultRedirectFactory + Registry $registry ) { $this->orderLoader = $orderLoader; $this->_coreRegistry = $registry; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Email.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Email.php index b1ef2eacce2f8ef835bedbe68f3dd2b2418018a0..34dc5bbb8af0e9882bf3cc447954b74272739f91 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Email.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Email.php @@ -12,23 +12,6 @@ namespace Magento\Sales\Controller\Adminhtml\Creditmemo\AbstractCreditmemo; */ class Email extends \Magento\Backend\App\Action { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context); - } - /** * @return bool */ diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php index 685b3042c42c0a4ea791dabacbcce9e7f78a88b4..8304f41f1d06c78d51e73af3028b7337aa365814 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php @@ -10,11 +10,6 @@ use Magento\Framework\App\Filesystem\DirectoryList; class Pdfcreditmemos extends \Magento\Backend\App\Action { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\App\Response\Http\FileFactory */ @@ -23,15 +18,12 @@ class Pdfcreditmemos extends \Magento\Backend\App\Action /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\App\Response\Http\FileFactory $fileFactory ) { $this->_fileFactory = $fileFactory; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Email.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Email.php index fa94f814062c093d048d0bc4da5b74c0a5cf438c..99e666227efba778c92577ae1523591edd420b5e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Email.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Email.php @@ -18,24 +18,16 @@ abstract class Email extends \Magento\Backend\App\Action */ protected $resultForwardFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory ) { parent::__construct($context); $this->resultForwardFactory = $resultForwardFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php index 1f8389a86a55c909ddbbc1575f140e07dd0356dc..fae61c7df106bf14ed025c871d446c6d60b52245 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php @@ -16,24 +16,16 @@ abstract class Pdfinvoices extends \Magento\Backend\App\Action */ protected $_fileFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\App\Response\Http\FileFactory $fileFactory ) { $this->_fileFactory = $fileFactory; parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order.php b/app/code/Magento/Sales/Controller/Adminhtml/Order.php index ee6934955fc08c5d7431b1a8f04ded1208ff0f30..4685341ddef97abe8fb366fb3eaa6c50dd351d30 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order.php @@ -44,11 +44,6 @@ class Order extends \Magento\Backend\App\Action */ protected $resultPageFactory; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Framework\Controller\Result\JsonFactory */ @@ -70,7 +65,6 @@ class Order extends \Magento\Backend\App\Action * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory * @param \Magento\Framework\Translate\InlineInterface $translateInline * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory @@ -81,7 +75,6 @@ class Order extends \Magento\Backend\App\Action \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Framework\Translate\InlineInterface $translateInline, \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory @@ -90,7 +83,6 @@ class Order extends \Magento\Backend\App\Action $this->_fileFactory = $fileFactory; $this->_translateInline = $translateInline; $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultJsonFactory = $resultJsonFactory; $this->resultLayoutFactory = $resultLayoutFactory; $this->resultRawFactory = $resultRawFactory; diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php index 0e56021124b3e5f7e69d05f733bac0b188d08ce5..42515bde1f868f30212138b87d483a1d5c7ec695 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php @@ -21,7 +21,6 @@ class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory * @param \Magento\Framework\Translate\InlineInterface $translateInline * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory @@ -35,7 +34,6 @@ class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Framework\Translate\InlineInterface $translateInline, \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, @@ -48,7 +46,6 @@ class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order $fileFactory, $translateInline, $resultPageFactory, - $resultRedirectFactory, $resultJsonFactory, $resultLayoutFactory, $resultRawFactory diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php index 3e067f1e396adc67109be4fde46d313acaa8dd00..54fcd049b388a6f9085c2cacfc537fafce6c74dd 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php @@ -7,7 +7,6 @@ namespace Magento\Sales\Controller\Adminhtml\Order; use Magento\Backend\App\Action; use Magento\Framework\View\Result\PageFactory; -use Magento\Backend\Model\View\Result\RedirectFactory; use Magento\Backend\Model\View\Result\ForwardFactory; /** @@ -28,11 +27,6 @@ class Create extends \Magento\Backend\App\Action */ protected $resultPageFactory; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Backend\Model\View\Result\ForwardFactory */ @@ -43,7 +37,6 @@ class Create extends \Magento\Backend\App\Action * @param \Magento\Catalog\Helper\Product $productHelper * @param \Magento\Framework\Escaper $escaper * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory * @param ForwardFactory $resultForwardFactory */ public function __construct( @@ -51,14 +44,12 @@ class Create extends \Magento\Backend\App\Action \Magento\Catalog\Helper\Product $productHelper, \Magento\Framework\Escaper $escaper, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, ForwardFactory $resultForwardFactory ) { parent::__construct($context); $productHelper->setSkipSaleableCheck(true); $this->escaper = $escaper; $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php index 56ecebf6e898ab4683df5cccc18810e2b7b19a61..ba4b0e833e2893fafea898a6392b7c0c2c3eff45 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/LoadBlock.php @@ -7,7 +7,6 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Create; use Magento\Backend\App\Action; use Magento\Backend\Model\View\Result\ForwardFactory; -use Magento\Backend\Model\View\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\Controller\Result\RawFactory; @@ -23,7 +22,6 @@ class LoadBlock extends \Magento\Sales\Controller\Adminhtml\Order\Create * @param \Magento\Catalog\Helper\Product $productHelper * @param \Magento\Framework\Escaper $escaper * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory * @param ForwardFactory $resultForwardFactory * @param RawFactory $resultRawFactory */ @@ -32,7 +30,6 @@ class LoadBlock extends \Magento\Sales\Controller\Adminhtml\Order\Create \Magento\Catalog\Helper\Product $productHelper, \Magento\Framework\Escaper $escaper, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, ForwardFactory $resultForwardFactory, RawFactory $resultRawFactory ) { @@ -42,7 +39,6 @@ class LoadBlock extends \Magento\Sales\Controller\Adminhtml\Order\Create $productHelper, $escaper, $resultPageFactory, - $resultRedirectFactory, $resultForwardFactory ); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php index e06ee1a7c43c795cb4a6752b9b97cb92a1abdefa..a3546de1fa6a7f37cd8e53e223f2a7963460c365 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/ShowUpdateResult.php @@ -7,7 +7,6 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Create; use Magento\Backend\App\Action; use Magento\Backend\Model\View\Result\ForwardFactory; -use Magento\Backend\Model\View\Result\RedirectFactory; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\Controller\Result\RawFactory; @@ -23,7 +22,6 @@ class ShowUpdateResult extends \Magento\Sales\Controller\Adminhtml\Order\Create * @param \Magento\Catalog\Helper\Product $productHelper * @param \Magento\Framework\Escaper $escaper * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory * @param ForwardFactory $resultForwardFactory * @param RawFactory $resultRawFactory */ @@ -32,7 +30,6 @@ class ShowUpdateResult extends \Magento\Sales\Controller\Adminhtml\Order\Create \Magento\Catalog\Helper\Product $productHelper, \Magento\Framework\Escaper $escaper, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, ForwardFactory $resultForwardFactory, RawFactory $resultRawFactory ) { @@ -42,7 +39,6 @@ class ShowUpdateResult extends \Magento\Sales\Controller\Adminhtml\Order\Create $productHelper, $escaper, $resultPageFactory, - $resultRedirectFactory, $resultForwardFactory ); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Cancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Cancel.php index a880a57bf0086f4b8f0da58acdce26b230dc960a..10714ace6578994dfc9d13361c7c641b3b9ca5a8 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Cancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Cancel.php @@ -14,11 +14,6 @@ class Cancel extends \Magento\Backend\App\Action */ protected $creditmemoLoader; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Backend\Model\View\Result\ForwardFactory */ @@ -27,17 +22,14 @@ class Cancel extends \Magento\Backend\App\Action /** * @param Action\Context $context * @param \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader $creditmemoLoader - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ public function __construct( Action\Context $context, \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader $creditmemoLoader, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory ) { $this->creditmemoLoader = $creditmemoLoader; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php index ced8a580b0c6ad0c69e49dc374b978c1de4510d2..6ba3acd497b1f06992c9b871cc1cc63f2a1da6de 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php @@ -21,11 +21,6 @@ class Save extends \Magento\Backend\App\Action */ protected $creditmemoSender; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Backend\Model\View\Result\ForwardFactory */ @@ -35,19 +30,16 @@ class Save extends \Magento\Backend\App\Action * @param Action\Context $context * @param \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader $creditmemoLoader * @param CreditmemoSender $creditmemoSender - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ public function __construct( Action\Context $context, \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader $creditmemoLoader, CreditmemoSender $creditmemoSender, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory ) { $this->creditmemoLoader = $creditmemoLoader; $this->creditmemoSender = $creditmemoSender; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php index 83876b4e643c84b47cd08faea1abe979703f50f5..4305bef4930e7e12b6a5f06e4a0b73a3b9948b32 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Start.php @@ -7,23 +7,6 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo; class Start extends \Magento\Backend\App\Action { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context); - } - /** * @return bool */ diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php index d6c103b9bd56a6746db57e4e15c33511062ebf58..23bd5f1ccdb82d889f8e800a620f91a43318300d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php @@ -14,11 +14,6 @@ class Void extends \Magento\Backend\App\Action */ protected $creditmemoLoader; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Backend\Model\View\Result\ForwardFactory */ @@ -27,17 +22,14 @@ class Void extends \Magento\Backend\App\Action /** * @param Action\Context $context * @param \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader $creditmemoLoader - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory */ public function __construct( Action\Context $context, \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader $creditmemoLoader, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory ) { $this->creditmemoLoader = $creditmemoLoader; - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Cancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Cancel.php index e8e15e6635671157b44dba07dd13fc20ae0d7c98..a717843c7e99c930a1de1fe22b8400128e5af439 100755 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Cancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Cancel.php @@ -6,34 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; -use Magento\Framework\Exception\LocalizedException; -use Magento\Backend\App\Action; -use Magento\Backend\App\Action\Context; -use Magento\Framework\Registry; - class Cancel extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param Context $context - * @param Registry $registry - * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - Context $context, - Registry $registry, - \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context, $registry, $resultForwardFactory); - } - /** * Cancel invoice action * @@ -58,7 +32,7 @@ class Cancel extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice $invoice->getOrder() )->save(); $this->messageManager->addSuccess(__('You canceled the invoice.')); - } catch (LocalizedException $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('Invoice canceling error')); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Capture.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Capture.php index cd3ffd55ff77d8c66c618b3fe33647a81ad571d8..20ff3bfeaa9ab6b2a845bdcc13a2a4d244d734f8 100755 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Capture.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Capture.php @@ -6,35 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; -use Magento\Framework\Exception\LocalizedException; -use Magento\Backend\App\Action; -use Magento\Backend\App\Action\Context; -use Magento\Framework\Registry; - class Capture extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { - - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param Context $context - * @param Registry $registry - * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - Context $context, - Registry $registry, - \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context, $registry, $resultForwardFactory); - } - /** * Capture invoice action * @@ -60,7 +33,7 @@ class Capture extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoic $invoice->getOrder() )->save(); $this->messageManager->addSuccess(__('The invoice has been captured.')); - } catch (LocalizedException $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('Invoice capturing error')); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php index 4b8c4751951aa96fab9f4db7aab48b865b8e1439..f7db6d19da3c1cea5dc45817cf69a1972eac2bd6 100755 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/NewAction.php @@ -9,7 +9,6 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; use Magento\Backend\App\Action; use Magento\Framework\Registry; use Magento\Framework\View\Result\PageFactory; -use Magento\Backend\Model\View\Result\RedirectFactory; class NewAction extends \Magento\Backend\App\Action { @@ -23,26 +22,18 @@ class NewAction extends \Magento\Backend\App\Action */ protected $resultPageFactory; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Action\Context $context * @param Registry $registry * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory */ public function __construct( Action\Context $context, Registry $registry, - PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory + PageFactory $resultPageFactory ) { $this->registry = $registry; $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } @@ -83,11 +74,13 @@ class NewAction extends \Magento\Backend\App\Action /** @var \Magento\Sales\Model\Order $order */ $order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId); if (!$order->getId()) { - throw new \Magento\Framework\Exception(__('The order no longer exists.')); + throw new \Magento\Framework\Exception\LocalizedException(__('The order no longer exists.')); } if (!$order->canInvoice()) { - throw new \Magento\Framework\Exception(__('The order does not allow an invoice to be created.')); + throw new \Magento\Framework\Exception\LocalizedException( + __('The order does not allow an invoice to be created.') + ); } /** @var \Magento\Sales\Model\Order\Invoice $invoice */ @@ -95,7 +88,9 @@ class NewAction extends \Magento\Backend\App\Action ->prepareInvoice($invoiceItems); if (!$invoice->getTotalQty()) { - throw new \Magento\Framework\Exception(__('Cannot create an invoice without products.')); + throw new \Magento\Framework\Exception\LocalizedException( + __('Cannot create an invoice without products.') + ); } $this->registry->register('current_invoice', $invoice); @@ -110,7 +105,7 @@ class NewAction extends \Magento\Backend\App\Action $resultPage->getConfig()->getTitle()->prepend(__('Invoices')); $resultPage->getConfig()->getTitle()->prepend(__('New Invoice')); return $resultPage; - } catch (\Magento\Framework\Exception $exception) { + } catch (\Magento\Framework\Exception\LocalizedException $exception) { $this->messageManager->addError($exception->getMessage()); return $this->_redirectToOrder($orderId); } catch (\Exception $exception) { diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php index 946d159b06c7b60b25c235e19ceb2343933f56b8..1fffaf8a03ee16324a611fdf6f1b9f862c1367af 100755 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php @@ -12,7 +12,6 @@ use Magento\Framework\Registry; use Magento\Sales\Model\Order\Email\Sender\InvoiceCommentSender; use Magento\Sales\Model\Order\Email\Sender\ShipmentSender; use Magento\Sales\Model\Order\Invoice; -use Magento\Backend\Model\View\Result\RedirectFactory; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -34,29 +33,21 @@ class Save extends \Magento\Backend\App\Action */ protected $registry; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Action\Context $context * @param Registry $registry * @param InvoiceCommentSender $invoiceCommentSender * @param ShipmentSender $shipmentSender - * @param RedirectFactory $resultRedirectFactory */ public function __construct( Action\Context $context, Registry $registry, InvoiceCommentSender $invoiceCommentSender, - ShipmentSender $shipmentSender, - RedirectFactory $resultRedirectFactory + ShipmentSender $shipmentSender ) { $this->registry = $registry; $this->invoiceCommentSender = $invoiceCommentSender; $this->shipmentSender = $shipmentSender; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } @@ -129,11 +120,13 @@ class Save extends \Magento\Backend\App\Action /** @var \Magento\Sales\Model\Order $order */ $order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId); if (!$order->getId()) { - throw new \Magento\Framework\Exception(__('The order no longer exists.')); + throw new \Magento\Framework\Exception\LocalizedException(__('The order no longer exists.')); } if (!$order->canInvoice()) { - throw new \Magento\Framework\Exception(__('The order does not allow an invoice to be created.')); + throw new \Magento\Framework\Exception\LocalizedException( + __('The order does not allow an invoice to be created.') + ); } /** @var \Magento\Sales\Model\Order\Invoice $invoice */ @@ -145,7 +138,9 @@ class Save extends \Magento\Backend\App\Action } if (!$invoice->getTotalQty()) { - throw new \Magento\Framework\Exception(__('Cannot create an invoice without products.')); + throw new \Magento\Framework\Exception\LocalizedException( + __('Cannot create an invoice without products.') + ); } $this->registry->register('current_invoice', $invoice); if (!empty($data['capture_case'])) { diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php index de0b55ad653d2fb3e107d11f37964f64b32be7c2..8db329dad0876ee1cb73483dcd62ba8131b0c5bc 100755 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Start.php @@ -6,34 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; -use Magento\Backend\Model\View\Result\RedirectFactory; -use Magento\Backend\App\Action\Context; -use Magento\Framework\Registry; - class Start extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { - - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param Context $context - * @param Registry $registry - * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory - * @param RedirectFactory $resultRedirectFactory - */ - public function __construct( - Context $context, - Registry $registry, - \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, - RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context, $registry, $resultForwardFactory); - } - /** * Start create invoice action * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php index a2c5ba9685349a2608e8084b9f4e43d1df1b710e..38d563101cb4f39051ddca879370da9b8e9fe45b 100755 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/UpdateQty.php @@ -67,11 +67,13 @@ class UpdateQty extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvo /** @var \Magento\Sales\Model\Order $order */ $order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId); if (!$order->getId()) { - throw new \Magento\Framework\Exception(__('The order no longer exists.')); + throw new \Magento\Framework\Exception\LocalizedException(__('The order no longer exists.')); } if (!$order->canInvoice()) { - throw new \Magento\Framework\Exception(__('The order does not allow an invoice to be created.')); + throw new \Magento\Framework\Exception\LocalizedException( + __('The order does not allow an invoice to be created.') + ); } /** @var \Magento\Sales\Model\Order\Invoice $invoice */ @@ -79,7 +81,9 @@ class UpdateQty extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvo ->prepareInvoice($invoiceItems); if (!$invoice->getTotalQty()) { - throw new \Magento\Framework\Exception(__('Cannot create an invoice without products.')); + throw new \Magento\Framework\Exception\LocalizedException( + __('Cannot create an invoice without products.') + ); } $this->registry->register('current_invoice', $invoice); // Save invoice comment text in current invoice object in order to display it in corresponding view diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php index 1c58ed16eca5673aba74a907938f5de2f668f51a..9f346af8a27c0bd9db73dc31f1573333bfc74303 100755 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php @@ -6,33 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Invoice; -use Magento\Framework\Exception\LocalizedException; -use Magento\Backend\App\Action\Context; -use Magento\Framework\Registry; - class Void extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param Context $context - * @param Registry $registry - * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - Context $context, - Registry $registry, - \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - $this->resultRedirectFactory = $resultRedirectFactory; - parent::__construct($context, $registry, $resultForwardFactory); - } - /** * Void invoice action * @@ -57,7 +32,7 @@ class Void extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\V $invoice->getOrder() )->save(); $this->messageManager->addSuccess(__('The invoice has been voided.')); - } catch (LocalizedException $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('Invoice voiding error')); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php index 0d0992344c9dd53648aaeab17039ab2bd966168f..43cc5fd46cde3c18591b704602143a9c55cf167a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/AssignPost.php @@ -6,31 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; -use Magento\Framework\Registry; -use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\View\Result\RedirectFactory; - class AssignPost extends \Magento\Sales\Controller\Adminhtml\Order\Status { - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param Context $context - * @param Registry $coreRegistry - * @param RedirectFactory $resultRedirectFactory - */ - public function __construct( - Context $context, - Registry $coreRegistry, - RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $coreRegistry); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * Save status assignment to state * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php index aa3f04ef236bee578c564f8f293c23a8564686a6..26ee0651e3657e65ba93868d13c2ae8e5751793c 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php @@ -9,7 +9,6 @@ namespace Magento\Sales\Controller\Adminhtml\Order\Status; use Magento\Framework\Registry; use Magento\Backend\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -use Magento\Backend\Model\View\Result\RedirectFactory; class Edit extends \Magento\Sales\Controller\Adminhtml\Order\Status { @@ -18,26 +17,18 @@ class Edit extends \Magento\Sales\Controller\Adminhtml\Order\Status */ protected $resultPageFactory; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Context $context * @param Registry $coreRegistry * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory */ public function __construct( Context $context, Registry $coreRegistry, - PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory + PageFactory $resultPageFactory ) { parent::__construct($context, $coreRegistry); $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php index 67ee80fa876a6a53a9886c11e814e529ae867527..65535942a16d6e35ff98957769fc6361589e4169 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Save.php @@ -6,31 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; -use Magento\Framework\Registry; -use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\View\Result\RedirectFactory; - class Save extends \Magento\Sales\Controller\Adminhtml\Order\Status { - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param Context $context - * @param Registry $coreRegistry - * @param RedirectFactory $resultRedirectFactory - */ - public function __construct( - Context $context, - Registry $coreRegistry, - RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $coreRegistry); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * Save status form processing * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php index 12b08328450a61c0272140e57a9edcf48e1527af..6debca9cf31421407735213157c0d72761719f5e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Unassign.php @@ -6,31 +6,8 @@ */ namespace Magento\Sales\Controller\Adminhtml\Order\Status; -use Magento\Framework\Registry; -use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\View\Result\RedirectFactory; - class Unassign extends \Magento\Sales\Controller\Adminhtml\Order\Status { - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param Context $context - * @param Registry $coreRegistry - * @param RedirectFactory $resultRedirectFactory - */ - public function __construct( - Context $context, - Registry $coreRegistry, - RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $coreRegistry); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * @return \Magento\Backend\Model\View\Result\Redirect */ diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php index c4535d45719a950d2fd546c49317b5e7dd959bde..2242f7a6360b94bf22af7faba152f06e86f7d941 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php @@ -22,10 +22,6 @@ class View extends \Magento\Sales\Controller\Adminhtml\Order try { $resultPage = $this->_initAction(); $resultPage->getConfig()->getTitle()->prepend(__('Orders')); - } catch (\Magento\Framework\App\Action\Exception $e) { - $this->messageManager->addError($e->getMessage()); - $resultRedirect->setPath('sales/order/index'); - return $resultRedirect; } catch (\Exception $e) { $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); $this->messageManager->addError(__('Exception occurred during order load')); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php index 4378121ad0aa2dfca58f2726a6a92612b5c39739..07a5b3d42dafb8e6ebdf89be3bed73bda4c2bd20 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php @@ -10,7 +10,6 @@ use Magento\Backend\App\Action\Context; use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Response\Http\FileFactory; -use Magento\Backend\Model\View\Result\RedirectFactory; abstract class Pdfshipments extends \Magento\Backend\App\Action { @@ -19,23 +18,13 @@ abstract class Pdfshipments extends \Magento\Backend\App\Action */ protected $_fileFactory; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param Context $context * @param FileFactory $fileFactory - * @param RedirectFactory $resultRedirectFactory */ - public function __construct( - Context $context, - FileFactory $fileFactory, - RedirectFactory $resultRedirectFactory - ) { + public function __construct(Context $context, FileFactory $fileFactory) + { $this->_fileFactory = $fileFactory; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Transactions.php b/app/code/Magento/Sales/Controller/Adminhtml/Transactions.php index 9c4d5ea2768771788c98a7ae20733186b6f85dcc..49b910be6a862ff0379be9adf7b365ba3babd40f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Transactions.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Transactions.php @@ -9,7 +9,6 @@ use Magento\Backend\App\Action; use Magento\Framework\Registry; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\View\Result\LayoutFactory; -use Magento\Backend\Model\View\Result\RedirectFactory; /** * Adminhtml sales transactions controller @@ -35,29 +34,21 @@ class Transactions extends \Magento\Backend\App\Action */ protected $resultLayoutFactory; - /** - * @var RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Backend\App\Action\Context $context * @param Registry $coreRegistry * @param PageFactory $resultPageFactory * @param LayoutFactory $resultLayoutFactory - * @param RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Backend\App\Action\Context $context, Registry $coreRegistry, PageFactory $resultPageFactory, - LayoutFactory $resultLayoutFactory, - RedirectFactory $resultRedirectFactory + LayoutFactory $resultLayoutFactory ) { $this->_coreRegistry = $coreRegistry; $this->resultPageFactory = $resultPageFactory; $this->resultLayoutFactory = $resultLayoutFactory; - $this->resultRedirectFactory = $resultRedirectFactory; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php old mode 100644 new mode 100755 index 1efcab46f5fb7fb3bd2654485ebd7045b3573d9a..946b8e36fd6c44e23650b17a0f9a2f857f2c4078 --- a/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php @@ -7,14 +7,13 @@ namespace Magento\Sales\Controller\Adminhtml\Transactions; use Magento\Backend\App\Action; -use Magento\Backend\Model\View\Result\Redirect; class Fetch extends \Magento\Sales\Controller\Adminhtml\Transactions { /** * Fetch transaction details action * - * @return Redirect + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -24,16 +23,18 @@ class Fetch extends \Magento\Sales\Controller\Adminhtml\Transactions if (!$txn) { return $resultRedirect->setPath('sales/*/'); } - try { - $txn->getOrderPaymentObject()->setOrder($txn->getOrder())->importTransactionInfo($txn); - $txn->save(); - $this->messageManager->addSuccess(__('The transaction details have been updated.')); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('We can\'t update the transaction details.')); - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); - } + $txn->getOrderPaymentObject()->setOrder($txn->getOrder())->importTransactionInfo($txn); + $txn->save(); + $this->messageManager->addSuccess(__('The transaction details have been updated.')); + return $this->getDefaultResult(); + } + + /** + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('sales/transactions/view', ['_current' => true]); } } diff --git a/app/code/Magento/Sales/Controller/Guest/Form.php b/app/code/Magento/Sales/Controller/Guest/Form.php index e2f90c18f31e77b5f82ccf839cac3c32177992a1..c9f87d44e7995fabf5078c1b200b2effcea693c1 100644 --- a/app/code/Magento/Sales/Controller/Guest/Form.php +++ b/app/code/Magento/Sales/Controller/Guest/Form.php @@ -13,24 +13,16 @@ class Form extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; - /** - * @var \Magento\Framework\Controller\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory */ public function __construct( \Magento\Framework\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory + \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context); $this->resultPageFactory = $resultPageFactory; - $this->resultRedirectFactory = $resultRedirectFactory; } /** diff --git a/app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php b/app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php index 5283ea8858e0d096ad6c7324c9d8c10a64f2d578..82a1a215399d68b364b4e85ee0da513c847f2505 100644 --- a/app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php +++ b/app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php @@ -6,7 +6,6 @@ */ namespace Magento\Sales\Controller\Guest; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; @@ -22,7 +21,6 @@ class PrintCreditmemo extends \Magento\Sales\Controller\AbstractController\Print * @param OrderViewAuthorization $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory * @param OrderLoader $orderLoader */ public function __construct( @@ -30,7 +28,6 @@ class PrintCreditmemo extends \Magento\Sales\Controller\AbstractController\Print OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; @@ -38,8 +35,7 @@ class PrintCreditmemo extends \Magento\Sales\Controller\AbstractController\Print $context, $orderAuthorization, $registry, - $resultPageFactory, - $resultRedirectFactory + $resultPageFactory ); } diff --git a/app/code/Magento/Sales/Controller/Guest/PrintInvoice.php b/app/code/Magento/Sales/Controller/Guest/PrintInvoice.php index 3999a1bf078bb23793c000f774cc9a00adeb56e0..27796157f51c3a2a1495e88017b706a37adff81e 100644 --- a/app/code/Magento/Sales/Controller/Guest/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/Guest/PrintInvoice.php @@ -6,7 +6,6 @@ */ namespace Magento\Sales\Controller\Guest; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; @@ -22,7 +21,6 @@ class PrintInvoice extends \Magento\Sales\Controller\AbstractController\PrintInv * @param OrderViewAuthorization $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory * @param OrderLoader $orderLoader */ public function __construct( @@ -30,7 +28,6 @@ class PrintInvoice extends \Magento\Sales\Controller\AbstractController\PrintInv OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; @@ -38,8 +35,7 @@ class PrintInvoice extends \Magento\Sales\Controller\AbstractController\PrintInv $context, $orderAuthorization, $registry, - $resultPageFactory, - $resultRedirectFactory + $resultPageFactory ); } diff --git a/app/code/Magento/Sales/Controller/Guest/PrintShipment.php b/app/code/Magento/Sales/Controller/Guest/PrintShipment.php index e3ae69ef3d99297faa98966dcdd5efb34599ad18..8dcbfe4ef735cb9d330de055feece6b5e9fe0fcb 100644 --- a/app/code/Magento/Sales/Controller/Guest/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/Guest/PrintShipment.php @@ -6,7 +6,6 @@ */ namespace Magento\Sales\Controller\Guest; -use Magento\Framework\Controller\Result\RedirectFactory; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; @@ -22,7 +21,6 @@ class PrintShipment extends \Magento\Sales\Controller\AbstractController\PrintSh * @param OrderViewAuthorization $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory - * @param RedirectFactory $resultRedirectFactory * @param OrderLoader $orderLoader */ public function __construct( @@ -30,7 +28,6 @@ class PrintShipment extends \Magento\Sales\Controller\AbstractController\PrintSh OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; @@ -38,8 +35,7 @@ class PrintShipment extends \Magento\Sales\Controller\AbstractController\PrintSh $context, $orderAuthorization, $registry, - $resultPageFactory, - $resultRedirectFactory + $resultPageFactory ); } diff --git a/app/code/Magento/Sales/Controller/Guest/Reorder.php b/app/code/Magento/Sales/Controller/Guest/Reorder.php index 202ceb99a222bddd847be92e32e55942bf1e1d3a..4739751df7ff5156f8e7bb75e8283408bc7214f9 100644 --- a/app/code/Magento/Sales/Controller/Guest/Reorder.php +++ b/app/code/Magento/Sales/Controller/Guest/Reorder.php @@ -6,23 +6,7 @@ */ namespace Magento\Sales\Controller\Guest; -use Magento\Framework\App\Action; -use Magento\Framework\Controller\Result\RedirectFactory; - class Reorder extends \Magento\Sales\Controller\AbstractController\Reorder { - /** - * @param Action\Context $context - * @param \Magento\Sales\Controller\Guest\OrderLoader $orderLoader - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - Action\Context $context, - \Magento\Sales\Controller\Guest\OrderLoader $orderLoader, - \Magento\Framework\Registry $registry, - RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $orderLoader, $registry, $resultRedirectFactory); - } + } diff --git a/app/code/Magento/Sales/Exception.php b/app/code/Magento/Sales/Exception.php deleted file mode 100644 index 8c69378b3ac6d5828bc58d7ff5df35b113d1fb5d..0000000000000000000000000000000000000000 --- a/app/code/Magento/Sales/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Sales; - -class Exception extends \Zend_Exception -{ -} diff --git a/app/code/Magento/Sales/Model/AbstractNotifier.php b/app/code/Magento/Sales/Model/AbstractNotifier.php index 7f0ad6c14e5ed0df0ec8070e8d4c2619fd864aaa..12a910b1c1644e44928695ee76614621105e41ff 100644 --- a/app/code/Magento/Sales/Model/AbstractNotifier.php +++ b/app/code/Magento/Sales/Model/AbstractNotifier.php @@ -7,7 +7,6 @@ namespace Magento\Sales\Model; use Psr\Log\LoggerInterface as Logger; -use Magento\Framework\Mail\Exception; use Magento\Sales\Model\Order\Email\Sender; use Magento\Sales\Model\Resource\Order\Status\History\CollectionFactory; @@ -52,7 +51,7 @@ abstract class AbstractNotifier extends \Magento\Framework\Model\AbstractModel * * @param AbstractModel $model * @return bool - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function notify(\Magento\Sales\Model\AbstractModel $model) { @@ -67,7 +66,7 @@ abstract class AbstractNotifier extends \Magento\Framework\Model\AbstractModel $historyItem->setIsCustomerNotified(1); $historyItem->save(); } - } catch (Exception $e) { + } catch (\Magento\Framework\Exception\MailException $e) { $this->logger->critical($e); return false; } diff --git a/app/code/Magento/Sales/Model/AdminOrder/EmailSender.php b/app/code/Magento/Sales/Model/AdminOrder/EmailSender.php index eed89a8a8548e8f717b7a5a633a77b17a0caca44..27e957ea5579bccb1e2b1aa3176e3a10ccca2e4d 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/EmailSender.php +++ b/app/code/Magento/Sales/Model/AdminOrder/EmailSender.php @@ -53,7 +53,7 @@ class EmailSender { try { $this->orderSender->send($order); - } catch (\Magento\Framework\Mail\Exception $exception) { + } catch (\Magento\Framework\Exception\MailException $exception) { $this->logger->critical($exception); $this->messageManager->addWarning( __('You did not email your customer. Please check your email settings.') diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/EmailTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/EmailTest.php index 5de7ddeb02231a5261d8201ac1f06738997ea436..bd9b80e880eb13d134d4d1ec7922aa1315a2e3ba 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/EmailTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/EmailTest.php @@ -86,7 +86,8 @@ class EmailTest extends \PHPUnit_Framework_TestCase 'getObjectManager', 'getSession', 'getActionFlag', - 'getHelper' + 'getHelper', + 'getResultRedirectFactory' ], [], '', @@ -120,34 +121,22 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->getMock(); + $this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager); + $this->context->expects($this->once())->method('getRequest')->willReturn($this->request); + $this->context->expects($this->once())->method('getResponse')->willReturn($this->response); + $this->context->expects($this->once())->method('getObjectManager')->willReturn($this->objectManager); + $this->context->expects($this->once())->method('getSession')->willReturn($this->session); + $this->context->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlag); + $this->context->expects($this->once())->method('getHelper')->willReturn($this->helper); $this->context->expects($this->once()) - ->method('getMessageManager') - ->will($this->returnValue($this->messageManager)); - $this->context->expects($this->once()) - ->method('getRequest') - ->will($this->returnValue($this->request)); - $this->context->expects($this->once()) - ->method('getResponse') - ->will($this->returnValue($this->response)); - $this->context->expects($this->once()) - ->method('getObjectManager') - ->will($this->returnValue($this->objectManager)); - $this->context->expects($this->once()) - ->method('getSession') - ->will($this->returnValue($this->session)); - $this->context->expects($this->once()) - ->method('getActionFlag') - ->will($this->returnValue($this->actionFlag)); - $this->context->expects($this->once()) - ->method('getHelper') - ->will($this->returnValue($this->helper)); + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $this->creditmemoEmail = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Creditmemo\AbstractCreditmemo\Email', [ 'context' => $this->context, 'request' => $this->request, 'response' => $this->response, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock ] ); } diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Invoice/AbstractInvoice/EmailTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Invoice/AbstractInvoice/EmailTest.php index 73d8438c5fa5f393934f8da431225302083f9016..8493e58d858c62477f45677564d12397a25d2bf6 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Invoice/AbstractInvoice/EmailTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Invoice/AbstractInvoice/EmailTest.php @@ -95,6 +95,14 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->session = $this->getMock('Magento\Backend\Model\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false); $this->helper = $this->getMock('\Magento\Backend\Helper\Data', [], [], '', false); + $this->resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->context->expects($this->once()) ->method('getMessageManager') ->willReturn($this->messageManager); @@ -116,14 +124,9 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->context->expects($this->once()) ->method('getHelper') ->willReturn($this->helper); - - $this->resultRedirect = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') - ->disableOriginalConstructor() - ->getMock(); - $this->resultRedirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); + $this->context->expects($this->once()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactory); $this->resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') ->disableOriginalConstructor() @@ -137,7 +140,6 @@ class EmailTest extends \PHPUnit_Framework_TestCase 'Magento\Sales\Controller\Adminhtml\Order\Invoice\Email', [ 'context' => $this->context, - 'resultRedirectFactory' => $this->resultRedirectFactory, 'resultForwardFactory' => $this->resultForwardFactory, ] ); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/CancelTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/CancelTest.php index bc849016a87c4412fd84dcc98f57a1cd7fca1185..5029fdac67c3d169b79dba22b2f3fe5412885a3c 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/CancelTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/CancelTest.php @@ -113,6 +113,23 @@ class CancelTest extends \PHPUnit_Framework_TestCase $this->helperMock = $this->getMockBuilder('Magento\Backend\Helper\Data') ->disableOriginalConstructor() ->getMock(); + $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') + ->disableOriginalConstructor() + ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') + ->disableOriginalConstructor() + ->getMock(); + $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') + ->disableOriginalConstructor() + ->getMock(); $this->contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() ->getMock(); @@ -124,42 +141,28 @@ class CancelTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contextMock->expects($this->any()) ->method('getSession') - ->will($this->returnValue($this->sessionMock)); + ->willReturn($this->sessionMock); $this->contextMock->expects($this->any()) ->method('getActionFlag') - ->will($this->returnValue($this->actionFlagMock)); + ->willReturn($this->actionFlagMock); $this->contextMock->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->requestMock)); + ->willReturn($this->requestMock); $this->contextMock->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->responseMock)); + ->willReturn($this->responseMock); $this->contextMock->expects($this->any()) ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); + ->willReturn($this->objectManagerMock); $this->contextMock->expects($this->any()) ->method('getTitle') - ->will($this->returnValue($titleMock)); + ->willReturn($titleMock); $this->contextMock->expects($this->any()) ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); - $this->loaderMock = $this->getMockBuilder('Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader') - ->disableOriginalConstructor() - ->getMock(); - $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') - ->disableOriginalConstructor() - ->getMock(); - $this->resultForwardMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') - ->disableOriginalConstructor() - ->getMock(); + ->willReturn($this->messageManagerMock); + $this->contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->controller = $objectManager->getObject( @@ -167,7 +170,6 @@ class CancelTest extends \PHPUnit_Framework_TestCase [ 'context' => $this->contextMock, 'creditmemoLoader' => $this->loaderMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock, 'resultForwardFactory' => $this->resultForwardFactoryMock ] ); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/SaveTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/SaveTest.php index 4d2620fdacfce2a1b820e7466fb3a725bc43858d..f834d01d208d5b7cfd885a92298e10018537d7aa 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/SaveTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/SaveTest.php @@ -126,6 +126,7 @@ class SaveTest extends \PHPUnit_Framework_TestCase 'session' => $this->_sessionMock, 'objectManager' => $this->_objectManager, 'messageManager' => $this->_messageManager, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock ]; $context = $helper->getObject('Magento\Backend\App\Action\Context', $arguments); @@ -138,7 +139,6 @@ class SaveTest extends \PHPUnit_Framework_TestCase [ 'context' => $context, 'creditmemoLoader' => $this->memoLoaderMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock ] ); } diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/VoidTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/VoidTest.php index fe28217d346f7f1872c40c83709182509da12e5d..6d2d02861be077932095d947a73f411ecf65d4c7 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/VoidTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/VoidTest.php @@ -148,28 +148,31 @@ class VoidTest extends \PHPUnit_Framework_TestCase $this->contextMock->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->requestMock)); + ->willReturn($this->requestMock); $this->contextMock->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->responseMock)); + ->willReturn($this->responseMock); $this->contextMock->expects($this->any()) ->method('getActionFlag') - ->will($this->returnValue($this->actionFlagMock)); + ->willReturn($this->actionFlagMock); $this->contextMock->expects($this->any()) ->method('getHelper') - ->will($this->returnValue($this->helperMock)); + ->willReturn($this->helperMock); $this->contextMock->expects($this->any()) ->method('getSession') - ->will($this->returnValue($this->sessionMock)); + ->willReturn($this->sessionMock); $this->contextMock->expects($this->any()) ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); + ->willReturn($this->objectManagerMock); $this->contextMock->expects($this->any()) ->method('getTitle') - ->will($this->returnValue($titleMock)); + ->willReturn($titleMock); $this->contextMock->expects($this->any()) ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); + ->willReturn($this->messageManagerMock); + $this->contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->controller = $objectManager->getObject( @@ -177,7 +180,6 @@ class VoidTest extends \PHPUnit_Framework_TestCase [ 'context' => $this->contextMock, 'creditmemoLoader' => $this->loaderMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock, 'resultForwardFactory' => $this->resultForwardFactoryMock ] ); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php index f8c328439d46c3f1f3ae95b3b4cae95ca99f72b0..6eedbf0af863639720e53d698b16284a99e319fd 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php @@ -81,7 +81,8 @@ class EmailTest extends \PHPUnit_Framework_TestCase 'getObjectManager', 'getSession', 'getActionFlag', - 'getHelper' + 'getHelper', + 'getResultRedirectFactory' ], [], '', @@ -120,35 +121,22 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->session = $this->getMock('Magento\Backend\Model\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', ['get', 'set'], [], '', false); $this->helper = $this->getMock('\Magento\Backend\Helper\Data', ['getUrl'], [], '', false); - $this->context->expects($this->once()) - ->method('getMessageManager') - ->will($this->returnValue($this->messageManager)); - $this->context->expects($this->once()) - ->method('getRequest') - ->will($this->returnValue($this->request)); - $this->context->expects($this->once()) - ->method('getResponse') - ->will($this->returnValue($this->response)); - $this->context->expects($this->once()) - ->method('getObjectManager') - ->will($this->returnValue($this->objectManager)); - $this->context->expects($this->once()) - ->method('getSession') - ->will($this->returnValue($this->session)); - $this->context->expects($this->once()) - ->method('getActionFlag') - ->will($this->returnValue($this->actionFlag)); - $this->context->expects($this->once()) - ->method('getHelper') - ->will($this->returnValue($this->helper)); $this->resultRedirect = $this->getMock('Magento\Backend\Model\View\Result\Redirect', [], [], '', false); $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect); + $this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager); + $this->context->expects($this->once())->method('getRequest')->willReturn($this->request); + $this->context->expects($this->once())->method('getResponse')->willReturn($this->response); + $this->context->expects($this->once())->method('getObjectManager')->willReturn($this->objectManager); + $this->context->expects($this->once())->method('getSession')->willReturn($this->session); + $this->context->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlag); + $this->context->expects($this->once())->method('getHelper')->willReturn($this->helper); + $this->context->expects($this->once())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory); + $this->orderEmail = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Email', [ 'context' => $this->context, - 'resultRedirectFactory' => $resultRedirectFactory, 'request' => $this->request, 'response' => $this->response ] diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/CancelTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/CancelTest.php index 3575638720b4aebf55f90d9f00ff0f30a716bd5d..682550783e2619c0d449511f8d0132da0c7b2bd3 100755 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/CancelTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/CancelTest.php @@ -102,47 +102,49 @@ class CancelTest extends \PHPUnit_Framework_TestCase ->setMethods([]) ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); $contextMock->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->requestMock)); + ->willReturn($this->requestMock); $contextMock->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->responseMock)); + ->willReturn($this->responseMock); $contextMock->expects($this->any()) ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); + ->willReturn($this->objectManagerMock); $contextMock->expects($this->any()) ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); + ->willReturn($this->messageManagerMock); $contextMock->expects($this->any()) ->method('getSession') - ->will($this->returnValue($this->sessionMock)); + ->willReturn($this->sessionMock); $contextMock->expects($this->any()) ->method('getActionFlag') - ->will($this->returnValue($this->actionFlagMock)); + ->willReturn($this->actionFlagMock); $contextMock->expects($this->any()) ->method('getHelper') - ->will($this->returnValue($this->helperMock)); - - $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); + ->willReturn($this->helperMock); + $contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\Cancel', [ 'context' => $contextMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock, 'resultForwardFactory' => $this->resultForwardFactoryMock ] ); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/CaptureTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/CaptureTest.php index 0e57e1af6c5198a9b4d45cdd921afa10b7b9745e..3c067f3f8603e01121813a572eb86ef6e93346cd 100755 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/CaptureTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/CaptureTest.php @@ -102,47 +102,49 @@ class CaptureTest extends \PHPUnit_Framework_TestCase ->setMethods([]) ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); $contextMock->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->requestMock)); + ->willReturn($this->requestMock); $contextMock->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->responseMock)); + ->willReturn($this->responseMock); $contextMock->expects($this->any()) ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); + ->willReturn($this->objectManagerMock); $contextMock->expects($this->any()) ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); + ->willReturn($this->messageManagerMock); $contextMock->expects($this->any()) ->method('getSession') - ->will($this->returnValue($this->sessionMock)); + ->willReturn($this->sessionMock); $contextMock->expects($this->any()) ->method('getActionFlag') - ->will($this->returnValue($this->actionFlagMock)); + ->willReturn($this->actionFlagMock); $contextMock->expects($this->any()) ->method('getHelper') - ->will($this->returnValue($this->helperMock)); - - $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); + ->willReturn($this->helperMock); + $contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\Capture', [ 'context' => $contextMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock, 'resultForwardFactory' => $this->resultForwardFactoryMock ] ); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/NewActionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/NewActionTest.php index c28b721ed21b34f2e123231da3de13e31218c807..5e60a34a3554103f0350c995c7742ea6c7a55b9e 100755 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/NewActionTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/NewActionTest.php @@ -134,6 +134,15 @@ class NewActionTest extends \PHPUnit_Framework_TestCase $this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title') ->disableOriginalConstructor() ->getMock(); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() @@ -141,34 +150,38 @@ class NewActionTest extends \PHPUnit_Framework_TestCase ->getMock(); $contextMock->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->requestMock)); + ->willReturn($this->requestMock); $contextMock->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->responseMock)); + ->willReturn($this->responseMock); $contextMock->expects($this->any()) ->method('getTitle') - ->will($this->returnValue($titleMock)); + ->willReturn($titleMock); $contextMock->expects($this->any()) ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); + ->willReturn($this->objectManagerMock); $contextMock->expects($this->any()) ->method('getView') - ->will($this->returnValue($this->viewMock)); + ->willReturn($this->viewMock); $contextMock->expects($this->any()) ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); + ->willReturn($this->objectManagerMock); $contextMock->expects($this->any()) ->method('getActionFlag') - ->will($this->returnValue($this->actionFlagMock)); + ->willReturn($this->actionFlagMock); $contextMock->expects($this->any()) ->method('getHelper') - ->will($this->returnValue($this->helperMock)); + ->willReturn($this->helperMock); $contextMock->expects($this->any()) ->method('getSession') - ->will($this->returnValue($this->sessionMock)); + ->willReturn($this->sessionMock); $contextMock->expects($this->any()) ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); + ->willReturn($this->messageManagerMock); + $contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); + $this->viewMock->expects($this->any()) ->method('getPage') ->willReturn($this->resultPageMock); @@ -179,21 +192,10 @@ class NewActionTest extends \PHPUnit_Framework_TestCase ->method('getTitle') ->willReturn($this->pageTitleMock); - $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\NewAction', [ 'context' => $contextMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock, 'resultPageFactory' => $this->resultPageFactoryMock ] ); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php index 1c5cf1cefa0223c32ab910f86143b27b7be09ff9..90b9a5abf31f39fa9357b2e3323e7cfd1c7b0501 100755 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/UpdateQtyTest.php @@ -264,7 +264,7 @@ class UpdateQtyTest extends \PHPUnit_Framework_TestCase */ public function testExecuteModelException() { - $message = 'Cannot update item quantity.'; + $message = 'The order no longer exists.'; $response = ['error' => true, 'message' => $message]; $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') @@ -307,7 +307,7 @@ class UpdateQtyTest extends \PHPUnit_Framework_TestCase */ public function testExecuteException() { - $message = 'Cannot update item quantity.'; + $message = 'The order no longer exists.'; $response = ['error' => true, 'message' => $message]; $orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/VoidTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/VoidTest.php index 21d1f3f644b4a43d25118b3db9ae0d2799726461..4f9b93ea6e279a165cd20d0786f7b8e954a8c6c0 100755 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/VoidTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/VoidTest.php @@ -112,50 +112,52 @@ class VoidTest extends \PHPUnit_Framework_TestCase ->setMethods([]) ->getMock(); + $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $contextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() ->setMethods([]) ->getMock(); $contextMock->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->requestMock)); + ->willReturn($this->requestMock); $contextMock->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->responseMock)); + ->willReturn($this->responseMock); $contextMock->expects($this->any()) ->method('getObjectManager') - ->will($this->returnValue($this->objectManagerMock)); + ->willReturn($this->objectManagerMock); $contextMock->expects($this->any()) ->method('getMessageManager') - ->will($this->returnValue($this->messageManagerMock)); + ->willReturn($this->messageManagerMock); $contextMock->expects($this->any()) ->method('getTitle') - ->will($this->returnValue($this->titleMock)); + ->willReturn($this->titleMock); $contextMock->expects($this->any()) ->method('getActionFlag') - ->will($this->returnValue($this->actionFlagMock)); + ->willReturn($this->actionFlagMock); $contextMock->expects($this->any()) ->method('getSession') - ->will($this->returnValue($this->sessionMock)); + ->willReturn($this->sessionMock); $contextMock->expects($this->any()) ->method('getHelper') - ->will($this->returnValue($this->helperMock)); - - $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); + ->willReturn($this->helperMock); + $contextMock->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactoryMock); $this->controller = $objectManager->getObject( 'Magento\Sales\Controller\Adminhtml\Order\Invoice\Void', [ 'context' => $contextMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock, 'resultForwardFactory' => $this->resultForwardFactoryMock ] ); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php index eadbaa5250cdd5e2776afe733f398a2d40c2af2b..b10539c45a0dbd285ef84ac9bc2f64c346037f71 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php @@ -133,7 +133,8 @@ class ViewTest extends \PHPUnit_Framework_TestCase 'request' => $this->requestMock, 'objectManager' => $this->objectManagerMock, 'actionFlag' => $this->actionFlagMock, - 'messageManager' => $this->messageManagerMock + 'messageManager' => $this->messageManagerMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock ] ); $this->viewAction = $objectManager->getObject( @@ -198,33 +199,6 @@ class ViewTest extends \PHPUnit_Framework_TestCase ); } - /** - * @covers \Magento\Sales\Controller\Adminhtml\Order\View::execute - */ - public function testExecuteException() - { - $id = 111; - $message = 'epic fail'; - $exception = new \Magento\Framework\App\Action\Exception($message); - $this->initOrder(); - $this->initOrderSuccess($id); - $this->prepareRedirect(); - - $this->resultPageFactoryMock->expects($this->once()) - ->method('create') - ->willThrowException($exception); - $this->messageManagerMock->expects($this->once()) - ->method('addError') - ->with($message) - ->willReturnSelf(); - $this->setPath('sales/order/index'); - - $this->assertInstanceOf( - 'Magento\Backend\Model\View\Result\Redirect', - $this->viewAction->execute() - ); - } - /** * @covers \Magento\Sales\Controller\Adminhtml\Order\View::execute */ diff --git a/app/code/Magento/Sales/Test/Unit/Model/AdminOrder/EmailSenderTest.php b/app/code/Magento/Sales/Test/Unit/Model/AdminOrder/EmailSenderTest.php index 6910282d040a994ae752456f70296d1bfd912f74..356317fa00d3815339a388bdfeff8c681d517170 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/AdminOrder/EmailSenderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/AdminOrder/EmailSenderTest.php @@ -79,7 +79,7 @@ class EmailSenderTest extends \PHPUnit_Framework_TestCase { $this->orderSenderMock->expects($this->once()) ->method('send') - ->will($this->throwException(new \Magento\Framework\Mail\Exception('test message'))); + ->willThrowException(new \Magento\Framework\Exception\MailException(__('test message'))); $this->messageManagerMock->expects($this->once()) ->method('addWarning'); $this->loggerMock->expects($this->once()) diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/CreditmemoNotifierTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/CreditmemoNotifierTest.php index 41f77cdf509d1c6360df90b33a43b30c840a0e46..ebffcd4ad781c98b65311e346245278eb1afe5eb 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/CreditmemoNotifierTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/CreditmemoNotifierTest.php @@ -8,7 +8,7 @@ namespace Magento\Sales\Test\Unit\Model\Order; use \Magento\Sales\Model\Order\CreditmemoNotifier; -use Magento\Framework\Mail\Exception; +use Magento\Framework\Exception\MailException; use Magento\Sales\Model\Resource\Order\Status\History\CollectionFactory; /** @@ -130,7 +130,7 @@ class CreditmemoNotifierTest extends \PHPUnit_Framework_TestCase */ public function testNotifyException() { - $exception = new Exception('Email has not been sent'); + $exception = new MailException(__('Email has not been sent')); $this->creditmemoSenderMock->expects($this->once()) ->method('send') ->with($this->equalTo($this->creditmemo)) diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceNotifierTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceNotifierTest.php index 1920800487b6a39ce628d20e54784b4f94acc088..214eb992d17233be956b12e9401ef544e2711c6a 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceNotifierTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/InvoiceNotifierTest.php @@ -8,7 +8,7 @@ namespace Magento\Sales\Test\Unit\Model\Order; use \Magento\Sales\Model\Order\InvoiceNotifier; -use Magento\Framework\Mail\Exception; +use Magento\Framework\Exception\MailException; use Magento\Sales\Model\Resource\Order\Status\History\CollectionFactory; /** @@ -130,7 +130,7 @@ class InvoiceNotifierTest extends \PHPUnit_Framework_TestCase */ public function testNotifyException() { - $exception = new Exception('Email has not been sent'); + $exception = new MailException(__('Email has not been sent')); $this->invoiceSenderMock->expects($this->once()) ->method('send') ->with($this->equalTo($this->invoice)) diff --git a/app/code/Magento/Sales/Test/Unit/Model/OrderNotifierTest.php b/app/code/Magento/Sales/Test/Unit/Model/OrderNotifierTest.php index 907a4ee588ba0b483f2848bb937bda0f66adb713..53cd9bf2d2e15c08b8a65caf29b5bc3fe9a9469a 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/OrderNotifierTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/OrderNotifierTest.php @@ -8,7 +8,7 @@ namespace Magento\Sales\Test\Unit\Model; use \Magento\Sales\Model\OrderNotifier; -use Magento\Framework\Mail\Exception; +use Magento\Framework\Exception\MailException; use Magento\Sales\Model\Resource\Order\Status\History\CollectionFactory; /** @@ -130,7 +130,7 @@ class OrderNotifierTest extends \PHPUnit_Framework_TestCase */ public function testNotifyException() { - $exception = new Exception('Email has not been sent'); + $exception = new MailException(__('Email has not been sent')); $this->orderSenderMock->expects($this->once()) ->method('send') ->with($this->equalTo($this->order)) diff --git a/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js b/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js index 1e53404f422e4a17de5bf3a45e9cb484379f83bb..2ba401a017ebe574235f18ac4f8f45adef712d1d 100644 --- a/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js +++ b/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js @@ -668,6 +668,7 @@ AdminOrder.prototype = { if (confirm(confirmMessage)) { this.collectElementsValue = false; order.sidebarApplyChanges({'sidebar[empty_customer_cart]': 1}); + this.collectElementsValue = true; } }, diff --git a/app/code/Magento/SalesRule/Exception.php b/app/code/Magento/SalesRule/Exception.php deleted file mode 100644 index 1332875e9513a508beeea56de0154aad2a6b8047..0000000000000000000000000000000000000000 --- a/app/code/Magento/SalesRule/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\SalesRule; - -class Exception extends \Zend_Exception -{ -} diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php index 264a6381e153388529635211b411a2aad3131101..0649b87dc8cfe37e91be354a9d1ea7a72e1fc87b 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Delete.php @@ -8,25 +8,6 @@ namespace Magento\Search\Controller\Adminhtml\Term; class Delete extends \Magento\Search\Controller\Adminhtml\Term { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $resultPageFactory); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * @return \Magento\Backend\Model\View\Result\Redirect */ diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/MassDelete.php b/app/code/Magento/Search/Controller/Adminhtml/Term/MassDelete.php index 6d473c2261d4e8c3b06db543c25e1ad94c8adb2a..535c0322f57a862fe1a6aa99003a6542ca58e41f 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/MassDelete.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/MassDelete.php @@ -8,25 +8,6 @@ namespace Magento\Search\Controller\Adminhtml\Term; class MassDelete extends \Magento\Search\Controller\Adminhtml\Term { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $resultPageFactory); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * @return \Magento\Backend\Model\View\Result\Redirect */ diff --git a/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php b/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php index a44592a5711831629febcedc5ad8fe8112cfdddf..cf503b4e612550124503e8cebd21fd52071b746c 100644 --- a/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php +++ b/app/code/Magento/Search/Controller/Adminhtml/Term/Save.php @@ -8,25 +8,6 @@ namespace Magento\Search\Controller\Adminhtml\Term; class Save extends \Magento\Search\Controller\Adminhtml\Term { - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - - /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - */ - public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory - ) { - parent::__construct($context, $resultPageFactory); - $this->resultRedirectFactory = $resultRedirectFactory; - } - /** * Save search query * diff --git a/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Term/MassDeleteTest.php b/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Term/MassDeleteTest.php index d72c283669650fcb643ea5d3bfa3e1695cfb118a..27fea3b5cd06d3ca4789d5b2334023337c39ba63 100644 --- a/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Term/MassDeleteTest.php +++ b/app/code/Magento/Search/Test/Unit/Controller/Adminhtml/Term/MassDeleteTest.php @@ -57,22 +57,6 @@ class MassDeleteTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->setMethods(['addSuccess', 'addError']) ->getMockForAbstractClass(); - $this->context = $this->getMockBuilder('Magento\Backend\App\Action\Context') - ->setMethods(['getRequest', 'getResponse', 'getObjectManager', 'getMessageManager']) - ->disableOriginalConstructor() - ->getMock(); - $this->context->expects($this->atLeastOnce()) - ->method('getRequest') - ->will($this->returnValue($this->request)); - $this->context->expects($this->atLeastOnce()) - ->method('getResponse') - ->will($this->returnValue($this->response)); - $this->context->expects($this->any()) - ->method('getObjectManager') - ->will($this->returnValue($this->objectManager)); - $this->context->expects($this->any()) - ->method('getMessageManager') - ->will($this->returnValue($this->messageManager)); $this->pageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') ->setMethods([]) ->disableOriginalConstructor() @@ -88,13 +72,31 @@ class MassDeleteTest extends \PHPUnit_Framework_TestCase $this->redirectFactory->expects($this->any()) ->method('create') ->will($this->returnValue($this->redirect)); + $this->context = $this->getMockBuilder('Magento\Backend\App\Action\Context') + ->disableOriginalConstructor() + ->getMock(); + $this->context->expects($this->atLeastOnce()) + ->method('getRequest') + ->willReturn($this->request); + $this->context->expects($this->atLeastOnce()) + ->method('getResponse') + ->willReturn($this->response); + $this->context->expects($this->any()) + ->method('getObjectManager') + ->willReturn($this->objectManager); + $this->context->expects($this->any()) + ->method('getMessageManager') + ->willReturn($this->messageManager); + $this->context->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->redirectFactory); + $this->objectManagerHelper = new ObjectManagerHelper($this); $this->controller = $this->objectManagerHelper->getObject( 'Magento\Search\Controller\Adminhtml\Term\MassDelete', [ 'context' => $this->context, 'resultPageFactory' => $this->pageFactory, - 'resultRedirectFactory' => $this->redirectFactory ] ); } diff --git a/app/code/Magento/Sendfriend/Controller/Product.php b/app/code/Magento/Sendfriend/Controller/Product.php index 1bb9f0ca10658763be7b0beae625ece1f59a25e8..9a9677d2e54c34b0345e1dd7a92108dbe92f68e5 100644 --- a/app/code/Magento/Sendfriend/Controller/Product.php +++ b/app/code/Magento/Sendfriend/Controller/Product.php @@ -5,7 +5,7 @@ */ namespace Magento\Sendfriend\Controller; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\App\RequestInterface; use Magento\Framework\Exception\NoSuchEntityException; @@ -63,7 +63,7 @@ class Product extends \Magento\Framework\App\Action\Action * * @param RequestInterface $request * @return \Magento\Framework\App\ResponseInterface - * @throws \Magento\Framework\App\Action\NotFoundException + * @throws \Magento\Framework\Exception\NotFoundException */ public function dispatch(RequestInterface $request) { @@ -73,7 +73,7 @@ class Product extends \Magento\Framework\App\Action\Action $session = $this->_objectManager->get('Magento\Customer\Model\Session'); if (!$helper->isEnabled()) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } if (!$helper->isAllowForGuest() && !$session->authenticate($this)) { diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Email.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Email.php old mode 100644 new mode 100755 index 850a8ac25c7e28ab7add7f41524cc692fc69386d..5f30722a08c906e5761723a95f286f3cd77d99ea --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Email.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Email.php @@ -45,27 +45,32 @@ class Email extends \Magento\Backend\App\Action /** * Send email with shipment data to customer * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { - try { - $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id')); - $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id')); - $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment')); - $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking')); - $shipment = $this->shipmentLoader->load(); - if ($shipment) { - $this->_objectManager->create('Magento\Shipping\Model\ShipmentNotifier') - ->notify($shipment); - $shipment->save(); - $this->messageManager->addSuccess(__('You sent the shipment.')); - } - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('Cannot send shipment information.')); + $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id')); + $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id')); + $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment')); + $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking')); + $shipment = $this->shipmentLoader->load(); + if ($shipment) { + $this->_objectManager->create('Magento\Shipping\Model\ShipmentNotifier') + ->notify($shipment); + $shipment->save(); + $this->messageManager->addSuccess(__('You sent the shipment.')); } - $this->_redirect('*/*/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]); + return $this->getDefaultResult(); + } + + /** + * @inheritdoc + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('*/*/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]); } } diff --git a/app/code/Magento/Shipping/Controller/Tracking/Popup.php b/app/code/Magento/Shipping/Controller/Tracking/Popup.php index d9ecbcd583b3e2a452fc306e3af9e673c580f5a5..9ae7590bdb44429914809f6cb387274b3ae22a18 100644 --- a/app/code/Magento/Shipping/Controller/Tracking/Popup.php +++ b/app/code/Magento/Shipping/Controller/Tracking/Popup.php @@ -6,7 +6,7 @@ */ namespace Magento\Shipping\Controller\Tracking; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; class Popup extends \Magento\Framework\App\Action\Action { @@ -57,7 +57,7 @@ class Popup extends \Magento\Framework\App\Action\Action $shippingInfoModel = $this->_shippingInfoFactory->create()->loadByHash($this->getRequest()->getParam('hash')); $this->_coreRegistry->register('current_shipping_info', $shippingInfoModel); if (count($shippingInfoModel->getTrackingInfo()) == 0) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $this->_view->loadLayout(); $this->_view->getPage()->getConfig()->getTitle()->set(__('Tracking Information')); diff --git a/app/code/Magento/Shipping/Exception.php b/app/code/Magento/Shipping/Exception.php old mode 100644 new mode 100755 index 12fef333cd12a8898e5b0ab904a15374af1b62b3..b140b961cf6d2bdf50fbc78e600517b55b8d3211 --- a/app/code/Magento/Shipping/Exception.php +++ b/app/code/Magento/Shipping/Exception.php @@ -5,6 +5,6 @@ */ namespace Magento\Shipping; -class Exception extends \Zend_Exception +class Exception extends \Magento\Framework\Exception\LocalizedException { } diff --git a/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/EmailTest.php b/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/EmailTest.php old mode 100644 new mode 100755 index 9f73339f8cdab8a679f52768a9d98f61043288ac..48ff3dd325790a61fe18e16f11a0cd23e3deaa63 --- a/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/EmailTest.php +++ b/app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/EmailTest.php @@ -15,6 +15,7 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHe * Class EmailTest * * @package Magento\Shipping\Controller\Adminhtml\Order\Shipment + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class EmailTest extends \PHPUnit_Framework_TestCase { @@ -63,6 +64,16 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ protected $helper; + /** + * @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirectFactory; + + /** + * @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirect; + /** * @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader|\PHPUnit_Framework_MockObject_MockObject */ @@ -88,7 +99,8 @@ class EmailTest extends \PHPUnit_Framework_TestCase 'getObjectManager', 'getSession', 'getActionFlag', - 'getHelper' + 'getHelper', + 'getResultRedirectFactory' ], [], '', @@ -129,27 +141,27 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->session = $this->getMock('Magento\Backend\Model\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', ['get'], [], '', false); $this->helper = $this->getMock('\Magento\Backend\Helper\Data', ['getUrl'], [], '', false); + $this->resultRedirect = $this->getMock('Magento\Backend\Model\View\Result\Redirect', [], [], '', false); + $this->resultRedirectFactory = $this->getMock( + 'Magento\Backend\Model\View\Result\RedirectFactory', + ['create'], + [], + '', + false + ); + $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect); + + $this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager); + $this->context->expects($this->once())->method('getRequest')->willReturn($this->request); + $this->context->expects($this->once())->method('getResponse')->willReturn($this->response); + $this->context->expects($this->once())->method('getObjectManager')->willReturn($this->objectManager); + $this->context->expects($this->once())->method('getSession')->willReturn($this->session); + $this->context->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlag); + $this->context->expects($this->once())->method('getHelper')->willReturn($this->helper); $this->context->expects($this->once()) - ->method('getMessageManager') - ->will($this->returnValue($this->messageManager)); - $this->context->expects($this->once()) - ->method('getRequest') - ->will($this->returnValue($this->request)); - $this->context->expects($this->once()) - ->method('getResponse') - ->will($this->returnValue($this->response)); - $this->context->expects($this->once()) - ->method('getObjectManager') - ->will($this->returnValue($this->objectManager)); - $this->context->expects($this->once()) - ->method('getSession') - ->will($this->returnValue($this->session)); - $this->context->expects($this->once()) - ->method('getActionFlag') - ->will($this->returnValue($this->actionFlag)); - $this->context->expects($this->once()) - ->method('getHelper') - ->will($this->returnValue($this->helper)); + ->method('getResultRedirectFactory') + ->willReturn($this->resultRedirectFactory); + $this->shipmentEmail = $objectManagerHelper->getObject( 'Magento\Shipping\Controller\Adminhtml\Order\Shipment\Email', [ @@ -240,14 +252,8 @@ class EmailTest extends \PHPUnit_Framework_TestCase $this->session->expects($this->any()) ->method('setIsUrlNotice') ->with(true); - - $url = $path . '/' . (!empty($arguments) ? $arguments['shipment_id'] : ''); - $this->helper->expects($this->at($index)) - ->method('getUrl') - ->with($path, $arguments) - ->will($this->returnValue($url)); - $this->response->expects($this->at($index)) - ->method('setRedirect') - ->with($url); + $this->resultRedirect->expects($this->at($index)) + ->method('setPath') + ->with($path, ['shipment_id' => $arguments['shipment_id']]); } } diff --git a/app/code/Magento/Shipping/Test/Unit/Model/ShipmentNotifierTest.php b/app/code/Magento/Shipping/Test/Unit/Model/ShipmentNotifierTest.php index 5d886942df8b32de00af60158359196093b5ad3a..254b84c536927339625d3eac444bc7ebaca8844a 100644 --- a/app/code/Magento/Shipping/Test/Unit/Model/ShipmentNotifierTest.php +++ b/app/code/Magento/Shipping/Test/Unit/Model/ShipmentNotifierTest.php @@ -8,7 +8,7 @@ namespace Magento\Shipping\Test\Unit\Model; use \Magento\Shipping\Model\ShipmentNotifier; -use Magento\Framework\Mail\Exception; +use Magento\Framework\Exception\MailException; use Magento\Sales\Model\Resource\Order\Status\History\CollectionFactory; /** @@ -130,7 +130,7 @@ class ShipmentNotifierTest extends \PHPUnit_Framework_TestCase */ public function testNotifyException() { - $exception = new Exception('Email has not been sent'); + $exception = new MailException(__('Email has not been sent')); $this->shipmentSenderMock->expects($this->once()) ->method('send') ->with($this->equalTo($this->shipment)) diff --git a/app/code/Magento/Store/App/Action/Plugin/StoreCheck.php b/app/code/Magento/Store/App/Action/Plugin/StoreCheck.php index 048f66b3a145133ccfba8169ba58c5fd259df35a..6467df3faf3914e93988aed1c18c2e782e9e50d4 100644 --- a/app/code/Magento/Store/App/Action/Plugin/StoreCheck.php +++ b/app/code/Magento/Store/App/Action/Plugin/StoreCheck.php @@ -29,7 +29,7 @@ class StoreCheck * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * @throws \Magento\Framework\App\InitException + * @throws \Magento\Framework\Exception\State\InitException */ public function aroundDispatch( \Magento\Framework\App\Action\Action $subject, @@ -37,8 +37,8 @@ class StoreCheck \Magento\Framework\App\RequestInterface $request ) { if (!$this->_storeManager->getStore()->getIsActive()) { - throw new \Magento\Framework\App\InitException( - 'Current store is not active.' + throw new \Magento\Framework\Exception\State\InitException( + __('Current store is not active.') ); } return $proceed($request); diff --git a/app/code/Magento/Store/Model/Resolver/Store.php b/app/code/Magento/Store/Model/Resolver/Store.php index 2acf0aedb21cbdc2dae145f6c9d9e1cd77a33322..6e9131fef50f093a6212da5b1faeb63c4cafc3ce 100644 --- a/app/code/Magento/Store/Model/Resolver/Store.php +++ b/app/code/Magento/Store/Model/Resolver/Store.php @@ -22,13 +22,13 @@ class Store implements \Magento\Framework\App\ScopeResolverInterface /** * {@inheritdoc} - * @throws \Magento\Framework\App\InitException + * @throws \Magento\Framework\Exception\State\InitException */ public function getScope($scopeId = null) { $scope = $this->_storeManager->getStore($scopeId); if (!$scope instanceof \Magento\Framework\App\ScopeInterface) { - throw new \Magento\Framework\App\InitException('Invalid scope object'); + throw new \Magento\Framework\Exception\State\InitException(__('Invalid scope object')); } return $scope; diff --git a/app/code/Magento/Store/Model/Resolver/Website.php b/app/code/Magento/Store/Model/Resolver/Website.php index cdfb825fc025c4609d8e7e668025ac6360438386..ef3c2eba7bef537293d6d5c9a3a0d69cd1aa2aa4 100644 --- a/app/code/Magento/Store/Model/Resolver/Website.php +++ b/app/code/Magento/Store/Model/Resolver/Website.php @@ -23,13 +23,13 @@ class Website implements \Magento\Framework\App\ScopeResolverInterface /** * {@inheritdoc} - * @throws \Magento\Framework\App\InitException + * @throws \Magento\Framework\Exception\State\InitException */ public function getScope($scopeId = null) { $scope = $this->_storeManager->getWebsite($scopeId); if (!($scope instanceof \Magento\Framework\App\ScopeInterface)) { - throw new \Magento\Framework\App\InitException('Invalid scope object'); + throw new \Magento\Framework\Exception\State\InitException(__('Invalid scope object')); } return $scope; diff --git a/app/code/Magento/Store/Model/Storage/Db.php b/app/code/Magento/Store/Model/Storage/Db.php index 77a22f6ca86b671c6c47523fd550251f5cb72f06..a6dd46ba85905edffcd373fe73d26e52c70f18cf 100644 --- a/app/code/Magento/Store/Model/Storage/Db.php +++ b/app/code/Magento/Store/Model/Storage/Db.php @@ -288,7 +288,7 @@ class Db implements \Magento\Store\Model\StoreManagerInterface * * @param null|string|bool|int|Store $storeId * @return Store - * @throws \Magento\Framework\App\InitException + * @throws \Magento\Framework\Exception\State\InitException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -318,8 +318,8 @@ class Db implements \Magento\Store\Model\StoreManagerInterface } if (!$store->getCode()) { - throw new \Magento\Framework\App\InitException( - 'Store Manager has been initialized not properly' + throw new \Magento\Framework\Exception\State\InitException( + __('Store Manager has been initialized not properly') ); } $this->_stores[$store->getStoreId()] = $store; @@ -357,7 +357,7 @@ class Db implements \Magento\Store\Model\StoreManagerInterface * * @param null|bool|int|string|Website $websiteId * @return Website - * @throws \Magento\Framework\App\InitException + * @throws \Magento\Framework\Exception\State\InitException */ public function getWebsite($websiteId = null) { @@ -374,7 +374,7 @@ class Db implements \Magento\Store\Model\StoreManagerInterface // load method will load website by code if given ID is not a numeric value $website->load($websiteId); if (!$website->hasWebsiteId()) { - throw new \Magento\Framework\App\InitException('Invalid website id/code requested.'); + throw new \Magento\Framework\Exception\State\InitException(__('Invalid website id/code requested.')); } $this->_websites[$website->getWebsiteId()] = $website; $this->_websites[$website->getCode()] = $website; @@ -412,7 +412,7 @@ class Db implements \Magento\Store\Model\StoreManagerInterface * * @param null|Group|string $groupId * @return Group - * @throws \Magento\Framework\App\InitException + * @throws \Magento\Framework\Exception\State\InitException */ public function getGroup($groupId = null) { @@ -426,7 +426,7 @@ class Db implements \Magento\Store\Model\StoreManagerInterface if (is_numeric($groupId)) { $group->load($groupId); if (!$group->hasGroupId()) { - throw new \Magento\Framework\App\InitException('Invalid store group id requested.'); + throw new \Magento\Framework\Exception\State\InitException(__('Invalid store group id requested.')); } } $this->_groups[$group->getGroupId()] = $group; diff --git a/app/code/Magento/Store/Model/StorageFactory.php b/app/code/Magento/Store/Model/StorageFactory.php index 764ddc2584e20ff71fb4bdc3d44ef2ea0f3f7672..bce9da866b684a8ed5da1191c6187ccd339e4836 100644 --- a/app/code/Magento/Store/Model/StorageFactory.php +++ b/app/code/Magento/Store/Model/StorageFactory.php @@ -134,7 +134,7 @@ class StorageFactory * @param \Magento\Store\Model\StoreManagerInterface $storage * @param array $arguments * @return void - * @throws \Magento\Framework\App\InitException + * @throws \Magento\Framework\Exception\State\InitException */ protected function _reinitStores(\Magento\Store\Model\StoreManagerInterface $storage, $arguments) { @@ -159,8 +159,8 @@ class StorageFactory $storage->setCurrentStore($this->_getStoreByWebsite($storage, $scopeCode)); break; default: - throw new \Magento\Framework\App\InitException( - 'Store Manager has not been initialized properly' + throw new \Magento\Framework\Exception\State\InitException( + __('Store Manager has not been initialized properly') ); } diff --git a/app/code/Magento/Store/Test/Unit/App/Action/Plugin/StoreCheckTest.php b/app/code/Magento/Store/Test/Unit/App/Action/Plugin/StoreCheckTest.php index 00782573b1ff07f25e0789f3ba595674205b23a7..61e6ebb28258f5c64dd90e72cf7ee75c5715707c 100644 --- a/app/code/Magento/Store/Test/Unit/App/Action/Plugin/StoreCheckTest.php +++ b/app/code/Magento/Store/Test/Unit/App/Action/Plugin/StoreCheckTest.php @@ -61,7 +61,7 @@ class StoreCheckTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\App\InitException + * @expectedException \Magento\Framework\Exception\State\InitException * @expectedExceptionMessage Current store is not active. */ public function testAroundDispatchWhenStoreNotActive() diff --git a/app/code/Magento/Store/Test/Unit/Model/Resolver/StoreTest.php b/app/code/Magento/Store/Test/Unit/Model/Resolver/StoreTest.php index c36b779f014873fd4056f9106dd6732ef87d2b33..6513f7cf34f3756a20c118141be000f9abbd85e7 100644 --- a/app/code/Magento/Store/Test/Unit/Model/Resolver/StoreTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/Resolver/StoreTest.php @@ -55,7 +55,7 @@ class StoreTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\App\InitException + * @expectedException \Magento\Framework\Exception\State\InitException */ public function testGetScopeWithInvalidScope() { diff --git a/app/code/Magento/Store/Test/Unit/Model/Resolver/WebsiteTest.php b/app/code/Magento/Store/Test/Unit/Model/Resolver/WebsiteTest.php index 8156dceae727327228d7746cd494c33f413a1ee7..51edf26170480ca5da26e1d16a1d2a7b84e4c106 100644 --- a/app/code/Magento/Store/Test/Unit/Model/Resolver/WebsiteTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/Resolver/WebsiteTest.php @@ -55,7 +55,7 @@ class WebsiteTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\App\InitException + * @expectedException \Magento\Framework\Exception\State\InitException */ public function testGetScopeWithInvalidScope() { diff --git a/app/code/Magento/Store/Test/Unit/Model/Storage/DbTest.php b/app/code/Magento/Store/Test/Unit/Model/Storage/DbTest.php index 8161bfad4663a4251549bf1b8a2eca152a4c415e..675b7520f374a42d10a0ab4e859976866ede3f49 100644 --- a/app/code/Magento/Store/Test/Unit/Model/Storage/DbTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/Storage/DbTest.php @@ -130,7 +130,7 @@ class DbTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\App\InitException + * @expectedException \Magento\Framework\Exception\State\InitException */ public function testGetWebsiteInvalidId() { @@ -176,7 +176,7 @@ class DbTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\App\InitException + * @expectedException \Magento\Framework\Exception\State\InitException */ public function testGetGroupInvalidId() { diff --git a/app/code/Magento/Store/Test/Unit/Model/StorageFactoryTest.php b/app/code/Magento/Store/Test/Unit/Model/StorageFactoryTest.php index 31e5f8033705f1ff1ab629118bf255bb96dfca06..7b22f6d43b1ac3f522de375bad726d6a1063841d 100644 --- a/app/code/Magento/Store/Test/Unit/Model/StorageFactoryTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/StorageFactoryTest.php @@ -300,7 +300,7 @@ class StorageFactoryTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\App\InitException + * @expectedException \Magento\Framework\Exception\State\InitException */ public function testGetWithStoresReinitUnknownScopeType() { diff --git a/app/code/Magento/Tax/Controller/Adminhtml/Rate/Delete.php b/app/code/Magento/Tax/Controller/Adminhtml/Rate/Delete.php old mode 100644 new mode 100755 index 7adb8bd4c18acb50668e0b0ebf19a1e5bfd95260..bcf14907b4eff3410da0d7a637f2fb7554a00f57 --- a/app/code/Magento/Tax/Controller/Adminhtml/Rate/Delete.php +++ b/app/code/Magento/Tax/Controller/Adminhtml/Rate/Delete.php @@ -13,7 +13,7 @@ class Delete extends \Magento\Tax\Controller\Adminhtml\Rate /** * Delete Rate and Data * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect|void */ public function execute() { @@ -29,17 +29,25 @@ class Delete extends \Magento\Tax\Controller\Adminhtml\Rate __('Something went wrong deleting this rate because of an incorrect rate ID.') ); $this->getResponse()->setRedirect($this->getUrl('tax/*/')); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('Something went wrong deleting this rate.')); + return; } + return $this->getDefaultResult(); + } + } - if ($referer = $this->getRequest()->getServer('HTTP_REFERER')) { - $this->getResponse()->setRedirect($referer); - } else { - $this->getResponse()->setRedirect($this->getUrl("*/*/")); - } + /** + * @inheritdoc + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + if ($this->getRequest()->getServer('HTTP_REFERER')) { + $resultRedirect->setRefererUrl(); + } else { + $resultRedirect->setUrl($this->getUrl("*/*/")); } + return $resultRedirect; } } diff --git a/app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php b/app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php old mode 100644 new mode 100755 index 2e79ae0fb0da19e84cb852ed3080a24f5900dcba..4fff21c62f6352e4c1c4ac14b9504864755317bf --- a/app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php +++ b/app/code/Magento/Tax/Controller/Adminhtml/Rule/Delete.php @@ -6,11 +6,10 @@ */ namespace Magento\Tax\Controller\Adminhtml\Rule; - class Delete extends \Magento\Tax\Controller\Adminhtml\Rule { /** - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect|void */ public function execute() { @@ -24,12 +23,18 @@ class Delete extends \Magento\Tax\Controller\Adminhtml\Rule $this->messageManager->addError(__('This rule no longer exists.')); $this->_redirect('tax/*/'); return; - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('Something went wrong deleting this tax rule.')); } + return $this->getDefaultResult(); + } - $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*'))); + /** + * @inheritdoc + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*'))); } } diff --git a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php old mode 100644 new mode 100755 index 3d21b9ccc06c6c6de5f508ba410be61453a22882..320e6c6b30cd46dfa56ad5cb7128f8146eba6f06 --- a/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php +++ b/app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Delete.php @@ -11,36 +11,42 @@ class Delete extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme /** * Delete action * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { - $redirectBack = (bool)$this->getRequest()->getParam('back', false); $themeId = $this->getRequest()->getParam('id'); - try { - if ($themeId) { - /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ - $theme = $this->_objectManager->create('Magento\Framework\View\Design\ThemeInterface')->load($themeId); - if (!$theme->getId()) { - throw new \InvalidArgumentException(sprintf('We cannot find a theme with id "%1".', $themeId)); - } - if (!$theme->isVirtual()) { - throw new \InvalidArgumentException( - sprintf('Only virtual theme is possible to delete and theme "%s" isn\'t virtual', $themeId) - ); - } - $theme->delete(); - $this->messageManager->addSuccess(__('You deleted the theme.')); + if ($themeId) { + /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ + $theme = $this->_objectManager->create('Magento\Framework\View\Design\ThemeInterface')->load($themeId); + if (!$theme->getId()) { + throw new \InvalidArgumentException(sprintf('We cannot find a theme with id "%1".', $themeId)); } - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('We cannot delete the theme.')); - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); + if (!$theme->isVirtual()) { + throw new \InvalidArgumentException( + sprintf('Only virtual theme is possible to delete and theme "%s" isn\'t virtual', $themeId) + ); + } + $theme->delete(); + $this->messageManager->addSuccess(__('You deleted the theme.')); } + return $this->getDefaultResult(); + } + + /** + * @inheritdoc + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { /** * @todo Temporary solution. Theme module should not know about the existence of editor module. */ - $redirectBack ? $this->_redirect('adminhtml/system_design_editor/index/') : $this->_redirect('adminhtml/*/'); + $path = (bool)$this->getRequest()->getParam('back', false) + ? 'adminhtml/system_design_editor/index/' + : 'adminhtml/*/'; + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath($path); } } diff --git a/app/code/Magento/Theme/Helper/Storage.php b/app/code/Magento/Theme/Helper/Storage.php index 7bc986ee5262b2c778cc96f9a91aa75399e3983f..e7cc74971716375988b6e74895cafdf7c7a255bd 100644 --- a/app/code/Magento/Theme/Helper/Storage.php +++ b/app/code/Magento/Theme/Helper/Storage.php @@ -179,7 +179,7 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper * Get storage type * * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getStorageType() { @@ -189,7 +189,7 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper ]; $type = (string)$this->_getRequest()->getParam(self::PARAM_CONTENT_TYPE); if (!in_array($type, $allowedTypes)) { - throw new \Magento\Framework\Exception('Invalid type'); + throw new \Magento\Framework\Exception\LocalizedException(__('Invalid type')); } return $type; } @@ -282,7 +282,7 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper * Get allowed extensions by type * * @return string[] - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getAllowedExtensionsByType() { @@ -294,7 +294,7 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper $extensions = ['jpg', 'jpeg', 'gif', 'png', 'xbm', 'wbmp']; break; default: - throw new \Magento\Framework\Exception('Invalid type'); + throw new \Magento\Framework\Exception\LocalizedException(__('Invalid type')); } return $extensions; } @@ -303,7 +303,7 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper * Get storage type name for display. * * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getStorageTypeName() { @@ -315,7 +315,7 @@ class Storage extends \Magento\Framework\App\Helper\AbstractHelper $name = self::IMAGES; break; default: - throw new \Magento\Framework\Exception('Invalid type'); + throw new \Magento\Framework\Exception\LocalizedException(__('Invalid type')); } return $name; diff --git a/app/code/Magento/Theme/Model/Theme/Collection.php b/app/code/Magento/Theme/Model/Theme/Collection.php index 0418a9172a7dbd241d63f2fc5e9c14c719831ed1..2b04f02a1ec18a44d68e39ac099541731c07ef66 100644 --- a/app/code/Magento/Theme/Model/Theme/Collection.php +++ b/app/code/Magento/Theme/Model/Theme/Collection.php @@ -94,13 +94,15 @@ class Collection extends \Magento\Framework\Data\Collection implements ListInter /** * Return target dir for themes with theme configuration file * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return array|string */ public function getTargetPatterns() { if (empty($this->_targetDirs)) { - throw new \Magento\Framework\Exception('Please specify at least one target pattern to theme config file.'); + throw new \Magento\Framework\Exception\LocalizedException( + __('Please specify at least one target pattern to theme config file.') + ); } return $this->_targetDirs; } diff --git a/app/code/Magento/Theme/Model/Theme/File.php b/app/code/Magento/Theme/Model/Theme/File.php index 0f6d4a0dfbb4f9e2f57cf04ee29142a191db6855..0ad82f4a51c2d6f84b5ffe7f8fb24271f36c2e91 100644 --- a/app/code/Magento/Theme/Model/Theme/File.php +++ b/app/code/Magento/Theme/Model/Theme/File.php @@ -122,13 +122,13 @@ class File extends AbstractModel implements FileInterface /** * {@inheritdoc} * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getTheme() { $theme = $this->_themeFactory->create($this->getData('theme_id')); if (!$theme) { - throw new \Magento\Framework\Exception('Theme id should be set'); + throw new \Magento\Framework\Exception\LocalizedException(__('Theme id should be set')); } return $theme; } diff --git a/app/code/Magento/Theme/Model/Wysiwyg/Storage.php b/app/code/Magento/Theme/Model/Wysiwyg/Storage.php index d77a56dc136a8ef708fa08d14df860109c5c3631..5eea783ab9a7d995e8e1d1402eec58f5ff84412a 100644 --- a/app/code/Magento/Theme/Model/Wysiwyg/Storage.php +++ b/app/code/Magento/Theme/Model/Wysiwyg/Storage.php @@ -159,7 +159,7 @@ class Storage $image->keepAspectRatio(true); $image->resize(self::THUMBNAIL_WIDTH, self::THUMBNAIL_HEIGHT); $image->save($this->mediaWriteDirectory->getAbsolutePath($thumbnailPath)); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); return false; } diff --git a/app/code/Magento/Translation/Model/Js/DataProvider.php b/app/code/Magento/Translation/Model/Js/DataProvider.php index a9a83fcf8d6b35d942c43313f9d6204f2c087577..d3f7d156ca83110fe0cb5e60e7face4ef6f053fa 100644 --- a/app/code/Magento/Translation/Model/Js/DataProvider.php +++ b/app/code/Magento/Translation/Model/Js/DataProvider.php @@ -65,7 +65,7 @@ class DataProvider implements DataProviderInterface * @param string $themePath * @return string[] * @throws \Exception - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getData($themePath) { diff --git a/app/code/Magento/UrlRewrite/Block/Catalog/Edit/Form.php b/app/code/Magento/UrlRewrite/Block/Catalog/Edit/Form.php index 75787c73f571d751fd65b04accb79dbdd52154d8..72896f855e57bc407fe0da9461110c61fb8aaba3 100644 --- a/app/code/Magento/UrlRewrite/Block/Catalog/Edit/Form.php +++ b/app/code/Magento/UrlRewrite/Block/Catalog/Edit/Form.php @@ -165,7 +165,7 @@ class Form extends \Magento\UrlRewrite\Block\Edit\Form * Get catalog entity associated stores * * @return array - * @throws \Magento\UrlRewrite\Model\EntityNotAssociatedWithWebsiteException + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getEntityStores() { @@ -183,7 +183,7 @@ class Form extends \Magento\UrlRewrite\Block\Edit\Form $entityStores = array_intersect($entityStores, $categoryStores); } if (!$entityStores) { - throw new \Magento\UrlRewrite\Model\EntityNotAssociatedWithWebsiteException( + throw new \Magento\Framework\Exception\LocalizedException( __( 'We can\'t set up a URL rewrite because the product you chose is not associated with a website.' ) @@ -196,7 +196,7 @@ class Form extends \Magento\UrlRewrite\Block\Edit\Form 'We can\'t set up a URL rewrite because the category you chose is not associated with a website.' ); if (!$entityStores) { - throw new \Magento\UrlRewrite\Model\EntityNotAssociatedWithWebsiteException($message); + throw new \Magento\Framework\Exception\LocalizedException($message); } $this->_requireStoresFilter = true; } diff --git a/app/code/Magento/UrlRewrite/Block/Cms/Page/Edit/Form.php b/app/code/Magento/UrlRewrite/Block/Cms/Page/Edit/Form.php index 865e5ccac116789c1741a474daaa9ab896bca005..e3e28f33127c8cfe490a42e01c0069cde42b2e3c 100644 --- a/app/code/Magento/UrlRewrite/Block/Cms/Page/Edit/Form.php +++ b/app/code/Magento/UrlRewrite/Block/Cms/Page/Edit/Form.php @@ -99,7 +99,7 @@ class Form extends \Magento\UrlRewrite\Block\Edit\Form * Get catalog entity associated stores * * @return array - * @throws \Magento\UrlRewrite\Model\EntityNotAssociatedWithWebsiteException + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getEntityStores() { @@ -112,7 +112,7 @@ class Form extends \Magento\UrlRewrite\Block\Edit\Form $this->_requireStoresFilter = !in_array(0, $entityStores); if (!$entityStores) { - throw new \Magento\UrlRewrite\Model\EntityNotAssociatedWithWebsiteException( + throw new \Magento\Framework\Exception\LocalizedException( __('Chosen cms page does not associated with any website.') ); } diff --git a/app/code/Magento/UrlRewrite/Block/Edit/Form.php b/app/code/Magento/UrlRewrite/Block/Edit/Form.php index 447c2f12c49b86c088866ac0b0036ef0c7e819a9..b4155ad94ae8d4a089554241c04f21ee05f50a5f 100644 --- a/app/code/Magento/UrlRewrite/Block/Edit/Form.php +++ b/app/code/Magento/UrlRewrite/Block/Edit/Form.php @@ -247,7 +247,7 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic ); try { $stores = $this->_getStoresListRestrictedByEntityStores($this->_getEntityStores()); - } catch (\Magento\UrlRewrite\Model\EntityNotAssociatedWithWebsiteException $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $stores = []; $storeElement->setAfterElementHtml($e->getMessage()); } diff --git a/app/code/Magento/UrlRewrite/Model/EntityNotAssociatedWithWebsiteException.php b/app/code/Magento/UrlRewrite/Model/EntityNotAssociatedWithWebsiteException.php deleted file mode 100644 index f43f2cb29498a035927e5e29e4736b05e01afb76..0000000000000000000000000000000000000000 --- a/app/code/Magento/UrlRewrite/Model/EntityNotAssociatedWithWebsiteException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\UrlRewrite\Model; - -class EntityNotAssociatedWithWebsiteException extends \Exception -{ -} diff --git a/app/code/Magento/UrlRewrite/Model/Storage/AbstractStorage.php b/app/code/Magento/UrlRewrite/Model/Storage/AbstractStorage.php index 4664dd4b7e721371c05b41952df26f45865bcc75..7e8c9bb28bfd46f8d09786460af5346ad8d23952 100644 --- a/app/code/Magento/UrlRewrite/Model/Storage/AbstractStorage.php +++ b/app/code/Magento/UrlRewrite/Model/Storage/AbstractStorage.php @@ -81,8 +81,10 @@ abstract class AbstractStorage implements StorageInterface try { $this->doReplace($urls); - } catch (DuplicateEntryException $e) { - throw new DuplicateEntryException(__('URL key for specified store already exists.')); + } catch (\Magento\Framework\Exception\AlreadyExistsException $e) { + throw new \Magento\Framework\Exception\AlreadyExistsException( + __('URL key for specified store already exists.') + ); } } @@ -91,7 +93,7 @@ abstract class AbstractStorage implements StorageInterface * * @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urls * @return int - * @throws DuplicateEntryException + * @throws \Magento\Framework\Exception\AlreadyExistsException */ abstract protected function doReplace($urls); diff --git a/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php b/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php index 519ac3fc6cfc0696c59f3f6288d4bad20ace3f8f..06c0643c6f7bf5736e1cd5eca2872d2aa53915c1 100644 --- a/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php +++ b/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php @@ -102,7 +102,7 @@ class DbStorage extends AbstractStorage * * @param array $data * @return void - * @throws DuplicateEntryException + * @throws \Magento\Framework\Exception\AlreadyExistsException * @throws \Exception */ protected function insertMultiple($data) @@ -113,7 +113,9 @@ class DbStorage extends AbstractStorage if ($e->getCode() === self::ERROR_CODE_DUPLICATE_ENTRY && preg_match('#SQLSTATE\[23000\]: [^:]+: 1062[^\d]#', $e->getMessage()) ) { - throw new DuplicateEntryException(); + throw new \Magento\Framework\Exception\AlreadyExistsException( + __('URL key for specified store already exists.') + ); } throw $e; } diff --git a/app/code/Magento/UrlRewrite/Model/Storage/DuplicateEntryException.php b/app/code/Magento/UrlRewrite/Model/Storage/DuplicateEntryException.php deleted file mode 100644 index afb45715f54bd7f3b81611c874462ce7bed7303b..0000000000000000000000000000000000000000 --- a/app/code/Magento/UrlRewrite/Model/Storage/DuplicateEntryException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\UrlRewrite\Model\Storage; - -class DuplicateEntryException extends \RuntimeException -{ -} diff --git a/app/code/Magento/UrlRewrite/Model/UrlPersistInterface.php b/app/code/Magento/UrlRewrite/Model/UrlPersistInterface.php index 1ff45cec5dc60fff10f0b0044817bb8cf4503b68..014c20e854a3caf652c6a64f87446a70f9d55181 100644 --- a/app/code/Magento/UrlRewrite/Model/UrlPersistInterface.php +++ b/app/code/Magento/UrlRewrite/Model/UrlPersistInterface.php @@ -15,7 +15,7 @@ interface UrlPersistInterface * * @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urls * @return void - * @throws \Magento\UrlRewrite\Model\Storage\DuplicateEntryException + * @throws \Magento\Framework\Exception\AlreadyExistsException */ public function replace(array $urls); diff --git a/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/AbstractStorageTest.php b/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/AbstractStorageTest.php index cf4623f3ac12ba59c82f1216da4f5ae33323eaf4..1216e2ab09c6965b0219ecc09aef49d5d6120145 100644 --- a/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/AbstractStorageTest.php +++ b/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/AbstractStorageTest.php @@ -5,8 +5,6 @@ */ namespace Magento\UrlRewrite\Test\Unit\Model\Storage; -use Magento\UrlRewrite\Model\Storage\DuplicateEntryException; - class AbstractStorageTest extends \PHPUnit_Framework_TestCase { /** @@ -117,7 +115,7 @@ class AbstractStorageTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \RuntimeException + * @expectedException \Magento\Framework\Exception\AlreadyExistsException * @expectedExceptionMessage URL key for specified store already exists. */ public function testReplaceIfThrewDuplicateEntryExceptionWithCustomMessage() @@ -125,7 +123,9 @@ class AbstractStorageTest extends \PHPUnit_Framework_TestCase $this->storage ->expects($this->once()) ->method('doReplace') - ->will($this->throwException(new DuplicateEntryException('Custom storage message'))); + ->will($this->throwException( + new \Magento\Framework\Exception\AlreadyExistsException(__('Custom storage message')) + )); $this->storage->replace([['UrlRewrite1']]); } diff --git a/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php b/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php index 8931b9531802b40a45302d8990e9ea38ae796e46..3be83d41040fac86f15bea417894fb3ea2561345 100644 --- a/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php +++ b/app/code/Magento/UrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php @@ -244,7 +244,7 @@ class DbStorageTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\UrlRewrite\Model\Storage\DuplicateEntryException + * @expectedException \Magento\Framework\Exception\AlreadyExistsException */ public function testReplaceIfThrewDuplicateEntryException() { diff --git a/app/code/Magento/User/Controller/Adminhtml/User/Role/Delete.php b/app/code/Magento/User/Controller/Adminhtml/User/Role/Delete.php old mode 100644 new mode 100755 index ab43536becc1d390e22b6cbf74fcd103d991a701..d9e5da50fc3faa0f5335c4d504e76480a54a9df6 --- a/app/code/Magento/User/Controller/Adminhtml/User/Role/Delete.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/Role/Delete.php @@ -11,7 +11,7 @@ class Delete extends \Magento\User\Controller\Adminhtml\User\Role /** * Remove role action * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect|void */ public function execute() { @@ -25,13 +25,19 @@ class Delete extends \Magento\User\Controller\Adminhtml\User\Role return; } - try { - $this->_initRole()->delete(); - $this->messageManager->addSuccess(__('You deleted the role.')); - } catch (\Exception $e) { - $this->messageManager->addError(__('An error occurred while deleting this role.')); - } + $this->_initRole()->delete(); + $this->messageManager->addSuccess(__('You deleted the role.')); + return $this->getDefaultResult(); + } - $this->_redirect("*/*/"); + /** + * @inheritdoc + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath("*/*/"); } } diff --git a/app/code/Magento/User/Controller/Adminhtml/User/Role/SaveRole.php b/app/code/Magento/User/Controller/Adminhtml/User/Role/SaveRole.php old mode 100644 new mode 100755 index dc382c00a17e0df41a3dbc46db36d618b3d6aca4..e5400e79a692ce75c2e69432ed41fabfb38f558f --- a/app/code/Magento/User/Controller/Adminhtml/User/Role/SaveRole.php +++ b/app/code/Magento/User/Controller/Adminhtml/User/Role/SaveRole.php @@ -52,7 +52,7 @@ class SaveRole extends \Magento\User\Controller\Adminhtml\User\Role /** * Role form submit action to save or create new role * - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { @@ -74,39 +74,41 @@ class SaveRole extends \Magento\User\Controller\Adminhtml\User\Role $role = $this->_initRole('role_id'); if (!$role->getId() && $rid) { $this->messageManager->addError(__('This role no longer exists.')); - $this->_redirect('adminhtml/*/'); - return; + return $this->getDefaultResult(); } - try { - $roleName = $this->_filterManager->removeTags($this->getRequest()->getParam('rolename', false)); - - $role->setName($roleName) - ->setPid($this->getRequest()->getParam('parent_id', false)) - ->setRoleType(RoleGroup::ROLE_TYPE) - ->setUserType(UserContextInterface::USER_TYPE_ADMIN); - $this->_eventManager->dispatch( - 'admin_permissions_role_prepare_save', - ['object' => $role, 'request' => $this->getRequest()] - ); - $role->save(); + $roleName = $this->_filterManager->removeTags($this->getRequest()->getParam('rolename', false)); + $role->setName($roleName) + ->setPid($this->getRequest()->getParam('parent_id', false)) + ->setRoleType(RoleGroup::ROLE_TYPE) + ->setUserType(UserContextInterface::USER_TYPE_ADMIN); + $this->_eventManager->dispatch( + 'admin_permissions_role_prepare_save', + ['object' => $role, 'request' => $this->getRequest()] + ); + $role->save(); - $this->_rulesFactory->create()->setRoleId($role->getId())->setResources($resource)->saveRel(); + $this->_rulesFactory->create()->setRoleId($role->getId())->setResources($resource)->saveRel(); - foreach ($oldRoleUsers as $oUid) { - $this->_deleteUserFromRole($oUid, $role->getId()); - } + foreach ($oldRoleUsers as $oUid) { + $this->_deleteUserFromRole($oUid, $role->getId()); + } - foreach ($roleUsers as $nRuid) { - $this->_addUserToRole($nRuid, $role->getId()); - } - $this->messageManager->addSuccess(__('You saved the role.')); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addError(__('An error occurred while saving this role.')); + foreach ($roleUsers as $nRuid) { + $this->_addUserToRole($nRuid, $role->getId()); } - $this->_redirect('adminhtml/*/'); - return; + $this->messageManager->addSuccess(__('You saved the role.')); + return $this->getDefaultResult(); + } + + /** + * @inheritdoc + * + * @return \Magento\Backend\Model\View\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('adminhtml/*/'); } } diff --git a/app/code/Magento/Variable/Controller/Adminhtml/System/Variable.php b/app/code/Magento/Variable/Controller/Adminhtml/System/Variable.php index 594ebf3aa0c37468e8304f461da415eb992169e6..918e6094d9b7e087b2e11f4f1d810cdce14936bd 100644 --- a/app/code/Magento/Variable/Controller/Adminhtml/System/Variable.php +++ b/app/code/Magento/Variable/Controller/Adminhtml/System/Variable.php @@ -21,11 +21,6 @@ class Variable extends Action */ protected $_coreRegistry; - /** - * @var \Magento\Backend\Model\View\Result\RedirectFactory - */ - protected $resultRedirectFactory; - /** * @var \Magento\Backend\Model\View\Result\ForwardFactory */ @@ -49,7 +44,6 @@ class Variable extends Action /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory @@ -58,7 +52,6 @@ class Variable extends Action public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, @@ -66,7 +59,6 @@ class Variable extends Action ) { $this->_coreRegistry = $coreRegistry; parent::__construct($context); - $this->resultRedirectFactory = $resultRedirectFactory; $this->resultForwardFactory = $resultForwardFactory; $this->resultJsonFactory = $resultJsonFactory; $this->resultPageFactory = $resultPageFactory; diff --git a/app/code/Magento/Webapi/Model/Soap/Fault.php b/app/code/Magento/Webapi/Model/Soap/Fault.php index c48d6fb55bc1e7f8c82d3301094865bfeae89a2a..c6cf9637602e9a0168de9f13af05fd9306d0bc13 100644 --- a/app/code/Magento/Webapi/Model/Soap/Fault.php +++ b/app/code/Magento/Webapi/Model/Soap/Fault.php @@ -9,7 +9,7 @@ namespace Magento\Webapi\Model\Soap; use Magento\Framework\App\State; -class Fault extends \RuntimeException +class Fault { const FAULT_REASON_INTERNAL = 'Internal Error.'; @@ -90,24 +90,35 @@ class Fault extends \RuntimeException */ protected $appState; + /** + * @var null|string + */ + protected $stackTrace; + + /** + * @var string + */ + protected $message; + /** * @param \Magento\Framework\App\RequestInterface $request * @param Server $soapServer - * @param \Magento\Framework\Webapi\Exception $previousException + * @param \Magento\Framework\Webapi\Exception $exception * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param State $appState */ public function __construct( \Magento\Framework\App\RequestInterface $request, Server $soapServer, - \Magento\Framework\Webapi\Exception $previousException, + \Magento\Framework\Webapi\Exception $exception, \Magento\Framework\Locale\ResolverInterface $localeResolver, State $appState ) { - parent::__construct($previousException->getMessage(), $previousException->getCode(), $previousException); - $this->_soapCode = $previousException->getOriginator(); - $this->_parameters = $previousException->getDetails(); - $this->_wrappedErrors = $previousException->getErrors(); + $this->_soapCode = $exception->getOriginator(); + $this->_parameters = $exception->getDetails(); + $this->_wrappedErrors = $exception->getErrors(); + $this->stackTrace = $exception->getStackTrace() ?: $exception->getTraceAsString(); + $this->message = $exception->getMessage(); $this->_request = $request; $this->_soapServer = $soapServer; $this->_localeResolver = $localeResolver; @@ -122,10 +133,7 @@ class Fault extends \RuntimeException public function toXml() { if ($this->appState->getMode() == State::MODE_DEVELOPER) { - $traceDetail = $this->getPrevious()->getStackTrace() - ? $this->getPrevious()->getStackTrace() - : $this->getTraceAsString(); - $this->addDetails([self::NODE_DETAIL_TRACE => "<![CDATA[{$traceDetail}]]>"]); + $this->addDetails([self::NODE_DETAIL_TRACE => "<![CDATA[{$this->stackTrace}]]>"]); } if ($this->getParameters()) { $this->addDetails([self::NODE_DETAIL_PARAMETERS => $this->getParameters()]); @@ -199,6 +207,14 @@ class Fault extends \RuntimeException return \Locale::getPrimaryLanguage($this->_localeResolver->getLocale()); } + /** + * @return string + */ + public function getMessage() + { + return $this->message; + } + /** * Generate SOAP fault message in XML format. * diff --git a/app/code/Magento/Webapi/Model/Soap/Server.php b/app/code/Magento/Webapi/Model/Soap/Server.php index 02370c9fc4f75302e884621d067eb3a5588cc7a0..9e9ee5f9a8db29924b980958f11ef62d9aa4cf7a 100644 --- a/app/code/Magento/Webapi/Model/Soap/Server.php +++ b/app/code/Magento/Webapi/Model/Soap/Server.php @@ -86,7 +86,7 @@ class Server ) { if (!extension_loaded('soap')) { throw new \Magento\Framework\Webapi\Exception( - 'SOAP extension is not loaded.', + __('SOAP extension is not loaded.'), 0, \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR ); diff --git a/app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php b/app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php index fa71cf08332d5ed0f9f5a1111c1cc5d60ccdd6d7..b1feef3a5282113e8da229caa0cb138b71004dce 100644 --- a/app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php @@ -135,7 +135,7 @@ class SoapTest extends \PHPUnit_Framework_TestCase public function testDispatchWithException() { $exceptionMessage = 'some error message'; - $exception = new \Magento\Framework\Webapi\Exception($exceptionMessage); + $exception = new \Magento\Framework\Webapi\Exception(__($exceptionMessage)); $this->_soapServerMock->expects($this->any())->method('handle')->will($this->throwException($exception)); $this->_errorProcessorMock->expects( $this->any() diff --git a/app/code/Magento/Webapi/Test/Unit/ExceptionTest.php b/app/code/Magento/Webapi/Test/Unit/ExceptionTest.php index 7c0ed509e321d1c348ff54ff7dcda1229b9f675f..ed5d4075fb694d0e5ea85fc9ca4c06264bb5a822 100644 --- a/app/code/Magento/Webapi/Test/Unit/ExceptionTest.php +++ b/app/code/Magento/Webapi/Test/Unit/ExceptionTest.php @@ -17,7 +17,7 @@ class ExceptionTest extends \PHPUnit_Framework_TestCase $code = 1111; $details = ['key1' => 'value1', 'key2' => 'value2']; $apiException = new \Magento\Framework\Webapi\Exception( - 'Message', + __('Message'), $code, \Magento\Framework\Webapi\Exception::HTTP_UNAUTHORIZED, $details @@ -46,13 +46,13 @@ class ExceptionTest extends \PHPUnit_Framework_TestCase $this->setExpectedException('InvalidArgumentException', "The specified HTTP code \"{$httpCode}\" is invalid."); /** Create \Magento\Framework\Webapi\Exception object with invalid code. */ /** Valid codes range is from 400 to 599. */ - new \Magento\Framework\Webapi\Exception('Message', 0, $httpCode); + new \Magento\Framework\Webapi\Exception(__('Message'), 0, $httpCode); } public function testGetOriginatorSender() { $apiException = new \Magento\Framework\Webapi\Exception( - 'Message', + __('Message'), 0, \Magento\Framework\Webapi\Exception::HTTP_UNAUTHORIZED ); @@ -67,7 +67,7 @@ class ExceptionTest extends \PHPUnit_Framework_TestCase public function testGetOriginatorReceiver() { $apiException = new \Magento\Framework\Webapi\Exception( - 'Message', + __('Message'), 0, \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR ); diff --git a/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php b/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php index fa0c51de71a8019044be6578cd7bab7158450e75..e0ea010724d62b7a97af4d9639e83f27dcacf2cb 100644 --- a/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php @@ -41,7 +41,7 @@ class FaultTest extends \PHPUnit_Framework_TestCase $details = ['param1' => 'value1', 'param2' => 2]; $code = 111; $webapiException = new \Magento\Framework\Webapi\Exception( - $message, + __($message), $code, \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR, $details @@ -211,7 +211,7 @@ XML; $details = ['param1' => 'value1', 'param2' => 2]; $code = 111; $webapiException = new \Magento\Framework\Webapi\Exception( - $message, + __($message), $code, \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR, $details diff --git a/app/code/Magento/Webapi/Test/Unit/Model/Soap/Wsdl/GeneratorTest.php b/app/code/Magento/Webapi/Test/Unit/Model/Soap/Wsdl/GeneratorTest.php index 2cf3ea04adba8613149537bf8dc9225c880032af..1d85bb91709df7d9fc1d839a80d164ef1186df05 100644 --- a/app/code/Magento/Webapi/Test/Unit/Model/Soap/Wsdl/GeneratorTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Model/Soap/Wsdl/GeneratorTest.php @@ -204,13 +204,9 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase ] )->getMock(); - $wsdlGeneratorMock->expects( - $this->once() - )->method( - '_collectCallInfo' - )->will( - $this->throwException(new \Magento\Framework\Webapi\Exception($exceptionMsg)) - ); + $wsdlGeneratorMock->expects($this->once()) + ->method('_collectCallInfo') + ->willThrowException(new \Magento\Framework\Webapi\Exception(__($exceptionMsg))); $this->assertEquals($genWSDL, $wsdlGeneratorMock->generate($requestedService, 'http://magento.host')); } diff --git a/app/code/Magento/Weee/Helper/Data.php b/app/code/Magento/Weee/Helper/Data.php index 85a6fa8e2776a21a2675bb6f3503bd4f6d1b36ca..306e860b7fb556d40dafdfff8178d70898f5e8e6 100644 --- a/app/code/Magento/Weee/Helper/Data.php +++ b/app/code/Magento/Weee/Helper/Data.php @@ -400,12 +400,12 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper * * @param \Magento\Framework\Object[] $attributes Result from getProductWeeeAttributes() * @return float - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getAmountInclTaxes($attributes) { if (!is_array($attributes)) { - throw new \Magento\Framework\Exception('$attributes must be an array'); + throw new \Magento\Framework\Exception\LocalizedException(__('$attributes must be an array')); } $amount = 0; diff --git a/app/code/Magento/Wishlist/Controller/Index/Add.php b/app/code/Magento/Wishlist/Controller/Index/Add.php old mode 100644 new mode 100755 index d957719932a2bdac2c787d9f46b72e0a7b66bb72..5adebd054bbefa21b0b84c0147be8988fd6a0ad9 --- a/app/code/Magento/Wishlist/Controller/Index/Add.php +++ b/app/code/Magento/Wishlist/Controller/Index/Add.php @@ -8,7 +8,7 @@ namespace Magento\Wishlist\Controller\Index; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\App\Action; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Wishlist\Controller\IndexInterface; @@ -60,7 +60,7 @@ class Add extends Action\Action implements IndexInterface { $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $session = $this->_customerSession; diff --git a/app/code/Magento/Wishlist/Controller/Index/Configure.php b/app/code/Magento/Wishlist/Controller/Index/Configure.php index 61d685b771278add911bb996572a18151d6c82be..8172c895ed70e361cdeff01b31484bd69917a396 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Configure.php +++ b/app/code/Magento/Wishlist/Controller/Index/Configure.php @@ -7,7 +7,7 @@ namespace Magento\Wishlist\Controller\Index; use Magento\Framework\App\Action; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Wishlist\Controller\IndexInterface; class Configure extends Action\Action implements IndexInterface @@ -65,7 +65,7 @@ class Configure extends Action\Action implements IndexInterface } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $this->_coreRegistry->register('wishlist_item', $item); diff --git a/app/code/Magento/Wishlist/Controller/Index/Fromcart.php b/app/code/Magento/Wishlist/Controller/Index/Fromcart.php old mode 100644 new mode 100755 index 2bf785573e273813fe50c286b3b40f69cada4ab8..085cf426a0a37cacae5decf0bfa6e020e229b6fb --- a/app/code/Magento/Wishlist/Controller/Index/Fromcart.php +++ b/app/code/Magento/Wishlist/Controller/Index/Fromcart.php @@ -7,7 +7,7 @@ namespace Magento\Wishlist\Controller\Index; use Magento\Framework\App\Action; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Wishlist\Controller\IndexInterface; class Fromcart extends Action\Action implements IndexInterface @@ -32,53 +32,57 @@ class Fromcart extends Action\Action implements IndexInterface /** * Add cart item to wishlist and remove from cart * - * @return \Magento\Framework\App\Response\Http + * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function execute() { $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $itemId = (int)$this->getRequest()->getParam('item'); /* @var \Magento\Checkout\Model\Cart $cart */ $cart = $this->_objectManager->get('Magento\Checkout\Model\Cart'); - $session = $this->_objectManager->get('Magento\Checkout\Model\Session'); + $this->_objectManager->get('Magento\Checkout\Model\Session'); - try { - $item = $cart->getQuote()->getItemById($itemId); - if (!$item) { - throw new \Magento\Framework\Exception\LocalizedException( - __('The requested cart item doesn\'t exist.') - ); - } + $item = $cart->getQuote()->getItemById($itemId); + if (!$item) { + throw new \Magento\Framework\Exception\LocalizedException( + __('The requested cart item doesn\'t exist.') + ); + } - $productId = $item->getProductId(); - $buyRequest = $item->getBuyRequest(); + $productId = $item->getProductId(); + $buyRequest = $item->getBuyRequest(); - $wishlist->addNewItem($productId, $buyRequest); + $wishlist->addNewItem($productId, $buyRequest); - $productIds[] = $productId; - $cart->getQuote()->removeItem($itemId); - $cart->save(); - $this->_objectManager->get('Magento\Wishlist\Helper\Data')->calculate(); - $productName = $this->_objectManager->get('Magento\Framework\Escaper') - ->escapeHtml($item->getProduct()->getName()); - $wishlistName = $this->_objectManager->get('Magento\Framework\Escaper') - ->escapeHtml($wishlist->getName()); - $this->messageManager->addSuccess(__("%1 has been moved to wish list %2", $productName, $wishlistName)); - $wishlist->save(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addException($e, __('We can\'t move the item to the wish list.')); - } + $productIds[] = $productId; + $cart->getQuote()->removeItem($itemId); + $cart->save(); + $this->_objectManager->get('Magento\Wishlist\Helper\Data')->calculate(); + $productName = $this->_objectManager->get('Magento\Framework\Escaper') + ->escapeHtml($item->getProduct()->getName()); + $wishlistName = $this->_objectManager->get('Magento\Framework\Escaper') + ->escapeHtml($wishlist->getName()); + $this->messageManager->addSuccess(__("%1 has been moved to wish list %2", $productName, $wishlistName)); + $wishlist->save(); + + return $this->getDefaultResult(); + } - return $this->getResponse()->setRedirect( - $this->_objectManager->get('Magento\Checkout\Helper\Cart')->getCartUrl() - ); + /** + * @inheritdoc + * + * @return \Magento\Framework\Controller\Result\Redirect + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setUrl($this->_objectManager->get('Magento\Checkout\Helper\Cart')->getCartUrl()); } } diff --git a/app/code/Magento/Wishlist/Controller/Index/Index.php b/app/code/Magento/Wishlist/Controller/Index/Index.php index 56f08a2e53190b4d28b46d11c9e23642c6b72ea5..9cb4bbe9fcdb089edab3d242f6a648b128c55890 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Index.php +++ b/app/code/Magento/Wishlist/Controller/Index/Index.php @@ -7,7 +7,7 @@ namespace Magento\Wishlist\Controller\Index; use Magento\Framework\App\Action; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Wishlist\Controller\IndexInterface; class Index extends Action\Action implements IndexInterface @@ -38,7 +38,7 @@ class Index extends Action\Action implements IndexInterface public function execute() { if (!$this->wishlistProvider->getWishlist()) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $this->_view->loadLayout(); $this->_view->getLayout()->initMessages(); diff --git a/app/code/Magento/Wishlist/Controller/Index/Plugin.php b/app/code/Magento/Wishlist/Controller/Index/Plugin.php index 423d631f212d4c3b4cea88a187e04e5a7a9ed486..76c05b3d3e6892a997b04d06d8fcbff0eaa1e8a7 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Plugin.php +++ b/app/code/Magento/Wishlist/Controller/Index/Plugin.php @@ -7,7 +7,7 @@ namespace Magento\Wishlist\Controller\Index; use Magento\Customer\Model\Session as CustomerSession; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\Response\RedirectInterface; @@ -58,7 +58,7 @@ class Plugin * @param \Magento\Framework\App\ActionInterface $subject * @param RequestInterface $request * @return void - * @throws \Magento\Framework\App\Action\NotFoundException + * @throws \Magento\Framework\Exception\NotFoundException */ public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request) { @@ -70,7 +70,7 @@ class Plugin $this->customerSession->setBeforeWishlistRequest($request->getParams()); } if (!$this->config->isSetFlag('wishlist/general/active')) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } } } diff --git a/app/code/Magento/Wishlist/Controller/Index/Remove.php b/app/code/Magento/Wishlist/Controller/Index/Remove.php index 0890e174dd1fc4db6987df35cd92f7867e5ee198..674d1118a614689e2c25958bb205c3eb5be668ae 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Remove.php +++ b/app/code/Magento/Wishlist/Controller/Index/Remove.php @@ -7,7 +7,7 @@ namespace Magento\Wishlist\Controller\Index; use Magento\Framework\App\Action; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Wishlist\Controller\IndexInterface; class Remove extends Action\Action implements IndexInterface @@ -40,11 +40,11 @@ class Remove extends Action\Action implements IndexInterface $id = (int)$this->getRequest()->getParam('item'); $item = $this->_objectManager->create('Magento\Wishlist\Model\Item')->load($id); if (!$item->getId()) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } try { $item->delete(); diff --git a/app/code/Magento/Wishlist/Controller/Index/Send.php b/app/code/Magento/Wishlist/Controller/Index/Send.php index c1ea762f0be24ed13665e2166e3f8772508c6770..6a54e1b7bf9f0ba2da61da6f0976f40f0ab81b9a 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Send.php +++ b/app/code/Magento/Wishlist/Controller/Index/Send.php @@ -7,7 +7,7 @@ namespace Magento\Wishlist\Controller\Index; use Magento\Framework\App\Action; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\App\ResponseInterface; use Magento\Wishlist\Controller\IndexInterface; @@ -98,7 +98,7 @@ class Send extends Action\Action implements IndexInterface $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit(); diff --git a/app/code/Magento/Wishlist/Controller/Index/Update.php b/app/code/Magento/Wishlist/Controller/Index/Update.php index 8e372f3265fe2faadd6e5f1e483ad0cc54e17b77..731a80cd743570abb624ee89bee2fb5a2e5179eb 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Update.php +++ b/app/code/Magento/Wishlist/Controller/Index/Update.php @@ -7,7 +7,7 @@ namespace Magento\Wishlist\Controller\Index; use Magento\Framework\App\Action; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\App\ResponseInterface; use Magento\Wishlist\Controller\IndexInterface; @@ -61,7 +61,7 @@ class Update extends Action\Action implements IndexInterface } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } $post = $this->getRequest()->getPostValue(); diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/AddTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/AddTest.php old mode 100644 new mode 100755 index 6b6695e96fa80008a4b0010f77c751f0c8f88e3a..98fbbc933f8a1da2f837a85079624e6ce180a314 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/AddTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/AddTest.php @@ -222,10 +222,11 @@ class AddTest extends \PHPUnit_Framework_TestCase ); } + /** + * @expectedException \Magento\Framework\Exception\NotFoundException + */ public function testExecuteWithoutWishList() { - $this->setExpectedException('Magento\Framework\App\Action\NotFoundException'); - $this->wishlistProvider ->expects($this->once()) ->method('getWishlist') diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/IndexTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/IndexTest.php index 7199faa0652cb2eb5d9af9f4f585d83bd47c1113..94888effcc121310c5f861654cf5638180e11860 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/IndexTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/IndexTest.php @@ -103,10 +103,11 @@ class IndexTest extends \PHPUnit_Framework_TestCase ); } + /** + * @expectedException \Magento\Framework\Exception\NotFoundException + */ public function testExecuteWithoutWishlist() { - $this->setExpectedException('Magento\Framework\App\Action\NotFoundException'); - $this->wishlistProvider ->expects($this->once()) ->method('getWishlist') diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/PluginTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/PluginTest.php index 7349d98623d3fde8d9406c2d625399c6fc131252..163cb1367e1c0d90069ab5a45d9240db5a2518de 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/PluginTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/PluginTest.php @@ -63,10 +63,11 @@ class PluginTest extends \PHPUnit_Framework_TestCase ); } + /** + * @expectedException \Magento\Framework\Exception\NotFoundException + */ public function testBeforeDispatch() { - $this->setExpectedException('Magento\Framework\App\Action\NotFoundException'); - $actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false); $indexController = $this->getMock('Magento\Wishlist\Controller\Index\Index', [], [], '', false); diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/RemoveTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/RemoveTest.php index 9dde615c6d4c0ac0162c82ede0214b4b772d988d..f2c2954f59d739e122c5e7b2b174136a1731cb9a 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/RemoveTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/RemoveTest.php @@ -133,10 +133,11 @@ class RemoveTest extends \PHPUnit_Framework_TestCase ); } + /** + * @expectedException \Magento\Framework\Exception\NotFoundException + */ public function testExecuteWithoutItem() { - $this->setExpectedException('Magento\Framework\App\Action\NotFoundException'); - $item = $this->getMock('Magento\Wishlist\Model\Item', [], [], '', false); $item ->expects($this->once()) @@ -163,10 +164,11 @@ class RemoveTest extends \PHPUnit_Framework_TestCase $this->getController()->execute(); } + /** + * @expectedException \Magento\Framework\Exception\NotFoundException + */ public function testExecuteWithoutWishlist() { - $this->setExpectedException('Magento\Framework\App\Action\NotFoundException'); - $item = $this->getMock('Magento\Wishlist\Model\Item', [], [], '', false); $item ->expects($this->once()) diff --git a/app/etc/di.xml b/app/etc/di.xml index cb45113bb261c8ce90486a5a1d4be251fc658744..7fbdfe5005a4f95c83050990570b91a563cb5042 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1074,6 +1074,12 @@ </argument> </arguments> </type> + <type name="Magento\Framework\App\FrontController"> + <arguments> + <argument name="appState" xsi:type="object">Magento\Framework\App\State\Proxy</argument> + <argument name="messageManager" xsi:type="object">Magento\Framework\Message\ManagerInterface\Proxy</argument> + </arguments> + </type> <type name="Magento\Framework\Webapi\Rest\Request\DeserializerFactory"> <arguments> <argument name="deserializers" xsi:type="array"> diff --git a/dev/tests/api-functional/_files/Magento/TestModule3/Service/V1/Error.php b/dev/tests/api-functional/_files/Magento/TestModule3/Service/V1/Error.php index 9ef7c6bda142674f4ebdbb87bef10d5bc720109d..eca76949e1cd41749f7a076b4ac98d680aff8f05 100644 --- a/dev/tests/api-functional/_files/Magento/TestModule3/Service/V1/Error.php +++ b/dev/tests/api-functional/_files/Magento/TestModule3/Service/V1/Error.php @@ -72,7 +72,7 @@ class Error implements \Magento\TestModule3\Service\V1\ErrorInterface public function webapiException() { throw new \Magento\Framework\Webapi\Exception( - 'Service not found', + __('Service not found'), 5555, \Magento\Framework\Webapi\Exception::HTTP_NOT_FOUND ); diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiDataFixture.php b/dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiDataFixture.php index 749c0de354ea2b9530f392c478be5eea5ccf5e61..1225eb5340e8a420b3839c3fa6d56749bce77224 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiDataFixture.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiDataFixture.php @@ -32,12 +32,14 @@ class ApiDataFixture * Constructor * * @param string $fixtureBaseDir - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct($fixtureBaseDir) { if (!is_dir($fixtureBaseDir)) { - throw new \Magento\Framework\Exception("Fixture base directory '{$fixtureBaseDir}' does not exist."); + throw new \Magento\Framework\Exception\LocalizedException( + __("Fixture base directory '%1' does not exist.", $fixtureBaseDir) + ); } $this->_fixtureBaseDir = realpath($fixtureBaseDir); } @@ -67,7 +69,7 @@ class ApiDataFixture * @param string $scope 'class' or 'method' * @param \PHPUnit_Framework_TestCase $test * @return array - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getFixtures($scope, \PHPUnit_Framework_TestCase $test) { @@ -77,7 +79,9 @@ class ApiDataFixture foreach ($annotations[$scope]['magentoApiDataFixture'] as $fixture) { if (strpos($fixture, '\\') !== false) { // usage of a single directory separator symbol streamlines search across the source code - throw new \Magento\Framework\Exception('Directory separator "\\" is prohibited in fixture declaration.'); + throw new \Magento\Framework\Exception\LocalizedException( + __('Directory separator "\\" is prohibited in fixture declaration.') + ); } $fixtureMethod = [get_class($test), $fixture]; if (is_callable($fixtureMethod)) { @@ -115,7 +119,7 @@ class ApiDataFixture * Execute fixture scripts if any * * @param array $fixtures - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _applyFixtures(array $fixtures) { diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php index 3891bc1870b3f75de6878ee72300cee8d7157163..c46a71474c3f5fb7fc7fe2b938ff306586e177d2 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php @@ -41,7 +41,7 @@ class AppArea * * @param array $annotations * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getTestAppArea($annotations) { @@ -56,8 +56,11 @@ class AppArea ) : \Magento\TestFramework\Application::DEFAULT_APP_AREA); if (false == in_array($area, $this->_allowedAreas)) { - throw new \Magento\Framework\Exception( - 'Invalid "@magentoAppArea" annotation, can be "' . implode('", "', $this->_allowedAreas) . '" only.' + throw new \Magento\Framework\Exception\LocalizedException( + __( + 'Invalid "@magentoAppArea" annotation, can be "%1" only.', + implode('", "', $this->_allowedAreas) + ) ); } diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppIsolation.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppIsolation.php index 605010c165afc8b4dbb845dcc24169490e244cf2..19c2cbe3682c206d40f118ea690a5be6f34d3420 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppIsolation.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/AppIsolation.php @@ -56,7 +56,7 @@ class AppIsolation * Handler for 'endTest' event * * @param \PHPUnit_Framework_TestCase $test - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function endTest(\PHPUnit_Framework_TestCase $test) { @@ -68,8 +68,8 @@ class AppIsolation if (isset($annotations['magentoAppIsolation'])) { $isolation = $annotations['magentoAppIsolation']; if ($isolation !== ['enabled'] && $isolation !== ['disabled']) { - throw new \Magento\Framework\Exception( - 'Invalid "@magentoAppIsolation" annotation, can be "enabled" or "disabled" only.' + throw new \Magento\Framework\Exception\LocalizedException( + __('Invalid "@magentoAppIsolation" annotation, can be "enabled" or "disabled" only.') ); } $isIsolationEnabled = $isolation === ['enabled']; diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php index c4c4f131b497e5be050a736ff52355bcdd3527c6..cf59f4469af36823c7fc5ca558e2fa8028728a09 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php @@ -27,12 +27,14 @@ class DataFixture * Constructor * * @param string $fixtureBaseDir - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct($fixtureBaseDir) { if (!is_dir($fixtureBaseDir)) { - throw new \Magento\Framework\Exception("Fixture base directory '{$fixtureBaseDir}' does not exist."); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Fixture base directory '%1' does not exist.", [$fixtureBaseDir]) + ); } $this->_fixtureBaseDir = realpath($fixtureBaseDir); } @@ -101,7 +103,7 @@ class DataFixture * @param \PHPUnit_Framework_TestCase $test * @param string $scope * @return array - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getFixtures(\PHPUnit_Framework_TestCase $test, $scope = null) { @@ -115,8 +117,8 @@ class DataFixture foreach ($annotations['magentoDataFixture'] as $fixture) { if (strpos($fixture, '\\') !== false) { // usage of a single directory separator symbol streamlines search across the source code - throw new \Magento\Framework\Exception( - 'Directory separator "\\" is prohibited in fixture declaration.' + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Directory separator "\\" is prohibited in fixture declaration.') ); } $fixtureMethod = [get_class($test), $fixture]; @@ -179,7 +181,7 @@ class DataFixture * Execute fixture scripts if any * * @param array $fixtures - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _applyFixtures(array $fixtures) { diff --git a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DbIsolation.php b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DbIsolation.php index 7ff949fb7a638f43d515b59ab8cd481e47581302..b405c205062a86342defd8a366093b66da79e334 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Annotation/DbIsolation.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Annotation/DbIsolation.php @@ -80,7 +80,7 @@ class DbIsolation * * @param \PHPUnit_Framework_TestCase $test * @return bool|null Returns NULL, if isolation is not defined for the current scope - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getIsolation(\PHPUnit_Framework_TestCase $test) { @@ -88,8 +88,8 @@ class DbIsolation if (isset($annotations[self::MAGENTO_DB_ISOLATION])) { $isolation = $annotations[self::MAGENTO_DB_ISOLATION]; if ($isolation !== ['enabled'] && $isolation !== ['disabled']) { - throw new \Magento\Framework\Exception( - 'Invalid "@magentoDbIsolation" annotation, can be "enabled" or "disabled" only.' + throw new \Magento\Framework\Exception\LocalizedException( + __('Invalid "@magentoDbIsolation" annotation, can be "enabled" or "disabled" only.') ); } return $isolation === ['enabled']; diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index b8d9e4424ce956d9840dc22b6ceabbcea6e0d4a0..c640f29e7381a2be153bccc2496f41f189884d02 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -331,7 +331,7 @@ class Application \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->configure( $objectManager->get('Magento\Framework\ObjectManager\DynamicConfigInterface')->getConfiguration() ); - \Magento\Framework\Phrase::setRenderer($objectManager->get('Magento\Framework\Phrase\RendererInterface')); + \Magento\Framework\Phrase::setRenderer($objectManager->get('Magento\Framework\Phrase\Renderer\Placeholder')); } /** @@ -380,7 +380,7 @@ class Application * Install an application * * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function install() { @@ -509,7 +509,7 @@ class Application * * @param string $dir * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _ensureDirExists($dir) { @@ -518,7 +518,7 @@ class Application mkdir($dir, 0777); umask($old); } elseif (!is_dir($dir)) { - throw new \Magento\Framework\Exception("'$dir' is not a directory."); + throw new \Magento\Framework\Exception\LocalizedException(__("'%1' is not a directory.", $dir)); } } diff --git a/dev/tests/integration/framework/Magento/TestFramework/Bootstrap/Settings.php b/dev/tests/integration/framework/Magento/TestFramework/Bootstrap/Settings.php index dec3fa8d6d6cf2c7c8cf82f148ff7540ca48dbd1..df65d4dd37d6ad68d66a19d7904cc0ea82ec3852 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Bootstrap/Settings.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Bootstrap/Settings.php @@ -86,7 +86,7 @@ class Settings * * @param string $settingName * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getAsConfigFile($settingName) { @@ -99,7 +99,9 @@ class Settings return $result; } } - throw new \Magento\Framework\Exception("Setting '{$settingName}' specifies the non-existing file '{$result}'."); + throw new \Magento\Framework\Exception\LocalizedException( + __("Setting '%1' specifies the non-existing file '%2'.", $settingName, $result) + ); } /** diff --git a/dev/tests/integration/framework/Magento/TestFramework/Event/Magento.php b/dev/tests/integration/framework/Magento/TestFramework/Event/Magento.php index 08812d8caf3b5f758a1f447e02dbf602d8a339ad..95d35b39eb61bc186d8a44a9e0647e915d86887c 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Event/Magento.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Event/Magento.php @@ -37,13 +37,15 @@ class Magento * Constructor * * @param \Magento\TestFramework\EventManager $eventManager - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct($eventManager = null) { $this->_eventManager = $eventManager ?: self::$_defaultEventManager; if (!$this->_eventManager instanceof \Magento\TestFramework\EventManager) { - throw new \Magento\Framework\Exception('Instance of the "Magento\TestFramework\EventManager" is expected.'); + throw new \Magento\Framework\Exception\LocalizedException( + __('Instance of the "Magento\TestFramework\EventManager" is expected.') + ); } } diff --git a/dev/tests/integration/framework/Magento/TestFramework/Event/PhpUnit.php b/dev/tests/integration/framework/Magento/TestFramework/Event/PhpUnit.php index d19fac4a9168a88197f31ad8bbcb76a79585ed7e..6f1413cd62060d25e6f99f3858fae6e010e9dd1d 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Event/PhpUnit.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Event/PhpUnit.php @@ -37,13 +37,13 @@ class PhpUnit implements \PHPUnit_Framework_TestListener * Constructor * * @param \Magento\TestFramework\EventManager $eventManager - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct(\Magento\TestFramework\EventManager $eventManager = null) { $this->_eventManager = $eventManager ?: self::$_defaultEventManager; if (!$this->_eventManager) { - throw new \Magento\Framework\Exception('Instance of the event manager is required.'); + throw new \Magento\Framework\Exception\LocalizedException(__('Instance of the event manager is required.')); } } diff --git a/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php b/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php index 6385156cea5ac2e2a8054b4170eded82826c7b98..80284facfa2fa2ac84d3e2461fbb6d105d83944e 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php @@ -121,7 +121,7 @@ class Transaction * * @param string $connectionName 'read' or 'write' * @return \Magento\Framework\DB\Adapter\AdapterInterface|\Magento\TestFramework\Db\Adapter\TransactionInterface - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getAdapter($connectionName = 'core_write') { diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Bootstrap.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Bootstrap.php index 8af390fa3c700cb195ff156447e6d7ca49977f89..8ca820180227565aa3a97ef105e883a874922ae7 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Bootstrap.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Bootstrap.php @@ -30,12 +30,12 @@ class Bootstrap * Set self instance for static access * * @param \Magento\TestFramework\Helper\Bootstrap $instance - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public static function setInstance(\Magento\TestFramework\Helper\Bootstrap $instance) { if (self::$_instance) { - throw new \Magento\Framework\Exception('Helper instance cannot be redefined.'); + throw new \Magento\Framework\Exception\LocalizedException(__('Helper instance cannot be redefined.')); } self::$_instance = $instance; } @@ -44,12 +44,12 @@ class Bootstrap * Self instance getter * * @return \Magento\TestFramework\Helper\Bootstrap - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public static function getInstance() { if (!self::$_instance) { - throw new \Magento\Framework\Exception('Helper instance is not defined yet.'); + throw new \Magento\Framework\Exception\LocalizedException(__('Helper instance is not defined yet.')); } return self::$_instance; } diff --git a/dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php b/dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php index f0cda8af73017be53f971c1bb7fd92f079509034..f4c0b07709a801ecd9b79728bed573cad63d6b26 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php @@ -50,7 +50,7 @@ class Memory // try to use the Windows command line // some ports of Unix commands on Windows, such as MinGW, have limited capabilities and cannot be used $result = $this->_getWinProcessMemoryUsage($pid); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { // fall back to the Unix command line $result = $this->_getUnixProcessMemoryUsage($pid); } diff --git a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractConfigFiles.php b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractConfigFiles.php index 9c713e80ac01ded20764f123915ccda3d970ccfa..086b8dd952a1adfd5be6a22f9c05047f9546029b 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractConfigFiles.php +++ b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractConfigFiles.php @@ -100,7 +100,7 @@ abstract class AbstractConfigFiles extends \PHPUnit_Framework_TestCase try { // this will merge all xml files and validate them $this->_reader->read('global'); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->fail($e->getMessage()); } } diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php index 2692e49779a5a846a7ddc88dcaf5c86c1d68d41f..c95620c61e5943cc5834b62f1f83595fbe6b02b2 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppAreaTest.php @@ -60,7 +60,7 @@ class AppAreaTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testGetTestAppAreaWithInvalidArea() { diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppIsolationTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppIsolationTest.php index 2f46aca7a6210017e242876e2d02a13345248d67..118fc8bbe9da39dcb87039d97f8897e32c020c2e 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppIsolationTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/AppIsolationTest.php @@ -47,7 +47,7 @@ class AppIsolationTest extends \PHPUnit_Framework_TestCase /** * @magentoAppIsolation invalid - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testEndTestIsolationInvalid() { @@ -57,7 +57,7 @@ class AppIsolationTest extends \PHPUnit_Framework_TestCase /** * @magentoAppIsolation enabled * @magentoAppIsolation disabled - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testEndTestIsolationAmbiguous() { diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php index c4324863f14162e56bd06f36119ba888f9df7e31..07cfebfa351e88bb3d4911a5c844a3e9aa99949a 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DataFixtureTest.php @@ -39,7 +39,7 @@ class DataFixtureTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testConstructorException() { @@ -98,7 +98,7 @@ class DataFixtureTest extends \PHPUnit_Framework_TestCase /** * @magentoDataFixture fixture\path\must\not\contain\backslash.php - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testStartTestTransactionRequestInvalidPath() { diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DbIsolationTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DbIsolationTest.php index 559bd7eba3d08cb1257a26166173d51f2cd95789..5b4314c302f3148cba8184c93cc547b32251af44 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DbIsolationTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Annotation/DbIsolationTest.php @@ -63,7 +63,7 @@ class DbIsolationTest extends \PHPUnit_Framework_TestCase /** * @magentoDbIsolation invalid - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testStartTestTransactionRequestInvalidAnnotation() { @@ -73,7 +73,7 @@ class DbIsolationTest extends \PHPUnit_Framework_TestCase /** * @magentoDbIsolation enabled * @magentoDbIsolation disabled - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testStartTestTransactionRequestAmbiguousAnnotation() { diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/DocBlockTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/DocBlockTest.php index 60d25f5018cb933b288dd4d69e727eaa60225c24..6f7643bf89d26e9dd2b74d4776705cdedf4d9fff 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/DocBlockTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/DocBlockTest.php @@ -44,7 +44,7 @@ class DocBlockTest extends \PHPUnit_Framework_TestCase try { new $listenerClass(); $this->fail("Inability to instantiate the event listener '{$listenerClass}' is expected."); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->assertEquals($expectedExceptionMsg, $e->getMessage()); } } diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/SettingsTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/SettingsTest.php index ec8dc75f29b381d5dd78e04347c0e11ba99fb2c5..2dda33120ba57e7c975d30739e6fc7c371472ef4 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/SettingsTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Bootstrap/SettingsTest.php @@ -199,7 +199,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase */ public function testGetAsConfigFileException($settingName, $expectedExceptionMsg) { - $this->setExpectedException('Magento\Framework\Exception', $expectedExceptionMsg); + $this->setExpectedException('Magento\Framework\Exception\LocalizedException', $expectedExceptionMsg); $this->_object->getAsConfigFile($settingName); } @@ -208,11 +208,11 @@ class SettingsTest extends \PHPUnit_Framework_TestCase return [ 'non-existing setting' => [ 'non_existing', - "Setting 'non_existing' specifies the non-existing file ''.", + __("Setting 'non_existing' specifies the non-existing file ''."), ], 'non-existing file' => [ 'item_label', - "Setting 'item_label' specifies the non-existing file '{$this->_fixtureDir}Item Label.dist'.", + __("Setting 'item_label' specifies the non-existing file '%1Item Label.dist'.", $this->_fixtureDir), ] ]; } diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/EntityTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/EntityTest.php index bd4cbab9a0ed6f0c94d0d3c7107fcbb917d03518..3cecd675ddeb9b33c9ab73e4c6b6a44d9a95dbe9 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/EntityTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/EntityTest.php @@ -34,14 +34,14 @@ class EntityTest extends \PHPUnit_Framework_TestCase /** * Callback for save method in mocked model * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function saveModelAndFailOnUpdate() { if (!$this->_model->getId()) { $this->saveModelSuccessfully(); } else { - throw new \Magento\Framework\Exception('Synthetic model update failure.'); + throw new \Magento\Framework\Exception\LocalizedException(__('Synthetic model update failure.')); } } @@ -66,7 +66,7 @@ class EntityTest extends \PHPUnit_Framework_TestCase { return [ 'successful CRUD' => ['saveModelSuccessfully'], - 'cleanup on update error' => ['saveModelAndFailOnUpdate', 'Magento\Framework\Exception'] + 'cleanup on update error' => ['saveModelAndFailOnUpdate', 'Magento\Framework\Exception\LocalizedException'] ]; } diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Event/MagentoTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Event/MagentoTest.php index 49a3510b412c615fdcfae65e5398047d16ad7a8b..119dc7bed56275c1f396628e89705ed99fb15fc1 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Event/MagentoTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Event/MagentoTest.php @@ -45,7 +45,7 @@ class MagentoTest extends \PHPUnit_Framework_TestCase /** * @dataProvider constructorExceptionDataProvider - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @param mixed $eventManager */ public function testConstructorException($eventManager) diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Event/PhpUnitTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Event/PhpUnitTest.php index 6d10c3f8005fc07fd4d9f0cff71725e88addc5f2..4a01266c9891b6189c85617045dbc4f49d4cdd4c 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Event/PhpUnitTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Event/PhpUnitTest.php @@ -44,7 +44,7 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testConstructorException() { diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/BootstrapTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/BootstrapTest.php index 20accc8da9089dd0ed58bdebd6d7c9edd1bf6b01..d7c9971203206faa040201d3276885150b6e6863 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/BootstrapTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/BootstrapTest.php @@ -75,7 +75,7 @@ class BootstrapTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Helper instance is not defined yet. */ public function testGetInstanceEmptyProhibited() @@ -99,7 +99,7 @@ class BootstrapTest extends \PHPUnit_Framework_TestCase /** * @depends testSetInstanceFirstAllowed - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Helper instance cannot be redefined. */ public function testSetInstanceChangeProhibited() diff --git a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/MemoryTest.php b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/MemoryTest.php index ba120cf6b806a39d36bdb094b5341fa38d244305..5234650a1118b33df7a6f2b9d6c258d959b4c309 100644 --- a/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/MemoryTest.php +++ b/dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/MemoryTest.php @@ -27,7 +27,7 @@ class MemoryTest extends \PHPUnit_Framework_TestCase )->with( $this->stringStartsWith('tasklist.exe ') )->will( - $this->throwException(new \Magento\Framework\Exception('command not found')) + $this->throwException(new \Magento\Framework\Exception\LocalizedException(__('command not found'))) ); $this->_shell->expects( $this->at(1) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/Group/Grid/ServiceCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/Group/Grid/ServiceCollectionTest.php index fce0d8bb3b4b007946be32d1704e67a647625bd7..cef578e0114a33c096cab9fde927099ba7dbfd01 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/Group/Grid/ServiceCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/Group/Grid/ServiceCollectionTest.php @@ -96,7 +96,7 @@ class ServiceCollectionTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage When passing in a field array there must be a matching condition array. */ public function testAddToFilterException() diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php b/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php old mode 100644 new mode 100755 index f7c9bcc53653adc6854ac860d56bab6bf17a6da3..70d92a6e3a017440a5333f356da2216e9d9b9d64 --- a/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php @@ -181,7 +181,7 @@ class TemplateTest extends \PHPUnit_Framework_TestCase /** * @dataProvider setDesignConfigExceptionDataProvider - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testSetDesignConfigException($config) { @@ -269,7 +269,7 @@ class TemplateTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Mail\Exception + * @expectedException \Magento\Framework\Exception\MailException * @expectedExceptionMessage The template Name must not be empty. */ public function testBeforeSaveEmptyTemplateCode() diff --git a/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php b/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php old mode 100644 new mode 100755 index 3795a48b9f0346a53978eeda461e42cf49d5f10a..5b84fa1bc9742a4822ca31e56c0d21e32e00ebfe --- a/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php @@ -37,6 +37,6 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $request = $this->_objectManager->create('Magento\Framework\App\Request\Http'); /* empty action */ $request->setRequestUri('core/index/index'); - $this->assertEmpty($this->_model->dispatch($request)->getBody()); + $this->assertInstanceOf('Magento\Framework\Controller\ResultInterface', $this->_model->dispatch($request)); } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php index bc195e9ac3d37be0b330269697bcdacf4bb6cd51..7dbb721cfc39f815b36c9d2d769e36ef22fbc310 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php @@ -60,7 +60,7 @@ class FileTest extends \PHPUnit_Framework_TestCase /** * test exception * - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testReadDirectoryRecursivelyFailure() { diff --git a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/ReadTest.php b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/ReadTest.php index 2ec0af24652246ae64ab535010b616fb851573e6..03d13b9ee8aeb9fa484064433154a6f41a5deb85 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/ReadTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/ReadTest.php @@ -26,7 +26,7 @@ class ReadTest extends \PHPUnit_Framework_TestCase * * @dataProvider providerNotValidFiles * @param string $path - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testAssertValid($path) { diff --git a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/WriteTest.php b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/WriteTest.php index fe5bbe9e413983ba25de2f51cfb2b126bee93aea..67c671e2f253f2be930c99fc6a97f5771c046f29 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/WriteTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/File/WriteTest.php @@ -35,7 +35,7 @@ class WriteTest extends \PHPUnit_Framework_TestCase * @dataProvider fileExistProvider * @param $path * @param $mode - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testFileExistException($path, $mode) { diff --git a/dev/tests/integration/testsuite/Magento/Framework/Module/Plugin/DbStatusValidatorTest.php b/dev/tests/integration/testsuite/Magento/Framework/Module/Plugin/DbStatusValidatorTest.php index 4bcae52e7362b5a7a9e95e623ac93103b787f003..e9d78a0385a79b2f798f4fbb21ad8fc7b0881520 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Module/Plugin/DbStatusValidatorTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Module/Plugin/DbStatusValidatorTest.php @@ -14,7 +14,7 @@ class DbStatusValidatorTest extends \Magento\TestFramework\TestCase\AbstractCont /** * @magentoDbIsolation enabled - * @expectedException \Magento\Framework\Module\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Please update your database */ public function testValidationOutdatedDb() diff --git a/dev/tests/integration/testsuite/Magento/Framework/TranslateCachingTest.php b/dev/tests/integration/testsuite/Magento/Framework/TranslateCachingTest.php index 214e3f39423b5ef98a51aa387b62a5dc453315d2..f9b9e1c67406066a031364fc81a476731e6655c8 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/TranslateCachingTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/TranslateCachingTest.php @@ -6,14 +6,33 @@ namespace Magento\Framework; use Magento\TestFramework\Helper\Bootstrap; +use Magento\Framework\Phrase; class TranslateCachingTest extends \PHPUnit_Framework_TestCase { - public static function tearDownAfterClass() + /** + * @var \Magento\Framework\Phrase\RendererInterface + */ + protected $renderer; + + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + protected $objectManager; + + protected function setUp() { - $objectManager = Bootstrap::getObjectManager(); + $this->objectManager = Bootstrap::getObjectManager(); + $this->renderer = Phrase::getRenderer(); + Phrase::setRenderer($this->objectManager->get('\Magento\Framework\Phrase\RendererInterface')); + } + + protected function tearDown() + { + Phrase::setRenderer($this->renderer); + /** @var \Magento\Framework\App\Cache\Type\Translate $cache */ - $cache = $objectManager->get('Magento\Framework\App\Cache\Type\Translate'); + $cache = $this->objectManager->get('Magento\Framework\App\Cache\Type\Translate'); $cache->clean(); } @@ -22,27 +41,26 @@ class TranslateCachingTest extends \PHPUnit_Framework_TestCase */ public function testLoadDataCaching() { - $objectManager = Bootstrap::getObjectManager(); /** @var \Magento\Framework\Translate $model */ - $model = $objectManager->get('Magento\Framework\Translate'); + $model = $this->objectManager->get('Magento\Framework\Translate'); $model->loadData(\Magento\Framework\App\Area::AREA_FRONTEND); // this is supposed to cache the fixture - $this->assertEquals('Fixture Db Translation', new \Magento\Framework\Phrase('Fixture String')); + $this->assertEquals('Fixture Db Translation', new Phrase('Fixture String')); /** @var \Magento\Translation\Model\Resource\String $translateString */ - $translateString = $objectManager->create('Magento\Translation\Model\Resource\String'); + $translateString = $this->objectManager->create('Magento\Translation\Model\Resource\String'); $translateString->saveTranslate('Fixture String', 'New Db Translation'); $this->assertEquals( 'Fixture Db Translation', - new \Magento\Framework\Phrase('Fixture String'), + new Phrase('Fixture String'), 'Translation is expected to be cached' ); $model->loadData(\Magento\Framework\App\Area::AREA_FRONTEND, true); $this->assertEquals( 'New Db Translation', - new \Magento\Framework\Phrase('Fixture String'), + new Phrase('Fixture String'), 'Forced load should not use cache' ); } diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php index cc9e4c4199c3df78a2ef2f613b3acaf9180f091e..da5a86c47a1496652cf53df739c93389f1c1e58c 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php @@ -58,7 +58,7 @@ class MinifierTest extends \PHPUnit_Framework_TestCase * @param string $requestedFilePath * @param string $testFile * @param callable $assertionCallback - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _testCssMinification($requestedUri, $requestedFilePath, $testFile, $assertionCallback) { diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php index 11c917fba00ba2ee5d7573949f9acfc64f289e2c..31ce3901f6bb41a32093f86c9fb9fcc62d485a67 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php @@ -208,7 +208,7 @@ class LayoutDirectivesTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testMoveBroken() { @@ -216,7 +216,7 @@ class LayoutDirectivesTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testMoveAliasBroken() { diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTest.php index 3e49061e65249d4bdc54546e8de9b58bab3a5221..70406c396b6059e7e75b0dfda708fe62afdae929 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/LayoutTest.php @@ -274,7 +274,7 @@ class LayoutTest extends \PHPUnit_Framework_TestCase $msg = 'Html tag "span" is forbidden for usage in containers. ' . 'Consider to use one of the allowed: dd, div, dl, fieldset, main, header, ' . 'footer, ol, p, section, table, tfoot, ul.'; - $this->setExpectedException('Magento\Framework\Exception', $msg); + $this->setExpectedException('Magento\Framework\Exception\LocalizedException', $msg); $this->_layout->addContainer('container', 'Container', ['htmlTag' => 'span']); } diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Model/QueueTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Model/QueueTest.php index b02773ae51c9e7eeb348ce8e71ee2c137729d065..f7ebc6d0764a60aa3dd7170843df72acdd97fded 100644 --- a/dev/tests/integration/testsuite/Magento/Newsletter/Model/QueueTest.php +++ b/dev/tests/integration/testsuite/Magento/Newsletter/Model/QueueTest.php @@ -68,13 +68,9 @@ class QueueTest extends \PHPUnit_Framework_TestCase $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $transport = $this->getMock('\Magento\Framework\Mail\TransportInterface'); - $transport->expects( - $this->any() - )->method( - 'sendMessage' - )->will( - $this->throwException(new \Magento\Framework\Mail\Exception($errorMsg, 99)) - ); + $transport->expects($this->any()) + ->method('sendMessage') + ->willThrowException(new \Magento\Framework\Exception\MailException(__($errorMsg))); $builder = $this->getMock( '\Magento\Newsletter\Model\Queue\TransportBuilder', @@ -100,7 +96,6 @@ class QueueTest extends \PHPUnit_Framework_TestCase $problem->load($queue->getId(), 'queue_id'); $this->assertNotEmpty($problem->getId()); - $this->assertEquals(99, $problem->getProblemErrorCode()); $this->assertEquals($errorMsg, $problem->getProblemErrorText()); } } diff --git a/dev/tests/integration/testsuite/Magento/Reports/Model/Resource/Report/Product/Viewed/CollectionTest.php b/dev/tests/integration/testsuite/Magento/Reports/Model/Resource/Report/Product/Viewed/CollectionTest.php old mode 100644 new mode 100755 index 4815f8adddaa5ae94101de9ae2a73c3f68267ebf..c0dd230f922cd0e9d63111f17d5a3a1fafc92f43 --- a/dev/tests/integration/testsuite/Magento/Reports/Model/Resource/Report/Product/Viewed/CollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Reports/Model/Resource/Report/Product/Viewed/CollectionTest.php @@ -119,6 +119,12 @@ class CollectionTest extends \PHPUnit_Framework_TestCase 'date_from' => $dateYearAgo, 'date_to' => null, ], + [ + 'period' => 'month', + 'table' => 'report_viewed_product_aggregated_monthly', + 'date_from' => null, + 'date_to' => $dateNow, + ], [ 'period' => 'year', 'table' => 'report_viewed_product_aggregated_yearly', diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/CacheFilesTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/CacheFilesTest.php index 21c973d53e95c434957940aa38f77167fc4bc996..430cced2f1a2e629d5ff66d25788609a6f851a9b 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/CacheFilesTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/CacheFilesTest.php @@ -25,7 +25,7 @@ class CacheFilesTest extends \PHPUnit_Framework_TestCase ); try { $reader->read($area); - } catch (\Magento\Framework\Exception $exception) { + } catch (\Magento\Framework\Exception\LocalizedException $exception) { $this->fail($exception->getMessage()); } } diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/LayoutFilesTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/LayoutFilesTest.php index 9d0ffa7695a494882eccb442e85078ede892c56e..d224cd6d346e32a7c981b7c1ff1cb0c13fecd732 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/LayoutFilesTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/LayoutFilesTest.php @@ -44,8 +44,6 @@ class LayoutFilesTest extends \PHPUnit_Framework_TestCase continue; } $this->_argInterpreter->evaluate($argumentData); - } catch (\Magento\Framework\Data\Argument\MissingOptionalValueException $e) { - // Argument value is missing in the testing environment, but it's optional, so no big deal } catch (\Exception $e) { $this->fail($e->getMessage()); } diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/SystemConfigFilesTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/SystemConfigFilesTest.php index 9f00b3cf290123a90ed81382480e1f9c0daab8ed..b942425f6fd48fe83537eeb5c277fe402aa2135f 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/SystemConfigFilesTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/Modular/SystemConfigFilesTest.php @@ -47,7 +47,7 @@ class SystemConfigFilesTest extends \PHPUnit_Framework_TestCase 'Magento\Config\Model\Config\Structure\Reader', ['moduleReader' => $configMock, 'runtimeValidation' => true] ); - } catch (\Magento\Framework\Exception $exp) { + } catch (\Magento\Framework\Exception\LocalizedException $exp) { $this->fail($exp->getMessage()); } } diff --git a/dev/tests/integration/testsuite/Magento/TestFixture/Controller/Adminhtml/Noroute.php b/dev/tests/integration/testsuite/Magento/TestFixture/Controller/Adminhtml/Noroute.php index 97d6e3f59cc0809b367e63f2f34eeb8565439c61..c21e6dbc7052c7333d71924fb628f1eb450b686e 100644 --- a/dev/tests/integration/testsuite/Magento/TestFixture/Controller/Adminhtml/Noroute.php +++ b/dev/tests/integration/testsuite/Magento/TestFixture/Controller/Adminhtml/Noroute.php @@ -5,7 +5,6 @@ */ namespace Magento\TestFixture\Controller\Adminhtml; -use Magento\Framework\App\Action; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\ResponseInterface; @@ -19,7 +18,7 @@ class Noroute implements \Magento\Framework\App\ActionInterface * * @param RequestInterface $request * @return ResponseInterface - * @throws Action\NotFoundException + * @throws \Magento\Framework\Exception\NotFoundException * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ @@ -35,4 +34,13 @@ class Noroute implements \Magento\Framework\App\ActionInterface public function getResponse() { } + + /** + * Get default result object + * + * @return void + */ + public function getDefaultResult() + { + } } diff --git a/dev/tests/performance/framework/Magento/TestFramework/Application.php b/dev/tests/performance/framework/Magento/TestFramework/Application.php index f60016b79f83035e4229600413d833184497ffd4..d3728db16b2fb43d6959c29772b3104c7a5d4647 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Application.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Application.php @@ -75,12 +75,12 @@ class Application * * @param string $path * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ private function _assertPath($path) { if (!is_file($path)) { - throw new \Magento\Framework\Exception("File '{$path}' is not found."); + throw new \Magento\Framework\Exception\LocalizedException(__("File '%1' is not found.", $path)); } return realpath($path); } @@ -142,14 +142,16 @@ class Application * Install application according to installation options * * @return \Magento\TestFramework\Application - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _install() { $installOptions = $this->_config->getInstallOptions(); $installOptionsNoValue = $this->_config->getInstallOptionsNoValue(); if (!$installOptions) { - throw new \Magento\Framework\Exception('Trying to install Magento, but installation options are not set'); + throw new \Magento\Framework\Exception\LocalizedException( + __('Trying to install Magento, but installation options are not set') + ); } // Populate install options with global options diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Bootstrap.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Bootstrap.php index 46bd3c4a08bfeb8e184cb808b21c9ab218b62fa5..f13126d189a49038a0263569ec69b6cfb8213242 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Bootstrap.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Bootstrap.php @@ -47,7 +47,7 @@ class Bootstrap /** * Ensure reports directory exists, empty, and has write permissions * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function cleanupReports() { @@ -57,9 +57,11 @@ class Bootstrap if ($filesystemAdapter->isExists($reportDir)) { $filesystemAdapter->deleteDirectory($reportDir); } - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { if (file_exists($reportDir)) { - throw new \Magento\Framework\Exception("Cannot cleanup reports directory '{$reportDir}'."); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Cannot cleanup reports directory '%1'.", $reportDir) + ); } } mkdir($reportDir, 0777, true); diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Config.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Config.php index 5d2ef422a633147fdbaf18f867f0c36b0cfd6e7d..f0a6f141fad07c67e1da25ee39666e4c0bcc44da 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Config.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Config.php @@ -58,14 +58,16 @@ class Config * @param string $testsBaseDir * @param string $appBaseDir * @throws \InvalidArgumentException - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct(array $configData, $testsBaseDir, $appBaseDir) { $this->_validateData($configData); if (!is_dir($testsBaseDir)) { - throw new \Magento\Framework\Exception("Base directory '{$testsBaseDir}' does not exist."); + throw new \Magento\Framework\Exception\LocalizedException( + __("Base directory '%1' does not exist.", $testsBaseDir) + ); } $this->_testsBaseDir = $testsBaseDir; $this->_reportDir = $this->_getTestsRelativePath($configData['report_dir']); @@ -100,7 +102,7 @@ class Config * Validate high-level configuration structure * * @param array $configData - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _validateData(array $configData) { @@ -108,7 +110,9 @@ class Config $requiredKeys = ['application', 'scenario', 'report_dir']; foreach ($requiredKeys as $requiredKeyName) { if (empty($configData[$requiredKeyName])) { - throw new \Magento\Framework\Exception("Configuration array must define '{$requiredKeyName}' key."); + throw new \Magento\Framework\Exception\LocalizedException( + __("Configuration array must define '%1' key.", $requiredKeyName) + ); } } @@ -116,8 +120,8 @@ class Config $requiredAdminKeys = ['admin_username', 'admin_password', 'backend_frontname']; foreach ($requiredAdminKeys as $requiredKeyName) { if (empty($configData['application']['installation']['options'][$requiredKeyName])) { - throw new \Magento\Framework\Exception( - "Installation options array must define '{$requiredKeyName}' key." + throw new \Magento\Framework\Exception\LocalizedException( + __("Installation options array must define '%1' key.", $requiredKeyName) ); } } diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/FailureException.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/FailureException.php index 9a1469617c20b20bbaa5d9b16f81822f764548c8..3f027ecf6e253a4581047585a01d26d08eb420f9 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/FailureException.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/FailureException.php @@ -9,7 +9,9 @@ */ namespace Magento\TestFramework\Performance\Scenario; -class FailureException extends \Magento\Framework\Exception +use Magento\Framework\Phrase; + +class FailureException extends \Magento\Framework\Exception\LocalizedException { /** * @var \Magento\TestFramework\Performance\Scenario @@ -20,11 +22,14 @@ class FailureException extends \Magento\Framework\Exception * Constructor * * @param \Magento\TestFramework\Performance\Scenario $scenario - * @param string $message + * @param Phrase $phrase */ - public function __construct(\Magento\TestFramework\Performance\Scenario $scenario, $message = '') + public function __construct(\Magento\TestFramework\Performance\Scenario $scenario, Phrase $phrase = null) { - parent::__construct($message); + if ($phrase === null) { + $phrase = new Phrase('Scenario failure.'); + } + parent::__construct($phrase); $this->_scenario = $scenario; } diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/FileFormat.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/FileFormat.php index 1d426a2133680fd7e9d239357a979164d3b5de97..deaf57b1ee4cfd6fa658205b03c06bf8c0f527c2 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/FileFormat.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/FileFormat.php @@ -47,7 +47,7 @@ class FileFormat implements \Magento\TestFramework\Performance\Scenario\HandlerI * * @param \Magento\TestFramework\Performance\Scenario $scenario * @param string|null $reportFile Report file to write results to, NULL disables report creation - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function run(\Magento\TestFramework\Performance\Scenario $scenario, $reportFile = null) { @@ -55,8 +55,8 @@ class FileFormat implements \Magento\TestFramework\Performance\Scenario\HandlerI /** @var $scenarioHandler \Magento\TestFramework\Performance\Scenario\HandlerInterface */ $scenarioHandler = $this->getHandler($scenarioExtension); if (!$scenarioHandler) { - throw new \Magento\Framework\Exception( - "Unable to run scenario '{$scenario->getTitle()}', format is not supported." + throw new \Magento\Framework\Exception\LocalizedException( + __("Unable to run scenario '%1', format is not supported.", $scenario->getTitle()) ); } $scenarioHandler->run($scenario, $reportFile); diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/Jmeter.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/Jmeter.php index 2d321e6a30805f89510a2ceb7c132fc196e76f51..a6a6ffeda8fc74edeeb3ba27c644c54fa0cbb382 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/Jmeter.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/Jmeter.php @@ -9,6 +9,8 @@ */ namespace Magento\TestFramework\Performance\Scenario\Handler; +use Magento\Framework\Phrase; + class Jmeter implements \Magento\TestFramework\Performance\Scenario\HandlerInterface { /** @@ -50,7 +52,7 @@ class Jmeter implements \Magento\TestFramework\Performance\Scenario\HandlerInter * * @param \Magento\TestFramework\Performance\Scenario $scenario * @param string|null $reportFile Report file to write results to, NULL disables report creation - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\TestFramework\Performance\Scenario\FailureException */ public function run(\Magento\TestFramework\Performance\Scenario $scenario, $reportFile = null) @@ -63,15 +65,15 @@ class Jmeter implements \Magento\TestFramework\Performance\Scenario\HandlerInter if ($reportFile) { if (!file_exists($reportFile)) { - throw new \Magento\Framework\Exception( - "Report file '{$reportFile}' for '{$scenario->getTitle()}' has not been created." + throw new \Magento\Framework\Exception\LocalizedException( + new Phrase("Report file '%1' for '%2' has not been created.", [$reportFile, $scenario->getTitle()]) ); } $reportErrors = $this->_getReportErrors($reportFile); if ($reportErrors) { throw new \Magento\TestFramework\Performance\Scenario\FailureException( $scenario, - implode(PHP_EOL, $reportErrors) + new Phrase(implode(PHP_EOL, $reportErrors)) ); } } diff --git a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/Php.php b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/Php.php index 791142633cd023fead90e11e8f5b1a9115a1a6db..76ba0bda7b9e9fbc47545c8640fb55aa8306e321 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/Php.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Performance/Scenario/Handler/Php.php @@ -50,7 +50,7 @@ class Php implements \Magento\TestFramework\Performance\Scenario\HandlerInterfac * * @param \Magento\TestFramework\Performance\Scenario $scenario * @param string|null $reportFile Report file to write results to, NULL disables report creation - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\TestFramework\Performance\Scenario\FailureException * * @todo Implement execution in concurrent threads defined by the "users" scenario argument @@ -72,7 +72,7 @@ class Php implements \Magento\TestFramework\Performance\Scenario\HandlerInterfac if ($reportErrors) { throw new \Magento\TestFramework\Performance\Scenario\FailureException( $scenario, - implode(PHP_EOL, $reportErrors) + new \Magento\Framework\Phrase(implode(PHP_EOL, $reportErrors)) ); } } @@ -97,7 +97,7 @@ class Php implements \Magento\TestFramework\Performance\Scenario\HandlerInterfac $executionTime = microtime(true); try { $result['output'] = $this->_shell->execute($scenarioCmd, $scenarioCmdArgs); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $result['success'] = false; $result['exit_code'] = $e->getPrevious()->getCode(); $result['output'] = $e->getPrevious()->getMessage(); diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/ConfigTest.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/ConfigTest.php index 0c56894bd75f27573c98b57a07ae5c0ab6b47462..7b2513aa5756a363d5c01953e33d2614a6829735 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/ConfigTest.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/ConfigTest.php @@ -70,8 +70,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase 'non-existing base dir' => [ require __DIR__ . '/_files/config_data.php', 'non_existing_dir', - 'Magento\Framework\Exception', - "Base directory 'non_existing_dir' does not exist", + 'Magento\Framework\Exception\LocalizedException', + new \Magento\Framework\Phrase("Base directory 'non_existing_dir' does not exist"), ], 'invalid scenarios format' => [ require __DIR__ . '/_files/config_data_invalid_scenarios_format.php', diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/FailureExceptionTest.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/FailureExceptionTest.php index 38d371796f4edaf11a5d85aa5125054dc7b2eadd..e9a4f38b97301d66d524ad9d0e7c02f733feed95 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/FailureExceptionTest.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/FailureExceptionTest.php @@ -22,7 +22,7 @@ class FailureExceptionTest extends \PHPUnit_Framework_TestCase $this->_scenario = new \Magento\TestFramework\Performance\Scenario('Title', '', [], [], []); $this->_object = new \Magento\TestFramework\Performance\Scenario\FailureException( $this->_scenario, - 'scenario has failed' + new \Magento\Framework\Phrase('scenario has failed') ); } diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/FileFormatTest.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/FileFormatTest.php index a49a8feffe8063be9ececa2779db20856b2f70a5..3cafda18c6ddfc08e7a86ba593f80df5fcbd9f21 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/FileFormatTest.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/FileFormatTest.php @@ -59,12 +59,12 @@ class FileFormatTest extends \PHPUnit_Framework_TestCase $this->_object->run($this->_scenario, $reportFile); } - /** - * @expectedException \Magento\Framework\Exception - * @expectedExceptionMessage Unable to run scenario 'Scenario', format is not supported. - */ public function testRunUnsupportedFormat() { + $this->setExpectedException( + 'Magento\Framework\Exception\LocalizedException', + new \Magento\Framework\Phrase("Unable to run scenario '%1', format is not supported", ['Scenario']) + ); $scenario = new \Magento\TestFramework\Performance\Scenario( 'Scenario', 'scenario.txt', diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/JmeterTest.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/JmeterTest.php index 178a3094ce836575a9d086394a7d6882bff47245..0b6e4882b1acce765a5ad25e8c26d7a10c54e575 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/JmeterTest.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/JmeterTest.php @@ -132,8 +132,11 @@ class JmeterTest extends \PHPUnit_Framework_TestCase 'no report created' => [ "{$fixtureDir}/scenario_without_report.jmx", "{$fixtureDir}/scenario_without_report.jtl", - 'Magento\Framework\Exception', - "Report file '{$fixtureDir}/scenario_without_report.jtl' for 'Scenario' has not been created.", + 'Magento\Framework\Exception\LocalizedException', + new \Magento\Framework\Phrase( + "Report file '%1/scenario_without_report.jtl' for 'Scenario' has not been created.", + [$fixtureDir] + ), ], 'scenario failure in report' => [ "{$fixtureDir}/scenario_failure.jmx", diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/PhpTest.php b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/PhpTest.php index fc3774ffdf76a90c2911cf335f792bd880a92265..6ca1dfcfd2f927af014605d1879ba40835b4ba47 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/PhpTest.php +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/Scenario/Handler/PhpTest.php @@ -117,9 +117,8 @@ class PhpTest extends \PHPUnit_Framework_TestCase */ public function testRunException() { - $failure = new \Magento\Framework\Exception( - 'Command returned non-zero exit code.', - 0, + $failure = new \Magento\Framework\Exception\LocalizedException( + __('Command returned non-zero exit code.'), new \Exception('command failure message', 1) ); $this->_shell->expects($this->any())->method('execute')->will($this->throwException($failure)); diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ComposerTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ComposerTest.php index 828c06aed1710679ceb5d4a5d7e6d001dc4a0e2c..bda8a6cbcf338a36002131366543b8bfc0e337ca 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/ComposerTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ComposerTest.php @@ -8,7 +8,7 @@ namespace Magento\Test\Integrity; use Magento\Framework\Composer\MagentoComponent; use Magento\Framework\App\Utility\Files; use Magento\Framework\Shell; -use Magento\Framework\Exception; +use Magento\Framework\Exception\LocalizedException; /** * A test that enforces validity of composer.json files and any other conventions in Magento components @@ -365,7 +365,7 @@ class ComposerTest extends \PHPUnit_Framework_TestCase { try { self::$shell->execute(self::$composerPath . ' --version'); - } catch (Exception $e) { + } catch (LocalizedException $e) { return false; } return true; diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php index 493f1310e380c6e586ca25d5afc032c727cbd891..780e83022c4aa53c7d9bd05fcec9514cd5966448 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php @@ -282,7 +282,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase { try { $this->_validator->validate($className); - } catch (\Magento\Framework\Code\ValidationException $exceptions) { + } catch (\Magento\Framework\Exception\ValidatorException $exceptions) { $this->fail($exceptions->getMessage()); } catch (\ReflectionException $exceptions) { $this->fail($exceptions->getMessage()); @@ -366,7 +366,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase if (\Magento\Framework\App\Utility\Files::init()->isModuleExists($module)) { $this->pluginValidator->validate($plugin, $type); } - } catch (\Magento\Framework\Interception\Code\ValidatorException $exception) { + } catch (\Magento\Framework\Exception\ValidatorException $exception) { $this->fail($exception->getMessage()); } } @@ -411,7 +411,7 @@ class CompilerTest extends \PHPUnit_Framework_TestCase { try { $this->_shell->execute($this->_command, [$this->_generationDir, $this->_compilationDir]); - } catch (\Magento\Framework\Exception $exception) { + } catch (\Magento\Framework\Exception\LocalizedException $exception) { $this->fail($exception->getPrevious()->getMessage()); } } diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php old mode 100644 new mode 100755 index 2f915d7ffb489af665131b0bea82328ecccc1a8f..462d614821e2916cc5ad5cf601996f11dc46d545 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -2296,7 +2296,7 @@ return [ ['Magento\Core\Model\Store', 'Magento\Store\Model\Store'], [ 'Magento\Store\Model\Exception', - 'Magento\Framework\Exception\LocalizedException, Magento\Framework\App\InitException' + 'Magento\Framework\Exception\LocalizedException, Magento\Framework\Exception\State\InitException' ], ['Magento\Core\Model\Store\Group', 'Magento\Store\Model\Group'], ['Magento\Core\Model\Store\Group\Factory', 'Magento\Store\Model\GroupFactory'], @@ -2424,7 +2424,8 @@ return [ ['Magento\Archive', 'Magento\Framework\Archive'], ['Magento\Event', 'Magento\Framework\Event'], ['Magento\EventFactory', 'Magento\Framework\EventFactory'], - ['Magento\Exception', 'Magento\Framework\Exception'], + ['Magento\Exception', 'Magento\Framework\Exception\LocalizedException'], + ['Magento\Framework\Exception', 'Magento\Framework\Exception\LocalizedException'], ['Magento\Filesystem', 'Magento\Framework\Filesystem'], ['Magento\ObjectManager', 'Magento\Framework\ObjectManagerInterface'], ['Magento\Translate', 'Magento\Framework\Translate'], @@ -2518,8 +2519,8 @@ return [ ['Magento\OsInfo', 'Magento\Framework\OsInfo'], ['Magento\Registry', 'Magento\Framework\Registry'], ['Magento\Util', 'Magento\Framework\Util'], - ['Magento\BootstrapException', 'Magento\Framework\App\InitException'], - ['Magento\Framework\BootstrapException', 'Magento\Framework\App\InitException'], + ['Magento\BootstrapException', 'Magento\Framework\Exception\State\InitException'], + ['Magento\Framework\BootstrapException', 'Magento\Framework\Exception\State\InitException'], ['Magento\Checkout\Helper\Url'], [ 'Magento\Customer\Service\V1\CustomerCurrentService', @@ -3117,4 +3118,24 @@ return [ ['Magento\LocaleFactory'], ['Magento\Framework\LocaleFactory'], ['Magento\Core\Helper\Data', 'Magento\Framework\Json\Helper\Data'], + ['Magento\Backup\Exception'], + ['Magento\Catalog\Exception'], + ['Magento\Reports\Exception'], + ['Magento\Sales\Exception'], + ['Magento\SalesRule\Exception'], + ['Magento\UrlRewrite\Model\EntityNotAssociatedWithWebsiteException'], + ['Magento\Framework\App\Action\Exception'], + ['Magento\Framework\App\Action\NotFoundException'], + ['Magento\Framework\Code\ValidationException'], + ['Magento\Framework\Css\PreProcessor\Adapter\AdapterException'], + ['Magento\Framework\Mail\Exception'], + ['Magento\Framework\Stdlib\DateTime\Timezone\ValidationException'], + ['Magento\Framework\Module\Exception'], + ['Magento\Framework\Data\Argument\MissingOptionalValueException'], + ['Magento\Framework\Session\SaveHandlerException'], + ['Magento\Framework\ForeignKey\Exception'], + ['Magento\CatalogInventory\Exception'], + ['Magento\CatalogRule\CatalogRuleException'], + ['Magento\Payment\Exception'], + ['Magento\UrlRewrite\Model\Storage\DuplicateEntryException'], ]; diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_namespaces.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_namespaces.php index 1d0e66fbbc949a5863f26103bfaa2a877fdbca6d..793473a809aeee2f23582035d0e64f0c3b171d81 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_namespaces.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_namespaces.php @@ -20,7 +20,7 @@ return [ ['Magento\Session', 'Magento\Framework\Session'], ['Magento\Cache', 'Magento\Framework\Cache'], ['Magento\ObjectManager', 'Magento\Framework\ObjectManager'], - ['Magento\Exception', 'Magento\Framework\Exception'], + ['Magento\Exception', 'Magento\Framework\Exception\LocalizedException'], ['Magento\Autoload', 'Magento\Framework\Autoload'], ['Magento\Translate', 'Magento\Framework\Translate'], ['Magento\Code', 'Magento\Framework\Code'], diff --git a/dev/tools/Magento/Tools/Di/Code/Generator.php b/dev/tools/Magento/Tools/Di/Code/Generator.php index 0eaf442daccdd7fd24cdb42882ab6bda68b7cae9..a33d2f74dc024dd0df2fc55f095eb844dcadec58 100644 --- a/dev/tools/Magento/Tools/Di/Code/Generator.php +++ b/dev/tools/Magento/Tools/Di/Code/Generator.php @@ -60,7 +60,7 @@ class Generator extends FrameworkGenerator * Generates list of classes * * @param array $classesToGenerate - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ public function generateList($classesToGenerate) diff --git a/dev/tools/Magento/Tools/Di/Code/Reader/ClassesScanner.php b/dev/tools/Magento/Tools/Di/Code/Reader/ClassesScanner.php index f91f9fbc27cd36ebd85eb189245175eb193c82b9..5b0204813ccb1b6c6a94922ea50bbe9b3be59448 100644 --- a/dev/tools/Magento/Tools/Di/Code/Reader/ClassesScanner.php +++ b/dev/tools/Magento/Tools/Di/Code/Reader/ClassesScanner.php @@ -5,7 +5,7 @@ */ namespace Magento\Tools\Di\Code\Reader; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; use Zend\Code\Scanner\FileScanner; class ClassesScanner implements ClassesScannerInterface @@ -39,13 +39,13 @@ class ClassesScanner implements ClassesScannerInterface * * @param string $path * @return array - * @throws FilesystemException + * @throws FileSystemException */ public function getList($path) { $realPath = realpath($path); if (!(bool)$realPath) { - throw new FilesystemException(); + throw new FileSystemException(new \Magento\Framework\Phrase('Invalid path: %1', $path)); } $recursiveIterator = new \RecursiveIteratorIterator( diff --git a/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Area.php b/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Area.php index a70c2291eeb668f2119f95ad4b768486bb195828..5830fc4e79ba8e318f9ccb6c94b6c61279ce9e81 100644 --- a/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Area.php +++ b/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Area.php @@ -7,7 +7,7 @@ namespace Magento\Tools\Di\Code\Reader\Decorator; use Magento\Tools\Di\Code\Reader\ClassesScanner; use Magento\Tools\Di\Code\Reader\ClassReaderDecorator; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; /** * Class Area @@ -44,7 +44,7 @@ class Area implements \Magento\Tools\Di\Code\Reader\ClassesScannerInterface * @param string $path path to dir with files * * @return array - * @throws FilesystemException + * @throws FileSystemException */ public function getList($path) { diff --git a/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Directory.php b/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Directory.php index 83d8e4107856096d3af9204e0affce0ab4cfa27c..430ec71706199009fcbba18fad6f03acbd1c805e 100644 --- a/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Directory.php +++ b/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Directory.php @@ -96,7 +96,7 @@ class Directory implements \Magento\Tools\Di\Code\Reader\ClassesScannerInterface $this->validator->validate($className); } $this->relations[$className] = $this->classReader->getParents($className); - } catch (\Magento\Framework\Code\ValidationException $exception) { + } catch (\Magento\Framework\Exception\ValidatorException $exception) { $this->log->add(Log::COMPILATION_ERROR, $className, $exception->getMessage()); } catch (\ReflectionException $e) { $this->log->add(Log::COMPILATION_ERROR, $className, $e->getMessage()); diff --git a/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Interceptions.php b/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Interceptions.php index 8836c53070b59d164c7d87833ddc7f987f8f290f..84e4ce0038e8c6b300ae0648cc6a16472180bb21 100644 --- a/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Interceptions.php +++ b/dev/tools/Magento/Tools/Di/Code/Reader/Decorator/Interceptions.php @@ -75,7 +75,7 @@ class Interceptions implements \Magento\Tools\Di\Code\Reader\ClassesScannerInter $this->validator->validate($className); } $nameList[] = $className; - } catch (\Magento\Framework\Code\ValidationException $exception) { + } catch (\Magento\Framework\Exception\ValidatorException $exception) { $this->log->add(Log::COMPILATION_ERROR, $className, $exception->getMessage()); } catch (\ReflectionException $e) { $this->log->add(Log::COMPILATION_ERROR, $className, $e->getMessage()); diff --git a/dev/tools/Magento/Tools/Di/Code/Scanner/PhpScanner.php b/dev/tools/Magento/Tools/Di/Code/Scanner/PhpScanner.php index bf5fc24e4749a2252511471bf3581476b9153d5e..ee0379367000787eb84f78feb03a03176fa9cc22 100644 --- a/dev/tools/Magento/Tools/Di/Code/Scanner/PhpScanner.php +++ b/dev/tools/Magento/Tools/Di/Code/Scanner/PhpScanner.php @@ -49,7 +49,7 @@ class PhpScanner implements ScannerInterface if (class_exists($missingClassName)) { continue; } - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { } $sourceClassName = $this->getSourceClassName($missingClassName, $entityType); if (!class_exists($sourceClassName) && !interface_exists($sourceClassName)) { diff --git a/dev/tools/Magento/Tools/Di/Code/Scanner/XmlScanner.php b/dev/tools/Magento/Tools/Di/Code/Scanner/XmlScanner.php index 9f0b2ec3304b621728a6e94efb15f738b96170a9..6ca33d3f08c846116affee7d238d5c60ddc839e3 100644 --- a/dev/tools/Magento/Tools/Di/Code/Scanner/XmlScanner.php +++ b/dev/tools/Magento/Tools/Di/Code/Scanner/XmlScanner.php @@ -68,7 +68,7 @@ class XmlScanner implements ScannerInterface $isClassExists = false; try { $isClassExists = class_exists($className); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { } if (false === $isClassExists) { if (class_exists($entityName) || interface_exists($entityName)) { diff --git a/dev/tools/Magento/Tools/Di/Test/Unit/Code/Reader/InstancesNamesList/DirectoryTest.php b/dev/tools/Magento/Tools/Di/Test/Unit/Code/Reader/InstancesNamesList/DirectoryTest.php index 585d6dadc196f9151db69cea710a322b699ed1d2..aaa02faa6f70e79bfa7793ebfc05903cf3cc2535 100644 --- a/dev/tools/Magento/Tools/Di/Test/Unit/Code/Reader/InstancesNamesList/DirectoryTest.php +++ b/dev/tools/Magento/Tools/Di/Test/Unit/Code/Reader/InstancesNamesList/DirectoryTest.php @@ -189,7 +189,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase public function getListExceptionDataProvider() { return [ - [new \Magento\Framework\Code\ValidationException('Not Valid!')], + [new \Magento\Framework\Exception\ValidatorException(new \Magento\Framework\Phrase('Not Valid!'))], [new \ReflectionException('Not Valid!')] ]; } diff --git a/dev/tools/Magento/Tools/Di/Test/Unit/Code/Reader/InstancesNamesList/InterceptionsTest.php b/dev/tools/Magento/Tools/Di/Test/Unit/Code/Reader/InstancesNamesList/InterceptionsTest.php index 8a161f49a0a54970b649dc578fc078fb887aaaa0..238274ff5f804db60ec726ede11fdba3b0c23936 100644 --- a/dev/tools/Magento/Tools/Di/Test/Unit/Code/Reader/InstancesNamesList/InterceptionsTest.php +++ b/dev/tools/Magento/Tools/Di/Test/Unit/Code/Reader/InstancesNamesList/InterceptionsTest.php @@ -160,7 +160,7 @@ class InterceptionsTest extends \PHPUnit_Framework_TestCase public function getListExceptionDataProvider() { return [ - [new \Magento\Framework\Code\ValidationException('Not Valid!')], + [new \Magento\Framework\Exception\ValidatorException(new \Magento\Framework\Phrase('Not Valid!'))], [new \ReflectionException('Not Valid!')] ]; } diff --git a/dev/tools/Magento/Tools/Di/entity_generator.php b/dev/tools/Magento/Tools/Di/entity_generator.php index 4ab81346a4e3b3b555936a9ed1136ea163e28fb8..17592837a0b0c2cd7274975c478a7cd879a94ab4 100644 --- a/dev/tools/Magento/Tools/Di/entity_generator.php +++ b/dev/tools/Magento/Tools/Di/entity_generator.php @@ -9,7 +9,7 @@ use Magento\Framework\Api\Code\Generator\SearchResults; use Magento\Framework\Autoload\AutoloaderRegistry; use Magento\Framework\Code\Generator; use Magento\Framework\Code\Generator\Io; -use Magento\Framework\Exception; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Interception\Code\Generator\Interceptor; use Magento\Framework\ObjectManager\Code\Generator\Converter; @@ -96,6 +96,6 @@ try { } else { print "Can't generate class {$className}. This class either not generated entity, or it already exists.\n"; } -} catch (Exception $e) { +} catch (LocalizedException $e) { print "Error! {$e->getMessage()}\n"; } diff --git a/lib/internal/Magento/Framework/Api/AbstractServiceCollection.php b/lib/internal/Magento/Framework/Api/AbstractServiceCollection.php index 1f261b1401f547b6712b0991b39a44b39f13c69a..08c81040594f58882c620f252e50e6d5224148da 100644 --- a/lib/internal/Magento/Framework/Api/AbstractServiceCollection.php +++ b/lib/internal/Magento/Framework/Api/AbstractServiceCollection.php @@ -7,7 +7,7 @@ namespace Magento\Framework\Api; use Magento\Framework\Data\Collection\EntityFactoryInterface; -use Magento\Framework\Exception; +use Magento\Framework\Exception\LocalizedException; /** * Base for service collections @@ -101,13 +101,15 @@ abstract class AbstractServiceCollection extends \Magento\Framework\Data\Collect * * @param string|array $field * @param string|int|array $condition - * @throws Exception if some error in the input could be detected. + * @throws LocalizedException if some error in the input could be detected. * @return $this */ public function addFieldToFilter($field, $condition) { if (is_array($field) && count($field) != count($condition)) { - throw new Exception('When passing in a field array there must be a matching condition array.'); + throw new LocalizedException( + new \Magento\Framework\Phrase('When passing in a field array there must be a matching condition array.') + ); } $this->fieldFilters[] = ['field' => $field, 'condition' => $condition]; return $this; diff --git a/lib/internal/Magento/Framework/Api/CriteriaInterface.php b/lib/internal/Magento/Framework/Api/CriteriaInterface.php index 76e4a4c6ec6e101b10b0d40ab1772ded2d635a57..e0bc18f381af7152f6b0020ae789e8832441557d 100644 --- a/lib/internal/Magento/Framework/Api/CriteriaInterface.php +++ b/lib/internal/Magento/Framework/Api/CriteriaInterface.php @@ -73,7 +73,7 @@ interface CriteriaInterface * @param string|array $field * @param string|int|array $condition * @param string $type - * @throws \Magento\Framework\Exception if some error in the input could be detected. + * @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected. * @return void */ public function addFilter($name, $field, $condition = null, $type = 'and'); diff --git a/lib/internal/Magento/Framework/App/Action/AbstractAction.php b/lib/internal/Magento/Framework/App/Action/AbstractAction.php index 50316c770caf622e4b3eb3c2158c78d900377380..b0027ca824ec085480664fcbfe0ce6d36e0c60bd 100644 --- a/lib/internal/Magento/Framework/App/Action/AbstractAction.php +++ b/lib/internal/Magento/Framework/App/Action/AbstractAction.php @@ -20,15 +20,19 @@ abstract class AbstractAction implements \Magento\Framework\App\ActionInterface protected $_response; /** - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\App\ResponseInterface $response + * @var \Magento\Framework\Controller\Result\RedirectFactory + */ + protected $resultRedirectFactory; + + /** + * @param \Magento\Framework\App\Action\Context $context */ public function __construct( - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\App\ResponseInterface $response + \Magento\Framework\App\Action\Context $context ) { - $this->_request = $request; - $this->_response = $response; + $this->_request = $context->getRequest(); + $this->_response = $context->getResponse(); + $this->resultRedirectFactory = $context->getResultRedirectFactory(); } /** @@ -50,4 +54,15 @@ abstract class AbstractAction implements \Magento\Framework\App\ActionInterface { return $this->_response; } + + /** + * Create redirect object, which can be used to redirect user to previous or main page + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function getDefaultResult() + { + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setRefererOrBaseUrl(); + } } diff --git a/lib/internal/Magento/Framework/App/Action/Action.php b/lib/internal/Magento/Framework/App/Action/Action.php index 38e64f43b23e06331703729e065501a48a2628c7..3334b9c810db4de3933b93d4a6adb8ae1cd4eafa 100644 --- a/lib/internal/Magento/Framework/App/Action/Action.php +++ b/lib/internal/Magento/Framework/App/Action/Action.php @@ -7,6 +7,7 @@ namespace Magento\Framework\App\Action; use Magento\Framework\App\RequestInterface; use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Exception\NotFoundException; /** * Default implementation of application action controller @@ -65,7 +66,7 @@ class Action extends AbstractAction */ public function __construct(Context $context) { - parent::__construct($context->getRequest(), $context->getResponse()); + parent::__construct($context); $this->_objectManager = $context->getObjectManager(); $this->_eventManager = $context->getEventManager(); $this->_url = $context->getUrl(); diff --git a/lib/internal/Magento/Framework/App/Action/Context.php b/lib/internal/Magento/Framework/App/Action/Context.php index a27f3862ecb23375bd0c984f053ce043347a6ca2..22aef5cc083c9dd8278100b6afcd6fffc6858884 100644 --- a/lib/internal/Magento/Framework/App/Action/Context.php +++ b/lib/internal/Magento/Framework/App/Action/Context.php @@ -52,6 +52,11 @@ class Context implements \Magento\Framework\ObjectManager\ContextInterface */ protected $messageManager; + /** + * @var \Magento\Framework\Controller\Result\RedirectFactory + */ + protected $resultRedirectFactory; + /** * @param \Magento\Framework\App\RequestInterface $request * @param \Magento\Framework\App\ResponseInterface $response @@ -62,6 +67,7 @@ class Context implements \Magento\Framework\ObjectManager\ContextInterface * @param \Magento\Framework\App\ActionFlag $actionFlag * @param \Magento\Framework\App\ViewInterface $view * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -74,7 +80,8 @@ class Context implements \Magento\Framework\ObjectManager\ContextInterface \Magento\Framework\App\Response\RedirectInterface $redirect, \Magento\Framework\App\ActionFlag $actionFlag, \Magento\Framework\App\ViewInterface $view, - \Magento\Framework\Message\ManagerInterface $messageManager + \Magento\Framework\Message\ManagerInterface $messageManager, + \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory ) { $this->_request = $request; $this->_response = $response; @@ -85,6 +92,7 @@ class Context implements \Magento\Framework\ObjectManager\ContextInterface $this->_actionFlag = $actionFlag; $this->_view = $view; $this->messageManager = $messageManager; + $this->resultRedirectFactory = $resultRedirectFactory; } /** @@ -158,4 +166,12 @@ class Context implements \Magento\Framework\ObjectManager\ContextInterface { return $this->messageManager; } + + /** + * @return \Magento\Framework\Controller\Result\RedirectFactory + */ + public function getResultRedirectFactory() + { + return $this->resultRedirectFactory; + } } diff --git a/lib/internal/Magento/Framework/App/Action/Exception.php b/lib/internal/Magento/Framework/App/Action/Exception.php deleted file mode 100644 index 12389da51db102683520c8dcdff6698f59dd6579..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/App/Action/Exception.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * Generic application action exception - * - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\App\Action; - -class Exception extends \Exception -{ -} diff --git a/lib/internal/Magento/Framework/App/ActionInterface.php b/lib/internal/Magento/Framework/App/ActionInterface.php index b26a3f898f68f382c36786314b7f3c67c0b0764a..7e30034efded484f62bdb75b54e909db99adaba5 100644 --- a/lib/internal/Magento/Framework/App/ActionInterface.php +++ b/lib/internal/Magento/Framework/App/ActionInterface.php @@ -24,7 +24,7 @@ interface ActionInterface * * @param RequestInterface $request * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface - * @throws Action\NotFoundException + * @throws \Magento\Framework\Exception\NotFoundException */ public function dispatch(RequestInterface $request); @@ -34,4 +34,14 @@ interface ActionInterface * @return ResponseInterface */ public function getResponse(); + + /** + * Get default result object + * + * Method is invoked to return default result of action execution within controllers. + * Can be used to generate 'execute' method result in action controllers. + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function getDefaultResult(); } diff --git a/lib/internal/Magento/Framework/App/Arguments/ArgumentInterpreter.php b/lib/internal/Magento/Framework/App/Arguments/ArgumentInterpreter.php index 572da3906610af05e902e3137ab424018a9a229c..269c5b860c0b4369c3ebd680570ec1b31a24a9b2 100644 --- a/lib/internal/Magento/Framework/App/Arguments/ArgumentInterpreter.php +++ b/lib/internal/Magento/Framework/App/Arguments/ArgumentInterpreter.php @@ -7,7 +7,6 @@ namespace Magento\Framework\App\Arguments; use Magento\Framework\Data\Argument\Interpreter\Constant; use Magento\Framework\Data\Argument\InterpreterInterface; -use Magento\Framework\Data\Argument\MissingOptionalValueException; /** * Interpreter that returns value of an application argument, retrieving its name from a constant @@ -30,7 +29,6 @@ class ArgumentInterpreter implements InterpreterInterface /** * {@inheritdoc} * @return mixed - * @throws MissingOptionalValueException */ public function evaluate(array $data) { diff --git a/lib/internal/Magento/Framework/App/Config/Initial/Reader.php b/lib/internal/Magento/Framework/App/Config/Initial/Reader.php index f92e4da1d99d69ee2eb19763329e0a8c71abb12a..d907d22223e42370c3c1881b04f6fa21b472073e 100644 --- a/lib/internal/Magento/Framework/App/Config/Initial/Reader.php +++ b/lib/internal/Magento/Framework/App/Config/Initial/Reader.php @@ -79,7 +79,7 @@ class Reader * * @return array * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function read() { @@ -106,7 +106,9 @@ class Reader $domDocument->merge($file); } } catch (\Magento\Framework\Config\Dom\ValidationException $e) { - throw new \Magento\Framework\Exception("Invalid XML in file " . $file . ":\n" . $e->getMessage()); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Invalid XML in file %1:\n%2", [$file, $e->getMessage()]) + ); } } diff --git a/lib/internal/Magento/Framework/App/FrontController.php b/lib/internal/Magento/Framework/App/FrontController.php old mode 100644 new mode 100755 index 91984933ca4e10f79ffa3b3a05ba7d06595e1cb5..d8d85460a66efb86f05264f879de30724a395d27 --- a/lib/internal/Magento/Framework/App/FrontController.php +++ b/lib/internal/Magento/Framework/App/FrontController.php @@ -7,6 +7,9 @@ */ namespace Magento\Framework\App; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class FrontController implements FrontControllerInterface { /** @@ -14,12 +17,41 @@ class FrontController implements FrontControllerInterface */ protected $_routerList; + /** + * Application state + * + * @var State + */ + protected $appState; + + /** + * Message manager + * + * @var \Magento\Framework\Message\ManagerInterface + */ + protected $messageManager; + + /** + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * @param RouterList $routerList + * @param State $appState + * @param \Magento\Framework\Message\ManagerInterface $messageManager + * @param \Psr\Log\LoggerInterface $logger */ - public function __construct(RouterList $routerList) - { + public function __construct( + RouterList $routerList, + State $appState, + \Magento\Framework\Message\ManagerInterface $messageManager, + \Psr\Log\LoggerInterface $logger + ) { $this->_routerList = $routerList; + $this->appState = $appState; + $this->messageManager = $messageManager; + $this->logger = $logger; } /** @@ -35,28 +67,65 @@ class FrontController implements FrontControllerInterface $routingCycleCounter = 0; $result = null; while (!$request->isDispatched() && $routingCycleCounter++ < 100) { - /** @var \Magento\Framework\App\RouterInterface $router */ - foreach ($this->_routerList as $router) { - try { - $actionInstance = $router->match($request); - if ($actionInstance) { - $request->setDispatched(true); - $actionInstance->getResponse()->setNoCacheHeaders(); + $result = $this->processRequest($request); + } + \Magento\Framework\Profiler::stop('routers_match'); + if ($routingCycleCounter > 100) { + throw new \LogicException('Front controller reached 100 router match iterations'); + } + return $result; + } + + /** + * Handle exception + * + * @param \Exception $e + * @return void + */ + protected function handleException($e) + { + $needToMaskDisplayMessage = !($e instanceof \Magento\Framework\Exception\LocalizedException) + && ($this->appState->getMode() != State::MODE_DEVELOPER); + $displayMessage = $needToMaskDisplayMessage + ? (string)new \Magento\Framework\Phrase('An error occurred while processing your request') + : $e->getMessage(); + $this->messageManager->addError($displayMessage); + $this->logger->critical($e->getMessage()); + } + + /** + * Route request and dispatch it + * + * @param RequestInterface $request + * @return ResponseInterface|\Magento\Framework\Controller\ResultInterface|null + */ + protected function processRequest(RequestInterface $request) + { + $result = null; + /** @var \Magento\Framework\App\RouterInterface $router */ + foreach ($this->_routerList as $router) { + try { + $actionInstance = $router->match($request); + if ($actionInstance) { + $request->setDispatched(true); + $actionInstance->getResponse()->setNoCacheHeaders(); + try { $result = $actionInstance->dispatch($request); - break; + } catch (\Magento\Framework\Exception\NotFoundException $e) { + throw $e; + } catch (\Exception $e) { + $this->handleException($e); + $result = $actionInstance->getDefaultResult(); } - } catch (Action\NotFoundException $e) { - $request->initForward(); - $request->setActionName('noroute'); - $request->setDispatched(false); break; } + } catch (\Magento\Framework\Exception\NotFoundException $e) { + $request->initForward(); + $request->setActionName('noroute'); + $request->setDispatched(false); + break; } } - \Magento\Framework\Profiler::stop('routers_match'); - if ($routingCycleCounter > 100) { - throw new \LogicException('Front controller reached 100 router match iterations'); - } return $result; } } diff --git a/lib/internal/Magento/Framework/App/Http.php b/lib/internal/Magento/Framework/App/Http.php index 54a71efa0c038bf015b91fa505fc73dd37cad368..755131e2309d36bd3af5c3cd9dbeb52e6a1d9468 100644 --- a/lib/internal/Magento/Framework/App/Http.php +++ b/lib/internal/Magento/Framework/App/Http.php @@ -224,7 +224,7 @@ class Http implements \Magento\Framework\AppInterface */ private function handleSessionException(\Exception $exception) { - if ($exception instanceof \Magento\Framework\Session\Exception) { + if ($exception instanceof \Magento\Framework\Exception\SessionException) { $this->_response->setRedirect($this->_request->getDistroBaseUrl()); $this->_response->sendHeaders(); return true; @@ -240,7 +240,7 @@ class Http implements \Magento\Framework\AppInterface */ private function handleInitException(\Exception $exception) { - if ($exception instanceof \Magento\Framework\App\InitException) { + if ($exception instanceof \Magento\Framework\Exception\State\InitException) { require $this->_filesystem->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/404.php'); return true; } diff --git a/lib/internal/Magento/Framework/App/Language/Config.php b/lib/internal/Magento/Framework/App/Language/Config.php index 880121b1647cbf02c747e2679ba7247556250c33..62c29d8f23b4c85635200af4ba67d6d5028ad579 100644 --- a/lib/internal/Magento/Framework/App/Language/Config.php +++ b/lib/internal/Magento/Framework/App/Language/Config.php @@ -24,7 +24,7 @@ class Config * Constructor * * @param string $source - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct($source) { @@ -32,7 +32,9 @@ class Config $config->loadXML($source); $errors = Dom::validateDomDocument($config, $this->getSchemaFile()); if (!empty($errors)) { - throw new \Magento\Framework\Exception("Invalid Document: \n" . implode("\n", $errors)); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Invalid Document: \n%1", [implode("\n", $errors)]) + ); } $this->_data = $this->_extractData($config); } diff --git a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php index 61ed3b457a27cde46c8df905ce20fec41e70f145..0814ad0cfbd267f8b178fd9ec3f3e4da3e8d04b5 100644 --- a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php +++ b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php @@ -224,7 +224,7 @@ class ObjectManagerFactory * @param mixed $argumentMapper * @param string $appMode * @return array - * @throws \Magento\Framework\App\InitException + * @throws \Magento\Framework\Exception\State\InitException */ protected function _loadPrimaryConfig(DirectoryList $directoryList, $driverPool, $argumentMapper, $appMode) { @@ -249,7 +249,10 @@ class ObjectManagerFactory ); $configData = $reader->read('primary'); } catch (\Exception $e) { - throw new \Magento\Framework\App\InitException($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\State\InitException( + new \Magento\Framework\Phrase($e->getMessage()), + $e + ); } return $configData; } diff --git a/lib/internal/Magento/Framework/App/State.php b/lib/internal/Magento/Framework/App/State.php index 6fcd7348336433cddb967ae824612a2b57437f95..727b30c68245e7bd24d7c046b18fb4a20398ce73 100644 --- a/lib/internal/Magento/Framework/App/State.php +++ b/lib/internal/Magento/Framework/App/State.php @@ -129,12 +129,14 @@ class State * * @param string $code * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function setAreaCode($code) { if (isset($this->_areaCode)) { - throw new \Magento\Framework\Exception('Area code is already set'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Area code is already set') + ); } $this->_configScope->setCurrentScope($code); $this->_areaCode = $code; @@ -144,12 +146,14 @@ class State * Get area code * * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getAreaCode() { if (!isset($this->_areaCode)) { - throw new \Magento\Framework\Exception('Area code is not set'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Area code is not set') + ); } return $this->_areaCode; } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Action/AbstractActionTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Action/AbstractActionTest.php new file mode 100644 index 0000000000000000000000000000000000000000..94b705692c7ccf4e39764dcc1c6a6a8d455a8f56 --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/Action/AbstractActionTest.php @@ -0,0 +1,68 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Framework\App\Test\Unit\Action; + +class AbstractActionTest extends \PHPUnit_Framework_TestCase +{ + /** @var \Magento\Framework\App\Action\AbstractAction|\PHPUnit_Framework_MockObject_MockObject */ + protected $action; + + /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $request; + + /** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $response; + + /** @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $redirectFactory; + + /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */ + protected $redirect; + + /** @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */ + protected $context; + + public function setUp() + { + $this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface') + ->disableOriginalConstructor()->getMock(); + $this->response = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false); + + $this->redirect = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') + ->setMethods(['setRefererOrBaseUrl']) + ->disableOriginalConstructor() + ->getMock(); + $this->redirectFactory = $this->getMockBuilder('Magento\Backend\Model\View\Result\RedirectFactory') + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + $this->redirectFactory->expects($this->any()) + ->method('create') + ->willReturn($this->redirect); + + $this->context = $this->getMockBuilder('Magento\Framework\App\Action\Context') + ->disableOriginalConstructor() + ->getMock(); + $this->context->expects($this->any()) + ->method('getResultRedirectFactory') + ->willReturn($this->redirectFactory); + + $this->action = $this->getMockForAbstractClass('Magento\Framework\App\Action\AbstractAction', [$this->context]); + } + + public function testGetDefaultRedirect() + { + $expectedResult = '/index'; + + $this->redirect->expects($this->once()) + ->method('setRefererOrBaseUrl') + ->willReturn('/index'); + + $result = $this->action->getDefaultResult(); + $this->assertSame($expectedResult, $result); + } +} diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Config/Initial/ReaderTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Config/Initial/ReaderTest.php index f3d28802f4da3e182f290759198b01b75a69f142..4c1fde2796bf5ab0b2ba6f64875c808055f18255 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Config/Initial/ReaderTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Config/Initial/ReaderTest.php @@ -106,7 +106,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase /** * @covers \Magento\Framework\App\Config\Initial\Reader::read - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessageRegExp /Invalid XML in file \w+/ */ public function testReadInvalidConfig() diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Filesystem/DirectoryListTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Filesystem/DirectoryListTest.php index 767595240e133484df05f6522850758f770b8e0f..d426fa8b1867537d99a59b1f535447a4f7439616 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Filesystem/DirectoryListTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Filesystem/DirectoryListTest.php @@ -24,7 +24,7 @@ class DirectoryListTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/root/dir/foo', $object->getPath(DirectoryList::APP)); $this->assertEquals('bar', $object->getUrlPath(DirectoryList::APP)); $this->setExpectedException( - '\Magento\Framework\Filesystem\FilesystemException', + '\Magento\Framework\Exception\FileSystemException', "Unknown directory type: 'unknown'" ); $object->getPath('unknown'); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/FrontControllerTest.php b/lib/internal/Magento/Framework/App/Test/Unit/FrontControllerTest.php old mode 100644 new mode 100755 index e2ebe0d3bc3897a5f0d7e6b55b6fbd11140d6a99..160256bf81e3e753fda23d01c360e0360009757c --- a/lib/internal/Magento/Framework/App/Test/Unit/FrontControllerTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/FrontControllerTest.php @@ -5,7 +5,8 @@ */ namespace Magento\Framework\App\Test\Unit; -use Magento\Framework\App\Action\NotFoundException; +use Magento\Framework\Exception\NotFoundException; +use Magento\Framework\App\State; class FrontControllerTest extends \PHPUnit_Framework_TestCase { @@ -29,6 +30,26 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ protected $router; + /** + * @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject + */ + protected $resultRedirect; + + /** + * @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $messageManager; + + /** + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $logger; + + /** + * @var State|\PHPUnit_Framework_MockObject_MockObject + */ + protected $appState; + protected function setUp() { $this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http') @@ -38,7 +59,19 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $this->router = $this->getMock('Magento\Framework\App\RouterInterface'); $this->routerList = $this->getMock('Magento\Framework\App\RouterList', [], [], '', false); - $this->model = new \Magento\Framework\App\FrontController($this->routerList); + $this->messageManager = $this->getMock('Magento\Framework\Message\ManagerInterface', [], [], '', false); + $this->logger = $this->getMock('Psr\Log\LoggerInterface', [], [], '', false); + $this->appState = $this->getMock('Magento\Framework\App\State', [], [], '', false); + $this->model = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)) + ->getObject( + 'Magento\Framework\App\FrontController', + [ + 'routerList' => $this->routerList, + 'messageManager' => $this->messageManager, + 'logger' => $this->logger, + 'appState' => $this->appState + ] + ); } /** @@ -120,7 +153,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $this->router->expects($this->at(0)) ->method('match') ->with($this->request) - ->will($this->throwException(new NotFoundException())); + ->willThrowException(new NotFoundException(new \Magento\Framework\Phrase('Page not found.'))); $this->router->expects($this->at(1)) ->method('match') ->with($this->request) @@ -140,4 +173,103 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($response, $this->model->dispatch($this->request)); } + + public function testDispatchedLocalizedException() + { + $message = 'Test'; + $this->routerList->expects($this->any()) + ->method('valid') + ->willReturn(true); + + $this->resultRedirect = $this->getMock('Magento\Framework\Controller\Result\Redirect', [], [], '', false); + + $response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); + $controllerInstance = $this->getMock('Magento\Framework\App\ActionInterface'); + $controllerInstance->expects($this->any()) + ->method('getResponse') + ->willReturn($response); + $controllerInstance->expects($this->any()) + ->method('dispatch') + ->with($this->request) + ->willThrowException( + new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase($message)) + ); + $controllerInstance->expects($this->once())->method('getDefaultResult')->willReturn($this->resultRedirect); + + $this->router->expects($this->once()) + ->method('match') + ->with($this->request) + ->willReturn($controllerInstance); + + $this->routerList->expects($this->any()) + ->method('current') + ->willReturn($this->router); + + $this->request->expects($this->at(0))->method('isDispatched')->willReturn(false); + $this->request->expects($this->once())->method('setDispatched')->with(true); + $this->request->expects($this->at(2))->method('isDispatched')->willReturn(true); + + $this->messageManager->expects($this->once())->method('addError')->with($message); + $this->logger->expects($this->once())->method('critical')->with($message); + + $this->assertEquals($this->resultRedirect, $this->model->dispatch($this->request)); + } + + /** + * @param string $mode + * @param string $exceptionMessage + * @param string $sessionMessage + * @dataProvider dispatchedWithPhpExceptionDataProvider + */ + public function testDispatchedPhpException($mode, $exceptionMessage, $sessionMessage) + { + $this->routerList->expects($this->any()) + ->method('valid') + ->willReturn(true); + + $this->resultRedirect = $this->getMock('Magento\Framework\Controller\Result\Redirect', [], [], '', false); + + $response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); + $controllerInstance = $this->getMock('Magento\Framework\App\ActionInterface'); + $controllerInstance->expects($this->any()) + ->method('getResponse') + ->willReturn($response); + $controllerInstance->expects($this->any()) + ->method('dispatch') + ->with($this->request) + ->willThrowException(new \Exception(new \Magento\Framework\Phrase($exceptionMessage))); + $controllerInstance->expects($this->once())->method('getDefaultResult')->willReturn($this->resultRedirect); + + $this->router->expects($this->once()) + ->method('match') + ->with($this->request) + ->willReturn($controllerInstance); + + $this->routerList->expects($this->any()) + ->method('current') + ->willReturn($this->router); + + $this->request->expects($this->at(0))->method('isDispatched')->willReturn(false); + $this->request->expects($this->once())->method('setDispatched')->with(true); + $this->request->expects($this->at(2))->method('isDispatched')->willReturn(true); + + $this->appState->expects($this->once())->method('getMode')->willReturn($mode); + + $this->messageManager->expects($this->once())->method('addError')->with($sessionMessage); + $this->logger->expects($this->once())->method('critical')->with($exceptionMessage); + + $this->assertEquals($this->resultRedirect, $this->model->dispatch($this->request)); + } + + /** + * @return array + */ + public function dispatchedWithPhpExceptionDataProvider() + { + return [ + [State::MODE_DEVELOPER, 'Test', 'Test'], + [State::MODE_DEFAULT, 'Test', 'An error occurred while processing your request'], + [State::MODE_PRODUCTION, 'Test', 'An error occurred while processing your request'], + ]; + } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/HttpTest.php b/lib/internal/Magento/Framework/App/Test/Unit/HttpTest.php index 2d071943fbd8e52d2c5dff474d926490a62c942d..202cc71761b318a577e6b50b38722ba68fc13a3e 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/HttpTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/HttpTest.php @@ -199,7 +199,10 @@ class HttpTest extends \PHPUnit_Framework_TestCase $this->responseMock->expects($this->once())->method('sendHeaders'); $bootstrap = $this->getMock('Magento\Framework\App\Bootstrap', [], [], '', false); $bootstrap->expects($this->once())->method('isDeveloperMode')->willReturn(false); - $this->assertTrue($this->http->catchException($bootstrap, new \Magento\Framework\Session\Exception('Test'))); + $this->assertTrue($this->http->catchException( + $bootstrap, + new \Magento\Framework\Exception\SessionException(new \Magento\Framework\Phrase('Test')) + )); } /** diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Router/ActionListTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Router/ActionListTest.php old mode 100644 new mode 100755 index 187192828067e85d8e61020659aa0aee11f347fa..dcb70fc401949e9240de847aad4b2ba7412258b0 --- a/lib/internal/Magento/Framework/App/Test/Unit/Router/ActionListTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Router/ActionListTest.php @@ -112,7 +112,7 @@ class ActionListTest extends \PHPUnit_Framework_TestCase $mockClassName = 'Mock_Action_Class'; $actionClass = $this->getMockClass( 'Magento\Framework\App\ActionInterface', - ['dispatch', 'getResponse'], + ['dispatch', 'getResponse', 'getDefaultResult'], [], $mockClassName ); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/StateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/StateTest.php index e8066f086c37b02ba2a8c15caaedfb323d891c7c..4bc544940975d7043a8683587af2e8ea10efdc31 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/StateTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/StateTest.php @@ -43,14 +43,14 @@ class StateTest extends \PHPUnit_Framework_TestCase $areaCode = 'some code'; $this->scopeMock->expects($this->once())->method('setCurrentScope')->with($areaCode); $this->model->setAreaCode($areaCode); - $this->setExpectedException('Magento\Framework\Exception'); + $this->setExpectedException('Magento\Framework\Exception\LocalizedException'); $this->model->setAreaCode('any code'); } public function testGetAreaCodeException() { $this->scopeMock->expects($this->never())->method('setCurrentScope'); - $this->setExpectedException('Magento\Framework\Exception'); + $this->setExpectedException('Magento\Framework\Exception\LocalizedException'); $this->model->getAreaCode(); } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/Version/Storage/FileTest.php b/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/Version/Storage/FileTest.php index 05a69a46d6d64021f6b4b0f49a7cef3356368c86..4683b8012302edfeb92644d357ca4956e1e6a494 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/Version/Storage/FileTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/Version/Storage/FileTest.php @@ -62,7 +62,9 @@ class FileTest extends \PHPUnit_Framework_TestCase */ public function testLoadExceptionWrapping() { - $filesystemException = new \Magento\Framework\Filesystem\FilesystemException('File does not exist'); + $filesystemException = new \Magento\Framework\Exception\FileSystemException( + new \Magento\Framework\Phrase('File does not exist') + ); $this->directory ->expects($this->once()) ->method('readFile') diff --git a/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php b/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php old mode 100644 new mode 100755 index a89986314b2ca32c7aac579cf2ab2ab95361eb09..65e059a58a3158ec6e5a627ad6ed85923a0317ac --- a/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php @@ -8,7 +8,6 @@ namespace Magento\Framework\App\Test\Unit\View\Deployment; use \Magento\Framework\App\View\Deployment\Version; - class VersionTest extends \PHPUnit_Framework_TestCase { /** @@ -40,7 +39,7 @@ class VersionTest extends \PHPUnit_Framework_TestCase ->method('getMode') ->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER)); $this->versionStorage->expects($this->never())->method($this->anything()); - $this->assertEquals(time(), $this->object->getValue(), '', 5); + $this->assertInternalType('integer', $this->object->getValue()); $this->object->getValue(); // Ensure computation occurs only once and result is cached in memory } @@ -71,6 +70,7 @@ class VersionTest extends \PHPUnit_Framework_TestCase public function testGetValueDefaultModeSaving() { + $versionType = 'integer'; $this->appState ->expects($this->once()) ->method('getMode') @@ -80,8 +80,8 @@ class VersionTest extends \PHPUnit_Framework_TestCase ->expects($this->once()) ->method('load') ->will($this->throwException($storageException)); - $this->versionStorage->expects($this->once())->method('save')->with($this->equalTo(time(), 5)); - $this->assertEquals(time(), $this->object->getValue()); + $this->versionStorage->expects($this->once())->method('save')->with($this->isType($versionType)); + $this->assertInternalType($versionType, $this->object->getValue()); $this->object->getValue(); // Ensure caching in memory } } diff --git a/lib/internal/Magento/Framework/App/View/Deployment/Version.php b/lib/internal/Magento/Framework/App/View/Deployment/Version.php old mode 100644 new mode 100755 diff --git a/lib/internal/Magento/Framework/App/View/Deployment/Version/Storage/File.php b/lib/internal/Magento/Framework/App/View/Deployment/Version/Storage/File.php index bf04e81dbc254027f258544ae958480ddd58510f..818eecb0040f5bec161b9b6c0bcb0b2b0f56c3d9 100644 --- a/lib/internal/Magento/Framework/App/View/Deployment/Version/Storage/File.php +++ b/lib/internal/Magento/Framework/App/View/Deployment/Version/Storage/File.php @@ -42,7 +42,7 @@ class File implements \Magento\Framework\App\View\Deployment\Version\StorageInte { try { return $this->directory->readFile($this->fileName); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { throw new \UnexpectedValueException( 'Unable to retrieve deployment version of static files from the file system.', 0, diff --git a/lib/internal/Magento/Framework/Archive/AbstractArchive.php b/lib/internal/Magento/Framework/Archive/AbstractArchive.php index 8ead7fd47b1172464ae4688179cedb58639c8476..9c8eed675fd1c2dfae7ff031c9301efbfaa30a6d 100644 --- a/lib/internal/Magento/Framework/Archive/AbstractArchive.php +++ b/lib/internal/Magento/Framework/Archive/AbstractArchive.php @@ -35,7 +35,7 @@ class AbstractArchive * * @param string $source * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _readFile($source) { @@ -43,7 +43,9 @@ class AbstractArchive if (is_file($source) && is_readable($source)) { $data = @file_get_contents($source); if ($data === false) { - throw new \Magento\Framework\Exception("Can't get contents from: " . $source); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Can't get contents from: %1", [$source]) + ); } } return $data; diff --git a/lib/internal/Magento/Framework/Archive/Helper/File.php b/lib/internal/Magento/Framework/Archive/Helper/File.php index f824c06a7b0410d0c13a9ea5aadd4b7c10143c27..549c3b8849fe73ba906f1fe643e8f45d2fae37bd 100644 --- a/lib/internal/Magento/Framework/Archive/Helper/File.php +++ b/lib/internal/Magento/Framework/Archive/Helper/File.php @@ -11,7 +11,7 @@ */ namespace Magento\Framework\Archive\Helper; -use Magento\Framework\Exception as MagentoException; +use Magento\Framework\Exception\LocalizedException as MagentoException; class File { @@ -96,23 +96,32 @@ class File if ($this->_isInWriteMode) { if (!is_writable($this->_fileLocation)) { - throw new MagentoException('Permission denied to write to ' . $this->_fileLocation); + throw new MagentoException( + new \Magento\Framework\Phrase('Permission denied to write to %1', [$this->_fileLocation]) + ); } if (is_file($this->_filePath) && !is_writable($this->_filePath)) { throw new MagentoException( - "Can't open file " . $this->_fileName . " for writing. Permission denied." + new \Magento\Framework\Phrase( + "Can't open file %1 for writing. Permission denied.", + [$this->_fileName] + ) ); } } if ($this->_isReadableMode($mode) && (!is_file($this->_filePath) || !is_readable($this->_filePath))) { if (!is_file($this->_filePath)) { - throw new MagentoException('File ' . $this->_filePath . ' does not exist'); + throw new MagentoException( + new \Magento\Framework\Phrase('File %1 does not exist', [$this->_filePath]) + ); } if (!is_readable($this->_filePath)) { - throw new MagentoException('Permission denied to read file ' . $this->_filePath); + throw new MagentoException( + new \Magento\Framework\Phrase('Permission denied to read file %1', [$this->_filePath]) + ); } } @@ -189,7 +198,7 @@ class File $this->_fileHandler = @fopen($this->_filePath, $mode); if (false === $this->_fileHandler) { - throw new MagentoException('Failed to open file ' . $this->_filePath); + throw new MagentoException(new \Magento\Framework\Phrase('Failed to open file %1', [$this->_filePath])); } } @@ -205,7 +214,7 @@ class File $result = @fwrite($this->_fileHandler, $data); if (false === $result) { - throw new MagentoException('Failed to write data to ' . $this->_filePath); + throw new MagentoException(new \Magento\Framework\Phrase('Failed to write data to %1', [$this->_filePath])); } } @@ -221,7 +230,9 @@ class File $result = fread($this->_fileHandler, $length); if (false === $result) { - throw new MagentoException('Failed to read data from ' . $this->_filePath); + throw new MagentoException( + new \Magento\Framework\Phrase('Failed to read data from %1', [$this->_filePath]) + ); } return $result; @@ -278,7 +289,7 @@ class File protected function _checkFileOpened() { if (!$this->_fileHandler) { - throw new MagentoException('File not opened'); + throw new MagentoException(new \Magento\Framework\Phrase('File not opened')); } } } diff --git a/lib/internal/Magento/Framework/Archive/Helper/File/Bz.php b/lib/internal/Magento/Framework/Archive/Helper/File/Bz.php index 46452bfa6e49d91b84271c7dadff8ee4c05ffc74..ada3317e13918a89775f19a5cfd479277ab90ee1 100644 --- a/lib/internal/Magento/Framework/Archive/Helper/File/Bz.php +++ b/lib/internal/Magento/Framework/Archive/Helper/File/Bz.php @@ -23,7 +23,9 @@ class Bz extends \Magento\Framework\Archive\Helper\File $this->_fileHandler = bzopen($this->_filePath, $mode); if (false === $this->_fileHandler) { - throw new \Magento\Framework\Exception('Failed to open file ' . $this->_filePath); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to open file ', [$this->_filePath]) + ); } } @@ -35,7 +37,9 @@ class Bz extends \Magento\Framework\Archive\Helper\File $result = bzwrite($this->_fileHandler, $data); if (false === $result) { - throw new \Magento\Framework\Exception('Failed to write data to ' . $this->_filePath); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to write data to ', [$this->_filePath]) + ); } } @@ -47,7 +51,9 @@ class Bz extends \Magento\Framework\Archive\Helper\File $data = bzread($this->_fileHandler, $length); if (false === $data) { - throw new \Magento\Framework\Exception('Failed to read data from ' . $this->_filePath); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to read data from ', [$this->_filePath]) + ); } return $data; diff --git a/lib/internal/Magento/Framework/Archive/Helper/File/Gz.php b/lib/internal/Magento/Framework/Archive/Helper/File/Gz.php index 52d18ed04f0430aa6206d48273fb01cd3ed6d4f7..dc5204d294785b0da90d778c72bfa703003957a6 100644 --- a/lib/internal/Magento/Framework/Archive/Helper/File/Gz.php +++ b/lib/internal/Magento/Framework/Archive/Helper/File/Gz.php @@ -25,7 +25,9 @@ class Gz extends \Magento\Framework\Archive\Helper\File $this->_fileHandler = gzopen($this->_filePath, $mode); if (false === $this->_fileHandler) { - throw new \Magento\Framework\Exception('Failed to open file ' . $this->_filePath); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to open file ', [$this->_filePath]) + ); } } @@ -37,7 +39,9 @@ class Gz extends \Magento\Framework\Archive\Helper\File $result = gzwrite($this->_fileHandler, $data); if (empty($result) && !empty($data)) { - throw new \Magento\Framework\Exception('Failed to write data to ' . $this->_filePath); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to write data to ', [$this->_filePath]) + ); } } diff --git a/lib/internal/Magento/Framework/Archive/Tar.php b/lib/internal/Magento/Framework/Archive/Tar.php index d8a532e0cc25ac4213c2eaaf3ffe239f8ca8a707..0b69b98930cd7aea95415e29615e8fe6655152e6 100644 --- a/lib/internal/Magento/Framework/Archive/Tar.php +++ b/lib/internal/Magento/Framework/Archive/Tar.php @@ -240,7 +240,7 @@ class Tar extends \Magento\Framework\Archive\AbstractArchive implements \Magento * @param bool $skipRoot * @param bool $finalize * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _createTar($skipRoot = false, $finalize = false) { @@ -254,7 +254,9 @@ class Tar extends \Magento\Framework\Archive\AbstractArchive implements \Magento $dirFiles = scandir($file); if (false === $dirFiles) { - throw new \Magento\Framework\Exception('Can\'t scan dir: ' . $file); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Can\'t scan dir: %1', [$file]) + ); } array_shift($dirFiles); @@ -381,7 +383,7 @@ class Tar extends \Magento\Framework\Archive\AbstractArchive implements \Magento * * @param string $destination path to file is unpacked * @return string[] list of files - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _unpackCurrentTar($destination) @@ -404,7 +406,9 @@ class Tar extends \Magento\Framework\Archive\AbstractArchive implements \Magento $mkdirResult = @mkdir($dirname, 0777, true); if (false === $mkdirResult) { - throw new \Magento\Framework\Exception('Failed to create directory ' . $dirname); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to create directory %1', [$dirname]) + ); } } @@ -415,7 +419,9 @@ class Tar extends \Magento\Framework\Archive\AbstractArchive implements \Magento $mkdirResult = @mkdir($currentFile, $header['mode'], true); if (false === $mkdirResult) { - throw new \Magento\Framework\Exception('Failed to create directory ' . $currentFile); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to create directory %1', [$currentFile]) + ); } } $list[] = $currentFile . '/'; diff --git a/lib/internal/Magento/Framework/Backup/AbstractBackup.php b/lib/internal/Magento/Framework/Backup/AbstractBackup.php index f980455dd5a6afd73d54141f63cf5cbff7d6778b..8c5020946fcd3b14b1ae1c12f9576c9981597f24 100644 --- a/lib/internal/Magento/Framework/Backup/AbstractBackup.php +++ b/lib/internal/Magento/Framework/Backup/AbstractBackup.php @@ -138,13 +138,15 @@ abstract class AbstractBackup implements BackupInterface * Set root directory of Magento installation * * @param string $rootDir - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function setRootDir($rootDir) { if (!is_dir($rootDir)) { - throw new \Magento\Framework\Exception('Bad root directory'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Bad root directory') + ); } $this->_rootDir = $rootDir; diff --git a/lib/internal/Magento/Framework/Backup/BackupException.php b/lib/internal/Magento/Framework/Backup/BackupException.php index 4efd0c3600ba06352d32d4e89e073c2afe6576c4..273fe476f67d0a357467012912a2b5b9e58b6ea9 100644 --- a/lib/internal/Magento/Framework/Backup/BackupException.php +++ b/lib/internal/Magento/Framework/Backup/BackupException.php @@ -11,6 +11,6 @@ */ namespace Magento\Framework\Backup; -class BackupException extends \Magento\Framework\Exception +class BackupException extends \Magento\Framework\Exception\LocalizedException { } diff --git a/lib/internal/Magento/Framework/Backup/Factory.php b/lib/internal/Magento/Framework/Backup/Factory.php index ba120c45615844b441b490d86e5bd9ba8e3be44b..d7827cea421f2da6ab22c92897492c9a798d5a3f 100644 --- a/lib/internal/Magento/Framework/Backup/Factory.php +++ b/lib/internal/Magento/Framework/Backup/Factory.php @@ -71,12 +71,17 @@ class Factory * * @param string $type * @return BackupInterface - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create($type) { if (!in_array($type, $this->_allowedTypes)) { - throw new \Magento\Framework\Exception('Current implementation not supported this type (' . $type . ') of backup.'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'Current implementation not supported this type (%1) of backup.', + [$type] + ) + ); } $class = 'Magento\Framework\Backup\\' . ucfirst($type); return $this->_objectManager->create($class); diff --git a/lib/internal/Magento/Framework/Backup/Filesystem.php b/lib/internal/Magento/Framework/Backup/Filesystem.php index 24ffe43be56c49f15cdc8fcdf4f85b45bbc50e04..2a36caf8e5522a427cbe787ed45ecff42561eb15 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem.php @@ -60,7 +60,7 @@ class Filesystem extends AbstractBackup /** * Implementation Rollback functionality for Filesystem * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return bool */ public function rollback() @@ -84,7 +84,7 @@ class Filesystem extends AbstractBackup /** * Implementation Create Backup functionality for Filesystem * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return boolean */ public function create() @@ -106,14 +106,16 @@ class Filesystem extends AbstractBackup if (!$filesInfo['readable']) { throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( - 'Not enough permissions to read files for backup' + new \Magento\Framework\Phrase('Not enough permissions to read files for backup') ); } $freeSpace = disk_free_space($this->getBackupsDir()); if (2 * $filesInfo['size'] > $freeSpace) { - throw new \Magento\Framework\Backup\Exception\NotEnoughFreeSpace('Not enough free space to create backup'); + throw new \Magento\Framework\Backup\Exception\NotEnoughFreeSpace( + new \Magento\Framework\Phrase('Not enough free space to create backup') + ); } $tarTmpPath = $this->_getTarTmpPath(); @@ -122,7 +124,9 @@ class Filesystem extends AbstractBackup $tarPacker->setSkipFiles($this->getIgnorePaths())->pack($this->getRootDir(), $tarTmpPath, true); if (!is_file($tarTmpPath) || filesize($tarTmpPath) == 0) { - throw new \Magento\Framework\Exception('Failed to create backup'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to create backup') + ); } $backupPath = $this->getBackupPath(); @@ -131,7 +135,9 @@ class Filesystem extends AbstractBackup $gzPacker->pack($tarTmpPath, $backupPath); if (!is_file($backupPath) || filesize($backupPath) == 0) { - throw new \Magento\Framework\Exception('Failed to create backup'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Failed to create backup') + ); } @unlink($tarTmpPath); @@ -241,7 +247,7 @@ class Filesystem extends AbstractBackup * Check backups directory existence and whether it's writeable * * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _checkBackupsDir() { @@ -251,7 +257,9 @@ class Filesystem extends AbstractBackup $backupsDirParentDirectory = basename($backupsDir); if (!is_writeable($backupsDirParentDirectory)) { - throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions('Cant create backups directory'); + throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( + new \Magento\Framework\Phrase('Cant create backups directory') + ); } mkdir($backupsDir); @@ -259,7 +267,9 @@ class Filesystem extends AbstractBackup } if (!is_writable($backupsDir)) { - throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions('Backups directory is not writeable'); + throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( + new \Magento\Framework\Phrase('Backups directory is not writeable') + ); } } diff --git a/lib/internal/Magento/Framework/Backup/Filesystem/Helper.php b/lib/internal/Magento/Framework/Backup/Filesystem/Helper.php index 5a2df37545d25b7ad98a628dedab4d505d86b63b..7e48f22c9e5006ee1d3e7204c7dd4ef7c144ac83 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem/Helper.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem/Helper.php @@ -51,7 +51,7 @@ class Helper * @param array $skipPaths * @param bool $removeRoot * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.ShortMethodName) */ public function rm($path, $skipPaths = [], $removeRoot = false) diff --git a/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php b/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php index 999302f8438a7a1d7cdb069c4b3be295f7b61d39..ff750d3c8b1e49e89659822ddc944c73995ca815 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php @@ -16,7 +16,7 @@ class Fs extends AbstractRollback * Files rollback implementation via local filesystem * * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * * @see AbstractRollback::run() */ @@ -25,7 +25,9 @@ class Fs extends AbstractRollback $snapshotPath = $this->_snapshot->getBackupPath(); if (!is_file($snapshotPath) || !is_readable($snapshotPath)) { - throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot('Cant load snapshot archive'); + throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot( + new \Magento\Framework\Phrase('Can\'t load snapshot archive') + ); } $fsHelper = new \Magento\Framework\Backup\Filesystem\Helper(); @@ -38,7 +40,7 @@ class Fs extends AbstractRollback if (!$filesInfo['writable']) { throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( - 'Unable to make rollback because not all files are writable' + new \Magento\Framework\Phrase('Unable to make rollback because not all files are writable') ); } diff --git a/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Ftp.php b/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Ftp.php index b9c0a9c6270db7bfac6e92fa5fad3df7211a69cf..395700ab0bb4e0f579d37adff29c4f95963a3d72 100644 --- a/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Ftp.php +++ b/lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Ftp.php @@ -8,7 +8,7 @@ namespace Magento\Framework\Backup\Filesystem\Rollback; /** * Rollback worker for rolling back via ftp * - * @author Magento Core Team <core@magentocommerce.com> + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Ftp extends AbstractRollback { @@ -23,7 +23,7 @@ class Ftp extends AbstractRollback * Files rollback implementation via ftp * * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * * @see AbstractRollback::run() */ @@ -32,7 +32,9 @@ class Ftp extends AbstractRollback $snapshotPath = $this->_snapshot->getBackupPath(); if (!is_file($snapshotPath) || !is_readable($snapshotPath)) { - throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot('Cant load snapshot archive'); + throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot( + new \Magento\Framework\Phrase('Can\'t load snapshot archive') + ); } $this->_initFtpClient(); @@ -61,7 +63,9 @@ class Ftp extends AbstractRollback $this->_ftpClient = new \Magento\Framework\System\Ftp(); $this->_ftpClient->connect($this->_snapshot->getFtpConnectString()); } catch (\Exception $e) { - throw new \Magento\Framework\Backup\Exception\FtpConnectionFailed($e->getMessage()); + throw new \Magento\Framework\Backup\Exception\FtpConnectionFailed( + new \Magento\Framework\Phrase($e->getMessage()) + ); } } @@ -69,7 +73,7 @@ class Ftp extends AbstractRollback * Perform ftp validation. Check whether ftp account provided points to current magento installation * * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _validateFtp() { @@ -80,7 +84,9 @@ class Ftp extends AbstractRollback @fclose($fh); if (!is_file($validationFilePath)) { - throw new \Magento\Framework\Exception('Unable to validate ftp account'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Unable to validate ftp account') + ); } $rootDir = $this->_snapshot->getRootDir(); @@ -90,7 +96,9 @@ class Ftp extends AbstractRollback @unlink($validationFilePath); if (!$fileExistsOnFtp) { - throw new \Magento\Framework\Backup\Exception\FtpValidationFailed('Failed to validate ftp account'); + throw new \Magento\Framework\Backup\Exception\FtpValidationFailed( + new \Magento\Framework\Phrase('Failed to validate ftp account') + ); } } @@ -110,7 +118,7 @@ class Ftp extends AbstractRollback /** * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _createTmpDir() { @@ -119,7 +127,9 @@ class Ftp extends AbstractRollback $result = @mkdir($tmpDir); if (false === $result) { - throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions('Failed to create directory ' . $tmpDir); + throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( + new \Magento\Framework\Phrase('Failed to create directory %1', [$tmpDir]) + ); } return $tmpDir; @@ -157,7 +167,7 @@ class Ftp extends AbstractRollback * * @param string $tmpDir * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function _uploadBackupToFtp($tmpDir) @@ -186,7 +196,7 @@ class Ftp extends AbstractRollback $result = $this->_ftpClient->put($ftpPath, $item->__toString()); if (false === $result) { throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions( - 'Failed to upload file ' . $item->__toString() . ' to ftp' + new \Magento\Framework\Phrase('Failed to upload file %1 to ftp', [$item->__toString()]) ); } } diff --git a/lib/internal/Magento/Framework/Backup/Media.php b/lib/internal/Magento/Framework/Backup/Media.php index 452e8a1e8f3256bc8960bc9996594aa375028115..5ae5b404d292c3fe9379d125296881ef89d1ec67 100644 --- a/lib/internal/Magento/Framework/Backup/Media.php +++ b/lib/internal/Magento/Framework/Backup/Media.php @@ -16,7 +16,7 @@ class Media extends Snapshot /** * Implementation Rollback functionality for Media * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return bool */ public function rollback() @@ -28,7 +28,7 @@ class Media extends Snapshot /** * Implementation Create Backup functionality for Media * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return bool */ public function create() diff --git a/lib/internal/Magento/Framework/Backup/Test/Unit/FactoryTest.php b/lib/internal/Magento/Framework/Backup/Test/Unit/FactoryTest.php index 7f4871f3f937ec6490b2821367efa703a3b7443f..b2c611c2cf991e964d067bd4d5acd7f8eaecfd64 100644 --- a/lib/internal/Magento/Framework/Backup/Test/Unit/FactoryTest.php +++ b/lib/internal/Magento/Framework/Backup/Test/Unit/FactoryTest.php @@ -24,7 +24,7 @@ class FactoryTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testCreateWrongType() { diff --git a/lib/internal/Magento/Framework/Cache/Backend/Memcached.php b/lib/internal/Magento/Framework/Cache/Backend/Memcached.php index 7d938dbe455f36ac9d7c69127aad0c29a5b62f38..9efb46607ff0a94dd5353b51fc82cc3869b82f56 100644 --- a/lib/internal/Magento/Framework/Cache/Backend/Memcached.php +++ b/lib/internal/Magento/Framework/Cache/Backend/Memcached.php @@ -21,7 +21,7 @@ class Memcached extends \Zend_Cache_Backend_Memcached implements \Zend_Cache_Bac * Constructor * * @param array $options @see \Zend_Cache_Backend_Memcached::__construct() - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct(array $options = []) { @@ -29,8 +29,10 @@ class Memcached extends \Zend_Cache_Backend_Memcached implements \Zend_Cache_Bac if (!isset($options['slab_size']) || !is_numeric($options['slab_size'])) { if (isset($options['slab_size'])) { - throw new \Magento\Framework\Exception( - "Invalid value for the node <slab_size>. Expected to be positive integer." + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + "Invalid value for the node <slab_size>. Expected to be positive integer." + ) ); } diff --git a/lib/internal/Magento/Framework/Code/Generator.php b/lib/internal/Magento/Framework/Code/Generator.php index 35026a88b69d1d66c4e10d913ea5b5fa35e2d155..03ac500f47daccb01521a26559f1b6b3669f8494 100644 --- a/lib/internal/Magento/Framework/Code/Generator.php +++ b/lib/internal/Magento/Framework/Code/Generator.php @@ -69,7 +69,7 @@ class Generator * * @param string $className * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @throws \InvalidArgumentException */ public function generateClass($className) @@ -102,7 +102,9 @@ class Generator $this->tryToLoadSourceClass($className, $generator); if (!($file = $generator->generate())) { $errors = $generator->getErrors(); - throw new \Magento\Framework\Exception(implode(' ', $errors)); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase(implode(' ', $errors)) + ); } $this->includeFile($file); return self::GENERATION_SUCCESS; @@ -167,15 +169,18 @@ class Generator * @param string $className * @param \Magento\Framework\Code\Generator\EntityAbstract $generator * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function tryToLoadSourceClass($className, $generator) { $sourceClassName = $generator->getSourceClassName(); if (!$this->definedClasses->classLoadable($sourceClassName)) { if ($this->generateClass($sourceClassName) !== self::GENERATION_SUCCESS) { - throw new \Magento\Framework\Exception( - sprintf('Source class "%s" for "%s" generation does not exist.', $sourceClassName, $className) + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'Source class "%1" for "%2" generation does not exist.', + [$sourceClassName, $className] + ) ); } } diff --git a/lib/internal/Magento/Framework/Code/Generator/Io.php b/lib/internal/Magento/Framework/Code/Generator/Io.php index 90898124ced2ad71b258cc48b5b98b79340615f5..945f1879afc3be38240514bf53246387b64df140 100644 --- a/lib/internal/Magento/Framework/Code/Generator/Io.php +++ b/lib/internal/Magento/Framework/Code/Generator/Io.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\Code\Generator; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; class Io { @@ -84,7 +84,7 @@ class Io /** * @param string $fileName * @param string $content - * @throws FilesystemException + * @throws FileSystemException * @return bool */ public function writeResultFile($fileName, $content) @@ -101,7 +101,7 @@ class Io try { $success = $this->filesystemDriver->rename($tmpFile, $fileName); - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { if (!file_exists($fileName)) { throw $e; } else { @@ -164,7 +164,7 @@ class Io $this->filesystemDriver->createDirectory($directory, self::DIRECTORY_PERMISSION); } return true; - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { return false; } } diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/GeneratorTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/GeneratorTest.php index efa21cde844f603a7e347bf46002d9b77312e529..e01f4c529c8274aaa48bc8b37b409da7037a4191 100644 --- a/lib/internal/Magento/Framework/Code/Test/Unit/GeneratorTest.php +++ b/lib/internal/Magento/Framework/Code/Test/Unit/GeneratorTest.php @@ -60,7 +60,7 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @dataProvider generateValidClassDataProvider */ public function testGenerateClass($className, $entityType) @@ -117,7 +117,7 @@ class GeneratorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testGenerateClassWithError() { diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ArgumentSequenceTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ArgumentSequenceTest.php index 054cee5cdb830eb3101a82d805176d3d0b34d7b0..2244c9f5d4a182b6bf200fa34c84b4bde73495ee 100644 --- a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ArgumentSequenceTest.php +++ b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ArgumentSequenceTest.php @@ -51,7 +51,7 @@ class ArgumentSequenceTest extends \PHPUnit_Framework_TestCase 'Actual : %s' . PHP_EOL; $message = sprintf($message, '\ArgumentSequence\InvalidChildClass', $expectedSequence, $actualSequence); - $this->setExpectedException('\Magento\Framework\Code\ValidationException', $message); + $this->setExpectedException('Magento\Framework\Exception\ValidatorException', $message); $this->_validator->validate('\ArgumentSequence\InvalidChildClass'); } } diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ConstructorArgumentTypesTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ConstructorArgumentTypesTest.php index 74fa005dae7a4b3f789e5ccb604936246b7f1810..da7d3a62f2705b09822d9179f2684b78cf3dfdc9 100644 --- a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ConstructorArgumentTypesTest.php +++ b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ConstructorArgumentTypesTest.php @@ -60,7 +60,7 @@ class ConstructorArgumentTypesTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Code\ValidationException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Invalid constructor argument(s) in \stdClass */ public function testValidateWithException() diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ConstructorIntegrityTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ConstructorIntegrityTest.php index b278d42c55637cf9513f5bac7c6042276237582a..8fffbc9c2706369a40f23df7a7a27e8f7f23c7b0 100644 --- a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ConstructorIntegrityTest.php +++ b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ConstructorIntegrityTest.php @@ -44,7 +44,7 @@ class ConstructorIntegrityTest extends \PHPUnit_Framework_TestCase $fileName = realpath(__DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Four/Test.php'); $fileName = str_replace('\\', '/', $fileName); $this->setExpectedException( - '\Magento\Framework\Code\ValidationException', + '\Magento\Framework\Exception\ValidatorException', 'Extra parameters passed to parent construct: $factory. File: ' . $fileName ); $this->_model->validate('Magento\SomeModule\Model\Four\Test'); @@ -55,7 +55,7 @@ class ConstructorIntegrityTest extends \PHPUnit_Framework_TestCase $fileName = realpath(__DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Five/Test.php'); $fileName = str_replace('\\', '/', $fileName); $this->setExpectedException( - '\Magento\Framework\Code\ValidationException', + '\Magento\Framework\Exception\ValidatorException', 'Missed required argument factory in parent::__construct call. File: ' . $fileName ); $this->_model->validate('Magento\SomeModule\Model\Five\Test'); @@ -66,7 +66,7 @@ class ConstructorIntegrityTest extends \PHPUnit_Framework_TestCase $fileName = realpath(__DIR__ . '/../_files/app/code/Magento/SomeModule/Model/Six/Test.php'); $fileName = str_replace('\\', '/', $fileName); $this->setExpectedException( - '\Magento\Framework\Code\ValidationException', + '\Magento\Framework\Exception\ValidatorException', 'Incompatible argument type: Required type: \Magento\SomeModule\Model\Proxy. ' . 'Actual type: \Magento\SomeModule\Model\ElementFactory; File: ' . PHP_EOL . @@ -80,7 +80,7 @@ class ConstructorIntegrityTest extends \PHPUnit_Framework_TestCase $fileName = realpath(__DIR__) . '/_files/ClassesForConstructorIntegrity.php'; $fileName = str_replace('\\', '/', $fileName); $this->setExpectedException( - '\Magento\Framework\Code\ValidationException', + '\Magento\Framework\Exception\ValidatorException', 'Incompatible argument type: Required type: \Context. ' . 'Actual type: \ClassA; File: ' . PHP_EOL . @@ -94,7 +94,7 @@ class ConstructorIntegrityTest extends \PHPUnit_Framework_TestCase $fileName = realpath(__DIR__) . '/_files/ClassesForConstructorIntegrity.php'; $fileName = str_replace('\\', '/', $fileName); $this->setExpectedException( - '\Magento\Framework\Code\ValidationException', + '\Magento\Framework\Exception\ValidatorException', 'Incompatible argument type: Required type: array. ' . 'Actual type: \ClassB; File: ' . PHP_EOL . $fileName ); $this->_model->validate('ClassArgumentWithWrongParentArgumentsType'); diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ContextAggregationTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ContextAggregationTest.php index 30667c6727828227b99c205d5bb9c119b8ef930d..b40b91bb42e0183a216769397fc78e5f98140ca3 100644 --- a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ContextAggregationTest.php +++ b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/ContextAggregationTest.php @@ -32,7 +32,7 @@ class ContextAggregationTest extends \PHPUnit_Framework_TestCase PHP_EOL . '\ClassFirst already exists in context object'; - $this->setExpectedException('\Magento\Framework\Code\ValidationException', $message); + $this->setExpectedException('\Magento\Framework\Exception\ValidatorException', $message); $this->_model->validate('ClassArgumentAlreadyInjectedInContext'); } @@ -53,7 +53,7 @@ class ContextAggregationTest extends \PHPUnit_Framework_TestCase PHP_EOL . '\\InterfaceFirst already exists in context object'; - $this->setExpectedException('\Magento\Framework\Code\ValidationException', $message); + $this->setExpectedException('\Magento\Framework\Exception\ValidatorException', $message); $this->_model->validate('ClassArgumentWithAlreadyInjectedInterface'); } } diff --git a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/TypeDuplicationTest.php b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/TypeDuplicationTest.php index acaeaa41033ed043f9d3584c246c4e67bcc4240a..0b0c00c72dc8797a736bd0ac4887a1764b3e262a 100644 --- a/lib/internal/Magento/Framework/Code/Test/Unit/Validator/TypeDuplicationTest.php +++ b/lib/internal/Magento/Framework/Code/Test/Unit/Validator/TypeDuplicationTest.php @@ -49,7 +49,7 @@ class TypeDuplicationTest extends \PHPUnit_Framework_TestCase $this->_fixturePath . PHP_EOL . 'Multiple type injection [\TypeDuplication\ArgumentBaseClass]'; - $this->setExpectedException('\Magento\Framework\Code\ValidationException', $message); + $this->setExpectedException('Magento\Framework\Exception\ValidatorException', $message); $this->_validator->validate('\TypeDuplication\InvalidClassWithDuplicatedTypes'); } } diff --git a/lib/internal/Magento/Framework/Code/ValidationException.php b/lib/internal/Magento/Framework/Code/ValidationException.php deleted file mode 100644 index b3831d4c930a108a397bccb69431ef54c01e4e0a..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Code/ValidationException.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Code; - -class ValidationException extends \Exception -{ -} diff --git a/lib/internal/Magento/Framework/Code/Validator.php b/lib/internal/Magento/Framework/Code/Validator.php index 5f371f781c0cc9c08a09f92e9b76673382de5c52..c20388fe944d0337ddba4a0018777c2bff94fac2 100644 --- a/lib/internal/Magento/Framework/Code/Validator.php +++ b/lib/internal/Magento/Framework/Code/Validator.php @@ -28,7 +28,7 @@ class Validator implements ValidatorInterface * * @param string $className * @return bool - * @throws \Magento\Framework\Code\ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className) { diff --git a/lib/internal/Magento/Framework/Code/Validator/ArgumentSequence.php b/lib/internal/Magento/Framework/Code/Validator/ArgumentSequence.php index 382983e35db84b77357773a611b84258a81ef57a..1c9e663a3bc7cded2024da27b252ac17ba91a8bf 100644 --- a/lib/internal/Magento/Framework/Code/Validator/ArgumentSequence.php +++ b/lib/internal/Magento/Framework/Code/Validator/ArgumentSequence.php @@ -7,7 +7,6 @@ */ namespace Magento\Framework\Code\Validator; -use Magento\Framework\Code\ValidationException; use Magento\Framework\Code\ValidatorInterface; class ArgumentSequence implements ValidatorInterface @@ -39,7 +38,7 @@ class ArgumentSequence implements ValidatorInterface * * @param string $className * @return bool - * @throws ValidationException + * @throws \Magento\Framework\Exception\ValidatorException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function validate($className) @@ -78,20 +77,19 @@ class ArgumentSequence implements ValidatorInterface if (false == $this->_checkArgumentSequence($classArguments, $requiredSequence)) { $classPath = str_replace('\\', '/', $class->getFileName()); - throw new ValidationException( - 'Incorrect argument sequence in class ' . - $className . - ' in ' . - $classPath . - PHP_EOL . - 'Required: $' . - implode( - ', $', - array_keys($requiredSequence) - ) . PHP_EOL . 'Actual : $' . implode( - ', $', - array_keys($classArguments) - ) . PHP_EOL + throw new \Magento\Framework\Exception\ValidatorException( + new \Magento\Framework\Phrase( + 'Incorrect argument sequence in class %1 in %2%3Required: $%4%5Actual : $%6%7', + [ + $className, + $classPath, + PHP_EOL, + implode(', $', array_keys($requiredSequence)), + PHP_EOL, + implode(', $', array_keys($classArguments)), + PHP_EOL + ] + ) ); } diff --git a/lib/internal/Magento/Framework/Code/Validator/ConstructorArgumentTypes.php b/lib/internal/Magento/Framework/Code/Validator/ConstructorArgumentTypes.php index 6fdfe35b430e59fce6838d9b68864e42ae91328f..644d863313a806e5d05377ab5ae127dfa87f5c80 100644 --- a/lib/internal/Magento/Framework/Code/Validator/ConstructorArgumentTypes.php +++ b/lib/internal/Magento/Framework/Code/Validator/ConstructorArgumentTypes.php @@ -37,7 +37,7 @@ class ConstructorArgumentTypes implements ValidatorInterface * * @param string $className * @return bool - * @throws \Magento\Framework\Code\ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className) { @@ -49,8 +49,11 @@ class ConstructorArgumentTypes implements ValidatorInterface }, $expectedArguments); $result = array_diff($expectedArguments, $actualArguments); if (!empty($result)) { - throw new \Magento\Framework\Code\ValidationException( - 'Invalid constructor argument(s) in ' . $className + throw new \Magento\Framework\Exception\ValidatorException( + new \Magento\Framework\Phrase( + 'Invalid constructor argument(s) in %1', + [$className] + ) ); } return true; diff --git a/lib/internal/Magento/Framework/Code/Validator/ConstructorIntegrity.php b/lib/internal/Magento/Framework/Code/Validator/ConstructorIntegrity.php index 63929f4a08ad7e24c1ff2ef93d3949fff6c7e7c9..62cd9b7675e48c38adcc0e0cafed8513b85bde27 100644 --- a/lib/internal/Magento/Framework/Code/Validator/ConstructorIntegrity.php +++ b/lib/internal/Magento/Framework/Code/Validator/ConstructorIntegrity.php @@ -8,6 +8,7 @@ namespace Magento\Framework\Code\Validator; use Magento\Framework\Code\ValidatorInterface; +use Magento\Framework\Phrase; class ConstructorIntegrity implements ValidatorInterface { @@ -29,7 +30,7 @@ class ConstructorIntegrity implements ValidatorInterface * * @param string $className * @return bool - * @throws \Magento\Framework\Code\ValidationException + * @throws \Magento\Framework\Exception\ValidatorException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -73,11 +74,11 @@ class ConstructorIntegrity implements ValidatorInterface } $classPath = str_replace('\\', '/', $class->getFileName()); - throw new \Magento\Framework\Code\ValidationException( - 'Missed required argument ' . - $requiredArgument['name'] . - ' in parent::__construct call. File: ' . - $classPath + throw new \Magento\Framework\Exception\ValidatorException( + new Phrase( + 'Missed required argument %1 in parent::__construct call. File: %2', + [$requiredArgument['name'], $classPath] + ) ); } @@ -87,15 +88,11 @@ class ConstructorIntegrity implements ValidatorInterface ); if (false == $isCompatibleTypes) { $classPath = str_replace('\\', '/', $class->getFileName()); - throw new \Magento\Framework\Code\ValidationException( - 'Incompatible argument type: Required type: ' . - $requiredArgument['type'] . - '. Actual type: ' . - $actualArgument['type'] . - '; File: ' . - PHP_EOL . - $classPath . - PHP_EOL + throw new \Magento\Framework\Exception\ValidatorException( + new Phrase( + 'Incompatible argument type: Required type: %1. Actual type: %2; File: %3%4%5', + [$requiredArgument['type'], $actualArgument['type'], PHP_EOL, $classPath, PHP_EOL] + ) ); } } @@ -112,8 +109,11 @@ class ConstructorIntegrity implements ValidatorInterface } $classPath = str_replace('\\', '/', $class->getFileName()); - throw new \Magento\Framework\Code\ValidationException( - 'Extra parameters passed to parent construct: ' . implode(', ', $names) . '. File: ' . $classPath + throw new \Magento\Framework\Exception\ValidatorException( + new Phrase( + 'Extra parameters passed to parent construct: %1. File: %2', + [implode(', ', $names), $classPath] + ) ); } return true; diff --git a/lib/internal/Magento/Framework/Code/Validator/ContextAggregation.php b/lib/internal/Magento/Framework/Code/Validator/ContextAggregation.php index eec24881210defa1dc4afe1c7d0c44cd75017608..18ebce1fbad128d35f7d6a33520889d7aaba53eb 100644 --- a/lib/internal/Magento/Framework/Code/Validator/ContextAggregation.php +++ b/lib/internal/Magento/Framework/Code/Validator/ContextAggregation.php @@ -7,7 +7,6 @@ */ namespace Magento\Framework\Code\Validator; -use Magento\Framework\Code\ValidationException; use Magento\Framework\Code\ValidatorInterface; class ContextAggregation implements ValidatorInterface @@ -30,7 +29,7 @@ class ContextAggregation implements ValidatorInterface * * @param string $className * @return bool - * @throws ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className) { @@ -62,10 +61,15 @@ class ContextAggregation implements ValidatorInterface if (false == empty($errors)) { $classPath = str_replace('\\', '/', $class->getFileName()); - throw new ValidationException( - 'Incorrect dependency in class ' . $className . ' in ' . $classPath . PHP_EOL . implode( - PHP_EOL, - $errors + throw new \Magento\Framework\Exception\ValidatorException( + new \Magento\Framework\Phrase( + 'Incorrect dependency in class %1 in %2%3%4', + [ + $className, + $classPath, + PHP_EOL, + implode(PHP_EOL, $errors) + ] ) ); } diff --git a/lib/internal/Magento/Framework/Code/Validator/TypeDuplication.php b/lib/internal/Magento/Framework/Code/Validator/TypeDuplication.php index ff78fc59a5acf19a5a1b19056f2a2a8eeab3d6ca..45d50b84a3b66fa1b77477ec3e5ce38503aad420 100644 --- a/lib/internal/Magento/Framework/Code/Validator/TypeDuplication.php +++ b/lib/internal/Magento/Framework/Code/Validator/TypeDuplication.php @@ -7,7 +7,6 @@ */ namespace Magento\Framework\Code\Validator; -use Magento\Framework\Code\ValidationException; use Magento\Framework\Code\ValidatorInterface; class TypeDuplication implements ValidatorInterface @@ -37,7 +36,7 @@ class TypeDuplication implements ValidatorInterface * * @param string $className * @return bool - * @throws ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className) { @@ -62,15 +61,15 @@ class TypeDuplication implements ValidatorInterface if (!empty($errors)) { if (false == $this->_ignoreWarning($class)) { $classPath = str_replace('\\', '/', $class->getFileName()); - throw new ValidationException( - 'Argument type duplication in class ' . - $class->getName() . - ' in ' . - $classPath . - PHP_EOL . - implode( - PHP_EOL, - $errors + throw new \Magento\Framework\Exception\ValidatorException( + new \Magento\Framework\Phrase( + 'Argument type duplication in class %1 in %2%3%4', + [ + $class->getName(), + $classPath, + PHP_EOL, + implode(PHP_EOL, $errors) + ] ) ); } diff --git a/lib/internal/Magento/Framework/Code/ValidatorInterface.php b/lib/internal/Magento/Framework/Code/ValidatorInterface.php index df90607007d7659319498c0de99e4fdf9e05e940..9a55182aa375acf155e9c76f5be8c024e97ded9c 100644 --- a/lib/internal/Magento/Framework/Code/ValidatorInterface.php +++ b/lib/internal/Magento/Framework/Code/ValidatorInterface.php @@ -12,7 +12,7 @@ interface ValidatorInterface * * @param string $className * @return bool - * @throws \Magento\Framework\Code\ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className); } diff --git a/lib/internal/Magento/Framework/Config/AbstractXml.php b/lib/internal/Magento/Framework/Config/AbstractXml.php index 323069c5488d5d2ee511192907d1736a8eeeb934..acdd49eeee201a5dc0bbb336f67255b7f8efad37 100644 --- a/lib/internal/Magento/Framework/Config/AbstractXml.php +++ b/lib/internal/Magento/Framework/Config/AbstractXml.php @@ -68,7 +68,7 @@ abstract class AbstractXml * * @param array $configFiles * @return \DOMDocument - * @throws \Magento\Framework\Exception If a non-existing or invalid XML-file passed + * @throws \Magento\Framework\Exception\LocalizedException If a non-existing or invalid XML-file passed */ protected function _merge($configFiles) { @@ -76,7 +76,9 @@ abstract class AbstractXml try { $this->_getDomConfigModel()->merge($content); } catch (\Magento\Framework\Config\Dom\ValidationException $e) { - throw new \Magento\Framework\Exception("Invalid XML in file " . $key . ":\n" . $e->getMessage()); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Invalid XML in file %1:\n%2", [$key, $e->getMessage()]) + ); } } if ($this->_isRuntimeValidated()) { @@ -90,13 +92,16 @@ abstract class AbstractXml * * @param string $file * @return $this - * @throws \Magento\Framework\Exception If invalid XML-file passed + * @throws \Magento\Framework\Exception\LocalizedException If invalid XML-file passed */ protected function _performValidate($file = null) { if (!$this->_getDomConfigModel()->validate($this->getSchemaFile(), $errors)) { - $message = is_null($file) ? "Invalid Document \n" : "Invalid XML-file: {$file}\n"; - throw new \Magento\Framework\Exception($message . implode("\n", $errors)); + $phrase = (null === $file) + ? new \Magento\Framework\Phrase('Invalid Document %1%2', [PHP_EOL, implode("\n", $errors)]) + : new \Magento\Framework\Phrase('Invalid XML-file: %1%2%3', [$file, PHP_EOL, implode("\n", $errors)]); + + throw new \Magento\Framework\Exception\LocalizedException($phrase); } return $this; } @@ -119,7 +124,7 @@ abstract class AbstractXml */ protected function _getDomConfigModel() { - if (is_null($this->_domConfig)) { + if (null === $this->_domConfig) { $schemaFile = $this->getPerFileSchemaFile() && $this->_isRuntimeValidated() ? $this->getPerFileSchemaFile() : null; $this->_domConfig = new \Magento\Framework\Config\Dom( diff --git a/lib/internal/Magento/Framework/Config/Dom.php b/lib/internal/Magento/Framework/Config/Dom.php index 57c18e8e6eb021cde44233bfaa54e6d2cc06ef46..1dbae5f157562717e939f98e2a45515dda13543f 100644 --- a/lib/internal/Magento/Framework/Config/Dom.php +++ b/lib/internal/Magento/Framework/Config/Dom.php @@ -13,6 +13,8 @@ namespace Magento\Framework\Config; /** * Class Dom + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Dom { @@ -223,7 +225,7 @@ class Dom * Getter for node by path * * @param string $nodePath - * @throws \Magento\Framework\Exception An exception is possible if original document contains multiple nodes for identifier + * @throws \Magento\Framework\Exception\LocalizedException An exception is possible if original document contains multiple nodes for identifier * @return \DOMElement|null */ protected function _getMatchedNode($nodePath) @@ -235,7 +237,9 @@ class Dom $matchedNodes = $xPath->query($nodePath); $node = null; if ($matchedNodes->length > 1) { - throw new \Magento\Framework\Exception("More than one node matching the query: {$nodePath}"); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("More than one node matching the query: %1", [$nodePath]) + ); } elseif ($matchedNodes->length == 1) { $node = $matchedNodes->item(0); } diff --git a/lib/internal/Magento/Framework/Config/Reader/Filesystem.php b/lib/internal/Magento/Framework/Config/Reader/Filesystem.php index fad1d245cfd9bec1f0f3fe05ad5440ebdc8e2f4c..992158c6edf6341e55f4b7d1a9d2f61589b7122e 100644 --- a/lib/internal/Magento/Framework/Config/Reader/Filesystem.php +++ b/lib/internal/Magento/Framework/Config/Reader/Filesystem.php @@ -126,7 +126,7 @@ class Filesystem implements \Magento\Framework\Config\ReaderInterface * * @param array $fileList * @return array - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _readFiles($fileList) { @@ -140,14 +140,18 @@ class Filesystem implements \Magento\Framework\Config\ReaderInterface $configMerger->merge($content); } } catch (\Magento\Framework\Config\Dom\ValidationException $e) { - throw new \Magento\Framework\Exception("Invalid XML in file " . $key . ":\n" . $e->getMessage()); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Invalid XML in file %1:\n%2", [$key, $e->getMessage()]) + ); } } if ($this->_isValidated) { $errors = []; if ($configMerger && !$configMerger->validate($this->_schemaFile, $errors)) { $message = "Invalid Document \n"; - throw new \Magento\Framework\Exception($message . implode("\n", $errors)); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase($message . implode("\n", $errors)) + ); } } diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php index 228d2bfd555616849ad22810dfe8845b134028fa..d759359f4ef03a1b6e8e044cd4350a39636d4d52 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/DomTest.php @@ -80,7 +80,7 @@ class DomTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage More than one node matching the query: /root/node/subnode */ public function testMergeException() diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/Reader/FilesystemTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/Reader/FilesystemTest.php index 99b86f3505dbc97bee0f0a9631016a7ef62f9a1a..bef2654e8c296a9f60e15ebbdde140aaa9d96d89 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/Reader/FilesystemTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/Reader/FilesystemTest.php @@ -84,7 +84,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid Document */ public function testReadWithInvalidDom() @@ -111,7 +111,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid XML in file */ public function testReadWithInvalidXml() diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/ViewTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/ViewTest.php index 5628898c95b4b0f88477898d05c5fd4e24d35de7..008d5ecfc3627b209d2a226faa5deb93441ccc54 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/ViewTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/ViewTest.php @@ -49,7 +49,7 @@ class ViewTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testInvalidXml() { diff --git a/lib/internal/Magento/Framework/Convert/ConvertArray.php b/lib/internal/Magento/Framework/Convert/ConvertArray.php index 902c7c99dee79309cb3af33e4c03fbcdbd130d73..a37021e1fbc830e1cc35e325dadcf2e74faa8010 100644 --- a/lib/internal/Magento/Framework/Convert/ConvertArray.php +++ b/lib/internal/Magento/Framework/Convert/ConvertArray.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\Convert; -use Magento\Framework\Exception; +use Magento\Framework\Exception\LocalizedException; /** * Convert the array data to SimpleXMLElement object @@ -19,12 +19,12 @@ class ConvertArray * @param array $array * @param string $rootName * @return \SimpleXMLElement - * @throws Exception + * @throws LocalizedException */ public function assocToXml(array $array, $rootName = '_') { if (empty($rootName) || is_numeric($rootName)) { - throw new Exception('Root element must not be empty or numeric'); + throw new LocalizedException(new \Magento\Framework\Phrase('Root element must not be empty or numeric')); } $xmlStr = <<<XML @@ -34,7 +34,7 @@ XML; $xml = new \SimpleXMLElement($xmlStr); foreach (array_keys($array) as $key) { if (is_numeric($key)) { - throw new Exception('Array root keys must not be numeric.'); + throw new LocalizedException(new \Magento\Framework\Phrase('Array root keys must not be numeric.')); } } return self::_assocToXml($array, $rootName, $xml); @@ -65,7 +65,7 @@ XML; * @param string $rootName * @param \SimpleXMLElement $xml * @return \SimpleXMLElement - * @throws Exception + * @throws LocalizedException */ private function _assocToXml(array $array, $rootName, \SimpleXMLElement $xml) { @@ -75,7 +75,11 @@ XML; if (!is_array($value)) { if (is_string($key)) { if ($key === $rootName) { - throw new Exception('Associative key must not be the same as its parent associative key.'); + throw new LocalizedException( + new \Magento\Framework\Phrase( + 'Associative key must not be the same as its parent associative key.' + ) + ); } $hasStringKey = true; $xml->addChild($key, $value); @@ -89,7 +93,9 @@ XML; } } if ($hasNumericKey && $hasStringKey) { - throw new Exception('Associative and numeric keys must not be mixed at one level.'); + throw new LocalizedException( + new \Magento\Framework\Phrase('Associative and numeric keys must not be mixed at one level.') + ); } return $xml; } diff --git a/lib/internal/Magento/Framework/Convert/Test/Unit/ConvertArrayTest.php b/lib/internal/Magento/Framework/Convert/Test/Unit/ConvertArrayTest.php index 056b58b3541e1dbafb8973143cc63c5d5898a789..f7c6a18bba13605858120553d891d4b82b1b3f85 100644 --- a/lib/internal/Magento/Framework/Convert/Test/Unit/ConvertArrayTest.php +++ b/lib/internal/Magento/Framework/Convert/Test/Unit/ConvertArrayTest.php @@ -50,7 +50,7 @@ XML; /** * @param array $array * @param string $rootName - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @dataProvider assocToXmlExceptionDataProvider */ public function testAssocToXmlException($array, $rootName = '_') diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/AdapterException.php b/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/AdapterException.php deleted file mode 100644 index 9aec56e0970fdbd8fe03fc4b0864daa7820b35a1..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/AdapterException.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Css\PreProcessor\Adapter; - -/** - * LESS adapter exception - */ -class AdapterException extends \Exception -{ -} diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index 64f38d98cfcaca8932ee42ebb185448812f0026d..c46f71cf9ebe447a028d6ce512819631ebd463e9 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -2215,7 +2215,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface * * @param array $options * @param string $ddlType Table DDL Column type constant - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return string * @throws \Zend_Db_Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) @@ -3343,7 +3343,9 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface { $fromSelect = $select->getPart(\Magento\Framework\DB\Select::FROM); if (empty($fromSelect)) { - throw new \Magento\Framework\DB\DBException('Select object must have correct "FROM" part'); + throw new \Magento\Framework\DB\DBException( + new \Magento\Framework\Phrase('Select object must have correct "FROM" part') + ); } $tableName = []; @@ -3451,7 +3453,9 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface } if (!$columns) { - throw new \Magento\Framework\DB\DBException('The columns for UPDATE statement are not defined'); + throw new \Magento\Framework\DB\DBException( + new \Magento\Framework\Phrase('The columns for UPDATE statement are not defined') + ); } $query = sprintf("%s\nSET %s", $query, implode(', ', $columns)); diff --git a/lib/internal/Magento/Framework/DB/DBException.php b/lib/internal/Magento/Framework/DB/DBException.php index df6bf9d109dc241d3bc6ebbda6dd05a9ead7fd11..6af4e98427bbf852c39c0b4494e4a5bba23339b1 100644 --- a/lib/internal/Magento/Framework/DB/DBException.php +++ b/lib/internal/Magento/Framework/DB/DBException.php @@ -10,6 +10,6 @@ namespace Magento\Framework\DB; * * @author Magento Core Team <core@magentocommerce.com> */ -class DBException extends \Magento\Framework\Exception +class DBException extends \Magento\Framework\Exception\LocalizedException { } diff --git a/lib/internal/Magento/Framework/DB/MapperFactory.php b/lib/internal/Magento/Framework/DB/MapperFactory.php index 0c701803e9b30b750174c7020d1d6bbaf164f9c0..5f125b76935edc5219a254db3dff8c8d62b311b3 100644 --- a/lib/internal/Magento/Framework/DB/MapperFactory.php +++ b/lib/internal/Magento/Framework/DB/MapperFactory.php @@ -33,13 +33,18 @@ class MapperFactory * @param string $className * @param array $arguments * @return MapperInterface - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create($className, array $arguments = []) { $mapper = $this->objectManager->create($className, $arguments); if (!$mapper instanceof MapperInterface) { - throw new \Magento\Framework\Exception($className . ' doesn\'t implement \Magento\Framework\DB\MapperInterface'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + '%1 doesn\'t implement \Magento\Framework\DB\MapperInterface', + [$className] + ) + ); } return $mapper; } diff --git a/lib/internal/Magento/Framework/DB/MapperInterface.php b/lib/internal/Magento/Framework/DB/MapperInterface.php index 74e3d926c5681ea311f48dd81f219bcb4850eb2c..67cb7d0ac6be3b48e0cae440485ff238aef29ea3 100644 --- a/lib/internal/Magento/Framework/DB/MapperInterface.php +++ b/lib/internal/Magento/Framework/DB/MapperInterface.php @@ -77,7 +77,7 @@ interface MapperInterface * * @param string|array $field * @param string|int|array $condition - * @throws \Magento\Framework\Exception if some error in the input could be detected. + * @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected. * @return void */ public function addFieldToFilter($field, $condition = null); diff --git a/lib/internal/Magento/Framework/DB/QueryBuilder.php b/lib/internal/Magento/Framework/DB/QueryBuilder.php index 68b24e06b5c905294a5ffb0e3ec34aa0637a3b5a..c764157be4ca43481b7ace33312b5580ed147496 100644 --- a/lib/internal/Magento/Framework/DB/QueryBuilder.php +++ b/lib/internal/Magento/Framework/DB/QueryBuilder.php @@ -75,7 +75,7 @@ class QueryBuilder /** * @return \Magento\Framework\DB\QueryInterface - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create() { diff --git a/lib/internal/Magento/Framework/DB/QueryFactory.php b/lib/internal/Magento/Framework/DB/QueryFactory.php index a78004fb03e48c4565b28379e825ebdbf3ad91d0..dea7d2da39a06697c26059c76453c6b9bacc5c5a 100644 --- a/lib/internal/Magento/Framework/DB/QueryFactory.php +++ b/lib/internal/Magento/Framework/DB/QueryFactory.php @@ -32,13 +32,18 @@ class QueryFactory * @param string $className * @param array $arguments * @return QueryInterface - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create($className, array $arguments = []) { $query = $this->objectManager->create($className, $arguments); if (!$query instanceof QueryInterface) { - throw new \Magento\Framework\Exception($className . ' doesn\'t implement \Magento\Framework\DB\QueryInterface'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + '%1 doesn\'t implement \Magento\Framework\DB\QueryInterface', + [$className] + ) + ); } return $query; } diff --git a/lib/internal/Magento/Framework/DB/Tree.php b/lib/internal/Magento/Framework/DB/Tree.php index e0a7b800b5df3925c8478680a09e815487a620f8..e2449c2bc8498fcd4758cc194862d3f78ee9742f 100644 --- a/lib/internal/Magento/Framework/DB/Tree.php +++ b/lib/internal/Magento/Framework/DB/Tree.php @@ -97,7 +97,9 @@ class Tree // make sure it's a \Zend_Db_Adapter if (!$connection instanceof \Zend_Db_Adapter_Abstract) { - throw new TreeException('db object does not implement \Zend_Db_Adapter_Abstract'); + throw new TreeException( + new \Magento\Framework\Phrase('db object does not implement \Zend_Db_Adapter_Abstract') + ); } // save the connection @@ -107,7 +109,7 @@ class Tree $conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); } } else { - throw new TreeException('db object is not set in config'); + throw new TreeException(new \Magento\Framework\Phrase('db object is not set in config')); } if (!empty($config['table'])) { diff --git a/lib/internal/Magento/Framework/DB/Tree/Node.php b/lib/internal/Magento/Framework/DB/Tree/Node.php index 80aa840e9de0563351cfc43171d2e0ab75e5f8c5..e9ea215876818ab635f24972875564cc4dd82ef7 100644 --- a/lib/internal/Magento/Framework/DB/Tree/Node.php +++ b/lib/internal/Magento/Framework/DB/Tree/Node.php @@ -65,10 +65,10 @@ class Node public function __construct($nodeData, $keys) { if (empty($nodeData)) { - throw new NodeException('Empty array of node information'); + throw new NodeException(new \Magento\Framework\Phrase('Empty array of node information')); } if (empty($keys)) { - throw new NodeException('Empty keys array'); + throw new NodeException(new \Magento\Framework\Phrase('Empty keys array')); } $this->id = $nodeData[$keys['id']]; diff --git a/lib/internal/Magento/Framework/Data/Argument/InterpreterInterface.php b/lib/internal/Magento/Framework/Data/Argument/InterpreterInterface.php index 0768805c048cdc592ad283a715df9688a58715ad..7dcffa444c719669b549f46d64c9cb11147a1e12 100644 --- a/lib/internal/Magento/Framework/Data/Argument/InterpreterInterface.php +++ b/lib/internal/Magento/Framework/Data/Argument/InterpreterInterface.php @@ -17,7 +17,6 @@ interface InterpreterInterface * @return mixed * @throws \InvalidArgumentException * @throws \UnexpectedValueException - * @throws MissingOptionalValueException */ public function evaluate(array $data); } diff --git a/lib/internal/Magento/Framework/Data/Argument/MissingOptionalValueException.php b/lib/internal/Magento/Framework/Data/Argument/MissingOptionalValueException.php deleted file mode 100644 index 4fa01c23167398539ab82c0d4aee18b819d0fb6e..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Data/Argument/MissingOptionalValueException.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Data\Argument; - -/** - * Recoverable situation of a missing argument value, presence of which is optional according to the business logic. - * Possible resolution is to use a default argument value, if there is one. - */ -class MissingOptionalValueException extends \RuntimeException -{ -} diff --git a/lib/internal/Magento/Framework/Data/Collection.php b/lib/internal/Magento/Framework/Data/Collection.php index 90e15d734012e950092d07ecc26c04a30e5e4206..91a3dfd10c9416cac9a0ba55f13679ed846f6f36 100644 --- a/lib/internal/Magento/Framework/Data/Collection.php +++ b/lib/internal/Magento/Framework/Data/Collection.php @@ -164,13 +164,13 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll * * @param string|array $field * @param string|int|array $condition - * @throws \Magento\Framework\Exception if some error in the input could be detected. + * @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected. * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function addFieldToFilter($field, $condition) { - throw new \Magento\Framework\Exception('Not implemented'); + throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Not implemented')); } /** diff --git a/lib/internal/Magento/Framework/Data/Collection/Db.php b/lib/internal/Magento/Framework/Data/Collection/Db.php old mode 100644 new mode 100755 index d1a1dfb924e6311cc34ba53592bca23c10e433cd..563a654811edc9222580dfd46caa0c229cab96a0 --- a/lib/internal/Magento/Framework/Data/Collection/Db.php +++ b/lib/internal/Magento/Framework/Data/Collection/Db.php @@ -159,12 +159,14 @@ class Db extends \Magento\Framework\Data\Collection * * @param \Zend_Db_Adapter_Abstract $conn * @return $this - * @throws \Zend_Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function setConnection($conn) { if (!$conn instanceof \Zend_Db_Adapter_Abstract) { - throw new \Zend_Exception('dbModel read resource does not implement \Zend_Db_Adapter_Abstract'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('dbModel read resource does not implement \Zend_Db_Adapter_Abstract') + ); } $this->_conn = $conn; diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Textarea.php b/lib/internal/Magento/Framework/Data/Form/Element/Textarea.php index 724a609189ba9022ed27595273eb7999dd21f0af..26826e2515fc1386ff4fdf7e29d3243a4b0620c6 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Textarea.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Textarea.php @@ -15,6 +15,16 @@ use Magento\Framework\Escaper; class Textarea extends AbstractElement { + /** + * Default number of rows + */ + const DEFAULT_ROWS = 2; + + /** + * Default number of columns + */ + const DEFAULT_COLS = 15; + /** * @param Factory $factoryElement * @param CollectionFactory $factoryCollection @@ -30,8 +40,12 @@ class Textarea extends AbstractElement parent::__construct($factoryElement, $factoryCollection, $escaper, $data); $this->setType('textarea'); $this->setExtType('textarea'); - $this->setRows(2); - $this->setCols(15); + if (!$this->getRows()) { + $this->setRows(self::DEFAULT_ROWS); + } + if (!$this->getCols()) { + $this->setCols(self::DEFAULT_COLS); + } } /** @@ -65,9 +79,8 @@ class Textarea extends AbstractElement public function getElementHtml() { $this->addClass('textarea'); - $html = '<textarea id="' . $this->getHtmlId() . '" name="' . $this->getName() . '" ' . $this->serialize( - $this->getHtmlAttributes() - ) . $this->_getUiId() . ' >'; + $html = '<textarea id="' . $this->getHtmlId() . '" name="' . $this->getName() . '" ' + . $this->serialize($this->getHtmlAttributes()) . $this->_getUiId() . ' >'; $html .= $this->getEscapedValue(); $html .= "</textarea>"; $html .= $this->getAfterElementHtml(); diff --git a/lib/internal/Magento/Framework/Data/FormFactory.php b/lib/internal/Magento/Framework/Data/FormFactory.php index cd35382e2644672c17e2d5cbe458835172fde526..57267e2413b6377219d204fa248316c0f1ff3bf9 100644 --- a/lib/internal/Magento/Framework/Data/FormFactory.php +++ b/lib/internal/Magento/Framework/Data/FormFactory.php @@ -33,8 +33,10 @@ class FormFactory * @param \Magento\Framework\ObjectManagerInterface $objectManager * @param string $instanceName */ - public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = 'Magento\Framework\Data\Form') - { + public function __construct( + \Magento\Framework\ObjectManagerInterface $objectManager, + $instanceName = 'Magento\Framework\Data\Form' + ) { $this->_objectManager = $objectManager; $this->_instanceName = $instanceName; } @@ -44,14 +46,16 @@ class FormFactory * * @param array $data * @return \Magento\Framework\Data\Form - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create(array $data = []) { /** @var $form \Magento\Framework\Data\Form */ $form = $this->_objectManager->create($this->_instanceName, $data); if (!$form instanceof \Magento\Framework\Data\Form) { - throw new \Magento\Framework\Exception($this->_instanceName . ' doesn\'t extend \Magento\Framework\Data\Form'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('%1 doesn\'t extend \Magento\Framework\Data\Form', [$this->_instanceName]) + ); } return $form; } diff --git a/lib/internal/Magento/Framework/Data/SearchResultIteratorFactory.php b/lib/internal/Magento/Framework/Data/SearchResultIteratorFactory.php index 6fc4110a9e59e1bd0fb3180a21a4b62c99896616..f6efdfefcd5419d60e72d811ec76d4a6429dea0c 100644 --- a/lib/internal/Magento/Framework/Data/SearchResultIteratorFactory.php +++ b/lib/internal/Magento/Framework/Data/SearchResultIteratorFactory.php @@ -29,14 +29,14 @@ class SearchResultIteratorFactory * @param string $className * @param array $arguments * @return SearchResultIterator - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create($className, array $arguments = []) { $resultIterator = $this->objectManager->create($className, $arguments); if (!$resultIterator instanceof \Traversable) { - throw new \Magento\Framework\Exception( - $className . ' should be an iterator' + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('%1 should be an iterator', [$className]) ); } return $resultIterator; diff --git a/lib/internal/Magento/Framework/Data/Structure.php b/lib/internal/Magento/Framework/Data/Structure.php index a5d09d08ca9a1e99799f7423cacd4159abd1338a..3e8b81ea66770f46c329d40f0c736741f24aef42 100644 --- a/lib/internal/Magento/Framework/Data/Structure.php +++ b/lib/internal/Magento/Framework/Data/Structure.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\Data; -use Magento\Framework\Exception; +use Magento\Framework\Exception\LocalizedException; /** * An associative data structure, that features "nested set" parent-child relations @@ -43,14 +43,16 @@ class Structure * * @param array $elements * @return void - * @throws Exception if any format issues identified + * @throws LocalizedException if any format issues identified */ public function importElements(array $elements) { $this->_elements = $elements; foreach ($elements as $elementId => $element) { if (is_numeric($elementId)) { - throw new Exception("Element ID must not be numeric: '{$elementId}'."); + throw new LocalizedException( + new \Magento\Framework\Phrase("Element ID must not be numeric: '%1'.", [$elementId]) + ); } $this->_assertParentRelation($elementId); if (isset($element[self::GROUPS])) { @@ -59,7 +61,12 @@ class Structure foreach ($groups as $groupName => $group) { $this->_assertArray($group); if ($group !== array_flip($group)) { - throw new Exception("Invalid format of group '{$groupName}': " . var_export($group, 1)); + throw new LocalizedException( + new \Magento\Framework\Phrase( + "Invalid format of group '%1': %2", + [$groupName, var_export($group, 1)] + ) + ); } foreach ($group as $groupElementId) { $this->_assertElementExists($groupElementId); @@ -74,7 +81,7 @@ class Structure * * @param string $elementId * @return void - * @throws Exception + * @throws LocalizedException */ protected function _assertParentRelation($elementId) { @@ -85,8 +92,11 @@ class Structure $parentId = $element[self::PARENT]; $this->_assertElementExists($parentId); if (empty($this->_elements[$parentId][self::CHILDREN][$elementId])) { - throw new Exception( - "Broken parent-child relation: the '{$elementId}' is not in the nested set of '{$parentId}'." + throw new LocalizedException( + new \Magento\Framework\Phrase( + "Broken parent-child relation: the '%1' is not in the nested set of '%2'.", + [$elementId, $parentId] + ) ); } } @@ -96,7 +106,9 @@ class Structure $children = $element[self::CHILDREN]; $this->_assertArray($children); if ($children !== array_flip(array_flip($children))) { - throw new Exception('Invalid format of children: ' . var_export($children, 1)); + throw new LocalizedException( + new \Magento\Framework\Phrase('Invalid format of children: %1', [var_export($children, 1)]) + ); } foreach (array_keys($children) as $childId) { $this->_assertElementExists($childId); @@ -104,8 +116,11 @@ class Structure $this->_elements[$childId][self::PARENT] ) || $elementId !== $this->_elements[$childId][self::PARENT] ) { - throw new Exception( - "Broken parent-child relation: the '{$childId}' is supposed to have '{$elementId}' as parent." + throw new LocalizedException( + new \Magento\Framework\Phrase( + "Broken parent-child relation: the '%1' is supposed to have '%2' as parent.", + [$childId, $elementId] + ) ); } } @@ -128,12 +143,14 @@ class Structure * @param string $elementId * @param array $data * @return void - * @throws Exception if an element with this id already exists + * @throws LocalizedException if an element with this id already exists */ public function createElement($elementId, array $data) { if (isset($this->_elements[$elementId])) { - throw new Exception("Element with ID '{$elementId}' already exists."); + throw new LocalizedException( + new \Magento\Framework\Phrase("Element with ID '%1' already exists.", [$elementId]) + ); } $this->_elements[$elementId] = []; foreach ($data as $key => $value) { @@ -237,13 +254,15 @@ class Structure * @param string $oldId * @param string $newId * @return $this - * @throws Exception if trying to overwrite another element + * @throws LocalizedException if trying to overwrite another element */ public function renameElement($oldId, $newId) { $this->_assertElementExists($oldId); if (!$newId || isset($this->_elements[$newId])) { - throw new Exception("Element with ID '{$newId}' is already defined."); + throw new LocalizedException( + new \Magento\Framework\Phrase("Element with ID '%1' is already defined.", [$newId]) + ); } // rename in registry @@ -278,17 +297,21 @@ class Structure * @param int|null $position * @see _insertChild() for position explanation * @return void - * @throws Exception if attempting to set parent as child to its child (recursively) + * @throws LocalizedException if attempting to set parent as child to its child (recursively) */ public function setAsChild($elementId, $parentId, $alias = '', $position = null) { if ($elementId == $parentId) { - throw new Exception("The '{$elementId}' cannot be set as child to itself."); + throw new LocalizedException( + new \Magento\Framework\Phrase("The '%1' cannot be set as child to itself.", [$elementId]) + ); } if ($this->_isParentRecursively($elementId, $parentId)) { - throw new Exception( - "The '{$elementId}' is a parent of '{$parentId}' recursively, " . - "therefore '{$elementId}' cannot be set as child to it." + throw new LocalizedException( + new \Magento\Framework\Phrase( + "The '%1' is a parent of '%2' recursively, therefore '%3' cannot be set as child to it.", + [$elementId, $parentId, $elementId] + ) ); } $this->unsetChild($elementId); @@ -512,13 +535,15 @@ class Structure * @param string $parentId * @param string $childId * @return int - * @throws Exception if specified elements have no parent-child relation + * @throws LocalizedException if specified elements have no parent-child relation */ protected function _getChildOffset($parentId, $childId) { $index = array_search($childId, array_keys($this->getChildren($parentId))); if (false === $index) { - throw new Exception("The '{$childId}' is not a child of '{$parentId}'."); + throw new LocalizedException( + new \Magento\Framework\Phrase("The '%1' is not a child of '%2'.", [$childId, $parentId]) + ); } return $index; } @@ -559,7 +584,7 @@ class Structure * @param int|null $offset * @param string $alias * @return void - * @throws Exception + * @throws LocalizedException */ protected function _insertChild($targetParentId, $elementId, $offset, $alias) { @@ -568,17 +593,27 @@ class Structure // validate $this->_assertElementExists($elementId); if (!empty($this->_elements[$elementId][self::PARENT])) { - throw new Exception( - "The element '{$elementId}' already has a parent: '{$this->_elements[$elementId][self::PARENT]}'" + throw new LocalizedException( + new \Magento\Framework\Phrase( + "The element '%1' already has a parent: '%2'", + [$elementId, $this->_elements[$elementId][self::PARENT]] + ) ); } $this->_assertElementExists($targetParentId); $children = $this->getChildren($targetParentId); if (isset($children[$elementId])) { - throw new Exception("The element '{$elementId}' already a child of '{$targetParentId}'"); + throw new LocalizedException( + new \Magento\Framework\Phrase("The element '%1' already a child of '%2'", [$elementId, $targetParentId]) + ); } if (false !== array_search($alias, $children)) { - throw new Exception("The element '{$targetParentId}' already has a child with alias '{$alias}'"); + throw new LocalizedException( + new \Magento\Framework\Phrase( + "The element '%1' already has a child with alias '%2'", + [$targetParentId, $alias] + ) + ); } // insert @@ -598,7 +633,7 @@ class Structure * * @param string $elementId * @return void - * @throws Exception if doesn't exist + * @throws LocalizedException if doesn't exist */ private function _assertElementExists($elementId) { @@ -612,12 +647,14 @@ class Structure * * @param array $value * @return void - * @throws Exception + * @throws LocalizedException */ private function _assertArray($value) { if (!is_array($value)) { - throw new Exception("An array expected: " . var_export($value, 1)); + throw new LocalizedException( + new \Magento\Framework\Phrase("An array expected: %1", [var_export($value, 1)]) + ); } } } diff --git a/lib/internal/Magento/Framework/Data/Test/Unit/Collection/DbTest.php b/lib/internal/Magento/Framework/Data/Test/Unit/Collection/DbTest.php old mode 100644 new mode 100755 index 0d2336846b991e392cbb712907dceb041d1ae64c..666655aefd385fe6cddaff1f7c172e69c042a9d5 --- a/lib/internal/Magento/Framework/Data/Test/Unit/Collection/DbTest.php +++ b/lib/internal/Magento/Framework/Data/Test/Unit/Collection/DbTest.php @@ -324,7 +324,7 @@ class DbTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Zend_Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage dbModel read resource does not implement \Zend_Db_Adapter_Abstract */ public function testSetConnectionException() diff --git a/lib/internal/Magento/Framework/Data/Test/Unit/FormFactoryTest.php b/lib/internal/Magento/Framework/Data/Test/Unit/FormFactoryTest.php index 9ebd3bc85e148af18ce49953ce37166cba52f63d..cf9ef32ca805c5a4bd5968349c6ee199f4665ecd 100644 --- a/lib/internal/Magento/Framework/Data/Test/Unit/FormFactoryTest.php +++ b/lib/internal/Magento/Framework/Data/Test/Unit/FormFactoryTest.php @@ -29,7 +29,7 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage WrongClass doesn't extend \Magento\Framework\Data\Form */ public function testWrongTypeException() diff --git a/lib/internal/Magento/Framework/Data/Test/Unit/StructureTest.php b/lib/internal/Magento/Framework/Data/Test/Unit/StructureTest.php index 4b994828b51d1745246f8276cd45ad2499333aec..87dfd68d30a0fbe3f57f7609c76401857c364117 100644 --- a/lib/internal/Magento/Framework/Data/Test/Unit/StructureTest.php +++ b/lib/internal/Magento/Framework/Data/Test/Unit/StructureTest.php @@ -69,7 +69,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase * @param array $elements * @return void * @dataProvider importExceptionDataProvider - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testImportException($elements) { @@ -184,7 +184,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase /** * @return void - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testCreateElementException() { @@ -365,7 +365,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase * @param string $elementId * @param string $parentId * @return void - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @dataProvider setAsChildExceptionDataProvider */ public function testSetAsChildException($elementId, $parentId) @@ -459,7 +459,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase /** * @return void - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testReorderChildException() { @@ -516,7 +516,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase /** * @return void - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testReorderToSiblingException() { diff --git a/lib/internal/Magento/Framework/Encryption/Crypt.php b/lib/internal/Magento/Framework/Encryption/Crypt.php index 9185fc38c03fa08e8a0d49d643cf49f267c3adfe..76ee991295b0eac5b35c10e45161248e134cdbdb 100644 --- a/lib/internal/Magento/Framework/Encryption/Crypt.php +++ b/lib/internal/Magento/Framework/Encryption/Crypt.php @@ -55,7 +55,9 @@ class Crypt try { $maxKeySize = mcrypt_enc_get_key_size($this->_handle); if (strlen($key) > $maxKeySize) { - throw new \Magento\Framework\Exception('Key must not exceed ' . $maxKeySize . ' bytes.'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Key must not exceed %1 bytes.', [$maxKeySize]) + ); } $initVectorSize = mcrypt_enc_get_iv_size($this->_handle); if (true === $initVector) { @@ -69,7 +71,9 @@ class Crypt /* Set vector to zero bytes to not use it */ $initVector = str_repeat("\0", $initVectorSize); } elseif (!is_string($initVector) || strlen($initVector) != $initVectorSize) { - throw new \Magento\Framework\Exception('Init vector must be a string of ' . $initVectorSize . ' bytes.'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Init vector must be a string of %1 bytes.', [$initVectorSize]) + ); } $this->_initVector = $initVector; } catch (\Exception $e) { diff --git a/lib/internal/Magento/Framework/Encryption/Test/Unit/CryptTest.php b/lib/internal/Magento/Framework/Encryption/Test/Unit/CryptTest.php index 6b003e09e285fb79a5a029aca076dcf160f1f259..4c430da55d5131a44bb191d82682fae3c09fa7e8 100644 --- a/lib/internal/Magento/Framework/Encryption/Test/Unit/CryptTest.php +++ b/lib/internal/Magento/Framework/Encryption/Test/Unit/CryptTest.php @@ -120,7 +120,7 @@ class CryptTest extends \PHPUnit_Framework_TestCase /** * @dataProvider getConstructorExceptionData - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testConstructorException($key, $cipher, $mode, $initVector) { diff --git a/lib/internal/Magento/Framework/Exception.php b/lib/internal/Magento/Framework/Exception.php deleted file mode 100644 index 2c7320a4e010647ae5577dc2b1c95b6ea1238e17..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Exception.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework; - -class Exception extends \Exception -{ - /** - * Check PCRE PREG error and throw exception - * - * @return void - * @throws \Magento\Framework\Exception - */ - public static function processPcreError() - { - if (preg_last_error() != PREG_NO_ERROR) { - switch (preg_last_error()) { - case PREG_INTERNAL_ERROR: - throw new \Magento\Framework\Exception('PCRE PREG internal error'); - case PREG_BACKTRACK_LIMIT_ERROR: - throw new \Magento\Framework\Exception('PCRE PREG Backtrack limit error'); - case PREG_RECURSION_LIMIT_ERROR: - throw new \Magento\Framework\Exception('PCRE PREG Recursion limit error'); - case PREG_BAD_UTF8_ERROR: - throw new \Magento\Framework\Exception('PCRE PREG Bad UTF-8 error'); - case PREG_BAD_UTF8_OFFSET_ERROR: - throw new \Magento\Framework\Exception('PCRE PREG Bad UTF-8 offset error'); - } - } - } -} diff --git a/lib/internal/Magento/Framework/Filesystem/FilesystemException.php b/lib/internal/Magento/Framework/Exception/FileSystemException.php similarity index 58% rename from lib/internal/Magento/Framework/Filesystem/FilesystemException.php rename to lib/internal/Magento/Framework/Exception/FileSystemException.php index 4f46cc8d7b1c8e31bd3260d57c8a29033731fa2d..4363e98eeca759027d3488b2838cef89927d9605 100644 --- a/lib/internal/Magento/Framework/Filesystem/FilesystemException.php +++ b/lib/internal/Magento/Framework/Exception/FileSystemException.php @@ -1,12 +1,13 @@ <?php /** - * Magento filesystem exception - * * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Filesystem; +namespace Magento\Framework\Exception; -class FilesystemException extends \Exception +/** + * Magento filesystem exception + */ +class FileSystemException extends LocalizedException { } diff --git a/lib/internal/Magento/Framework/Session/SaveHandlerException.php b/lib/internal/Magento/Framework/Exception/MailException.php similarity index 51% rename from lib/internal/Magento/Framework/Session/SaveHandlerException.php rename to lib/internal/Magento/Framework/Exception/MailException.php index 02cfc44d280cbd7251c718a7d75b44adabca2085..9f6fc0489e3d161a682828c190e63de9376d3141 100644 --- a/lib/internal/Magento/Framework/Session/SaveHandlerException.php +++ b/lib/internal/Magento/Framework/Exception/MailException.php @@ -3,11 +3,11 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Session; +namespace Magento\Framework\Exception; /** - * Save handler exception + * Magento mail exception */ -class SaveHandlerException extends \Exception +class MailException extends LocalizedException { } diff --git a/lib/internal/Magento/Framework/App/Action/NotFoundException.php b/lib/internal/Magento/Framework/Exception/NotFoundException.php similarity index 55% rename from lib/internal/Magento/Framework/App/Action/NotFoundException.php rename to lib/internal/Magento/Framework/Exception/NotFoundException.php index 8b97313de8963987cca201e67d0c904beccd9905..e2aa845315fd6940c20ab4fa4125a6666458f5a8 100644 --- a/lib/internal/Magento/Framework/App/Action/NotFoundException.php +++ b/lib/internal/Magento/Framework/Exception/NotFoundException.php @@ -1,11 +1,10 @@ <?php /** - * * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\App\Action; +namespace Magento\Framework\Exception; -class NotFoundException extends \Exception +class NotFoundException extends LocalizedException { } diff --git a/lib/internal/Magento/Framework/Session/Exception.php b/lib/internal/Magento/Framework/Exception/SessionException.php similarity index 60% rename from lib/internal/Magento/Framework/Session/Exception.php rename to lib/internal/Magento/Framework/Exception/SessionException.php index 260f375253b435d9d0410a655e2ffee07828130e..0addcc69cb6f4eb3a9d7b799e1f372f9326aa7b1 100644 --- a/lib/internal/Magento/Framework/Session/Exception.php +++ b/lib/internal/Magento/Framework/Exception/SessionException.php @@ -3,11 +3,11 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Session; +namespace Magento\Framework\Exception; /** * Session exception */ -class Exception extends \Exception +class SessionException extends LocalizedException { } diff --git a/lib/internal/Magento/Framework/App/InitException.php b/lib/internal/Magento/Framework/Exception/State/InitException.php similarity index 55% rename from lib/internal/Magento/Framework/App/InitException.php rename to lib/internal/Magento/Framework/Exception/State/InitException.php index ae298122381c1bcd50c1bea1e64b4129248b09aa..d5e35f0cbafb36754f630b2fddc66b1e46653bd8 100644 --- a/lib/internal/Magento/Framework/App/InitException.php +++ b/lib/internal/Magento/Framework/Exception/State/InitException.php @@ -3,12 +3,13 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +namespace Magento\Framework\Exception\State; -namespace Magento\Framework\App; +use Magento\Framework\Exception\LocalizedException; /** * An exception that indicates application initialization error */ -class InitException extends \Exception +class InitException extends LocalizedException { } diff --git a/lib/internal/Magento/Framework/Interception/Code/ValidatorException.php b/lib/internal/Magento/Framework/Exception/ValidatorException.php similarity index 54% rename from lib/internal/Magento/Framework/Interception/Code/ValidatorException.php rename to lib/internal/Magento/Framework/Exception/ValidatorException.php index c0734c9f31a2af1742f6d777b751ce25788e1f6b..5c37418d513aeb4dcc15d400ff355e2b6db3750d 100644 --- a/lib/internal/Magento/Framework/Interception/Code/ValidatorException.php +++ b/lib/internal/Magento/Framework/Exception/ValidatorException.php @@ -3,8 +3,8 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Interception\Code; +namespace Magento\Framework\Exception; -class ValidatorException extends \Exception +class ValidatorException extends LocalizedException { } diff --git a/lib/internal/Magento/Framework/Filesystem.php b/lib/internal/Magento/Framework/Filesystem.php index 6c4e7de35c2833b927ae99aecc83801bdff82ec3..9c21dbcc2e76c29432a45e7265310152c5fc069d 100644 --- a/lib/internal/Magento/Framework/Filesystem.php +++ b/lib/internal/Magento/Framework/Filesystem.php @@ -73,7 +73,7 @@ class Filesystem * @param string $directoryCode * @param string $driverCode * @return \Magento\Framework\Filesystem\Directory\WriteInterface - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function getDirectoryWrite($directoryCode, $driverCode = DriverPool::FILE) { diff --git a/lib/internal/Magento/Framework/Filesystem/Directory/Read.php b/lib/internal/Magento/Framework/Filesystem/Directory/Read.php index 189a0c8b24644260bf9a633c5ce40f98e14fada8..94b74e657920a3581a2924b72414e28df6dd62ef 100644 --- a/lib/internal/Magento/Framework/Filesystem/Directory/Read.php +++ b/lib/internal/Magento/Framework/Filesystem/Directory/Read.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\Filesystem\Directory; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; class Read implements ReadInterface { @@ -146,7 +146,7 @@ class Read implements ReadInterface * * @param string $path [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function isExist($path = null) { @@ -158,7 +158,7 @@ class Read implements ReadInterface * * @param string $path * @return array - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function stat($path) { @@ -170,7 +170,7 @@ class Read implements ReadInterface * * @param string $path [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function isReadable($path = null) { @@ -199,7 +199,7 @@ class Read implements ReadInterface * @param string|null $flag * @param resource|null $context * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function readFile($path, $flag = null, $context = null) { diff --git a/lib/internal/Magento/Framework/Filesystem/Directory/ReadInterface.php b/lib/internal/Magento/Framework/Filesystem/Directory/ReadInterface.php index d91ec52ed6c7efb69c58ec18bf3a25e6ffb0918e..4d142da833f6484399e1a9ad8610231117fc4f2b 100644 --- a/lib/internal/Magento/Framework/Filesystem/Directory/ReadInterface.php +++ b/lib/internal/Magento/Framework/Filesystem/Directory/ReadInterface.php @@ -95,7 +95,7 @@ interface ReadInterface * @param string|null $flag * @param resource|null $context * @return string - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function readFile($path, $flag = null, $context = null); } diff --git a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php index 1f76bf8c6d61fdc7333adb7532cf3cb61600ebb1..2cd338bbb2aa5810988c5d9160ab059bddac86e9 100644 --- a/lib/internal/Magento/Framework/Filesystem/Directory/Write.php +++ b/lib/internal/Magento/Framework/Filesystem/Directory/Write.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\Filesystem\Directory; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; class Write extends Read implements WriteInterface { @@ -43,13 +43,13 @@ class Write extends Read implements WriteInterface * * @param string $path * @return void - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ protected function assertWritable($path) { if ($this->isWritable($path) === false) { $path = $this->getAbsolutePath($this->path, $path); - throw new FilesystemException(sprintf('The path "%s" is not writable', $path)); + throw new FileSystemException(new \Magento\Framework\Phrase('The path "%1" is not writable', [$path])); } } @@ -58,14 +58,16 @@ class Write extends Read implements WriteInterface * * @param string $path * @return void - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ protected function assertIsFile($path) { clearstatcache(); $absolutePath = $this->driver->getAbsolutePath($this->path, $path); if (!$this->driver->isFile($absolutePath)) { - throw new FilesystemException(sprintf('The "%s" file doesn\'t exist or not a file', $absolutePath)); + throw new FileSystemException( + new \Magento\Framework\Phrase('The "%1" file doesn\'t exist or not a file', [$absolutePath]) + ); } } @@ -74,7 +76,7 @@ class Write extends Read implements WriteInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function create($path = null) { @@ -92,7 +94,7 @@ class Write extends Read implements WriteInterface * @param string $newPath * @param WriteInterface $targetDirectory * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function renameFile($path, $newPath, WriteInterface $targetDirectory = null) { @@ -113,7 +115,7 @@ class Write extends Read implements WriteInterface * @param string $destination * @param WriteInterface $targetDirectory * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function copyFile($path, $destination, WriteInterface $targetDirectory = null) { @@ -136,7 +138,7 @@ class Write extends Read implements WriteInterface * @param string $destination * @param WriteInterface $targetDirectory [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function createSymlink($path, $destination, WriteInterface $targetDirectory = null) { @@ -158,7 +160,7 @@ class Write extends Read implements WriteInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function delete($path = null) { @@ -180,7 +182,7 @@ class Write extends Read implements WriteInterface * @param string $path * @param int $permissions * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function changePermissions($path, $permissions) { @@ -194,7 +196,7 @@ class Write extends Read implements WriteInterface * @param string $path * @param int|null $modificationTime * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function touch($path, $modificationTime = null) { @@ -209,7 +211,7 @@ class Write extends Read implements WriteInterface * * @param null $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function isWritable($path = null) { @@ -239,7 +241,7 @@ class Write extends Read implements WriteInterface * @param string $content * @param string|null $mode * @return int The number of bytes that were written. - * @throws FilesystemException + * @throws FileSystemException */ public function writeFile($path, $content, $mode = 'w+') { diff --git a/lib/internal/Magento/Framework/Filesystem/Directory/WriteInterface.php b/lib/internal/Magento/Framework/Filesystem/Directory/WriteInterface.php index 65c0de80d1f76bbe077995df6eadd59232485baa..71ac8bcba0a2899dffc30b591e18732a5a9a8215 100644 --- a/lib/internal/Magento/Framework/Filesystem/Directory/WriteInterface.php +++ b/lib/internal/Magento/Framework/Filesystem/Directory/WriteInterface.php @@ -12,7 +12,7 @@ interface WriteInterface extends ReadInterface * * @param string $path [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function create($path = null); @@ -21,7 +21,7 @@ interface WriteInterface extends ReadInterface * * @param string $path [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function delete($path = null); @@ -32,7 +32,7 @@ interface WriteInterface extends ReadInterface * @param string $newPath * @param WriteInterface $targetDirectory [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function renameFile($path, $newPath, WriteInterface $targetDirectory = null); @@ -43,7 +43,7 @@ interface WriteInterface extends ReadInterface * @param string $destination * @param WriteInterface $targetDirectory [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function copyFile($path, $destination, WriteInterface $targetDirectory = null); @@ -54,7 +54,7 @@ interface WriteInterface extends ReadInterface * @param string $destination * @param WriteInterface $targetDirectory [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function createSymlink($path, $destination, WriteInterface $targetDirectory = null); @@ -64,7 +64,7 @@ interface WriteInterface extends ReadInterface * @param string $path * @param int $permissions * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function changePermissions($path, $permissions); @@ -74,7 +74,7 @@ interface WriteInterface extends ReadInterface * @param string $path * @param int $modificationTime [optional] * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function touch($path, $modificationTime = null); @@ -102,7 +102,7 @@ interface WriteInterface extends ReadInterface * @param string $content * @param string $mode [optional] * @return int The number of bytes that were written. - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function writeFile($path, $content, $mode = null); diff --git a/lib/internal/Magento/Framework/Filesystem/DirectoryList.php b/lib/internal/Magento/Framework/Filesystem/DirectoryList.php index 438ce7202543f5e3170329548106278016036533..2174a010a6c19a268ae6f0569c4e026d12f2ef98 100644 --- a/lib/internal/Magento/Framework/Filesystem/DirectoryList.php +++ b/lib/internal/Magento/Framework/Filesystem/DirectoryList.php @@ -228,13 +228,15 @@ class DirectoryList * Asserts that specified directory code is in the registry * * @param string $code - * @throws FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException * @return void */ private function assertCode($code) { if (!isset($this->directories[$code])) { - throw new FilesystemException("Unknown directory type: '$code'"); + throw new \Magento\Framework\Exception\FileSystemException( + new \Magento\Framework\Phrase('Unknown directory type: \'%1\'', [$code]) + ); } } } diff --git a/lib/internal/Magento/Framework/Filesystem/Driver/File.php b/lib/internal/Magento/Framework/Filesystem/Driver/File.php index e053ca69564b780066f0d08a358a1d911f253cf8..67320447f54701e037679b3f20667606c1c367b2 100644 --- a/lib/internal/Magento/Framework/Filesystem/Driver/File.php +++ b/lib/internal/Magento/Framework/Filesystem/Driver/File.php @@ -8,7 +8,7 @@ namespace Magento\Framework\Filesystem\Driver; use Magento\Framework\Filesystem\DriverInterface; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; class File implements DriverInterface { @@ -36,14 +36,16 @@ class File implements DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function isExists($path) { clearstatcache(); $result = @file_exists($this->getScheme() . $path); if ($result === null) { - throw new FilesystemException(sprintf('Error occurred during execution %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('Error occurred during execution %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -53,14 +55,16 @@ class File implements DriverInterface * * @param string $path * @return array - * @throws FilesystemException + * @throws FileSystemException */ public function stat($path) { clearstatcache(); $result = @stat($this->getScheme() . $path); if (!$result) { - throw new FilesystemException(sprintf('Cannot gather stats! %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('Cannot gather stats! %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -70,14 +74,16 @@ class File implements DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function isReadable($path) { clearstatcache(); $result = @is_readable($this->getScheme() . $path); if ($result === null) { - throw new FilesystemException(sprintf('Error occurred during execution %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('Error occurred during execution %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -87,14 +93,16 @@ class File implements DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function isFile($path) { clearstatcache(); $result = @is_file($this->getScheme() . $path); if ($result === null) { - throw new FilesystemException(sprintf('Error occurred during execution %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('Error occurred during execution %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -104,14 +112,16 @@ class File implements DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function isDirectory($path) { clearstatcache(); $result = @is_dir($this->getScheme() . $path); if ($result === null) { - throw new FilesystemException(sprintf('Error occurred during execution %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('Error occurred during execution %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -123,15 +133,18 @@ class File implements DriverInterface * @param string|null $flag * @param resource|null $context * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileGetContents($path, $flag = null, $context = null) { clearstatcache(); $result = @file_get_contents($this->getScheme() . $path, $flag, $context); if (false === $result) { - throw new FilesystemException( - sprintf('Cannot read contents from file "%s" %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Cannot read contents from file "%1" %2', + [$path, $this->getWarningMessage()] + ) ); } return $result; @@ -142,14 +155,16 @@ class File implements DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function isWritable($path) { clearstatcache(); $result = @is_writable($this->getScheme() . $path); if ($result === null) { - throw new FilesystemException(sprintf('Error occurred during execution %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('Error occurred during execution %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -171,14 +186,17 @@ class File implements DriverInterface * @param string $path * @param int $permissions * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function createDirectory($path, $permissions) { $result = @mkdir($this->getScheme() . $path, $permissions, true); if (!$result) { - throw new FilesystemException( - sprintf('Directory "%s" cannot be created %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Directory "%1" cannot be created %2', + [$path, $this->getWarningMessage()] + ) ); } return $result; @@ -189,7 +207,7 @@ class File implements DriverInterface * * @param string $path * @return string[] - * @throws FilesystemException + * @throws FileSystemException */ public function readDirectory($path) { @@ -204,7 +222,7 @@ class File implements DriverInterface sort($result); return $result; } catch (\Exception $e) { - throw new FilesystemException($e->getMessage(), $e->getCode(), $e); + throw new FileSystemException(new \Magento\Framework\Phrase($e->getMessage()), $e); } } @@ -214,7 +232,7 @@ class File implements DriverInterface * @param string $pattern * @param string $path * @return string[] - * @throws FilesystemException + * @throws FileSystemException */ public function search($pattern, $path) { @@ -231,7 +249,7 @@ class File implements DriverInterface * @param string $newPath * @param DriverInterface|null $targetDriver * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function rename($oldPath, $newPath, DriverInterface $targetDriver = null) { @@ -246,8 +264,11 @@ class File implements DriverInterface } } if (!$result) { - throw new FilesystemException( - sprintf('The "%s" path cannot be renamed into "%s" %s', $oldPath, $newPath, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'The "%1" path cannot be renamed into "%2" %3', + [$oldPath, $newPath, $this->getWarningMessage()] + ) ); } return $result; @@ -260,7 +281,7 @@ class File implements DriverInterface * @param string $destination * @param DriverInterface|null $targetDriver * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function copy($source, $destination, DriverInterface $targetDriver = null) { @@ -272,12 +293,14 @@ class File implements DriverInterface $result = $targetDriver->filePutContents($destination, $content); } if (!$result) { - throw new FilesystemException( - sprintf( - 'The file or directory "%s" cannot be copied to "%s" %s', - $source, - $destination, - $this->getWarningMessage() + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'The file or directory "%1" cannot be copied to "%2" %3', + [ + $source, + $destination, + $this->getWarningMessage() + ] ) ); } @@ -291,7 +314,7 @@ class File implements DriverInterface * @param string $destination * @param DriverInterface|null $targetDriver * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function symlink($source, $destination, DriverInterface $targetDriver = null) { @@ -300,12 +323,14 @@ class File implements DriverInterface $result = @symlink($this->getScheme() . $source, $destination); } if (!$result) { - throw new FilesystemException( - sprintf( - 'Cannot create a symlink for "%s" and place it to "%s" %s', - $source, - $destination, - $this->getWarningMessage() + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Cannot create a symlink for "%1" and place it to "%2" %3', + [ + $source, + $destination, + $this->getWarningMessage() + ] ) ); } @@ -317,14 +342,14 @@ class File implements DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function deleteFile($path) { $result = @unlink($this->getScheme() . $path); if (!$result) { - throw new FilesystemException( - sprintf('The file "%s" cannot be deleted %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase('The file "%1" cannot be deleted %2', [$path, $this->getWarningMessage()]) ); } return $result; @@ -335,7 +360,7 @@ class File implements DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function deleteDirectory($path) { @@ -351,8 +376,11 @@ class File implements DriverInterface } $result = @rmdir($this->getScheme() . $path); if (!$result) { - throw new FilesystemException( - sprintf('The directory "%s" cannot be deleted %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'The directory "%1" cannot be deleted %2', + [$path, $this->getWarningMessage()] + ) ); } return $result; @@ -364,14 +392,17 @@ class File implements DriverInterface * @param string $path * @param int $permissions * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function changePermissions($path, $permissions) { $result = @chmod($this->getScheme() . $path, $permissions); if (!$result) { - throw new FilesystemException( - sprintf('Cannot change permissions for path "%s" %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Cannot change permissions for path "%1" %2', + [$path, $this->getWarningMessage()] + ) ); } return $result; @@ -383,7 +414,7 @@ class File implements DriverInterface * @param string $path * @param int|null $modificationTime * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function touch($path, $modificationTime = null) { @@ -393,8 +424,11 @@ class File implements DriverInterface $result = @touch($this->getScheme() . $path, $modificationTime); } if (!$result) { - throw new FilesystemException( - sprintf('The file or directory "%s" cannot be touched %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'The file or directory "%1" cannot be touched %2', + [$path, $this->getWarningMessage()] + ) ); } return $result; @@ -407,14 +441,17 @@ class File implements DriverInterface * @param string $content * @param string|null $mode * @return int The number of bytes that were written. - * @throws FilesystemException + * @throws FileSystemException */ public function filePutContents($path, $content, $mode = null) { $result = @file_put_contents($this->getScheme() . $path, $content, $mode); if (!$result) { - throw new FilesystemException( - sprintf('The specified "%s" file could not be written %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'The specified "%1" file could not be written %2', + [$path, $this->getWarningMessage()] + ) ); } return $result; @@ -426,13 +463,15 @@ class File implements DriverInterface * @param string $path * @param string $mode * @return resource file - * @throws FilesystemException + * @throws FileSystemException */ public function fileOpen($path, $mode) { $result = @fopen($this->getScheme() . $path, $mode); if (!$result) { - throw new FilesystemException(sprintf('File "%s" cannot be opened %s', $path, $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('File "%1" cannot be opened %2', [$path, $this->getWarningMessage()]) + ); } return $result; } @@ -444,13 +483,15 @@ class File implements DriverInterface * @param int $length * @param string $ending [optional] * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileReadLine($resource, $length, $ending = null) { $result = @stream_get_line($resource, $length, $ending); if (false === $result) { - throw new FilesystemException(sprintf('File cannot be read %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('File cannot be read %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -461,13 +502,15 @@ class File implements DriverInterface * @param resource $resource * @param int $length * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileRead($resource, $length) { $result = @fread($resource, $length); if ($result === false) { - throw new FilesystemException(sprintf('File cannot be read %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('File cannot be read %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -481,13 +524,15 @@ class File implements DriverInterface * @param string $enclosure [optional] * @param string $escape [optional] * @return array|bool|null - * @throws FilesystemException + * @throws FileSystemException */ public function fileGetCsv($resource, $length = 0, $delimiter = ',', $enclosure = '"', $escape = '\\') { $result = @fgetcsv($resource, $length, $delimiter, $enclosure, $escape); if ($result === null) { - throw new FilesystemException(sprintf('Wrong CSV handle %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('Wrong CSV handle %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -497,13 +542,15 @@ class File implements DriverInterface * * @param resource $resource * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileTell($resource) { $result = @ftell($resource); if ($result === null) { - throw new FilesystemException(sprintf('Error occurred during execution %s', $this->getWarningMessage())); + throw new FileSystemException( + new \Magento\Framework\Phrase('Error occurred during execution %1', [$this->getWarningMessage()]) + ); } return $result; } @@ -515,14 +562,17 @@ class File implements DriverInterface * @param int $offset * @param int $whence * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileSeek($resource, $offset, $whence = SEEK_SET) { $result = @fseek($resource, $offset, $whence); if ($result === -1) { - throw new FilesystemException( - sprintf('Error occurred during execution of fileSeek %s', $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Error occurred during execution of fileSeek %1', + [$this->getWarningMessage()] + ) ); } return $result; @@ -544,14 +594,17 @@ class File implements DriverInterface * * @param resource $resource * @return boolean - * @throws FilesystemException + * @throws FileSystemException */ public function fileClose($resource) { $result = @fclose($resource); if (!$result) { - throw new FilesystemException( - sprintf('Error occurred during execution of fileClose %s', $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Error occurred during execution of fileClose %1', + [$this->getWarningMessage()] + ) ); } return $result; @@ -563,14 +616,17 @@ class File implements DriverInterface * @param resource $resource * @param string $data * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileWrite($resource, $data) { $result = @fwrite($resource, $data); if (false === $result) { - throw new FilesystemException( - sprintf('Error occurred during execution of fileWrite %s', $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Error occurred during execution of fileWrite %1', + [$this->getWarningMessage()] + ) ); } return $result; @@ -584,14 +640,17 @@ class File implements DriverInterface * @param string $delimiter * @param string $enclosure * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure = '"') { $result = @fputcsv($resource, $data, $delimiter, $enclosure); if (!$result) { - throw new FilesystemException( - sprintf('Error occurred during execution of filePutCsv %s', $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Error occurred during execution of filePutCsv %1', + [$this->getWarningMessage()] + ) ); } return $result; @@ -602,14 +661,17 @@ class File implements DriverInterface * * @param resource $resource * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function fileFlush($resource) { $result = @fflush($resource); if (!$result) { - throw new FilesystemException( - sprintf('Error occurred during execution of fileFlush %s', $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Error occurred during execution of fileFlush %1', + [$this->getWarningMessage()] + ) ); } return $result; @@ -621,14 +683,17 @@ class File implements DriverInterface * @param resource $resource * @param int $lockMode * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function fileLock($resource, $lockMode = LOCK_EX) { $result = @flock($resource, $lockMode); if (!$result) { - throw new FilesystemException( - sprintf('Error occurred during execution of fileLock %s', $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Error occurred during execution of fileLock %1', + [$this->getWarningMessage()] + ) ); } return $result; @@ -639,14 +704,17 @@ class File implements DriverInterface * * @param resource $resource * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function fileUnlock($resource) { $result = @flock($resource, LOCK_UN); if (!$result) { - throw new FilesystemException( - sprintf('Error occurred during execution of fileUnlock %s', $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Error occurred during execution of fileUnlock %1', + [$this->getWarningMessage()] + ) ); } return $result; @@ -709,7 +777,7 @@ class File implements DriverInterface * * @param string $path * @return string[] - * @throws FilesystemException + * @throws FileSystemException */ public function readDirectoryRecursively($path = null) { @@ -725,7 +793,7 @@ class File implements DriverInterface $result[] = $file->getPathname(); } } catch (\Exception $e) { - throw new FilesystemException($e->getMessage(), $e->getCode(), $e); + throw new FileSystemException(new \Magento\Framework\Phrase($e->getMessage()), $e); } return $result; } diff --git a/lib/internal/Magento/Framework/Filesystem/Driver/Http.php b/lib/internal/Magento/Framework/Filesystem/Driver/Http.php index 0c760c1daa45bfbfe3aae196df184ea92b2bf693..2e60f74c6f15f0ae865fbcd809ae82c336f0cf2b 100644 --- a/lib/internal/Magento/Framework/Filesystem/Driver/Http.php +++ b/lib/internal/Magento/Framework/Filesystem/Driver/Http.php @@ -7,7 +7,7 @@ */ namespace Magento\Framework\Filesystem\Driver; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; /** * Class Http @@ -27,7 +27,7 @@ class Http extends File * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function isExists($path) { @@ -82,15 +82,18 @@ class Http extends File * @param string|null $flags * @param resource|null $context * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileGetContents($path, $flags = null, $context = null) { clearstatcache(); $result = @file_get_contents($this->getScheme() . $path, $flags, $context); if (false === $result) { - throw new FilesystemException( - sprintf('Cannot read contents from file "%s" %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'Cannot read contents from file "%1" %2', + [$path, $this->getWarningMessage()] + ) ); } return $result; @@ -104,14 +107,17 @@ class Http extends File * @param string|null $mode * @param resource|null $context * @return int The number of bytes that were written - * @throws FilesystemException + * @throws FileSystemException */ public function filePutContents($path, $content, $mode = null, $context = null) { $result = @file_put_contents($this->getScheme() . $path, $content, $mode, $context); if (!$result) { - throw new FilesystemException( - sprintf('The specified "%s" file could not be written %s', $path, $this->getWarningMessage()) + throw new FileSystemException( + new \Magento\Framework\Phrase( + 'The specified "%1" file could not be written %2', + [$path, $this->getWarningMessage()] + ) ); } return $result; @@ -123,7 +129,7 @@ class Http extends File * @param string $path * @param string $mode * @return resource file - * @throws FilesystemException + * @throws FileSystemException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function fileOpen($path, $mode) @@ -131,7 +137,7 @@ class Http extends File $urlProp = $this->parseUrl($this->getScheme() . $path); if (false === $urlProp) { - throw new FilesystemException((string)new \Magento\Framework\Phrase('Please correct the download URL.')); + throw new FileSystemException(new \Magento\Framework\Phrase('Please correct the download URL.')); } $hostname = $urlProp['host']; @@ -188,7 +194,7 @@ class Http extends File * @param int $length * @param string $ending [optional] * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileReadLine($resource, $length, $ending = null) { @@ -228,15 +234,15 @@ class Http extends File * * @param string $hostname * @param int $port - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException * @return array */ protected function open($hostname, $port) { $result = @fsockopen($hostname, $port, $errorNumber, $errorMessage); if ($result === false) { - throw new FilesystemException( - (string)new \Magento\Framework\Phrase( + throw new FileSystemException( + new \Magento\Framework\Phrase( 'Something went wrong connecting to the host. Error#%1 - %2.', [$errorNumber, $errorMessage] ) diff --git a/lib/internal/Magento/Framework/Filesystem/DriverInterface.php b/lib/internal/Magento/Framework/Filesystem/DriverInterface.php index c02447ee8c48f1ff0a0c8a065a023a28b535c79f..66e544311a8c4aeffea9cdeb1cb4b4b6dc4185c4 100644 --- a/lib/internal/Magento/Framework/Filesystem/DriverInterface.php +++ b/lib/internal/Magento/Framework/Filesystem/DriverInterface.php @@ -7,6 +7,8 @@ */ namespace Magento\Framework\Filesystem; +use Magento\Framework\Exception\FileSystemException; + /** * Class Driver */ @@ -16,7 +18,7 @@ interface DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function isExists($path); @@ -25,7 +27,7 @@ interface DriverInterface * * @param string $path * @return array - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function stat($path); @@ -34,7 +36,7 @@ interface DriverInterface * * @param string $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function isReadable($path); @@ -43,7 +45,7 @@ interface DriverInterface * * @param string $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function isFile($path); @@ -52,7 +54,7 @@ interface DriverInterface * * @param string $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function isDirectory($path); @@ -63,7 +65,7 @@ interface DriverInterface * @param string|null $flag * @param resource|null $context * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileGetContents($path, $flag = null, $context = null); @@ -72,7 +74,7 @@ interface DriverInterface * * @param string $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function isWritable($path); @@ -90,7 +92,7 @@ interface DriverInterface * @param string $path * @param int $permissions * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function createDirectory($path, $permissions); @@ -99,7 +101,7 @@ interface DriverInterface * * @param string $path * @return array - * @throws FilesystemException + * @throws FileSystemException */ public function readDirectory($path); @@ -108,7 +110,7 @@ interface DriverInterface * * @param string|null $path * @return array - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function readDirectoryRecursively($path = null); @@ -118,7 +120,7 @@ interface DriverInterface * @param string $pattern * @param string $path * @return array - * @throws FilesystemException + * @throws FileSystemException */ public function search($pattern, $path); @@ -129,7 +131,7 @@ interface DriverInterface * @param string $newPath * @param DriverInterface|null $targetDriver * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function rename($oldPath, $newPath, DriverInterface $targetDriver = null); @@ -140,7 +142,7 @@ interface DriverInterface * @param string $destination * @param DriverInterface|null $targetDriver * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function copy($source, $destination, DriverInterface $targetDriver = null); @@ -151,7 +153,7 @@ interface DriverInterface * @param string $destination * @param DriverInterface|null $targetDriver * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function symlink($source, $destination, DriverInterface $targetDriver = null); @@ -160,7 +162,7 @@ interface DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function deleteFile($path); @@ -169,7 +171,7 @@ interface DriverInterface * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function deleteDirectory($path); @@ -179,7 +181,7 @@ interface DriverInterface * @param string $path * @param int $permissions * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function changePermissions($path, $permissions); @@ -189,7 +191,7 @@ interface DriverInterface * @param string $path * @param int|null $modificationTime * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function touch($path, $modificationTime = null); @@ -200,7 +202,7 @@ interface DriverInterface * @param string $content * @param string|null $mode * @return int The number of bytes that were written. - * @throws FilesystemException + * @throws FileSystemException */ public function filePutContents($path, $content, $mode = null); @@ -210,7 +212,7 @@ interface DriverInterface * @param string $path * @param string $mode * @return resource - * @throws FilesystemException + * @throws FileSystemException */ public function fileOpen($path, $mode); @@ -221,7 +223,7 @@ interface DriverInterface * @param int $length * @param string $ending [optional] * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileReadLine($resource, $length, $ending = null); @@ -231,7 +233,7 @@ interface DriverInterface * @param resource $resource * @param int $length * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileRead($resource, $length); @@ -244,7 +246,7 @@ interface DriverInterface * @param string $enclosure [optional] * @param string $escape [optional] * @return array|bool|null - * @throws FilesystemException + * @throws FileSystemException */ public function fileGetCsv($resource, $length = 0, $delimiter = ',', $enclosure = '"', $escape = '\\'); @@ -253,7 +255,7 @@ interface DriverInterface * * @param resource $resource * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileTell($resource); @@ -264,7 +266,7 @@ interface DriverInterface * @param int $offset * @param int $whence * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileSeek($resource, $offset, $whence = SEEK_SET); @@ -281,7 +283,7 @@ interface DriverInterface * * @param resource $resource * @return boolean - * @throws FilesystemException + * @throws FileSystemException */ public function fileClose($resource); @@ -291,7 +293,7 @@ interface DriverInterface * @param resource $resource * @param string $data * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileWrite($resource, $data); @@ -303,7 +305,7 @@ interface DriverInterface * @param string $delimiter * @param string $enclosure * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure = '"'); @@ -312,7 +314,7 @@ interface DriverInterface * * @param resource $resource * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function fileFlush($resource); @@ -322,7 +324,7 @@ interface DriverInterface * @param resource $resource * @param int $lockMode * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function fileLock($resource, $lockMode = LOCK_EX); @@ -331,7 +333,7 @@ interface DriverInterface * * @param resource $resource * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function fileUnlock($resource); diff --git a/lib/internal/Magento/Framework/Filesystem/File/Read.php b/lib/internal/Magento/Framework/Filesystem/File/Read.php index a62e34d9321725667905db0f7b9aac0e950c1fd0..06964e61aa9f0ef4737556d3fe2d80ea08f3a755 100644 --- a/lib/internal/Magento/Framework/Filesystem/File/Read.php +++ b/lib/internal/Magento/Framework/Filesystem/File/Read.php @@ -6,7 +6,7 @@ namespace Magento\Framework\Filesystem\File; use Magento\Framework\Filesystem\DriverInterface; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; class Read implements ReadInterface { @@ -67,12 +67,12 @@ class Read implements ReadInterface * Assert file existence * * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ protected function assertValid() { if (!$this->driver->isExists($this->path)) { - throw new FilesystemException(sprintf('The file "%s" doesn\'t exist', $this->path)); + throw new FileSystemException(new \Magento\Framework\Phrase('The file "%1" doesn\'t exist', [$this->path])); } return true; } diff --git a/lib/internal/Magento/Framework/Filesystem/File/Write.php b/lib/internal/Magento/Framework/Filesystem/File/Write.php index a2f0995c2938c501a83fef851d385c068f0199e6..fc5efbb17710ec909dea031b30f2e77ca42a4758 100644 --- a/lib/internal/Magento/Framework/Filesystem/File/Write.php +++ b/lib/internal/Magento/Framework/Filesystem/File/Write.php @@ -6,7 +6,7 @@ namespace Magento\Framework\Filesystem\File; use Magento\Framework\Filesystem\DriverInterface; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; class Write extends Read implements WriteInterface { @@ -27,15 +27,15 @@ class Write extends Read implements WriteInterface * Assert file existence for proper mode * * @return void - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ protected function assertValid() { $fileExists = $this->driver->isExists($this->path); if (!$fileExists && preg_match('/r/', $this->mode)) { - throw new FilesystemException(sprintf('The file "%s" doesn\'t exist', $this->path)); + throw new FileSystemException(new \Magento\Framework\Phrase('The file "%1" doesn\'t exist', [$this->path])); } elseif ($fileExists && preg_match('/x/', $this->mode)) { - throw new FilesystemException(sprintf('The file "%s" already exists', $this->path)); + throw new FileSystemException(new \Magento\Framework\Phrase('The file "%1" already exists', [$this->path])); } } @@ -44,14 +44,16 @@ class Write extends Read implements WriteInterface * * @param string $data * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function write($data) { try { return $this->driver->fileWrite($this->resource, $data); - } catch (FilesystemException $e) { - throw new FilesystemException(sprintf('Cannot write to the "%s" file. %s', $this->path, $e->getMessage())); + } catch (FileSystemException $e) { + throw new FileSystemException( + new \Magento\Framework\Phrase('Cannot write to the "%1" file. %2', [$this->path, $e->getMessage()]) + ); } } @@ -62,14 +64,16 @@ class Write extends Read implements WriteInterface * @param string $delimiter * @param string $enclosure * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function writeCsv(array $data, $delimiter = ',', $enclosure = '"') { try { return $this->driver->filePutCsv($this->resource, $data, $delimiter, $enclosure); - } catch (FilesystemException $e) { - throw new FilesystemException(sprintf('Cannot write to the "%s" file. %s', $this->path, $e->getMessage())); + } catch (FileSystemException $e) { + throw new FileSystemException( + new \Magento\Framework\Phrase('Cannot write to the "%1" file. %2', [$this->path, $e->getMessage()]) + ); } } @@ -77,14 +81,16 @@ class Write extends Read implements WriteInterface * Flushes the output. * * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function flush() { try { return $this->driver->fileFlush($this->resource); - } catch (FilesystemException $e) { - throw new FilesystemException(sprintf('Cannot flush the "%s" file. %s', $this->path, $e->getMessage())); + } catch (FileSystemException $e) { + throw new FileSystemException( + new \Magento\Framework\Phrase('Cannot flush the "%1" file. %2', [$this->path, $e->getMessage()]) + ); } } diff --git a/lib/internal/Magento/Framework/Filesystem/File/WriteInterface.php b/lib/internal/Magento/Framework/Filesystem/File/WriteInterface.php index d83d89d83a1ff289bd84982f4a7f48517cb5cb18..cf36ee69758f9d3a545bdae8ba954554b7db32f1 100644 --- a/lib/internal/Magento/Framework/Filesystem/File/WriteInterface.php +++ b/lib/internal/Magento/Framework/Filesystem/File/WriteInterface.php @@ -12,7 +12,7 @@ interface WriteInterface extends ReadInterface * * @param string $data * @return int - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function write($data); @@ -23,7 +23,7 @@ interface WriteInterface extends ReadInterface * @param string $delimiter * @param string $enclosure * @return int - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function writeCsv(array $data, $delimiter = ',', $enclosure = '"'); @@ -31,7 +31,7 @@ interface WriteInterface extends ReadInterface * Flushes the output. * * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function flush(); diff --git a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php index 1624a74b5754192f4f5277c06aeb795cab60163a..ed850baec96a9bb36bea2aaaa294ec3073394519 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php @@ -74,7 +74,7 @@ class Ftp extends AbstractIo { if (empty($args['host'])) { $this->_error = self::ERROR_EMPTY_HOST; - throw new IoException('Empty host specified'); + throw new IoException(new \Magento\Framework\Phrase('Empty host specified')); } if (empty($args['port'])) { @@ -107,20 +107,22 @@ class Ftp extends AbstractIo } if (!$this->_conn) { $this->_error = self::ERROR_INVALID_CONNECTION; - throw new IoException('Could not establish FTP connection, invalid host or port'); + throw new IoException( + new \Magento\Framework\Phrase('Could not establish FTP connection, invalid host or port') + ); } if (!@ftp_login($this->_conn, $this->_config['user'], $this->_config['password'])) { $this->_error = self::ERROR_INVALID_LOGIN; $this->close(); - throw new IoException('Invalid user name or password'); + throw new IoException(new \Magento\Framework\Phrase('Invalid user name or password')); } if (!empty($this->_config['path'])) { if (!@ftp_chdir($this->_conn, $this->_config['path'])) { $this->_error = self::ERROR_INVALID_PATH; $this->close(); - throw new IoException('Invalid path'); + throw new IoException(new \Magento\Framework\Phrase('Invalid path')); } } @@ -128,7 +130,7 @@ class Ftp extends AbstractIo if (!@ftp_pasv($this->_conn, true)) { $this->_error = self::ERROR_INVALID_MODE; $this->close(); - throw new IoException('Invalid file transfer mode'); + throw new IoException(new \Magento\Framework\Phrase('Invalid file transfer mode')); } } diff --git a/lib/internal/Magento/Framework/Filesystem/Io/IoException.php b/lib/internal/Magento/Framework/Filesystem/Io/IoException.php index dffe2d6695e5b5f9788f33654433de2ccf8323c1..3d94334dcae56b811afb12cc45fbe2deec95296f 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/IoException.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/IoException.php @@ -9,6 +9,6 @@ namespace Magento\Framework\Filesystem\Io; /** * Io exception */ -class IoException extends \Magento\Framework\Exception +class IoException extends \Magento\Framework\Exception\LocalizedException { } diff --git a/lib/internal/Magento/Framework/Filesystem/Test/Unit/DirectoryListTest.php b/lib/internal/Magento/Framework/Filesystem/Test/Unit/DirectoryListTest.php index 20b847670670c6bfadb4b5b9e00345a185c98da1..d749a5dd5d4bfff87e725f79a9e9a7a14e2bd34d 100644 --- a/lib/internal/Magento/Framework/Filesystem/Test/Unit/DirectoryListTest.php +++ b/lib/internal/Magento/Framework/Filesystem/Test/Unit/DirectoryListTest.php @@ -59,7 +59,7 @@ class DirectoryListTest extends \PHPUnit_Framework_TestCase /** * @param string $method - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException * @expectedExceptionMessage Unknown directory type: 'foo' * @dataProvider assertCodeDataProvider */ diff --git a/lib/internal/Magento/Framework/Filesystem/Test/Unit/Driver/HttpTest.php b/lib/internal/Magento/Framework/Filesystem/Test/Unit/Driver/HttpTest.php index bcd02a4d3a76d04a0a4b4e0e1d2659115fa336dd..6d28b1f25034cc5f5bdfe84fcbc3eb5fac1b0a9c 100644 --- a/lib/internal/Magento/Framework/Filesystem/Test/Unit/Driver/HttpTest.php +++ b/lib/internal/Magento/Framework/Filesystem/Test/Unit/Driver/HttpTest.php @@ -120,7 +120,7 @@ class HttpTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testFilePutContentsFail() { @@ -129,7 +129,7 @@ class HttpTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException * @expectedExceptionMessage Please correct the download URL. */ public function testFileOpenInvalidUrl() diff --git a/lib/internal/Magento/Framework/Filesystem/Test/Unit/File/ReadTest.php b/lib/internal/Magento/Framework/Filesystem/Test/Unit/File/ReadTest.php index 26e6cb01ba5eaf93d85041d347ae7bb93c58c048..016fb70e27d377973f8ad22dac323c04d87e38aa 100644 --- a/lib/internal/Magento/Framework/Filesystem/Test/Unit/File/ReadTest.php +++ b/lib/internal/Magento/Framework/Filesystem/Test/Unit/File/ReadTest.php @@ -59,7 +59,7 @@ class ReadTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testInstanceFileNotExists() { diff --git a/lib/internal/Magento/Framework/Filesystem/Test/Unit/File/WriteTest.php b/lib/internal/Magento/Framework/Filesystem/Test/Unit/File/WriteTest.php index af2a4f64459570ad41dcfe9b51998c12c85fd7f6..4216bf42b2e1957c97e5212a56225905d8e518a9 100644 --- a/lib/internal/Magento/Framework/Filesystem/Test/Unit/File/WriteTest.php +++ b/lib/internal/Magento/Framework/Filesystem/Test/Unit/File/WriteTest.php @@ -59,7 +59,7 @@ class WriteTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testInstanceFileNotExists() { @@ -73,7 +73,7 @@ class WriteTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testInstanceFileAlreadyExists() { @@ -121,7 +121,7 @@ class WriteTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testWriteException() { @@ -129,12 +129,14 @@ class WriteTest extends \PHPUnit_Framework_TestCase $this->driver->expects($this->once()) ->method('fileWrite') ->with($this->resource, $data) - ->will($this->throwException(new \Magento\Framework\Filesystem\FilesystemException())); + ->willThrowException( + new \Magento\Framework\Exception\FileSystemException(new \Magento\Framework\Phrase('')) + ); $this->file->write($data); } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testWriteCsvException() { @@ -144,19 +146,23 @@ class WriteTest extends \PHPUnit_Framework_TestCase $this->driver->expects($this->once()) ->method('filePutCsv') ->with($this->resource, $data, $delimiter, $enclosure) - ->will($this->throwException(new \Magento\Framework\Filesystem\FilesystemException())); + ->willThrowException( + new \Magento\Framework\Exception\FileSystemException(new \Magento\Framework\Phrase('')) + ); $this->file->writeCsv($data, $delimiter, $enclosure); } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testFlushException() { $this->driver->expects($this->once()) ->method('fileFlush') ->with($this->resource) - ->will($this->throwException(new \Magento\Framework\Filesystem\FilesystemException())); + ->willThrowException( + new \Magento\Framework\Exception\FileSystemException(new \Magento\Framework\Phrase('')) + ); $this->file->flush(); } diff --git a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php index 3a7742a7efb1faa0afd922c5f4d0a7188537effe..35f2ee5a1b5f2b9dd34669493436f67cadffd83c 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php +++ b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php @@ -682,7 +682,7 @@ abstract class AbstractAdapter implements AdapterInterface if (!is_writable($destination)) { try { $this->directoryWrite->create($this->directoryWrite->getRelativePath($destination)); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { $this->logger->critical($e); throw new \Exception('Unable to write file into directory ' . $destination . '. Access forbidden.'); } diff --git a/lib/internal/Magento/Framework/Image/Test/Unit/Adapter/ImageMagickTest.php b/lib/internal/Magento/Framework/Image/Test/Unit/Adapter/ImageMagickTest.php index 02a15478b09c36dd4021825d85825df694f1c69b..8b6040295019264e3cc6c77fe38a851638e2f391 100644 --- a/lib/internal/Magento/Framework/Image/Test/Unit/Adapter/ImageMagickTest.php +++ b/lib/internal/Magento/Framework/Image/Test/Unit/Adapter/ImageMagickTest.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\Image\Test\Unit\Adapter; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; class ImageMagickTest extends \PHPUnit_Framework_TestCase @@ -32,8 +32,8 @@ class ImageMagickTest extends \PHPUnit_Framework_TestCase public function setup() { $objectManager = new ObjectManager($this); - $this->loggerMock = $this->getMockBuilder( 'Psr\Log\LoggerInterface')->getMock(); - $this->writeMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')->getMock(); + $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); + $this->writeMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')->getMock(); $this->filesystemMock = $this->getMock( 'Magento\Framework\Filesystem', ['getDirectoryWrite'], @@ -44,7 +44,7 @@ class ImageMagickTest extends \PHPUnit_Framework_TestCase $this->filesystemMock ->expects($this->once()) ->method('getDirectoryWrite') - ->will($this->returnValue( $this->writeMock)); + ->willReturn($this->writeMock); $this->imageMagic = $objectManager ->getObject( @@ -85,7 +85,7 @@ class ImageMagickTest extends \PHPUnit_Framework_TestCase */ public function testSaveWithException() { - $exception = new FilesystemException(); + $exception = new FileSystemException(new \Magento\Framework\Phrase('')); $this->writeMock->method('create')->will($this->throwException($exception)); $this->loggerMock->expects($this->once())->method('critical')->with($exception); $this->imageMagic->save('product/cache', 'sample.jpg'); diff --git a/lib/internal/Magento/Framework/Interception/Code/InterfaceValidator.php b/lib/internal/Magento/Framework/Interception/Code/InterfaceValidator.php index d8582f819bf4f94ad4722246455f517e0f1eb730..c945033d93316f9cfc93aa93944b6f9a68a157cc 100644 --- a/lib/internal/Magento/Framework/Interception/Code/InterfaceValidator.php +++ b/lib/internal/Magento/Framework/Interception/Code/InterfaceValidator.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Interception\Code; +use Magento\Framework\Exception\ValidatorException; +use Magento\Framework\Phrase; + class InterfaceValidator { const METHOD_BEFORE = 'before'; @@ -55,13 +58,10 @@ class InterfaceValidator } if (!$type->hasMethod($originMethodName)) { throw new ValidatorException( - 'Incorrect interface in ' . - $pluginClass . - '. There is no method [ ' . - $originMethodName . - ' ] in ' . - $interceptedType . - ' interface' + new Phrase( + 'Incorrect interface in %1. There is no method [ %2 ] in %3 interface', + [$pluginClass, $originMethodName, $interceptedType] + ) ); } $originMethod = $type->getMethod($originMethodName); @@ -78,16 +78,10 @@ class InterfaceValidator ) || $subject['type'] === null ) { throw new ValidatorException( - 'Invalid [' . - $subject['type'] . - '] $' . - $subject['name'] . - ' type in ' . - $pluginClass . - '::' . - $pluginMethod->getName() . - '. It must be compatible with ' . - $interceptedType + new Phrase( + 'Invalid [%1] $%2 type in %3::%4. It must be compatible with %5', + [$subject['type'], $subject['name'], $pluginClass, $pluginMethod->getName(), $interceptedType] + ) ); } @@ -104,15 +98,10 @@ class InterfaceValidator $proceed = array_shift($pluginMethodParameters); if (!$this->_argumentsReader->isCompatibleType($proceed['type'], '\\Closure')) { throw new ValidatorException( - 'Invalid [' . - $proceed['type'] . - '] $' . - $proceed['name'] . - ' type in ' . - $pluginClass . - '::' . - $pluginMethod->getName() . - '. It must be compatible with \\Closure' + new Phrase( + 'Invalid [%1] $%2 type in %3::%4. It must be compatible with \\Closure', + [$proceed['type'], $proceed['name'], $pluginClass, $pluginMethod->getName()] + ) ); } $this->validateMethodsParameters( @@ -125,11 +114,10 @@ class InterfaceValidator case self::METHOD_AFTER: if (count($pluginMethodParameters) > 1) { throw new ValidatorException( - 'Invalid method signature. Detected extra parameters' . - ' in ' . - $pluginClass . - '::' . - $pluginMethod->getName() + new Phrase( + 'Invalid method signature. Detected extra parameters in %1::%2', + [$pluginClass, $pluginMethod->getName()] + ) ); } break; @@ -152,23 +140,19 @@ class InterfaceValidator { if (count($pluginParameters) != count($originParameters)) { throw new ValidatorException( - 'Invalid method signature. Invalid method parameters count' . ' in ' . $class . '::' . $method + new Phrase( + 'Invalid method signature. Invalid method parameters count in %1::%2', + [$class, $method] + ) ); } foreach ($pluginParameters as $position => $data) { if (!$this->_argumentsReader->isCompatibleType($data['type'], $originParameters[$position]['type'])) { throw new ValidatorException( - 'Incompatible parameter type [' . - $data['type'] . - ' $' . - $data['name'] . - ']' . - ' in ' . - $class . - '::' . - $method . - '. It must be compatible with ' . - $originParameters[$position]['type'] + new Phrase( + 'Incompatible parameter type [%1 $%2] in %3::%4. It must be compatible with %5', + [$data['type'], $data['name'], $class, $method, $originParameters[$position]['type']] + ) ); } } diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/Code/InterfaceValidatorTest.php b/lib/internal/Magento/Framework/Interception/Test/Unit/Code/InterfaceValidatorTest.php index 463282a829dbbd23c7caf2e3061a1c8b91ccf585..6b1f1bbef4ebfe7e05a63289abe73ce61a33f5e2 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/Code/InterfaceValidatorTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/Code/InterfaceValidatorTest.php @@ -53,7 +53,7 @@ class InterfaceValidatorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Interception\Code\ValidatorException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Incorrect interface in * @covers \Magento\Framework\Interception\Code\InterfaceValidator::validate */ @@ -66,7 +66,7 @@ class InterfaceValidatorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Interception\Code\ValidatorException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Invalid [\Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item] $subject type * @covers \Magento\Framework\Interception\Code\InterfaceValidator::validate */ @@ -79,7 +79,7 @@ class InterfaceValidatorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Interception\Code\ValidatorException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Invalid method signature. Invalid method parameters count * @covers \Magento\Framework\Interception\Code\InterfaceValidator::validate * @covers \Magento\Framework\Interception\Code\InterfaceValidator::validateMethodsParameters @@ -94,7 +94,7 @@ class InterfaceValidatorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Interception\Code\ValidatorException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Incompatible parameter type * @covers \Magento\Framework\Interception\Code\InterfaceValidator::validate * @covers \Magento\Framework\Interception\Code\InterfaceValidator::validateMethodsParameters @@ -109,7 +109,7 @@ class InterfaceValidatorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Interception\Code\ValidatorException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Invalid method signature. Detected extra parameters * @covers \Magento\Framework\Interception\Code\InterfaceValidator::validate */ @@ -122,7 +122,7 @@ class InterfaceValidatorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Interception\Code\ValidatorException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Invalid [] $name type in * @covers \Magento\Framework\Interception\Code\InterfaceValidator::validate */ diff --git a/lib/internal/Magento/Framework/Mail/Exception.php b/lib/internal/Magento/Framework/Mail/Exception.php deleted file mode 100644 index ffa3d56d90cfb43b0e68dfc5e39fcf0c2d16543f..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Mail/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Mail; - -class Exception extends \Exception -{ -} diff --git a/lib/internal/Magento/Framework/Mail/Template/SenderResolverInterface.php b/lib/internal/Magento/Framework/Mail/Template/SenderResolverInterface.php index 53a68730acb0513264f97046f263b712ce0e38b7..a440f983a47f10fb2148300d2e1bb340cb276928 100644 --- a/lib/internal/Magento/Framework/Mail/Template/SenderResolverInterface.php +++ b/lib/internal/Magento/Framework/Mail/Template/SenderResolverInterface.php @@ -11,7 +11,7 @@ interface SenderResolverInterface { /** * Resolve sender data - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException * @param string|array $sender * @param int|null $scopeId * @return array diff --git a/lib/internal/Magento/Framework/Mail/Test/Unit/TransportTest.php b/lib/internal/Magento/Framework/Mail/Test/Unit/TransportTest.php index cb5590497f3aebce6a4cc42f1f45f8ba746fde76..ac9afb81f3b5c8a2541fb3a76415dd9018322025 100644 --- a/lib/internal/Magento/Framework/Mail/Test/Unit/TransportTest.php +++ b/lib/internal/Magento/Framework/Mail/Test/Unit/TransportTest.php @@ -35,7 +35,7 @@ class TransportTest extends \PHPUnit_Framework_TestCase /** * @covers \Magento\Framework\Mail\Transport::sendMessage - * @expectedException \Magento\Framework\Mail\Exception + * @expectedException \Magento\Framework\Exception\MailException * @expectedExceptionMessage No body specified */ public function testSendMessageBrokenMessage() diff --git a/lib/internal/Magento/Framework/Mail/Transport.php b/lib/internal/Magento/Framework/Mail/Transport.php index 8a7a9c2f43329d1de8df3c5d456a364bdb087715..89efe6b006e3f94a9c58858d0a857758d26ed726 100644 --- a/lib/internal/Magento/Framework/Mail/Transport.php +++ b/lib/internal/Magento/Framework/Mail/Transport.php @@ -31,14 +31,14 @@ class Transport extends \Zend_Mail_Transport_Sendmail implements \Magento\Framew * Send a mail using this transport * * @return void - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function sendMessage() { try { parent::send($this->_message); } catch (\Exception $e) { - throw new \Magento\Framework\Mail\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e); } } } diff --git a/lib/internal/Magento/Framework/Mail/TransportInterface.php b/lib/internal/Magento/Framework/Mail/TransportInterface.php index 554daa553e1371b317b3e49926aea2b97e2667b2..53d1bd04e0720db87e615317c4fe9549957fdaf1 100644 --- a/lib/internal/Magento/Framework/Mail/TransportInterface.php +++ b/lib/internal/Magento/Framework/Mail/TransportInterface.php @@ -13,7 +13,7 @@ interface TransportInterface * Send a mail using this transport * * @return void - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function sendMessage(); } diff --git a/lib/internal/Magento/Framework/Module/Exception.php b/lib/internal/Magento/Framework/Module/Exception.php deleted file mode 100644 index 15e5f6ac7b166f9e0d02d8a3e91ff67aa3e76ccf..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Module/Exception.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Framework\Module; - -class Exception extends \Exception -{ -} diff --git a/lib/internal/Magento/Framework/Module/ModuleList/Loader.php b/lib/internal/Magento/Framework/Module/ModuleList/Loader.php index 943ed35520cbc0406eb694274fc8143147cc9d93..08660d98bb6ebeabb6085bf9689db4cb18189dad 100644 --- a/lib/internal/Magento/Framework/Module/ModuleList/Loader.php +++ b/lib/internal/Magento/Framework/Module/ModuleList/Loader.php @@ -55,7 +55,7 @@ class Loader /** * Loads the full module list information * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return array */ public function load() @@ -67,10 +67,12 @@ class Loader try { $this->parser->loadXML($contents); - } catch (\Magento\Framework\Exception $e) { - throw new \Magento\Framework\Exception( - 'Invalid Document: ' . $file . PHP_EOL . ' Error: ' . $e->getMessage(), - $e->getCode(), + } catch (\Magento\Framework\Exception\LocalizedException $e) { + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'Invalid Document: %1%2 Error: %3', + [$file, PHP_EOL, $e->getMessage()] + ), $e ); } diff --git a/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php b/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php index 52cbea3c74f5deb867a27b2b12b944c443cce3b3..e8ff84ee476765a4ef471c9bc92b3a8489a53e1c 100644 --- a/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php +++ b/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php @@ -42,7 +42,7 @@ class DbStatusValidator * @param \Closure $proceed * @param \Magento\Framework\App\RequestInterface $request * - * @throws \Magento\Framework\Module\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ @@ -55,9 +55,11 @@ class DbStatusValidator $errors = $this->dbVersionInfo->getDbVersionErrors(); if ($errors) { $formattedErrors = $this->formatErrors($errors); - throw new \Magento\Framework\Module\Exception( - 'Please update your database: Run "php -f index.php update" from the Magento root/setup directory.' - . PHP_EOL . 'The following modules are outdated:' . PHP_EOL . implode(PHP_EOL, $formattedErrors) + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'Please update your database: Run "php -f index.php update" from the Magento root/setup directory. %1The following modules are outdated:%2%3', + [PHP_EOL, PHP_EOL, implode(PHP_EOL, $formattedErrors)] + ) ); } else { $this->cache->save('true', 'db_is_up_to_date'); diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php index 8a760ccec43eb2243a6f0cfe60c2cdbd683819e3..10e21e701802b59a7be38144bb7fb5d1cbf684d6 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php @@ -116,7 +116,7 @@ class DbStatusValidatorTest extends \PHPUnit_Framework_TestCase * @param array $dbVersionErrors * * @dataProvider aroundDispatchExceptionDataProvider - * @expectedException \Magento\Framework\Module\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Please update your database: */ public function testAroundDispatchException(array $dbVersionErrors) diff --git a/lib/internal/Magento/Framework/Object.php b/lib/internal/Magento/Framework/Object.php index c13d48075dfb44aec6064c4b9d4d557658c85115..81be913e5543c7dc3f664bfbfd570175a50bf534 100644 --- a/lib/internal/Magento/Framework/Object.php +++ b/lib/internal/Magento/Framework/Object.php @@ -494,7 +494,7 @@ class Object implements \ArrayAccess * @param string $method * @param array $args * @return mixed - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function __call($method, $args) { @@ -514,8 +514,8 @@ class Object implements \ArrayAccess $key = $this->_underscore(substr($method, 3)); return isset($this->_data[$key]); } - throw new \Magento\Framework\Exception( - sprintf('Invalid method %s::%s(%s)', get_class($this), $method, print_r($args, 1)) + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Invalid method %1::%2(%3)', [get_class($this), $method, print_r($args, 1)]) ); } diff --git a/lib/internal/Magento/Framework/Object/Cache.php b/lib/internal/Magento/Framework/Object/Cache.php index 519021a01914b2c50198480dbf774fb6bf39eb93..911eaf0749cbd18d0dfb8b21b9a22dda8c59cf24 100644 --- a/lib/internal/Magento/Framework/Object/Cache.php +++ b/lib/internal/Magento/Framework/Object/Cache.php @@ -122,7 +122,7 @@ class Cache * @param string $idx * @param array|string $tags * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -150,11 +150,10 @@ class Cache } if (isset($this->_objects[$idx])) { - throw new \Magento\Framework\Exception( - 'Object already exists in registry (' . $idx . '). Old object class: ' . get_class( - $this->_objects[$idx] - ) . ', new object class: ' . get_class( - $object + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'Object already exists in registry (%1). Old object class: %2, new object class: %3', + [$idx, get_class($this->_objects[$idx]), get_class($object)] ) ); } @@ -184,7 +183,7 @@ class Cache * @param string|array $refName * @param string $idx * @return bool|void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function reference($refName, $idx) { @@ -196,13 +195,11 @@ class Cache } if (isset($this->_references[$refName])) { - throw new \Magento\Framework\Exception( - 'The reference already exists: ' . - $refName . - '. New index: ' . - $idx . - ', old index: ' . - $this->_references[$refName] + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'The reference already exists: %1. New index: %2, old index: %3', + [$refName, $idx, $this->_references[$refName]] + ) ); } $this->_references[$refName] = $idx; diff --git a/lib/internal/Magento/Framework/Object/Test/Unit/CacheTest.php b/lib/internal/Magento/Framework/Object/Test/Unit/CacheTest.php index afcfad8fb5d296f3368a62ef0931db1cf2b275f0..6e66bb3f370abf3a2d20745cb84cabf06ad733af 100644 --- a/lib/internal/Magento/Framework/Object/Test/Unit/CacheTest.php +++ b/lib/internal/Magento/Framework/Object/Test/Unit/CacheTest.php @@ -24,7 +24,7 @@ class CacheTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Object already exists in registry (#1). Old object class: stdClass */ public function testSaveWhenObjectAlreadyExistsInRegistry() @@ -54,7 +54,7 @@ class CacheTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage The reference already exists: refName. New index: idx, old index: idx */ public function testReferenceWhenReferenceAlreadyExist() diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Relations/RuntimeTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Relations/RuntimeTest.php index 3fde1b24d33603ef8159914db3ec962de5c9299b..2485e8e156228c7e2206971dd890e3e125e100e7 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Relations/RuntimeTest.php +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Relations/RuntimeTest.php @@ -42,7 +42,7 @@ class RuntimeTest extends \PHPUnit_Framework_TestCase /** * @param $entity - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @dataProvider nonExistentGeneratorsDataProvider */ public function testHasIfNonExists($entity) diff --git a/lib/internal/Magento/Framework/Session/SaveHandler.php b/lib/internal/Magento/Framework/Session/SaveHandler.php index bfd8a6958a712c8a52d9e2031748180c675e6d53..6f6595805bafe95a9c16c224e10a08e165c47aa6 100644 --- a/lib/internal/Magento/Framework/Session/SaveHandler.php +++ b/lib/internal/Magento/Framework/Session/SaveHandler.php @@ -6,6 +6,7 @@ namespace Magento\Framework\Session; use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Exception\SessionException; /** * Magento session save handler @@ -34,7 +35,7 @@ class SaveHandler implements SaveHandlerInterface $saveMethod = $deploymentConfig->get(\Magento\Framework\Session\Config::PARAM_SESSION_SAVE_METHOD); try { $adapter = $saveHandlerFactory->create($saveMethod); - } catch (SaveHandlerException $e) { + } catch (SessionException $e) { $adapter = $saveHandlerFactory->create($default); } $this->saveHandlerAdapter = $adapter; diff --git a/lib/internal/Magento/Framework/Session/SaveHandler/DbTable.php b/lib/internal/Magento/Framework/Session/SaveHandler/DbTable.php index b9e9b8a27aa94186ac3a9bb24522d571ecfa3ace..7ff33f1f72b0791298ee803dafbd2623fb97d70a 100644 --- a/lib/internal/Magento/Framework/Session/SaveHandler/DbTable.php +++ b/lib/internal/Magento/Framework/Session/SaveHandler/DbTable.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Session\SaveHandler; +use Magento\Framework\Exception\SessionException; +use Magento\Framework\Phrase; + /** * Data base session save handler */ @@ -40,15 +43,15 @@ class DbTable extends \SessionHandler * Check DB connection * * @return void - * @throws \Magento\Framework\Session\SaveHandlerException + * @throws \Magento\Framework\Exception\SessionException */ protected function checkConnection() { if (!$this->_write) { - throw new \Magento\Framework\Session\SaveHandlerException('Write DB connection is not available'); + throw new SessionException(new Phrase('Write DB connection is not available')); } if (!$this->_write->isTableExists($this->_sessionTable)) { - throw new \Magento\Framework\Session\SaveHandlerException('DB storage table does not exist'); + throw new SessionException(new Phrase('DB storage table does not exist')); } } diff --git a/lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/DbTableTest.php b/lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/DbTableTest.php index cecf0740fe13b4b7cc8164eeef63a40873def4ca..89efdac63f84246370f00225a167f1b9c976e1d7 100644 --- a/lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/DbTableTest.php +++ b/lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/DbTableTest.php @@ -100,7 +100,7 @@ class DbTableTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Session\SaveHandlerException + * @expectedException \Magento\Framework\Exception\SessionException * @expectedExceptionMessage Write DB connection is not available */ public function testCheckConnectionNoConnection() @@ -124,7 +124,7 @@ class DbTableTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Session\SaveHandlerException + * @expectedException \Magento\Framework\Exception\SessionException * @expectedExceptionMessage DB storage table does not exist */ public function testCheckConnectionNoTable() diff --git a/lib/internal/Magento/Framework/Session/Validator.php b/lib/internal/Magento/Framework/Session/Validator.php index 7fbf90088d08713d7b96b43bebcfd203e9e1dad5..7ddca4963110c662de5a3faba46562d558a7e074 100644 --- a/lib/internal/Magento/Framework/Session/Validator.php +++ b/lib/internal/Magento/Framework/Session/Validator.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Session; +use Magento\Framework\Exception\SessionException; +use Magento\Framework\Phrase; + /** * Session Validator */ @@ -71,7 +74,7 @@ class Validator implements ValidatorInterface * * @param SessionManagerInterface $session * @return void - * @throws Exception + * @throws SessionException */ public function validate(SessionManagerInterface $session) { @@ -80,7 +83,7 @@ class Validator implements ValidatorInterface } else { try { $this->_validate(); - } catch (Exception $e) { + } catch (SessionException $e) { $session->destroy(['clear_storage' => false]); // throw core session exception throw $e; @@ -92,7 +95,7 @@ class Validator implements ValidatorInterface * Validate data * * @return bool - * @throws Exception + * @throws SessionException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _validate() @@ -105,14 +108,24 @@ class Validator implements ValidatorInterface $this->_scopeType ) && $sessionData[self::VALIDATOR_REMOTE_ADDR_KEY] != $validatorData[self::VALIDATOR_REMOTE_ADDR_KEY] ) { - throw new Exception('Invalid session ' . self::VALIDATOR_REMOTE_ADDR_KEY . ' value.'); + throw new SessionException( + new Phrase( + 'Invalid session %1 value.', + [self::VALIDATOR_REMOTE_ADDR_KEY] + ) + ); } if ($this->_scopeConfig->getValue( self::XML_PATH_USE_HTTP_VIA, $this->_scopeType ) && $sessionData[self::VALIDATOR_HTTP_VIA_KEY] != $validatorData[self::VALIDATOR_HTTP_VIA_KEY] ) { - throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_VIA_KEY . ' value.'); + throw new SessionException( + new Phrase( + 'Invalid session %1 value.', + [self::VALIDATOR_HTTP_VIA_KEY] + ) + ); } $httpXForwardedKey = $sessionData[self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY]; @@ -122,7 +135,12 @@ class Validator implements ValidatorInterface $this->_scopeType ) && $httpXForwardedKey != $validatorXForwarded ) { - throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY . ' value.'); + throw new SessionException( + new Phrase( + 'Invalid session %1 value.', + [self::VALIDATOR_HTTP_X_FORWARDED_FOR_KEY] + ) + ); } if ($this->_scopeConfig->getValue( self::XML_PATH_USE_USER_AGENT, @@ -134,7 +152,12 @@ class Validator implements ValidatorInterface return true; } } - throw new Exception('Invalid session ' . self::VALIDATOR_HTTP_USER_AGENT_KEY . ' value.'); + throw new SessionException( + new Phrase( + 'Invalid session %1 value.', + [self::VALIDATOR_HTTP_USER_AGENT_KEY] + ) + ); } return true; diff --git a/lib/internal/Magento/Framework/Session/ValidatorInterface.php b/lib/internal/Magento/Framework/Session/ValidatorInterface.php index 147e9dd587f59b150ec85f1b29542bce74c2eb13..f1407c41b4b023919f99619ba8e238a4a75c94d3 100644 --- a/lib/internal/Magento/Framework/Session/ValidatorInterface.php +++ b/lib/internal/Magento/Framework/Session/ValidatorInterface.php @@ -17,7 +17,7 @@ interface ValidatorInterface * * @param \Magento\Framework\Session\SessionManagerInterface $session * @return void - * @throws \Magento\Framework\Session\Exception + * @throws \Magento\Framework\Exception\SessionException */ public function validate(\Magento\Framework\Session\SessionManagerInterface $session); } diff --git a/lib/internal/Magento/Framework/Shell.php b/lib/internal/Magento/Framework/Shell.php index 38b06f0d39d74fa72ef8f5f38ba70b18963a78e6..0652d49d039e0c43d21375d3d87153db78b1e243 100644 --- a/lib/internal/Magento/Framework/Shell.php +++ b/lib/internal/Magento/Framework/Shell.php @@ -42,7 +42,7 @@ class Shell implements ShellInterface * @param string $command Command with optional argument markers '%s' * @param string[] $arguments Argument values to substitute markers with * @return string Output of an executed command - * @throws \Magento\Framework\Exception If a command returns non-zero exit code + * @throws \Magento\Framework\Exception\LocalizedException If a command returns non-zero exit code */ public function execute($command, array $arguments = []) { @@ -51,7 +51,7 @@ class Shell implements ShellInterface $disabled = explode(',', ini_get('disable_functions')); if (in_array('exec', $disabled)) { - throw new Exception("exec function is disabled."); + throw new Exception\LocalizedException(new \Magento\Framework\Phrase("exec function is disabled.")); } exec($command, $output, $exitCode); @@ -59,7 +59,10 @@ class Shell implements ShellInterface $this->log($output); if ($exitCode) { $commandError = new \Exception($output, $exitCode); - throw new Exception("Command returned non-zero exit code:\n`{$command}`", 0, $commandError); + throw new Exception\LocalizedException( + new \Magento\Framework\Phrase("Command returned non-zero exit code:\n`%1`", [$command]), + $commandError + ); } return $output; } diff --git a/lib/internal/Magento/Framework/ShellInterface.php b/lib/internal/Magento/Framework/ShellInterface.php index 3f891b3fc345b1a21d5973fce34af2bff089ee93..dae36d58f8d63735e4debaf52e3b8f6f3642dc98 100644 --- a/lib/internal/Magento/Framework/ShellInterface.php +++ b/lib/internal/Magento/Framework/ShellInterface.php @@ -15,7 +15,7 @@ interface ShellInterface * * @param string $command Command with optional argument markers '%s' * @param string[] $arguments Argument values to substitute markers with - * @throws \Magento\Framework\Exception If a command returns non-zero exit code + * @throws \Magento\Framework\Exception\LocalizedException If a command returns non-zero exit code * @return string */ public function execute($command, array $arguments = []); diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/ValidationException.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/ValidationException.php deleted file mode 100644 index ca2ccc8e291c5d127d125dbfb1855064e30557a9..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/ValidationException.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -/** - * Datetime timezone exception - * - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Stdlib\DateTime\Timezone; - -class ValidationException extends \Exception -{ -} diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/Validator.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/Validator.php index 451c851f03d43d646ad617a3a6a3a579bfc39ae3..5474f1916b581ac9aad4ae8800c73f8166859340 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/Validator.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/Validator.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Stdlib\DateTime\Timezone; +use Magento\Framework\Exception\ValidatorException; +use Magento\Framework\Phrase; + class Validator { /** @@ -39,18 +42,22 @@ class Validator * @param int|string $timestamp * @param int|string $toDate * @return void - * @throws ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($timestamp, $toDate) { $transitionYear = date('Y', $timestamp); if ($transitionYear > $this->_yearMaxValue || $transitionYear < $this->_yearMinValue) { - throw new ValidationException('Transition year is out of system date range.'); + throw new ValidatorException( + new Phrase('Transition year is out of system date range.') + ); } if ((int) $timestamp > (int) $toDate) { - throw new ValidationException('Transition year is out of specified date range.'); + throw new ValidatorException( + new Phrase('Transition year is out of specified date range.') + ); } } } diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Timezone/ValidatorTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Timezone/ValidatorTest.php index 2744763c7fbfe37af5db4e7998f33cd7c78a0895..8df4113d4392f7dba73b1ffcd8fbaa0c394b8a40 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Timezone/ValidatorTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Timezone/ValidatorTest.php @@ -14,7 +14,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase /** * @dataProvider validateWithTimestampOutOfSystemRangeDataProvider - * @expectedException \Magento\Framework\Stdlib\DateTime\Timezone\ValidationException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Transition year is out of system date range. */ public function testValidateWithTimestampOutOfSystemRangeThrowsException($range, $validateArgs) @@ -24,7 +24,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Stdlib\DateTime\Timezone\ValidationException + * @expectedException \Magento\Framework\Exception\ValidatorException * @expectedExceptionMessage Transition year is out of specified date range. */ public function testValidateWithTimestampOutOfSpecifiedRangeThrowsException() diff --git a/lib/internal/Magento/Framework/Test/Unit/ObjectTest.php b/lib/internal/Magento/Framework/Test/Unit/ObjectTest.php index 5af6181770b7a0f6bc5ae7734e246333a8e1f4a3..66edf78695dfb5e65b9e4516ad23f296e7d26745 100644 --- a/lib/internal/Magento/Framework/Test/Unit/ObjectTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/ObjectTest.php @@ -328,7 +328,7 @@ string', /** * Tests \Magento\Framework\Object->__call() * - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testCall() { diff --git a/lib/internal/Magento/Framework/Test/Unit/ShellTest.php b/lib/internal/Magento/Framework/Test/Unit/ShellTest.php index 43ed43aedf902d1fb22e9876ea0f7dacea8b9cd5..093c3df126f8d3f4fab9d56f1c81ab075c594a21 100644 --- a/lib/internal/Magento/Framework/Test/Unit/ShellTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/ShellTest.php @@ -111,7 +111,7 @@ class ShellTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Command returned non-zero exit code: * @expectedExceptionCode 0 */ @@ -133,7 +133,7 @@ class ShellTest extends \PHPUnit_Framework_TestCase /* Force command to return non-zero exit code */ $commandArgs[count($commandArgs) - 1] .= ' exit(42);'; $this->testExecute($command, $commandArgs, ''); // no result is expected in a case of a command failure - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->assertInstanceOf('Exception', $e->getPrevious()); $this->assertEquals($expectedError, $e->getPrevious()->getMessage()); $this->assertEquals(42, $e->getPrevious()->getCode()); diff --git a/lib/internal/Magento/Framework/Url/ScopeResolver.php b/lib/internal/Magento/Framework/Url/ScopeResolver.php index e53d1dd145cbcf1a7aa40261c5eb819507c8ed36..456eadcd11b8144a1b72bdfdb8339170df2a8717 100644 --- a/lib/internal/Magento/Framework/Url/ScopeResolver.php +++ b/lib/internal/Magento/Framework/Url/ScopeResolver.php @@ -39,7 +39,9 @@ class ScopeResolver implements \Magento\Framework\Url\ScopeResolverInterface { $scope = $this->scopeResolver->getScope($scopeId); if (!$scope instanceof \Magento\Framework\Url\ScopeInterface) { - throw new \Magento\Framework\Exception('Invalid scope object'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Invalid scope object') + ); } return $scope; diff --git a/lib/internal/Magento/Framework/Url/Test/Unit/ScopeResolverTest.php b/lib/internal/Magento/Framework/Url/Test/Unit/ScopeResolverTest.php index 75b457c0813949a1e479504f9afe8ef44e5d5c5e..dfffc00248b5c65138014c1436906984c3effd3b 100644 --- a/lib/internal/Magento/Framework/Url/Test/Unit/ScopeResolverTest.php +++ b/lib/internal/Magento/Framework/Url/Test/Unit/ScopeResolverTest.php @@ -47,7 +47,7 @@ class ScopeResolverTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid scope object */ public function testGetScopeException() diff --git a/lib/internal/Magento/Framework/Validator/Test/Unit/ConfigTest.php b/lib/internal/Magento/Framework/Validator/Test/Unit/ConfigTest.php index 5c4e34a97356e571e99d8a1189391fb38abc75c6..5bc402bae8c4bd06e3d5c928ba06fd5605955e81 100644 --- a/lib/internal/Magento/Framework/Validator/Test/Unit/ConfigTest.php +++ b/lib/internal/Magento/Framework/Validator/Test/Unit/ConfigTest.php @@ -255,7 +255,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase * Check XSD schema validates invalid config files * * @dataProvider getInvalidXmlFiles - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * * @param array|string $configFile */ diff --git a/lib/internal/Magento/Framework/View/Asset/MergeStrategy/Direct.php b/lib/internal/Magento/Framework/View/Asset/MergeStrategy/Direct.php index 8144fc1660bfbab4e41a4c80b175ebada284a84b..a7e94e698e2e45489f22bb2e31b0ee5c47f7ad60 100644 --- a/lib/internal/Magento/Framework/View/Asset/MergeStrategy/Direct.php +++ b/lib/internal/Magento/Framework/View/Asset/MergeStrategy/Direct.php @@ -60,7 +60,7 @@ class Direct implements \Magento\Framework\View\Asset\MergeStrategyInterface * @param \Magento\Framework\View\Asset\MergeableInterface[] $assetsToMerge * @param \Magento\Framework\View\Asset\LocalInterface $resultAsset * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ private function composeMergedContent(array $assetsToMerge, Asset\LocalInterface $resultAsset) { diff --git a/lib/internal/Magento/Framework/View/Asset/Minified/AbstractAsset.php b/lib/internal/Magento/Framework/View/Asset/Minified/AbstractAsset.php index 461ddb41c745636748484c230005b34cd64a7c8c..bbfa28664ed345a80e178071ee967ecbe281aca3 100644 --- a/lib/internal/Magento/Framework/View/Asset/Minified/AbstractAsset.php +++ b/lib/internal/Magento/Framework/View/Asset/Minified/AbstractAsset.php @@ -9,6 +9,7 @@ namespace Magento\Framework\View\Asset\Minified; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\View\Asset\MergeableInterface; use Magento\Framework\View\Asset\LocalInterface; +use \Magento\Framework\Phrase; /** * Minified page asset @@ -225,9 +226,8 @@ abstract class AbstractAsset implements MergeableInterface $this->fillPropertiesByMinifyingAsset(); } catch (\Exception $e) { $this->logger->critical( - new \Magento\Framework\Exception( - 'Could not minify file: ' . $this->originalAsset->getSourceFile(), - 0, + new \Magento\Framework\Exception\LocalizedException( + new Phrase('Could not minify file: %1', [$this->originalAsset->getSourceFile()]), $e ) ); diff --git a/lib/internal/Magento/Framework/View/Asset/MinifyService.php b/lib/internal/Magento/Framework/View/Asset/MinifyService.php index 74a1518513ac4354ebefc67ca077d21bfdff45ff..7d5720fb4a8d618c5056106df90c30638da18efb 100644 --- a/lib/internal/Magento/Framework/View/Asset/MinifyService.php +++ b/lib/internal/Magento/Framework/View/Asset/MinifyService.php @@ -100,22 +100,28 @@ class MinifyService * * @param string $contentType * @return \Magento\Framework\Code\Minifier\AdapterInterface - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function getAdapter($contentType) { if (!isset($this->adapters[$contentType])) { $adapterClass = $this->config->getAssetMinificationAdapter($contentType); if (!$adapterClass) { - throw new \Magento\Framework\Exception( - "Minification adapter is not specified for '$contentType' content type" + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + "Minification adapter is not specified for '%1' content type", + [$contentType] + ) ); } $adapter = $this->objectManager->get($adapterClass); if (!($adapter instanceof \Magento\Framework\Code\Minifier\AdapterInterface)) { $type = get_class($adapter); - throw new \Magento\Framework\Exception( - "Invalid adapter: '{$type}'. Expected: \\Magento\\Framework\\Code\\Minifier\\AdapterInterface" + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + "Invalid adapter: '%1'. Expected: \\Magento\\Framework\\Code\\Minifier\\AdapterInterface", + [$type] + ) ); } $this->adapters[$contentType] = $adapter; @@ -130,7 +136,7 @@ class MinifyService * @param string $strategy * @param bool $isDirectRequest * @return AssetInterface - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function getAssetDecorated(AssetInterface $asset, $strategy, $isDirectRequest) { diff --git a/lib/internal/Magento/Framework/View/Asset/Repository.php b/lib/internal/Magento/Framework/View/Asset/Repository.php index fda21b7564074f7412b7430e9927ddef9a64e1bf..4b6801310a3758ad679dba0cefa1128d7c24e47d 100644 --- a/lib/internal/Magento/Framework/View/Asset/Repository.php +++ b/lib/internal/Magento/Framework/View/Asset/Repository.php @@ -346,7 +346,7 @@ class Repository * * @param string $fileId * @return array - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public static function extractModule($fileId) { @@ -355,7 +355,9 @@ class Repository } $result = explode(self::FILE_ID_SEPARATOR, $fileId, 2); if (empty($result[0])) { - throw new \Magento\Framework\Exception('Scope separator "::" cannot be used without scope identifier.'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Scope separator "::" cannot be used without scope identifier.') + ); } return [$result[0], $result[1]]; } diff --git a/lib/internal/Magento/Framework/View/Design/Theme/Domain/Factory.php b/lib/internal/Magento/Framework/View/Design/Theme/Domain/Factory.php index f3c8a76bd2896f1677be47030204d9761beac023..7fa18b8bb0b9682ad2e919524cb622ec1a23e3d4 100644 --- a/lib/internal/Magento/Framework/View/Design/Theme/Domain/Factory.php +++ b/lib/internal/Magento/Framework/View/Design/Theme/Domain/Factory.php @@ -45,13 +45,13 @@ class Factory * * @param ThemeInterface $theme * @return mixed - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function create(ThemeInterface $theme) { if (!isset($this->_types[$theme->getType()])) { - throw new \Magento\Framework\Exception( - sprintf('Invalid type of theme domain model "%s"', $theme->getType()) + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Invalid type of theme domain model "%1"', [$theme->getType()]) ); } $class = $this->_types[$theme->getType()]; diff --git a/lib/internal/Magento/Framework/View/Design/Theme/Image.php b/lib/internal/Magento/Framework/View/Design/Theme/Image.php index 5ec518abeb1c50aab01c6985baaa2795da235f4b..0101382d06c3230da510cf947483754ee52aad25 100644 --- a/lib/internal/Magento/Framework/View/Design/Theme/Image.php +++ b/lib/internal/Magento/Framework/View/Design/Theme/Image.php @@ -157,7 +157,7 @@ class Image $targetRelativePath = $this->mediaDirectory->getRelativePath($previewDir . '/' . $destinationFileName); $isCopied = $this->rootDirectory->copyFile($sourceRelativePath, $targetRelativePath, $this->mediaDirectory); $this->theme->setPreviewImage($destinationFileName); - } catch (\Magento\Framework\Filesystem\FilesystemException $e) { + } catch (\Magento\Framework\Exception\FileSystemException $e) { $this->theme->setPreviewImage(null); $this->logger->critical($e); } diff --git a/lib/internal/Magento/Framework/View/Design/Theme/Image/Uploader.php b/lib/internal/Magento/Framework/View/Design/Theme/Image/Uploader.php index da5596876a7f1197a5e01fd5a006600186726a61..3e1a690653314e35e292d853802383b45615d817 100644 --- a/lib/internal/Magento/Framework/View/Design/Theme/Image/Uploader.php +++ b/lib/internal/Magento/Framework/View/Design/Theme/Image/Uploader.php @@ -61,7 +61,7 @@ class Uploader * @param string $scope the request key for file * @param string $destinationPath path to upload directory * @return bool - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function uploadPreviewImage($scope, $destinationPath) { @@ -69,8 +69,8 @@ class Uploader return false; } if (!$this->_transferAdapter->isValid($scope)) { - throw new \Magento\Framework\Exception( - (string)new \Magento\Framework\Phrase('Uploaded image is not valid') + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Uploaded image is not valid') ); } $upload = $this->_uploaderFactory->create(['fileId' => $scope]); @@ -80,10 +80,14 @@ class Uploader $upload->setFilesDispersion(false); if (!$upload->checkAllowedExtension($upload->getFileExtension())) { - throw new \Magento\Framework\Exception((string)new \Magento\Framework\Phrase('Invalid image file type.')); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Invalid image file type.') + ); } if (!$upload->save($destinationPath)) { - throw new \Magento\Framework\Exception((string)new \Magento\Framework\Phrase('Image can not be saved.')); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Image can not be saved.') + ); } return $destinationPath . '/' . $upload->getUploadedFileName(); } diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index 278e493e671b836f7296a08b9e24c246cde56de3..cf0c87c49d3a4ab8450d97e5b31af3704ff3ebdb 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -261,12 +261,14 @@ abstract class AbstractBlock extends \Magento\Framework\Object implements BlockI * Retrieve layout object * * @return \Magento\Framework\View\LayoutInterface - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getLayout() { if (!$this->_layout) { - throw new \Magento\Framework\Exception('Layout must be initialized'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Layout must be initialized') + ); } return $this->_layout; } @@ -744,7 +746,7 @@ abstract class AbstractBlock extends \Magento\Framework\Object implements BlockI try { $params = array_merge(['_secure' => $this->getRequest()->isSecure()], $params); return $this->_assetRepo->getUrlWithParams($fileId, $params); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->_logger->critical($e); return $this->_getNotFoundUrl(); } diff --git a/lib/internal/Magento/Framework/View/File/Collector/Override/ThemeModular.php b/lib/internal/Magento/Framework/View/File/Collector/Override/ThemeModular.php index 2edd72d7e9d61c8c98f854403cc66fb24311b52a..db731cdbabed60c6fa9b7d085e92966f41e0929b 100644 --- a/lib/internal/Magento/Framework/View/File/Collector/Override/ThemeModular.php +++ b/lib/internal/Magento/Framework/View/File/Collector/Override/ThemeModular.php @@ -12,7 +12,7 @@ use Magento\Framework\View\Design\ThemeInterface; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\View\File\Factory; -use Magento\Framework\Exception; +use Magento\Framework\Exception\LocalizedException; /** * Source of view files that explicitly override modular files of ancestor themes @@ -61,7 +61,7 @@ class ThemeModular implements CollectorInterface * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getFiles(ThemeInterface $theme, $filePath) { @@ -90,12 +90,10 @@ class ThemeModular implements CollectorInterface $moduleFull = $matches['module']; $ancestorThemeCode = $matches['themeVendor'] . '/' . $matches['themeName']; if (!isset($themes[$ancestorThemeCode])) { - throw new Exception( - sprintf( - "Trying to override modular view file '%s' for theme '%s', which is not ancestor of theme '%s'", - $filename, - $ancestorThemeCode, - $theme->getCode() + throw new LocalizedException( + new \Magento\Framework\Phrase( + "Trying to override modular view file '%1' for theme '%2', which is not ancestor of theme '%3'", + [$filename, $ancestorThemeCode, $theme->getCode()] ) ); } diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index c6b2596c14f4991cbefb950fbdd9f0706170ea56..c2184cfff688e3f04e0863954a831e68b82b9ce2 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -480,7 +480,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra * * @param string $name * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _renderBlock($name) { @@ -493,7 +493,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra * * @param string $name * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _renderUiComponent($name) { @@ -906,12 +906,14 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra * * @param string $type * @return \Magento\Framework\App\Helper\AbstractHelper - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getBlockSingleton($type) { if (empty($type)) { - throw new \Magento\Framework\Exception('Invalid block type'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Invalid block type') + ); } if (!isset($this->sharedBlocks[$type])) { $this->sharedBlocks[$type] = $this->createBlock($type); diff --git a/lib/internal/Magento/Framework/View/Layout/Generator/Container.php b/lib/internal/Magento/Framework/View/Layout/Generator/Container.php index d3fb8247a2336e374dc35a4423954e536a9b37c8..e0ebfb972ca90b4f4b84b7889374ff3e1128cecd 100644 --- a/lib/internal/Magento/Framework/View/Layout/Generator/Container.php +++ b/lib/internal/Magento/Framework/View/Layout/Generator/Container.php @@ -101,7 +101,7 @@ class Container implements Layout\GeneratorInterface /** * @param array $options * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function validateOptions($options) { @@ -111,11 +111,10 @@ class Container implements Layout\GeneratorInterface $this->allowedTags ) ) { - throw new \Magento\Framework\Exception( - sprintf( - 'Html tag "%s" is forbidden for usage in containers. Consider to use one of the allowed: %s.', - $options[Layout\Element::CONTAINER_OPT_HTML_TAG], - implode(', ', $this->allowedTags) + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'Html tag "%1" is forbidden for usage in containers. Consider to use one of the allowed: %2.', + [$options[Layout\Element::CONTAINER_OPT_HTML_TAG], implode(', ', $this->allowedTags)] ) ); } @@ -126,8 +125,8 @@ class Container implements Layout\GeneratorInterface || !empty($options[Layout\Element::CONTAINER_OPT_HTML_CLASS]) ) ) { - throw new \Magento\Framework\Exception( - 'HTML ID or class will not have effect, if HTML tag is not specified.' + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('HTML ID or class will not have effect, if HTML tag is not specified.') ); } } diff --git a/lib/internal/Magento/Framework/View/Layout/ProcessorInterface.php b/lib/internal/Magento/Framework/View/Layout/ProcessorInterface.php index 42105c9e90b723cf1d744a8d49ff579dfb08cfa1..f008321a24922542cbc15ae8d39607a9bc772f4d 100644 --- a/lib/internal/Magento/Framework/View/Layout/ProcessorInterface.php +++ b/lib/internal/Magento/Framework/View/Layout/ProcessorInterface.php @@ -93,7 +93,7 @@ interface ProcessorInterface * Load layout updates by handles * * @param array|string $handles - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return ProcessorInterface */ public function load($handles = []); diff --git a/lib/internal/Magento/Framework/View/Layout/Reader/Move.php b/lib/internal/Magento/Framework/View/Layout/Reader/Move.php index d656c2d0448a9f57733d0ee2df6c534d3d9f3277..af3f01aa46e205d0ebb1ebb2d3e63f7afef8cf8a 100644 --- a/lib/internal/Magento/Framework/View/Layout/Reader/Move.php +++ b/lib/internal/Magento/Framework/View/Layout/Reader/Move.php @@ -43,7 +43,7 @@ class Move implements Layout\ReaderInterface * * @param \Magento\Framework\View\Layout\ScheduledStructure $scheduledStructure * @param \Magento\Framework\View\Layout\Element $currentElement - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ protected function scheduleMove(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentElement) @@ -58,7 +58,9 @@ class Move implements Layout\ReaderInterface [$destination, $siblingName, $isAfter, $alias] ); } else { - throw new \Magento\Framework\Exception('Element name and destination must be specified.'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Element name and destination must be specified.') + ); } return $this; } diff --git a/lib/internal/Magento/Framework/View/Model/Layout/Merge.php b/lib/internal/Magento/Framework/View/Model/Layout/Merge.php index 6f438e29c8f21ebbc6deea8ec47416775d602aae..95c51d545c726b8ab4d7b6cb050202ed6e4686fa 100644 --- a/lib/internal/Magento/Framework/View/Model/Layout/Merge.php +++ b/lib/internal/Magento/Framework/View/Model/Layout/Merge.php @@ -405,7 +405,7 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface * Load layout updates by handles * * @param array|string $handles - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function load($handles = []) @@ -413,7 +413,9 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface if (is_string($handles)) { $handles = [$handles]; } elseif (!is_array($handles)) { - throw new \Magento\Framework\Exception('Invalid layout update handle'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Invalid layout update handle') + ); } $this->addHandle($handles); @@ -580,6 +582,8 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface * * @param string $handle * @return string + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getDbUpdateString($handle) { @@ -666,7 +670,7 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface * Collect and merge layout updates from files * * @return \Magento\Framework\View\Layout\Element - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _loadFileLayoutUpdatesXml() { @@ -688,8 +692,11 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface continue; } if (!$file->isBase() && $fileXml->xpath(self::XPATH_HANDLE_DECLARATION)) { - throw new \Magento\Framework\Exception( - sprintf("Theme layout update file '%s' must not declare page types.", $file->getFileName()) + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'Theme layout update file \'%1\' must not declare page types.', + [$file->getFileName()] + ) ); } $handleName = basename($file->getFilename(), '.xml'); @@ -730,7 +737,7 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return \Magento\Theme\Model\Theme - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getPhysicalTheme(\Magento\Framework\View\Design\ThemeInterface $theme) { @@ -739,8 +746,11 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface $result = $result->getParentTheme(); } if (!$result) { - throw new \Magento\Framework\Exception( - "Unable to find a physical ancestor for a theme '{$theme->getThemeTitle()}'." + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + 'Unable to find a physical ancestor for a theme \'%1\'.', + [$theme->getThemeTitle()] + ) ); } return $result; diff --git a/lib/internal/Magento/Framework/View/Page/Config.php b/lib/internal/Magento/Framework/View/Page/Config.php index 9fe5599d6a992a40cef269d645cc203413412e50..f01721a2704d401083bc98b5b86245d9d52b2e24 100644 --- a/lib/internal/Magento/Framework/View/Page/Config.php +++ b/lib/internal/Magento/Framework/View/Page/Config.php @@ -433,13 +433,15 @@ class Config * @param string $attribute * @param mixed $value * @return $this - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function setElementAttribute($elementType, $attribute, $value) { $this->build(); if (array_search($elementType, $this->allowedTypes) === false) { - throw new \Magento\Framework\Exception($elementType . ' isn\'t allowed'); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('%1 isn\'t allowed', [$elementType]) + ); } $this->elements[$elementType][$attribute] = $value; return $this; diff --git a/lib/internal/Magento/Framework/View/Page/Config/Renderer.php b/lib/internal/Magento/Framework/View/Page/Config/Renderer.php index ebfd7944a88aa054f316917dbd1da419ffdfde71..0f3b7cdf09f8d87cfc17acb8591a5e146a86bc34 100644 --- a/lib/internal/Magento/Framework/View/Page/Config/Renderer.php +++ b/lib/internal/Magento/Framework/View/Page/Config/Renderer.php @@ -363,7 +363,7 @@ class Renderer implements RendererInterface foreach ($assets as $asset) { $result .= sprintf($template, $asset->getUrl()); } - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->logger->critical($e); $result .= sprintf($template, $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound'])); } diff --git a/lib/internal/Magento/Framework/View/Result/Page.php b/lib/internal/Magento/Framework/View/Result/Page.php index e2f12e786c4421c20f67263c67fca8e4c1c3c2d5..2fab155de566867946cb5fff6a868c117667d5c5 100644 --- a/lib/internal/Magento/Framework/View/Result/Page.php +++ b/lib/internal/Magento/Framework/View/Result/Page.php @@ -328,7 +328,7 @@ class Page extends Layout try { $params = array_merge(['_secure' => $this->request->isSecure()], $params); return $this->assetRepo->getUrlWithParams($fileId, $params); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->logger->critical($e); return $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']); } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/MinifyServiceTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/MinifyServiceTest.php index d2d76f16bca9895f7c7f55e0eddb2df149702459..2e31f4d67733e308603855cac3dc43dd3d7e7514 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/MinifyServiceTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/MinifyServiceTest.php @@ -127,7 +127,7 @@ class MinifyServiceTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Minification adapter is not specified for 'js' content type */ public function testGetAssetsNoAdapterDefined() @@ -151,7 +151,7 @@ class MinifyServiceTest extends \PHPUnit_Framework_TestCase public function testGetAssetsInvalidAdapter() { $this->setExpectedException( - '\Magento\Framework\Exception', + '\Magento\Framework\Exception\LocalizedException', 'Invalid adapter: \'stdClass\'. Expected: \Magento\Framework\Code\Minifier\AdapterInterface' ); $asset = $this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface'); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/RepositoryTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/RepositoryTest.php index 1ee041ddd1ec0fa01cf2afd41f67df3e87765039..60a2d297e4b5ba5a56bff218941ed1ea2fa7884c 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/RepositoryTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/RepositoryTest.php @@ -309,7 +309,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Scope separator "::" cannot be used without scope identifier. */ public function testExtractModuleException() diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/Domain/FactoryTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/Domain/FactoryTest.php index 07c1058228492ad620689c4c671c70c6a78c4795..3204ae36d8cf8b4ae018dbf3ab2e3616a65a61a7 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/Domain/FactoryTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/Domain/FactoryTest.php @@ -57,7 +57,7 @@ class FactoryTest extends \PHPUnit_Framework_TestCase $themeDomainFactory = new \Magento\Framework\View\Design\Theme\Domain\Factory($objectManager); $this->setExpectedException( - 'Magento\Framework\Exception', + 'Magento\Framework\Exception\LocalizedException', sprintf('Invalid type of theme domain model "%s"', $wrongThemeType) ); $themeDomainFactory->create($themeMock); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/Image/UploaderTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/Image/UploaderTest.php index 8218420f5fcd080904f3ca2c1fb31a1cf088c1be..603e49038c4e1609d4d9e644f08ea0ab9bb3f8fd 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/Image/UploaderTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Design/Theme/Image/UploaderTest.php @@ -102,7 +102,7 @@ class UploaderTest extends \PHPUnit_Framework_TestCase 'checkAllowedExtension' => true, 'save' => true, 'result' => false, - 'exception' => 'Magento\Framework\Exception' + 'exception' => 'Magento\Framework\Exception\LocalizedException' ], [ 'isUploaded' => true, @@ -110,7 +110,7 @@ class UploaderTest extends \PHPUnit_Framework_TestCase 'checkAllowedExtension' => false, 'save' => true, 'result' => false, - 'exception' => 'Magento\Framework\Exception' + 'exception' => 'Magento\Framework\Exception\LocalizedException' ], [ 'isUploaded' => true, @@ -118,7 +118,7 @@ class UploaderTest extends \PHPUnit_Framework_TestCase 'checkAllowedExtension' => true, 'save' => false, 'result' => false, - 'exception' => 'Magento\Framework\Exception' + 'exception' => 'Magento\Framework\Exception\LocalizedException' ] ]; } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/File/Collector/Override/ThemeModularTest.php b/lib/internal/Magento/Framework/View/Test/Unit/File/Collector/Override/ThemeModularTest.php index 00721963a9bedc0aec8848c62bedbb8060bbe9a5..1902c4884fe18ddfedf598125b8bf1d036160697 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/File/Collector/Override/ThemeModularTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/File/Collector/Override/ThemeModularTest.php @@ -113,7 +113,7 @@ class ThemeModularTest extends \PHPUnit_Framework_TestCase { $filePath = 'design/area/theme_path/Module_One/override/theme/vendor/parent_theme/1.xml'; $this->setExpectedException( - 'Magento\Framework\Exception', + 'Magento\Framework\Exception\LocalizedException', "Trying to override modular view file '$filePath' for theme 'vendor/parent_theme'" . ", which is not ancestor of theme 'vendor/theme_path'" ); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Generator/ContainerTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Generator/ContainerTest.php index 07f1c2aca8be0d22adeccf510f3986fee0bcea8a..547b646035cf9d7a199a9aa2851a243dd51338cc 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Generator/ContainerTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Generator/ContainerTest.php @@ -124,7 +124,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase * @param array $structureElements * * @dataProvider processWithExceptionDataProvider - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testProcessWithException($structureElements) { diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/MoveTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/MoveTest.php index 8d5c858b4e73af8bace4f445634f66e9b7025b25..1b3a28a7435e5c4f468135127c9f47c2639d24de 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/MoveTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/MoveTest.php @@ -100,7 +100,7 @@ class MoveTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testProcessInvalidData() { diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Model/Layout/MergeTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Model/Layout/MergeTest.php index b2f6f82a775feffb903cd352711d677a1a16327d..281bb8ac0519d7f345fbe8d264cb0834a9ca4f40 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Model/Layout/MergeTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Model/Layout/MergeTest.php @@ -12,7 +12,9 @@ class MergeTest extends \PHPUnit_Framework_TestCase /** * Fixture XML instruction(s) to be used in tests */ + // @codingStandardsIgnoreStart const FIXTURE_LAYOUT_XML = '<block class="Magento\Framework\View\Element\Template" template="fixture_template_one.phtml"/>'; + // @codingStandardsIgnoreEnd /** * @var \Magento\Framework\View\Model\Layout\Merge @@ -291,7 +293,10 @@ class MergeTest extends \PHPUnit_Framework_TestCase $handles = ['fixture_handle_one']; $this->_model->load($handles); $this->assertEquals($handles, $this->_model->getHandles()); - $this->assertXmlStringEqualsXmlString('<body>' . self::FIXTURE_LAYOUT_XML . '</body>', $this->_model->asString()); + $this->assertXmlStringEqualsXmlString( + '<body>' . self::FIXTURE_LAYOUT_XML . '</body>', + $this->_model->asString() + ); } public function testGetFileLayoutUpdatesXml() @@ -378,7 +383,7 @@ class MergeTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid layout update handle */ public function testLoadWithInvalidArgumentThrowsException() diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php index e407988f77df31cddaa18ff21d82c26401b4f078..2917b75f726441b8b1b9f1e0e643c02ea19f3f12 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php @@ -264,7 +264,7 @@ class RendererTest extends \PHPUnit_Framework_TestCase $assetUrl = 'url'; $assetNoRoutUrl = 'no_route_url'; - $exception = new \Magento\Framework\Exception('my message'); + $exception = new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('my message')); $assetMockOne = $this->getMock('Magento\Framework\View\Asset\AssetInterface'); $assetMockOne->expects($this->exactly(2)) diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Page/ConfigTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Page/ConfigTest.php index 403522b7aa4dceb8546b9377a664a90c4814e3fb..ae61cf0509216bda474b126185b0cfcb112afa37 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Page/ConfigTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Page/ConfigTest.php @@ -360,7 +360,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase */ public function testElementAttributeException($elementType, $attribute, $value) { - $this->setExpectedException('\Magento\Framework\Exception', $elementType . " isn't allowed"); + $this->setExpectedException('\Magento\Framework\Exception\LocalizedException', $elementType . " isn't allowed"); $this->model->setElementAttribute($elementType, $attribute, $value); } diff --git a/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php b/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php index 06b78b7c35cd5edcad9fd870d6b2c9fb89a9a14a..75b9df3174ca200c7e735d713f97b1aca45e0c9b 100644 --- a/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php +++ b/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php @@ -100,7 +100,9 @@ class ErrorProcessor $isDevMode = $this->_appState->getMode() === State::MODE_DEVELOPER; $stackTrace = $isDevMode ? $exception->getTraceAsString() : null; - if ($exception instanceof LocalizedException) { + if ($exception instanceof WebapiException) { + $maskedException = $exception; + } elseif ($exception instanceof LocalizedException) { // Map HTTP codes for LocalizedExceptions according to exception type if ($exception instanceof NoSuchEntityException) { $httpCode = WebapiException::HTTP_NOT_FOUND; @@ -120,7 +122,7 @@ class ErrorProcessor } $maskedException = new WebapiException( - $exception->getRawMessage(), + new Phrase($exception->getRawMessage()), $exception->getCode(), $httpCode, $exception->getParameters(), @@ -128,8 +130,6 @@ class ErrorProcessor $errors, $stackTrace ); - } elseif ($exception instanceof WebapiException) { - $maskedException = $exception; } else { $message = $exception->getMessage(); $code = $exception->getCode(); @@ -141,7 +141,7 @@ class ErrorProcessor $code = 0; } $maskedException = new WebapiException( - $message, + new Phrase($message), $code, WebapiException::HTTP_INTERNAL_ERROR, [], diff --git a/lib/internal/Magento/Framework/Webapi/Exception.php b/lib/internal/Magento/Framework/Webapi/Exception.php index b5b46c0e562bcf5aaebc986c7ecc7164380f93e7..208202fb0c5883504224885b010534ac1cccb3f5 100644 --- a/lib/internal/Magento/Framework/Webapi/Exception.php +++ b/lib/internal/Magento/Framework/Webapi/Exception.php @@ -8,8 +8,10 @@ namespace Magento\Framework\Webapi; use Magento\Framework\Exception\ErrorMessage; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Phrase; -class Exception extends \RuntimeException +class Exception extends LocalizedException { /**#@+ * Error HTTP response codes. @@ -74,7 +76,7 @@ class Exception extends \RuntimeException /** * Initialize exception with HTTP code. * - * @param string $message + * @param \Magento\Framework\Phrase $phrase * @param int $code Error code * @param int $httpCode * @param array $details Additional exception details @@ -85,7 +87,7 @@ class Exception extends \RuntimeException * @throws \InvalidArgumentException */ public function __construct( - $message, + Phrase $phrase, $code = 0, $httpCode = self::HTTP_BAD_REQUEST, array $details = [], @@ -97,7 +99,8 @@ class Exception extends \RuntimeException if ($httpCode < 400 || $httpCode > 599) { throw new \InvalidArgumentException(sprintf('The specified HTTP code "%d" is invalid.', $httpCode)); } - parent::__construct($message, $code); + parent::__construct($phrase); + $this->code = $code; $this->_httpCode = $httpCode; $this->_details = $details; $this->_name = $name; diff --git a/lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Json.php b/lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Json.php index 34f3936ce563c3b399eb280640bb532025ba507b..ba0091bc725a7e94f6073f2ea2fb21bbac36ca6d 100644 --- a/lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Json.php +++ b/lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Json.php @@ -52,10 +52,10 @@ class Json implements \Magento\Framework\Webapi\Rest\Request\DeserializerInterfa throw new \Magento\Framework\Webapi\Exception(new Phrase('Decoding error.')); } else { throw new \Magento\Framework\Webapi\Exception( - (string)(new Phrase( + new Phrase( 'Decoding error: %1%2%3%4', [PHP_EOL, $e->getMessage(), PHP_EOL, $e->getTraceAsString()] - )) + ) ); } } diff --git a/lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Xml.php b/lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Xml.php index 3fe5eb8c0dd143010fa561452862cdc7746889e9..35c2c95a4d52dbad707009c902f95fd158bc19dc 100644 --- a/lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Xml.php +++ b/lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Xml.php @@ -66,7 +66,7 @@ class Xml implements \Magento\Framework\Webapi\Rest\Request\DeserializerInterfac if ($this->_appState->getMode() !== State::MODE_DEVELOPER) { $exceptionMessage = new Phrase('Decoding error.'); } else { - $exceptionMessage = 'Decoding Error: ' . $this->_errorMessage; + $exceptionMessage = new Phrase('Decoding Error: %1', [$this->_errorMessage]); } throw new \Magento\Framework\Webapi\Exception($exceptionMessage); } @@ -87,7 +87,7 @@ class Xml implements \Magento\Framework\Webapi\Rest\Request\DeserializerInterfac */ public function handleErrors($errorNumber, $errorMessage, $errorFile, $errorLine) { - if (is_null($this->_errorMessage)) { + if ($this->_errorMessage === null) { $this->_errorMessage = $errorMessage; } else { $this->_errorMessage .= $errorMessage; diff --git a/lib/internal/Magento/Framework/Webapi/Rest/Request/DeserializerFactory.php b/lib/internal/Magento/Framework/Webapi/Rest/Request/DeserializerFactory.php index 2d3b3e57561cde5b57fbadd1cc2a1406ff60e74d..d901cda77240e3aba1668db5b6d15e0d57f158ca 100644 --- a/lib/internal/Magento/Framework/Webapi/Rest/Request/DeserializerFactory.php +++ b/lib/internal/Magento/Framework/Webapi/Rest/Request/DeserializerFactory.php @@ -7,6 +7,8 @@ */ namespace Magento\Framework\Webapi\Rest\Request; +use Magento\Framework\Phrase; + class DeserializerFactory { /** @@ -53,7 +55,7 @@ class DeserializerFactory if (!isset($deserializerClass) || empty($deserializerClass)) { throw new \Magento\Framework\Webapi\Exception( - 'Server cannot understand Content-Type HTTP header media type ' . $contentType + new Phrase('Server cannot understand Content-Type HTTP header media type %1', [$contentType]) ); } diff --git a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php index 75d2a77d1cbd91cb954174264f64c699099f1c2b..df6496e33e57ba62e571b2e938d05befe23d40f9 100644 --- a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php +++ b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php @@ -9,7 +9,6 @@ namespace Magento\Framework\Webapi; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\Api\AttributeValue; -use Magento\Framework\Api\Config\Reader as ServiceConfigReader; use Magento\Framework\Api\SimpleDataObjectConverter; use Magento\Framework\App\Cache\Type\Webapi as WebapiCache; use Magento\Framework\Exception\InputException; @@ -256,7 +255,7 @@ class ServiceInputProcessor try { $result = $this->typeProcessor->processSimpleAndAnyType($value, $type); } catch (SerializationException $e) { - throw new WebapiException($e->getMessage()); + throw new WebapiException(new Phrase($e->getMessage())); } } else { /** Complex type or array of complex types */ diff --git a/lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/ResponseTest.php b/lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/ResponseTest.php index 2ca021aad47386081f62c9c52fad53a3ce5f59c3..b98ebe0c941b9bc63973aabd1971f7f477281a08 100644 --- a/lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/ResponseTest.php +++ b/lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/ResponseTest.php @@ -7,6 +7,8 @@ */ namespace Magento\Framework\Webapi\Test\Unit\Rest; +use Magento\Framework\Phrase; + class ResponseTest extends \PHPUnit_Framework_TestCase { /** @var \Magento\Framework\Webapi\Rest\Response */ @@ -61,7 +63,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase { /** Init \Magento\Framework\Webapi\Exception */ $apiException = new \Magento\Framework\Webapi\Exception( - 'Exception message.', + new Phrase('Exception message.'), 0, \Magento\Framework\Webapi\Exception::HTTP_UNAUTHORIZED ); @@ -98,7 +100,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR ); /** Set exception to Rest response to get in to the _renderMessages method. */ - $this->responseRest->setException(new \Magento\Framework\Webapi\Exception('Message.')); + $this->responseRest->setException(new \Magento\Framework\Webapi\Exception(new Phrase('Message.'))); $this->responseRest->sendResponse(); } @@ -108,7 +110,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase public function testSendResponseRenderMessagesHttpNotAcceptable() { $exception = new \Magento\Framework\Webapi\Exception( - 'Message', + new Phrase('Message'), 0, \Magento\Framework\Webapi\Exception::HTTP_NOT_ACCEPTABLE ); @@ -132,7 +134,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase /** Set exception to Rest response to get in to the _renderMessages method. */ $this->responseRest->setException( new \Magento\Framework\Webapi\Exception( - 'Message.', + new Phrase('Message.'), 0, \Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST ) @@ -162,7 +164,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase ); $exceptionMessage = 'Message'; $exceptionHttpCode = \Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST; - $exception = new \Magento\Framework\Webapi\Exception($exceptionMessage, 0, $exceptionHttpCode); + $exception = new \Magento\Framework\Webapi\Exception(new Phrase($exceptionMessage), 0, $exceptionHttpCode); $this->errorProcessorMock->expects( $this->any() )->method( diff --git a/lib/internal/Magento/Framework/Xml/Parser.php b/lib/internal/Magento/Framework/Xml/Parser.php index 02c762922afb447497dc935f649a783a024150d9..08d82718d6b0c3f05f1b48775022fcf2903fb5a7 100644 --- a/lib/internal/Magento/Framework/Xml/Parser.php +++ b/lib/internal/Magento/Framework/Xml/Parser.php @@ -5,8 +5,6 @@ */ namespace Magento\Framework\Xml; -use \Magento\Framework\Exception; - class Parser { /** @@ -149,6 +147,7 @@ class Parser /** * @param string $string * @return $this + * @throws \Magento\Framework\Exception\LocalizedException */ public function loadXML($string) { @@ -158,9 +157,12 @@ class Parser try { $this->getDom()->loadXML($string); - } catch (\Magento\Framework\Exception $e) { + } catch (\Magento\Framework\Exception\LocalizedException $e) { restore_error_handler(); - throw new \Magento\Framework\Exception($e->getMessage(), $e->getCode(), $e); + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase($e->getMessage()), + $e + ); } if ($this->errorHandlerIsActive) { @@ -177,14 +179,14 @@ class Parser * @param string $errorStr * @param string $errorFile * @param int $errorLine - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ public function errorHandler($errorNo, $errorStr, $errorFile, $errorLine) { if ($errorNo != 0) { $message = "{$errorStr} in {$errorFile} on line {$errorLine}"; - throw new \Magento\Framework\Exception($message); + throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase($message)); } } } diff --git a/lib/internal/Magento/Framework/Xml/Test/Unit/ParserTest.php b/lib/internal/Magento/Framework/Xml/Test/Unit/ParserTest.php index aeddfa9afbad0344bef7c5b19b94cad095305287..ed966cb8abfa2daadf6c883db60b7935e3caf766 100644 --- a/lib/internal/Magento/Framework/Xml/Test/Unit/ParserTest.php +++ b/lib/internal/Magento/Framework/Xml/Test/Unit/ParserTest.php @@ -33,7 +33,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage DOMDocument::loadXML(): Opening and ending tag mismatch */ public function testLoadXmlInvalid() diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index da913b7a324170265ed334ae9d204376bf5878ae..e9d7aa483c4c141caed3341ce3bf3456edf2b415 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -17,7 +17,7 @@ use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\MaintenanceMode; use Magento\Framework\Filesystem; -use Magento\Framework\Filesystem\FilesystemException; +use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Math\Random; use Magento\Framework\Module\ModuleList\DeploymentConfig; use Magento\Framework\Module\ModuleList\DeploymentConfigFactory; @@ -1209,7 +1209,7 @@ class Installer $this->log->log("{$dirPath}{$path}"); try { $dir->delete($path); - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { $this->log->log($e->getMessage()); } } @@ -1232,7 +1232,7 @@ class Installer try { $this->log->log($absolutePath); $configDir->delete($file); - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { $this->log->log($e->getMessage()); } }