diff --git a/app/code/Magento/Backend/App/Action/Context.php b/app/code/Magento/Backend/App/Action/Context.php index 0630d8213d241..e6618170e4d6b 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 @@ public function __construct( \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 @@ public function __construct( $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 b8e22be3ef59b..6aed5e22c5282 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 0f632337827b1..098022bed0a8d 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 @@ 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 f200ef062d37f..f7d1548519d70 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 @@ public function __construct( \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 95c03bc8ccdc5..23d056c9a208a 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 8133c1f530bb1..95af905952ce6 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 503637b67520d..a5f0d8d38ed88 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 0125bdfd6aea8..597f6f13e0a70 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 7f9c0b2d3050d..78db76ec2d82d 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 5172f791b6d02..7f4b2d919f3c0 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 04c0cdf98cd40..c77bb09fb0054 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Denied.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Denied.php @@ -8,11 +8,6 @@ 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 4fca603999c5a..9505f4b1d6d2f 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 @@ 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 da57138a8b57b..0298a2b9d36b7 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 @@ 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 86ec95f344e19..06ade97d1e905 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 @@ public function execute() /** @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 @@ public function execute() 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 66e2b5739f615..fb5725b74bbf8 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 @@ public function __construct( \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 @@ public function __construct( $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 e9b7e2d6b7a0c..869f8af792347 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 @@ public function execute() 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 f17843629a420..a6efb535ec265 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 @@ public function __construct( \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 4450de457669c..aa771ac2ec80f 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 @@ public function execute() 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 0d325541d82df..1eca177ae08e9 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 @@ public function execute() 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 c1d1c98779e8e..09c9f363b8b54 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 @@ public function execute() 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 2b06e285b559f..7dc805fa57f2d 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 f8717a0b3e1fa..2545f7e084a6a 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 @@ public function __construct( 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 0000000000000..a848ed6ea46fa --- /dev/null +++ b/app/code/Magento/Backend/Model/View/Result/RedirectFactory.php @@ -0,0 +1,51 @@ +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 7fba92c348bdf..a61bd01156c9d 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 @@ public function testExecute() ); $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 @@ public function testExecute() ] ) ); - $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 f13a680af4a3b..e1ac51552586a 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 @@ public function setUp() $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 49a1f4a21b24e..012d90382443e 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 @@ protected function setUp() ->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 6b90cdc5f8248..2b450fd1a3bef 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 @@ public function testIsAllowedReturnsFalseIfResourceIsNotAvailable() )->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 0000000000000..ca51c9d8a2e28 --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Model/View/Result/RedirectTest.php @@ -0,0 +1,62 @@ +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 52ad8d4ac6e96..c9fe2c5758624 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 @@ public function __construct( \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 @@ public function __construct( $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 ef03c35226aef..d797caeebfb4d 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 @@ public function execute() } 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 2f783199aa4a3..0000000000000 --- a/app/code/Magento/Backup/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -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 @@ public function open($write = false) $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 @@ public function open($write = false) * 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 @@ public function eof() * * @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 bba764fa20551..4aaebd08b4add 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 @@ public function setUp() [ 'objectManager' => $this->objectManagerMock, 'request' => $this->requestMock, - 'response' => $this->responseMock + 'response' => $this->responseMock, + 'resultRedirectFactory' => $this->resultRedirectFactoryMock ] ); $this->downloadController = $this->objectManager->getObject( @@ -136,7 +137,6 @@ public function setUp() '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 d195bd29bf24f..2e82417babb2a --- a/app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php +++ b/app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php @@ -7,6 +7,11 @@ 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 @@ public function testIsCorrect() { 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 @@ protected function _getSessionStub() ); $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 048739d49b1dd..718bf23d4965f 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category.php @@ -10,23 +10,6 @@ */ 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 06bb17ec517b6..5cd9fffd001c4 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 5fec84fb27a85..6f9cf5cc6e551 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 e0a7db83c41fc..cc0e60a82a391 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 0d0b763cfec6b..8834b03f6a895 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 aa775168229db..fdecd7c392290 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 3c395c8ff2514..1b0bbf347f509 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 c35247eaacf79..fb0d48aacc43c 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 @@ public function execute() } 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 8b19840c3c083..150b019466489 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 01f622f6996f3..9949ffe5699e9 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 14d7bf780c053..94c8010cc3980 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 6604d3fc116a0..9acd075bc8276 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 4e114334b66f7..0b6377c4b4702 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 ef791cd838cda..3661567d5fa00 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 @@ public function __construct( \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 @@ public function __construct( $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 bcc311e379449..3fbda63630e30 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 @@ 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 7eee03d9f842e..f149ff2506a6c 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 c78d3aea2e0e6..4faadeba7d39f 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 @@ public function __construct( \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 @@ public function __construct( $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 4e5ba91e59392..d335b898f71ce 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 34d74da1fa0c0..30e1299ca1749 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 bab900046dc23..19a6a11743b62 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 @@ 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 26665c88a5f2f..749b55d0ee127 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 @@ public function _validateMassStatus(array $productIds, $status) * 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 @@ public function execute() $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 9a28b53da5648..1ef2d92da33a5 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 506552221c95b..110cb1a5f752d 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 @@ 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 1d124a7cd04c0..d40982a5d5641 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 fc228f2cf35d1..09e77fbdec769 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 50c79ade7e64e..2941bf03189cd 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 @@ public function __construct( \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 @@ public function __construct( $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 f90d14005efc6..5ea3a57caf483 100644 --- a/app/code/Magento/Catalog/Controller/Index/Index.php +++ b/app/code/Magento/Catalog/Controller/Index/Index.php @@ -1,35 +1,12 @@ 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 441646f6e71e1..89952430169bf 100644 --- a/app/code/Magento/Catalog/Controller/Product/Compare.php +++ b/app/code/Magento/Catalog/Controller/Product/Compare.php @@ -7,7 +7,6 @@ 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 @@ public function __construct( \Magento\Catalog\Model\Session $catalogSession, \Magento\Store\Model\StoreManagerInterface $storeManager, Validator $formKeyValidator, - Result\RedirectFactory $resultRedirectFactory, PageFactory $resultPageFactory, ProductRepositoryInterface $productRepository ) { @@ -131,7 +123,6 @@ public function __construct( $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 0a27a74c35267..8c25b8c0e5d59 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 @@ public function execute() $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 93b985ec094a5..954437bf09576 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 @@ 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 @@ public function __construct( \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 @@ public function __construct( $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 f5dcaa74f8a73..b4e9c7480ba1d 100644 --- a/app/code/Magento/Catalog/Controller/Product/Gallery.php +++ b/app/code/Magento/Catalog/Controller/Product/Gallery.php @@ -12,11 +12,6 @@ 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 c9a9957da33c1..9cdee4fc826f8 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 e6beec63ca739..0000000000000 --- a/app/code/Magento/Catalog/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -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 8c74ca3126cb3..09733d3b8a0cb --- 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 2aad332960bc6..cd367f0682f6e --- 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 e05aa311a0f13..9414f898aeda4 --- 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 9860c748d27cd..7a7f81a109178 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 2f408c71ea765..6e43b0666791c --- 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 @@ public function getTypeIndexers() * * @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 835c7f3e15463..61700737da9d2 --- 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 @@ public function execute($ids = null) } $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 a5a629823c589..8ba3086616817 --- 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 962435d557d83..9a7daacc654d2 --- 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 a066164bd7aeb..9e54f0e78ddab 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 @@ public function copy(\Magento\Catalog\Model\Product $product) 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 b68f8f1bec8e7..f1f80f7701c0c 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 a8f61ba1e3633..beb1b3d2f8da1 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 2a59073ff7f5f..94612dbf200a5 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 @@ public function processFileQueue() 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 b0185bcf13971..7c488ecf2ec36 --- 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 @@ public function setTypeId($typeCode) * 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 d28536b4ebb77..517b00635c2a5 --- 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 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan * @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 f360e3a6c3ffd..bec5548f8bbc3 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 @@ protected function setUp() $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 @@ protected function setUp() '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 9b5bb8d759b6b..e903fbbfacebc 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 @@ protected function setUp() 'getObjectManager', 'getEventManager', 'getResponse', - 'getMessageManager' + 'getMessageManager', + 'getResultRedirectFactory' ], [], '', @@ -165,30 +166,20 @@ protected function setUp() ['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 dbe1bd83b11df..b83afa0e6361f 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 @@ protected function setUp() ->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 @@ protected function setUp() 'attributeHelper' => $this->attributeHelper, 'stockIndexerProcessor' => $this->stockIndexerProcessor, 'dataObjectHelper' => $this->dataObjectHelperMock, - 'resultRedirectFactory' => $resultRedirectFactory ] ); } @@ -189,33 +193,32 @@ protected function prepareContext() '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 0627241e28305..438cec2b2d7cb 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 @@ protected function setUp() ->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 77f31ab47a4f6..17a99b3ab8f52 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 @@ protected function setUp() 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 9c6a309197f2e..9c58d09dfe443 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 @@ protected function setUp() ->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 3e04c8a0c27f3..84ba97726acdf 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 @@ protected function initContext() 'getActionFlag', 'getHelper', 'getTitle', - 'getView' + 'getView', + 'getResultRedirectFactory' ], [], '', @@ -89,6 +93,10 @@ protected function initContext() $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 1ee181ccdaec8..81633cf019cbd 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 @@ protected function setUp() $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 @@ protected function setUp() $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 15ff5136c76ca..fc1a0758eecb9 --- 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 @@ public function testExecuteWithAdapterErrorThrowsException() $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 80a1f2ea8c5e1..b40ffc2e186c9 --- 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 @@ public function setUp() } /** - * @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 994e561ade36f..95577b9fcf189 --- 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 @@ public function setUp() } /** - * @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 0910824ecfe79..27369edc62456 --- 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 @@ public function setUp() } /** - * @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 5ab73e71e4593..36814e3bf8df9 --- 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 @@ public function setUp() } /** - * @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 8a7930bb0f6d7..bf60494dae250 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 @@ public function testSaveException() $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 61edb1d7f44a0..0000000000000 --- a/app/code/Magento/CatalogInventory/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -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 2ddf25ac201eb..0103d0849f897 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 5e6a31a6b70d7..ed9b5827e8c3d 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 664492933324e..a096f71925e83 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 @@ public function testExecuteWithAdapterErrorThrowsException() $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 a6071c6213c71..9a2bb4ec376b3 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 @@ public function setUp() } /** - * @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 70d917aa59e80..460f300c153a7 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 @@ public function setUp() } /** - * @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 0b93d3c00f4e4..0000000000000 --- a/app/code/Magento/CatalogRule/CatalogRuleException.php +++ /dev/null @@ -1,10 +0,0 @@ -_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 a4d8b53934937..13dc23422a50c 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 @@ public function getIdentities() * 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 protected function doExecuteList($ids); * 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 @@ public function executeRow($id) * 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 2394d6afaae2b..a2cfaba45a1e0 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 @@ public function reindexById($id) * 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 @@ public function reindexByIds(array $ids) $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 @@ protected function doReindexByIds($ids) /** * Full reindex * - * @throws CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * @return void */ public function reindexFull() @@ -168,7 +167,7 @@ public function reindexFull() $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 b9a21020e4120..dfec1c047ab09 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 @@ public function testExecuteFull() } /** - * @expectedException \Magento\CatalogRule\CatalogRuleException + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Could not rebuild index for empty products array * * @return void @@ -85,7 +85,7 @@ public function testExecuteListWithEmptyIds() } /** - * @throws \Magento\CatalogRule\CatalogRuleException + * @throws \Magento\Framework\Exception\LocalizedException * * @return void */ @@ -98,7 +98,7 @@ public function testExecuteList() } /** - * @expectedException \Magento\CatalogRule\CatalogRuleException + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Could not rebuild index for undefined product * * @return void @@ -109,7 +109,7 @@ public function testExecuteRowWithEmptyId() } /** - * @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 daa22d34d16b5..0306ebf24acd7 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 2b056aeac07fa..9aa93f99d0352 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 @@ public function __construct( \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 69aa88b0b3dc8..c26c171daea13 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 @@ public function __construct( \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 @@ public function __construct( $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 eebb127c786c5..cedc400e20b9f 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 @@ public function __construct( \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 @@ public function __construct( $checkoutSession, $storeManager, $formKeyValidator, - $cart, - $resultRedirectFactory + $cart ); $this->resultPageFactory = $resultPageFactory; } @@ -51,6 +48,7 @@ public function __construct( * 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 @@ public function execute() $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 26225b39fa6f9..2b93e3d1cb184 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 @@ public function __construct( \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 @@ public function __construct( $checkoutSession, $storeManager, $formKeyValidator, - $cart, - $resultRedirectFactory + $cart ); $this->quoteRepository = $quoteRepository; } @@ -50,6 +47,7 @@ public function __construct( * Initialize coupon * * @return \Magento\Framework\Controller\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ @@ -71,41 +69,44 @@ public function execute() 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 88a1d46d971e6..ce6bbc95511f5 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 @@ public function __construct( \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 @@ public function __construct( $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 8a29029fd1836..de1a954f86ae2 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 @@ public function __construct( \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 @@ public function __construct( $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 7e34b412e3383..de5f3dea47424 100644 --- a/app/code/Magento/Checkout/Controller/Index/Index.php +++ b/app/code/Magento/Checkout/Controller/Index/Index.php @@ -8,23 +8,6 @@ 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 3a47eca2e4f86..2257347e9150b 100644 --- a/app/code/Magento/Checkout/Controller/Onepage.php +++ b/app/code/Magento/Checkout/Controller/Onepage.php @@ -7,7 +7,7 @@ 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 @@ public function __construct( \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 @@ public function __construct( $context, $customerSession, $customerRepository, - $accountManagement, - $resultRedirectFactory + $accountManagement ); } @@ -141,7 +138,7 @@ public function __construct( * * @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 @@ public function dispatch(RequestInterface $request) } 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 18a3f1524908e..19e17acf91ee5 100644 --- a/app/code/Magento/Checkout/Controller/Onepage/SavePayment.php +++ b/app/code/Magento/Checkout/Controller/Onepage/SavePayment.php @@ -45,11 +45,6 @@ public function execute() 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 2ee13bca5009c..f0e271627daea --- 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 67669a198a926..e5142f4ef2e3c 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 @@ public function setUp() ->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 fba6b572166c1..9be4d20c91f2f 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 @@ public function execute() 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 6788811a85054..9b28ef8015ea1 100644 --- a/app/code/Magento/Cms/Block/Page.php +++ b/app/code/Magento/Cms/Block/Page.php @@ -118,7 +118,7 @@ protected function _prepareLayout() * 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 c3a871112593f..defddb1877922 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 df5ed33ff756e..c5bf68c00e127 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 @@ 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 d042bb4fc351e..bc8f586567c58 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 @@ 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 7fa41aace2be1..1fe7e266c91be 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 @@ 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 306668ffe6ac4..278515e3f1017 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 36e68c281a54a..c53641376c471 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 fc89acb6d7d72..46b0998de61fd 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 72fab43cf7fb4..9728519a5e210 100644 --- a/app/code/Magento/Cms/Helper/Wysiwyg/Images.php +++ b/app/code/Magento/Cms/Helper/Wysiwyg/Images.php @@ -206,7 +206,7 @@ public function getCurrentPath() 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 683506fc7b36f..2adc979aacac0 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 @@ public function createDirectory($name, $path) '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 @@ public function deleteDirectory($path) $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 71d3b9146c48f..9f8bf3a73f177 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 @@ 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 @@ public function __construct( \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 8cc81e08d4009..f5969841a7db1 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 @@ public function __construct( \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 f143741ec2c78..bbce2b525d4e6 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 @@ public function isSectionAllowed($sectionId) } 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 060672c505204..23d788e710f5b 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 @@ protected function setUp() $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 @@ protected function setUp() 'eventManager' => $this->_eventManagerMock, 'auth' => $this->_authMock, 'messageManager' => $this->messageManagerMock, + 'resultRedirectFactory' => $resultRedirectFactory ]; $this->_sectionCheckerMock = $this->getMock( @@ -146,21 +162,6 @@ protected function setUp() 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 @@ protected function setUp() $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 d144b198916e8..df15306308938 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 @@ public function __construct( * * @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 4cd4d71f5b746..9db82a0300c8d 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 @@ public function setUp() } /** - * @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 d860910e844bd..a99c5d696096d 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 e89ab91b3aab4..01940a5bee4c2 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 @@ public function execute() } } - 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 15b3136eb5427..286f3f4cd6c55 100644 --- a/app/code/Magento/Customer/Controller/Account.php +++ b/app/code/Magento/Customer/Controller/Account.php @@ -8,7 +8,6 @@ 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 a42a81c43f858..04e84dd7ceebc 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\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 @@ public function __construct( $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 @@ public function execute() $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 ba7ee81e3eaf8..0eea2052db37f 100644 --- a/app/code/Magento/Customer/Controller/Account/Confirmation.php +++ b/app/code/Magento/Customer/Controller/Account/Confirmation.php @@ -8,7 +8,6 @@ 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 215f1a0198d18..887ec8d996a35 100644 --- a/app/code/Magento/Customer/Controller/Account/Create.php +++ b/app/code/Magento/Customer/Controller/Account/Create.php @@ -8,7 +8,6 @@ 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 69f5eb09d5100..22ef71e47e3cf 100644 --- a/app/code/Magento/Customer/Controller/Account/CreatePassword.php +++ b/app/code/Magento/Customer/Controller/Account/CreatePassword.php @@ -8,7 +8,6 @@ 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 420139f171cfa..c132eb904d144 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\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 @@ public function __construct( 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 b4de05f17140b..df4dde04fc35c 100644 --- a/app/code/Magento/Customer/Controller/Account/Edit.php +++ b/app/code/Magento/Customer/Controller/Account/Edit.php @@ -9,7 +9,6 @@ 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 a3df334fbf835..c61860f64004d 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\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 @@ public function __construct( $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 3b82507dc7f45..fc391f4143525 100644 --- a/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php +++ b/app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php @@ -9,7 +9,6 @@ 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 1f05dff29314e..500a2f7b68302 100644 --- a/app/code/Magento/Customer/Controller/Account/LoginPost.php +++ b/app/code/Magento/Customer/Controller/Account/LoginPost.php @@ -8,7 +8,6 @@ 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 @@ public function __construct( 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 32735a80177b4..d8486b21549a9 100644 --- a/app/code/Magento/Customer/Controller/Account/ResetPassword.php +++ b/app/code/Magento/Customer/Controller/Account/ResetPassword.php @@ -8,7 +8,6 @@ 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 b8055dc7354e7..2d53034cb6897 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\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 60b2c38fd2676..27f6b54271ee3 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 @@ public function __construct( \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 @@ public function __construct( $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 cfb5fc0580777..bf2975bb3b054 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 @@ public function __construct( \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 @@ public function __construct( $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 099e121b9de5d..a77e904edbea3 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 @@ 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 47e6c1c04309b..cfbca15cae361 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 @@ public function __construct( \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 @@ public function __construct( $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 94581d7783830..614abdb1c686c 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 @@ public function __construct( \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 @@ public function __construct( $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 eec31225f83ea..2d84f59c80f84 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 @@ public function __construct( \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 @@ public function __construct( $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 d6d46cb468d66..9ca36cab18553 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 86f937f8981a7..aeb28057de13b 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\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 @@ public function __construct( \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 @@ public function __construct( $layoutFactory, $resultLayoutFactory, $resultPageFactory, - $resultRedirectFactory, $resultForwardFactory, $resultJsonFactory ); @@ -148,7 +145,7 @@ public function execute() ); $plain = true; } else { - throw new NotFoundException(); + throw new NotFoundException(__('Page not found.')); } /** @var \Magento\Framework\Filesystem $filesystem */ @@ -159,7 +156,7 @@ public function execute() 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 4a9028ee2968d..c1e7e8307c834 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 @@ 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 4d0ca1e9efbed..d4b541e090af2 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\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 0e6792f095f42..fb05d732285d7 100644 --- a/app/code/Magento/Customer/Model/GroupManagement.php +++ b/app/code/Magento/Customer/Model/GroupManagement.php @@ -120,7 +120,7 @@ public function getDefaultGroup($storeId = null) \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 c356f2f352c29..f5404347c8c84 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 @@ public function testSetLayoutWithOwnAddressAndPostedData() } /** - * @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 a4fe483205641..bbcbfe8192d33 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 @@ protected function setUp() $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 @@ protected function setUp() 'customerRepository' => $this->customerRepositoryMock, 'addressHelper' => $this->addressHelperMock, 'urlFactory' => $urlFactoryMock, - 'resultRedirectFactory' => $redirectFactoryMock, ] ); } @@ -190,7 +192,30 @@ public function testIsLoggedIn() $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 @@ public function testNoCustomerIdInRequest($customerId, $key) ->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 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad 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 @@ public function testSuccessRedirect( ->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 @@ public function getSuccessRedirectDataProvider() null, 'http://example.com/back', true, - __('Thank you for registering with'), + 'Thank you for registering with', ], [ 1, @@ -426,7 +430,7 @@ public function getSuccessRedirectDataProvider() 'http://example.com/success', 'http://example.com/success', true, - __('Thank you for registering with'), + 'Thank you for registering with', ], [ 1, @@ -435,7 +439,7 @@ public function getSuccessRedirectDataProvider() '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 46bd9cbf68c9c..41115e5ac8649 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 @@ protected function setUp() $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 @@ protected function setUp() '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 86113cef969df..eabe54ae5d46d 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 @@ public function setUp() $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 53ffa02b353e2..336877afcab7e 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 @@ protected function setUp() '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 @@ protected function setUp() '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 0d38fb9a0ee18..3021161364bf1 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 @@ public function setUp() } /** - * @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 5d9f67f24e56e..1094b73194e5b 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 @@ public function testGetSearchCriteriaAnd() * @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 3a7213c67e7ad..918f008e68065 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 @@ protected function _prepareForm() \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 70fd186f3cc70..d2b47b2815926 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 @@ public function execute() 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 78dc2dfe98ce0..363d73270fa89 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 @@ protected function _extractParams(\DOMElement $control, $useKeyIdentifier = true * * @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 8819a67da581f..9799b2c78974e 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 @@ public function __construct( * @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 @@ protected function _getFilePathByType($type, $theme) * @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 @@ public function create( $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 f92754bacf369..efbea06e71044 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 @@ public function create(array $data = []) $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 59e3441a782e3..eaf588a27cc67 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 @@ protected function renderAssetHtml($template, $assets) $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 6c2dcc71ed12a..cc3d3950d01b2 100644 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -733,7 +733,7 @@ public function walkAttributes($partMethod, array $args = [], $collectExceptionM /** @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 b74c562458caa..423c51fb6554b 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 @@ * * @author Magento Core Team */ -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 94cf7b362fa72..4eba984b8fcfa 100644 --- a/app/code/Magento/Email/Model/AbstractTemplate.php +++ b/app/code/Magento/Email/Model/AbstractTemplate.php @@ -143,12 +143,12 @@ public function getDesignConfig() * * @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 8287fa82aca1e..577393b498924 100644 --- a/app/code/Magento/Email/Model/Template.php +++ b/app/code/Magento/Email/Model/Template.php @@ -410,7 +410,7 @@ public function getType() * * @param array $variables * @return string - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function getProcessedTemplate(array $variables = []) { @@ -440,7 +440,7 @@ public function getProcessedTemplate(array $variables = []) $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 @@ public function getSendingException() * * @param array $variables * @return string - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function getProcessedTemplateSubject(array $variables) { @@ -511,7 +511,7 @@ public function getProcessedTemplateSubject(array $variables) $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 @@ public function getVariablesOptionArray($withGroup = false) /** * 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 @@ public function beforeSave() * Get processed template * * @return string - * @throws \Magento\Framework\Mail\Exception + * @throws \Magento\Framework\Exception\MailException */ public function processTemplate() { @@ -627,7 +627,9 @@ public function processTemplate() } 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 3c152b34f5a33..c95b3f4e21572 100644 --- a/app/code/Magento/Email/Model/Template/Filter.php +++ b/app/code/Magento/Email/Model/Template/Filter.php @@ -526,7 +526,7 @@ public function modifierEscape($value, $type = 'html') * 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 @@ public function protocolDirective($construction) 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 f1e1a4b659883..761aaffd756df 100644 --- a/app/code/Magento/Email/Model/Template/SenderResolver.php +++ b/app/code/Magento/Email/Model/Template/SenderResolver.php @@ -45,7 +45,7 @@ public function resolve($sender, $scopeId = null) } 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 42ecbba29562e..29f65b1f795ad 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 @@ public function toHtmlDataProvider() /** * 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 bfdd32f7e5542..d0bd4041ac324 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 @@ protected function setUp() /** * @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 a2abe73a45fca..b9098d3c1e480 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 40f937d29059c..6cb5d6885d135 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 43f836ddb771c..f8e4e7a1a7cd3 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 @@ public function execute() $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 c09a012798e1d..b3aaeec836d2a 100644 --- a/app/code/Magento/ImportExport/Model/Import.php +++ b/app/code/Magento/ImportExport/Model/Import.php @@ -494,7 +494,7 @@ public function uploadSource() $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 8941368a8f061..386f4aea620f1 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 @@ public function __construct( ) { 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 2cea74eb72dd2..25e6e1a441c08 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 @@ protected function setUp() */ 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 141784d46b976..89a575dac8080 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 aebe506f736a3..f2b69c6a65751 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 @@ 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 @@ public function testDeleteActionMissingId() // 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 0e3fdb67644dd..d3fd636940bac 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 @@ protected function _createIntegrationController($actionName) ->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 @@ protected function _createIntegrationController($actionName) '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 527a932ee63ea..3d2b755575ad0 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 @@ public function execute() $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 e56b7af11f1b5..404434584903b 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 @@ 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 @@ public function save() $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 decccfd2ba0d5..88a72ad5c6e6b 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 @@ 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 @@ public function synchronize($relativeFileName, $filePath) $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 511ae4dad60e4..2682dd691a46d 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 @@ public function saveFile($filePath, $content, $overwrite = false) $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 5482e8239be1f..ded1bf1b30821 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 5dd2f85ddefe6..a782a26e6bfa1 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 @@ public function __construct( \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 @@ public function __construct( $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 33becad798415..4c34f3419f10a 100644 --- a/app/code/Magento/Newsletter/Model/Queue.php +++ b/app/code/Magento/Newsletter/Model/Queue.php @@ -239,7 +239,7 @@ public function sendPerSubscriber($count = 20) 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 a1cb1547bda89..f288561028194 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -8,7 +8,7 @@ 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 5ca752b37e3e7..0000000000000 --- a/app/code/Magento/Payment/Exception.php +++ /dev/null @@ -1,37 +0,0 @@ - - */ -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 cbaca7b85a3d7..72deb26aefc07 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 @@ public function testGetCcExpDate($ccExpMonth, $ccExpYear) 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 aacabec010c73..e2b9bf759f64b 100644 --- a/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php +++ b/app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php @@ -9,21 +9,29 @@ 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 3d9b989cdbb8c..c8dec914e9540 100644 --- a/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php +++ b/app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php @@ -9,21 +9,29 @@ 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/Reports/Controller/Adminhtml/Report/Statistics.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics.php index f0c6995732236..7de4649499c06 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 17966d0a21e7e..0000000000000 --- a/app/code/Magento/Reports/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -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 0edc1cc9c4c26..90818ea3d9d8c 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 ee2379d4e143c..61da0e27c2e12 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 e6bba8d7424c4..e3679a100212d 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 @@ public function execute() } 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 4df5440a1700a..63575ad8e44ec 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 @@ public function execute() $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 43e1ab5177159..f093608f46f42 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 @@ protected function _joinTablesToCollection( * @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 @@ protected function _getMappedSqlCondition(AbstractCondition $condition, $value = $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 0fe2f97dcd9b2..567433355f3ed 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php +++ b/app/code/Magento/Sales/Controller/AbstractController/OrderLoader.php @@ -9,7 +9,6 @@ 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 c2ac3856a201e..4c97760450e22 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php @@ -8,7 +8,6 @@ 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 6757cdde059b1..15cc2a5c2c48e 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php @@ -8,7 +8,6 @@ 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 c912a736bf9fc..74fbb3439445d 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -8,7 +8,6 @@ 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 096e26f65c839..7010d3bd5c041 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 b1ef2eacce2f8..34dc5bbb8af0e 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 @@ */ 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 685b3042c42c0..8304f41f1d06c 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 @@ 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 fa94f814062c0..99e666227efba 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 1f8389a86a55c..fae61c7df106b 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 ee6934955fc08..4685341ddef97 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 @@ public function __construct( \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 @@ public function __construct( $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 0e56021124b3e..42515bde1f868 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 @@ public function __construct( \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 @@ public function __construct( $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 3e067f1e396ad..54fcd049b388a 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 @@ 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 @@ public function __construct( \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 56ecebf6e898a..ba4b0e833e289 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 @@ 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 @@ public function __construct( \Magento\Catalog\Helper\Product $productHelper, \Magento\Framework\Escaper $escaper, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, ForwardFactory $resultForwardFactory, RawFactory $resultRawFactory ) { @@ -42,7 +39,6 @@ public function __construct( $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 e06ee1a7c43c7..a3546de1fa6a7 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 @@ 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 @@ public function __construct( \Magento\Catalog\Helper\Product $productHelper, \Magento\Framework\Escaper $escaper, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, ForwardFactory $resultForwardFactory, RawFactory $resultRawFactory ) { @@ -42,7 +39,6 @@ public function __construct( $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 a880a57bf0086..10714ace65789 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 ced8a580b0c6a..6ba3acd497b1f 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 83876b4e643c8..4305bef4930e7 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 @@ 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 d6c103b9bd56a..23bd5f1ccdb82 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 e8e15e6635671..a717843c7e99c 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 @@ public function execute() $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 cd3ffd55ff77d..20ff3bfeaa9ab 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 @@ public function execute() $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 4b8c4751951aa..f7db6d19da3c1 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 @@ 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 @@ public function execute() /** @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 @@ public function execute() ->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 @@ public function execute() $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 946d159b06c7b..1fffaf8a03ee1 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\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 @@ public function execute() /** @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 @@ public function execute() } 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 de0b55ad653d2..8db329dad0876 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 a2c5ba9685349..38d563101cb4f 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 @@ public function execute() /** @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 @@ public function execute() ->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 1c58ed16eca56..9f346af8a27c0 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 @@ public function execute() $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 0d0992344c9dd..43cc5fd46cde3 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 aa3f04ef236be..26ee0651e3657 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 @@ 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 67ee80fa876a6..65535942a16d6 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 12b08328450a6..6debca9cf3142 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 c4535d45719a9..2242f7a6360b9 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 @@ public function execute() 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 4378121ad0aa2..07a5b3d42dafb 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\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 9c4d5ea276877..49b910be6a862 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\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 1efcab46f5fb7..946b8e36fd6c4 --- 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 @@ public function execute() 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 e2f90c18f31e7..c9f87d44e7995 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 5283ea8858e0d..82a1a215399d6 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 @@ public function __construct( OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; @@ -38,8 +35,7 @@ public function __construct( $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 3999a1bf078bb..27796157f51c3 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 @@ public function __construct( OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; @@ -38,8 +35,7 @@ public function __construct( $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 e3ae69ef3d992..8dcbfe4ef735c 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 @@ public function __construct( OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory, - RedirectFactory $resultRedirectFactory, OrderLoader $orderLoader ) { $this->orderLoader = $orderLoader; @@ -38,8 +35,7 @@ public function __construct( $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 202ceb99a222b..4739751df7ff5 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 8c69378b3ac6d..0000000000000 --- a/app/code/Magento/Sales/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -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 eed89a8a8548e..27e957ea5579b 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/EmailSender.php +++ b/app/code/Magento/Sales/Model/AdminOrder/EmailSender.php @@ -53,7 +53,7 @@ public function send(Order $order) { 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 5de7ddeb02231..bd9b80e880eb1 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 @@ public function setUp() 'getObjectManager', 'getSession', 'getActionFlag', - 'getHelper' + 'getHelper', + 'getResultRedirectFactory' ], [], '', @@ -120,34 +121,22 @@ public function setUp() $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 73d8438c5fa5f..8493e58d858c6 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 @@ public function setUp() $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 @@ public function setUp() $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 @@ public function setUp() '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 bc849016a87c4..5029fdac67c3d 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 @@ public function setUp() $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 @@ public function setUp() ->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 @@ public function setUp() [ '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 4d2620fdacfce..f834d01d208d5 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 @@ protected function setUp() '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 @@ protected function setUp() [ '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 fe28217d346f7..6d2d02861be07 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 @@ public function setUp() $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 @@ public function setUp() [ '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 f8c328439d46c..6eedbf0af8636 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 @@ public function setUp() 'getObjectManager', 'getSession', 'getActionFlag', - 'getHelper' + 'getHelper', + 'getResultRedirectFactory' ], [], '', @@ -120,35 +121,22 @@ public function setUp() $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 3575638720b4a..682550783e261 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 @@ public function setUp() ->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 0e57e1af6c519..3c067f3f8603e 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 @@ public function setUp() ->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 c28b721ed21b3..5e60a34a35541 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 @@ public function setUp() $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 @@ public function setUp() ->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 @@ public function setUp() ->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 1c5cf1cefa022..90b9a5abf31f3 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 @@ public function testExecute() */ 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 @@ public function testExecuteModelException() */ 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 21d1f3f644b4a..4f9b93ea6e279 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 @@ public function setUp() ->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 eadbaa5250cdd..b10539c45a0db 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 @@ public function setUp() '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 @@ public function testExecuteNoOrder() ); } - /** - * @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 6910282d040a9..356317fa00d38 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 @@ public function testSendFailure() { $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 41f77cdf509d1..ebffcd4ad781c 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 @@ 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 @@ public function testNotifyFail() */ 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 1920800487b6a..214eb992d1723 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 @@ 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 @@ public function testNotifyFail() */ 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 907a4ee588ba0..53cd9bf2d2e15 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 @@ 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 @@ public function testNotifyFail() */ 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/SalesRule/Exception.php b/app/code/Magento/SalesRule/Exception.php deleted file mode 100644 index 1332875e9513a..0000000000000 --- a/app/code/Magento/SalesRule/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -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 6d473c2261d4e..535c0322f57a8 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 @@ 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 a44592a571183..cf503b4e61255 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 @@ 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 d72c283669650..27fea3b5cd06d 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 @@ protected function setUp() ->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 @@ protected function setUp() $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 1bb9f0ca10658..9a9677d2e54c3 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 @@ public function __construct( * * @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 @@ public function dispatch(RequestInterface $request) $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 850a8ac25c7e2..5f30722a08c90 --- 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 @@ protected function _isAllowed() /** * 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 d9ecbcd583b3e..9ae7590bdb444 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 @@ public function execute() $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 12fef333cd12a..b140b961cf6d2 --- 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 9f73339f8cdab..48ff3dd325790 --- 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 @@ * 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 @@ public function setUp() 'getObjectManager', 'getSession', 'getActionFlag', - 'getHelper' + 'getHelper', + 'getResultRedirectFactory' ], [], '', @@ -129,27 +141,27 @@ public function setUp() $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 @@ protected function prepareRedirect($path, $arguments, $index) $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 5d886942df8b3..254b84c536927 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 @@ 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 @@ public function testNotifyFail() */ 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 048f66b3a1451..6467df3faf391 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 @@ public function __construct( * * @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 @@ public function aroundDispatch( \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 2acf0aedb21cb..6e9131fef50f0 100644 --- a/app/code/Magento/Store/Model/Resolver/Store.php +++ b/app/code/Magento/Store/Model/Resolver/Store.php @@ -22,13 +22,13 @@ public function __construct(\Magento\Store\Model\StoreManagerInterface $storeMan /** * {@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 cdfb825fc025c..ef3c2eba7bef5 100644 --- a/app/code/Magento/Store/Model/Resolver/Website.php +++ b/app/code/Magento/Store/Model/Resolver/Website.php @@ -23,13 +23,13 @@ public function __construct( /** * {@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 77a22f6ca86b6..a6dd46ba85905 100644 --- a/app/code/Magento/Store/Model/Storage/Db.php +++ b/app/code/Magento/Store/Model/Storage/Db.php @@ -288,7 +288,7 @@ public function isSingleStoreMode() * * @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 @@ public function getStore($storeId = null) } 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 @@ public function getStores($withDefault = false, $codeKey = false) * * @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 @@ public function getWebsite($websiteId = null) // 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 @@ public function getWebsites($withDefault = false, $codeKey = false) * * @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 @@ public function getGroup($groupId = null) 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 764ddc2584e20..bce9da866b684 100644 --- a/app/code/Magento/Store/Model/StorageFactory.php +++ b/app/code/Magento/Store/Model/StorageFactory.php @@ -134,7 +134,7 @@ public function get(array $arguments = []) * @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 @@ protected function _reinitStores(\Magento\Store\Model\StoreManagerInterface $sto $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 00782573b1ff0..61e6ebb28258f 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 @@ protected function setUp() } /** - * @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 c36b779f01487..6513f7cf34f37 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 @@ public function testGetScope() } /** - * @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 8156dceae7273..51edf26170480 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 @@ public function testGetScope() } /** - * @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 8161bfad4663a..675b7520f374a 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 @@ public function testGetWebsite() } /** - * @expectedException \Magento\Framework\App\InitException + * @expectedException \Magento\Framework\Exception\State\InitException */ public function testGetWebsiteInvalidId() { @@ -176,7 +176,7 @@ public function testGetGroup() } /** - * @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 31e5f8033705f..7b22f6d43b1ac 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 @@ public function getWithStoresReinitDataProvider() } /** - * @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 7adb8bd4c18ac..bcf14907b4eff --- 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 @@ public function execute() __('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 2e79ae0fb0da1..4fff21c62f635 --- 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 @@ public function execute() $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 3d21b9ccc06c6..320e6c6b30cd4 --- 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 7bc986ee5262b..e7cc749717163 100644 --- a/app/code/Magento/Theme/Helper/Storage.php +++ b/app/code/Magento/Theme/Helper/Storage.php @@ -179,7 +179,7 @@ protected function _getTheme() * Get storage type * * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getStorageType() { @@ -189,7 +189,7 @@ public function getStorageType() ]; $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 @@ public function getRequestParams() * Get allowed extensions by type * * @return string[] - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getAllowedExtensionsByType() { @@ -294,7 +294,7 @@ public function getAllowedExtensionsByType() $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 @@ public function getAllowedExtensionsByType() * Get storage type name for display. * * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getStorageTypeName() { @@ -315,7 +315,7 @@ public function getStorageTypeName() $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 0418a9172a7db..2b04f02a1ec18 100644 --- a/app/code/Magento/Theme/Model/Theme/Collection.php +++ b/app/code/Magento/Theme/Model/Theme/Collection.php @@ -94,13 +94,15 @@ public function clearTargetPatterns() /** * 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 0f6d4a0dfbb4f..0ad82f4a51c2d 100644 --- a/app/code/Magento/Theme/Model/Theme/File.php +++ b/app/code/Magento/Theme/Model/Theme/File.php @@ -122,13 +122,13 @@ public function setTheme(\Magento\Framework\View\Design\ThemeInterface $theme) /** * {@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 d77a56dc136a8..5eea783ab9a7d 100644 --- a/app/code/Magento/Theme/Model/Wysiwyg/Storage.php +++ b/app/code/Magento/Theme/Model/Wysiwyg/Storage.php @@ -159,7 +159,7 @@ public function _createThumbnail($source) $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 a9a83fcf8d6b3..d3f7d156ca831 100644 --- a/app/code/Magento/Translation/Model/Js/DataProvider.php +++ b/app/code/Magento/Translation/Model/Js/DataProvider.php @@ -65,7 +65,7 @@ public function __construct(State $appState, Config $config, Filesystem $filesys * @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 75787c73f571d..72896f855e57b 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 @@ protected function getTargetPath($product = null, $category = null) * Get catalog entity associated stores * * @return array - * @throws \Magento\UrlRewrite\Model\EntityNotAssociatedWithWebsiteException + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getEntityStores() { @@ -183,7 +183,7 @@ protected function _getEntityStores() $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 @@ protected function _getEntityStores() '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 865e5ccac1167..e3e28f33127c8 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 @@ protected function _formPostInit($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 @@ protected function _getEntityStores() $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 447c2f12c49b8..b4155ad94ae8d 100644 --- a/app/code/Magento/UrlRewrite/Block/Edit/Form.php +++ b/app/code/Magento/UrlRewrite/Block/Edit/Form.php @@ -247,7 +247,7 @@ protected function _prepareStoreElement($fieldset) ); 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 f43f2cb29498a..0000000000000 --- a/app/code/Magento/UrlRewrite/Model/EntityNotAssociatedWithWebsiteException.php +++ /dev/null @@ -1,10 +0,0 @@ -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 @@ public function replace(array $urls) * * @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 519ac3fc6cfc0..06c0643c6f7bf 100644 --- a/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php +++ b/app/code/Magento/UrlRewrite/Model/Storage/DbStorage.php @@ -102,7 +102,7 @@ protected function doReplace($urls) * * @param array $data * @return void - * @throws DuplicateEntryException + * @throws \Magento\Framework\Exception\AlreadyExistsException * @throws \Exception */ protected function insertMultiple($data) @@ -113,7 +113,9 @@ protected function insertMultiple($data) 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 afb45715f54bd..0000000000000 --- a/app/code/Magento/UrlRewrite/Model/Storage/DuplicateEntryException.php +++ /dev/null @@ -1,10 +0,0 @@ -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 8931b9531802b..3be83d41040fa 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 @@ public function testReplace() } /** - * @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 ab43536becc1d..d9e5da50fc3fa --- 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 @@ public function execute() 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 dc382c00a17e0..e5400e79a692c --- 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 @@ protected function _deleteUserFromRole($userId, $roleId) /** * 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 @@ public function execute() $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 594ebf3aa0c37..918e6094d9b7e 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 @@ public function __construct( ) { $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 c48d6fb55bc1e..c6cf9637602e9 100644 --- a/app/code/Magento/Webapi/Model/Soap/Fault.php +++ b/app/code/Magento/Webapi/Model/Soap/Fault.php @@ -9,7 +9,7 @@ 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 @@ public function __construct( 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 => ""]); + $this->addDetails([self::NODE_DETAIL_TRACE => "stackTrace}]]>"]); } if ($this->getParameters()) { $this->addDetails([self::NODE_DETAIL_PARAMETERS => $this->getParameters()]); @@ -199,6 +207,14 @@ public function getLanguage() 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 02370c9fc4f75..9e9ee5f9a8db2 100644 --- a/app/code/Magento/Webapi/Model/Soap/Server.php +++ b/app/code/Magento/Webapi/Model/Soap/Server.php @@ -86,7 +86,7 @@ public function __construct( ) { 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 fa71cf08332d5..b1feef3a52821 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 @@ public function testDispatchSoapRequest() 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 7c0ed509e321d..ed5d4075fb694 100644 --- a/app/code/Magento/Webapi/Test/Unit/ExceptionTest.php +++ b/app/code/Magento/Webapi/Test/Unit/ExceptionTest.php @@ -17,7 +17,7 @@ public function testConstruct() $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 @@ public function testConstructInvalidHttpCode($httpCode) $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 @@ public function testGetOriginatorSender() 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 fa0c51de71a80..e0ea010724d62 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 @@ protected function setUp() $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 @@ public function testConstructor() $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 2cf3ea04adba8..1d85bb91709df 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 @@ public function testHandleWithException() ] )->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 85a6fa8e2776a..306e860b7fb55 100644 --- a/app/code/Magento/Weee/Helper/Data.php +++ b/app/code/Magento/Weee/Helper/Data.php @@ -400,12 +400,12 @@ public function getAmountForDisplay($product) * * @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 d957719932a2b..5adebd054bbef --- a/app/code/Magento/Wishlist/Controller/Index/Add.php +++ b/app/code/Magento/Wishlist/Controller/Index/Add.php @@ -8,7 +8,7 @@ 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 @@ public function execute() { $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 61d685b771278..8172c895ed70e 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 @@ public function execute() } $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 2bf785573e273..085cf426a0a37 --- 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 @@ public function __construct( /** * 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 56f08a2e53190..9cb4bbe9fcdb0 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 @@ public function __construct( 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 423d631f212d4..76c05b3d3e689 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 @@ public function __construct( * @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 @@ public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, $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 0890e174dd1fc..674d1118a6146 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 @@ public function execute() $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 c1ea762f0be24..6a54e1b7bf9f0 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 @@ public function execute() $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 8e372f3265fe2..731a80cd74357 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 @@ public function execute() } $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 6b6695e96fa80..98fbbc933f8a1 --- 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 @@ protected function createController() ); } + /** + * @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 7199faa0652cb..94888effcc121 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 @@ public function getController() ); } + /** + * @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 7349d98623d3f..163cb1367e1c0 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 @@ protected function getPlugin() ); } + /** + * @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 9dde615c6d4c0..f2c2954f59d73 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 @@ public function getController() ); } + /** + * @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 @@ public function testExecuteWithoutItem() $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 cb45113bb261c..7fbdfe5005a4f 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1074,6 +1074,12 @@ + + + Magento\Framework\App\State\Proxy + Magento\Framework\Message\ManagerInterface\Proxy + + 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 9ef7c6bda1426..eca76949e1cd4 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 @@ public function authorizationException() 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 749c0de354ea2..1225eb5340e8a 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 @@ public function endTest() * @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 @@ protected function _getFixtures($scope, \PHPUnit_Framework_TestCase $test) 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 @@ protected function _applyOneFixture($fixture) * 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 3891bc1870b3f..c46a71474c3f5 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 @@ public function __construct(\Magento\TestFramework\Application $application) * * @param array $annotations * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getTestAppArea($annotations) { @@ -56,8 +56,11 @@ protected function _getTestAppArea($annotations) ) : \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 605010c165afc..19c2cbe3682c2 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 @@ public function startTestSuite() * 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 @@ public function endTest(\PHPUnit_Framework_TestCase $test) 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 c4c4f131b497e..cf59f4469af36 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 @@ public function rollbackTransaction() * @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 @@ protected function _getFixtures(\PHPUnit_Framework_TestCase $test, $scope = null 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 @@ protected function _applyOneFixture($fixture) * 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 7ff949fb7a638..b405c205062a8 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 @@ public function rollbackTransaction() * * @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 @@ protected function _getIsolation(\PHPUnit_Framework_TestCase $test) 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 b8d9e4424ce95..c640f29e7381a 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -331,7 +331,7 @@ public function initialize($overriddenParams = []) \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 @@ public function cleanup() * Install an application * * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function install() { @@ -509,7 +509,7 @@ protected function _resetApp() * * @param string $dir * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _ensureDirExists($dir) { @@ -518,7 +518,7 @@ protected function _ensureDirExists($dir) 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 dec3fa8d6d6cf..df65d4dd37d6a 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 @@ public function getAsFile($settingName, $defaultValue = '') * * @param string $settingName * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getAsConfigFile($settingName) { @@ -99,7 +99,9 @@ public function getAsConfigFile($settingName) 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 08812d8caf3b5..95d35b39eb61b 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 @@ public static function setDefaultEventManager(\Magento\TestFramework\EventManage * 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 d19fac4a9168a..6f1413cd62060 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 @@ public static function setDefaultEventManager(\Magento\TestFramework\EventManage * 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 6385156cea5ac..80284facfa2fa 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 @@ protected function _rollbackTransaction() * * @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 8af390fa3c700..8ca8201802275 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 @@ public static function setInstance(\Magento\TestFramework\Helper\Bootstrap $inst * 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 f0cda8af73017..f4c0b07709a80 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 @@ public function getRealMemoryUsage() // 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 9c713e80ac01d..086b8dd952a1a 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 @@ public function testMergedConfig() 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 2692e49779a5a..c95620c61e594 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 @@ public function getTestAppAreaDataProvider() } /** - * @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 2f46aca7a6210..118fc8bbe9da3 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 @@ public function testStartTestSuite() /** * @magentoAppIsolation invalid - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testEndTestIsolationInvalid() { @@ -57,7 +57,7 @@ public function testEndTestIsolationInvalid() /** * @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 c4324863f1416..07cfebfa351e8 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 @@ public static function sampleFixtureTwoRollback() } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testConstructorException() { @@ -98,7 +98,7 @@ public function testDisabledDbIsolation() /** * @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 559bd7eba3d08..5b4314c302f31 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 @@ public function testStartTestTransactionRequestMethodIsolationDisabled() /** * @magentoDbIsolation invalid - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testStartTestTransactionRequestInvalidAnnotation() { @@ -73,7 +73,7 @@ public function testStartTestTransactionRequestInvalidAnnotation() /** * @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 60d25f5018cb9..6f7643bf89d26 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 @@ protected function _expectNoListenerCreation($listenerClass, $expectedExceptionM 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 ec8dc75f29b38..2dda33120ba57 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 @@ public function getAsConfigFileDataProvider() */ 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 @@ public function getAsConfigFileExceptionDataProvider() 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 bd4cbab9a0ed6..3cecd675ddeb9 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 @@ public function saveModelSuccessfully() /** * 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 @@ public function crudDataProvider() { 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 49a3510b412c6..119dc7bed5627 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 @@ public function testConstructorDefaultEventManager() /** * @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 6d10c3f8005fc..4a01266c9891b 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 @@ public function testConstructorDefaultEventManager() } /** - * @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 20accc8da9089..d7c9971203206 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 @@ protected function tearDown() } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Helper instance is not defined yet. */ public function testGetInstanceEmptyProhibited() @@ -99,7 +99,7 @@ public function testGetInstanceAllowed(\Magento\TestFramework\Helper\Bootstrap $ /** * @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 ba120cf6b806a..5234650a1118b 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 @@ public function testGetRealMemoryUsageUnix() )->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 fce0d8bb3b4b0..cef578e0114a3 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 @@ public function testSingleLikeFilter() } /** - * @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 f7c9bcc53653a..70d92a6e3a017 --- a/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php @@ -181,7 +181,7 @@ public function testGetDefaultEmailLogo() /** * @dataProvider setDesignConfigExceptionDataProvider - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testSetDesignConfigException($config) { @@ -269,7 +269,7 @@ public function testGetVariablesOptionArrayInGroup() } /** - * @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 3795a48b9f034..5b84fa1bc9742 --- a/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/App/FrontControllerTest.php @@ -37,6 +37,6 @@ public function testDispatch() $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 bc195e9ac3d37..7dbb721cfc39f 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 @@ public function testReadDirectoryRecursively() /** * 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 2ec0af2465224..03d13b9ee8aeb 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 @@ public function testInstance() * * @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 fe5bbe9e41398..67c671e2f253f 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 @@ public function testInstance() * @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 4bcae52e7362b..e9d78a0385a79 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 @@ public function testValidationUpToDateDb() /** * @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 214e3f39423b5..f9b9e1c674060 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 @@ public static function tearDownAfterClass() */ 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 cc9e4c4199c3d..da5a86c47a149 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 @@ public function testCssMinifierLibrary() * @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 11c917fba00ba..31ce3901f6bb4 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 @@ public function testMove() } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testMoveBroken() { @@ -216,7 +216,7 @@ public function testMoveBroken() } /** - * @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 3e49061e65249..70406c396b605 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 @@ public function testAddContainerInvalidHtmlTag() $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 b02773ae51c9e..f7ebc6d0764a6 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 @@ public function testSendPerSubscriberProblem() $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 @@ public function testSendPerSubscriberProblem() $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 4815f8adddaa5..c0dd230f922cd --- 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 @@ public function tableForPeriodDataProvider() '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 21c973d53e95c..430cced2f1a2e 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 @@ public function testCacheConfig($area) ); 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 9d0ffa7695a49..d224cd6d346e3 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 @@ public function testLayoutArguments($area, $layoutFile) 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 9f00b3cf29012..b942425f6fd48 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 @@ public function testConfiguration() '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 97d6e3f59cc08..c21e6dbc7052c 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 @@ public function dispatch(RequestInterface $request) 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 f60016b79f830..d3728db16b2fb 100644 --- a/dev/tests/performance/framework/Magento/TestFramework/Application.php +++ b/dev/tests/performance/framework/Magento/TestFramework/Application.php @@ -75,12 +75,12 @@ public function __construct( * * @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 @@ protected function _uninstall() * 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 46bd3c4a08bfe..f13126d189a49 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 @@ public function __construct(\Magento\Framework\App\Bootstrap $appBootstrap, $tes /** * 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 @@ public function cleanupReports() 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 5d2ef422a6331..f0a6f141fad07 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 @@ public function getTestsBaseDir() * 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 @@ protected function _validateData(array $configData) $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 @@ protected function _validateData(array $configData) $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 9a1469617c20b..3f027ecf6e253 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 1d426a2133680..deaf57b1ee4cf 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 @@ public function getHandler($fileExtension) * * @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 @@ public function run(\Magento\TestFramework\Performance\Scenario $scenario, $repo /** @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 2d321e6a30805..a6a6ffeda8fc7 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 @@ protected function _validateScenarioExecutable() * * @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 @@ public function run(\Magento\TestFramework\Performance\Scenario $scenario, $repo 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 791142633cd02..76ba0bda7b9e9 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 @@ protected function _validateScenarioExecutable() * * @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 @@ public function run(\Magento\TestFramework\Performance\Scenario $scenario, $repo 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 @@ protected function _executeScenario(\Magento\TestFramework\Performance\Scenario $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 0c56894bd75f2..7b2513aa5756a 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 @@ public function constructorExceptionDataProvider() '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 38d371796f4ed..e9a4f38b97301 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 @@ protected function setUp() $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 a49a8feffe806..3cafda18c6ddf 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 @@ public function testRunDelegation() $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 178a3094ce836..0b6e4882b1acc 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 @@ public function runExceptionDataProvider() '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 fc3774ffdf76a..6ca1dfcfd2f92 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 @@ public function testRunReport() */ 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 828c06aed1710..bda8a6cbcf338 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 @@ 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 @@ private static function isComposerAvailable() { 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 493f1310e380c..780e83022c4aa 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 @@ protected function _validateClass($className) { 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 @@ protected function validatePlugins($plugin, $type) 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 @@ public function testCompiler() { 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 2f915d7ffb489..462d614821e29 --- 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 @@ ['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 @@ ['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 @@ ['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 @@ ['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 1d0e66fbbc949..793473a809aee 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 @@ ['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 0eaf442daccdd..a33d2f74dc024 100644 --- a/dev/tools/Magento/Tools/Di/Code/Generator.php +++ b/dev/tools/Magento/Tools/Di/Code/Generator.php @@ -60,7 +60,7 @@ protected function createGeneratorInstance($generatorClass, $entityName, $classN * 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 f91f9fbc27cd3..5b0204813ccb1 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 @@ public function addExcludePatterns(array $excludePatterns) * * @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 a70c2291eeb66..5830fc4e79ba8 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 @@ 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 @@ public function __construct( * @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 83d8e41078560..430ec71706199 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 @@ public function getList($path) $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 8836c53070b59..84e4ce0038e8c 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 @@ public function getList($path) $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 bf5fc24e4749a..ee03793670007 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 @@ protected function _findMissingClasses($file, $classReflection, $methodName, $en 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 9f0b2ec3304b6..6ca33d3f08c84 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 @@ protected function _filterEntities(array $output) $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 585d6dadc196f..aaa02faa6f70e 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 @@ public function testGetListException(\Exception $exception) 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 8a161f49a0a54..238274ff5f804 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 @@ public function testGetListException(\Exception $exception) 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 4ab81346a4e3b..17592837a0b0c 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\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 @@ } 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 1f261b1401f54..08c81040594f5 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 @@ public function __construct( * * @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 76e4a4c6ec6e1..e0bc18f381af7 100644 --- a/lib/internal/Magento/Framework/Api/CriteriaInterface.php +++ b/lib/internal/Magento/Framework/Api/CriteriaInterface.php @@ -73,7 +73,7 @@ public function addField($field, $alias = null); * @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 50316c770caf6..b0027ca824ec0 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 @@ public function getResponse() { 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 38e64f43b23e0..3334b9c810db4 100644 --- a/lib/internal/Magento/Framework/App/Action/Action.php +++ b/lib/internal/Magento/Framework/App/Action/Action.php @@ -7,6 +7,7 @@ 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 a27f3862ecb23..22aef5cc083c9 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 @@ public function __construct( \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 @@ public function __construct( $this->_actionFlag = $actionFlag; $this->_view = $view; $this->messageManager = $messageManager; + $this->resultRedirectFactory = $resultRedirectFactory; } /** @@ -158,4 +166,12 @@ public function getMessageManager() { 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 12389da51db10..0000000000000 --- a/lib/internal/Magento/Framework/App/Action/Exception.php +++ /dev/null @@ -1,12 +0,0 @@ -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 91984933ca4e1..d8d85460a66ef --- 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 @@ public function dispatch(RequestInterface $request) $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 54a71efa0c038..755131e2309d3 100644 --- a/lib/internal/Magento/Framework/App/Http.php +++ b/lib/internal/Magento/Framework/App/Http.php @@ -224,7 +224,7 @@ private function handleBootstrapErrors(Bootstrap $bootstrap, \Exception &$except */ 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 @@ private function handleSessionException(\Exception $exception) */ 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 880121b1647cb..62c29d8f23b4c 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 @@ public function __construct($source) $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 61ed3b457a27c..0814ad0cfbd26 100644 --- a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php +++ b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php @@ -224,7 +224,7 @@ protected function createArgumentInterpreter( * @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 @@ protected function _loadPrimaryConfig(DirectoryList $directoryList, $driverPool, ); $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 6fcd734833643..727b30c68245e 100644 --- a/lib/internal/Magento/Framework/App/State.php +++ b/lib/internal/Magento/Framework/App/State.php @@ -129,12 +129,14 @@ public function setIsDownloader($flag = true) * * @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 @@ public function setAreaCode($code) * 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 0000000000000..94b705692c7cc --- /dev/null +++ b/lib/internal/Magento/Framework/App/Test/Unit/Action/AbstractActionTest.php @@ -0,0 +1,68 @@ +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 f3d28802f4da3..4c1fde2796bf5 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 @@ public function testReadValidConfig() /** * @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 767595240e133..d426fa8b18675 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 @@ public function testDirectoriesCustomization() $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 e2ebe0d3bc389..160256bf81e3e --- 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 @@ protected function setUp() $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 @@ public function testDispatchedNotFoundException() $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 @@ public function testDispatchedNotFoundException() $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 2d071943fbd8e..202cc71761b31 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 @@ public function testCatchExceptionSessionException() $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 187192828067e..dcb70fc401949 --- 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 @@ public function getDataProvider() $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 e8066f086c37b..4bc544940975d 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 @@ public function testSetAreaCode() $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 05a69a46d6d64..4683b8012302e 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 @@ public function testLoadExceptionPropagation() */ 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 b0db3653f1b80..65e059a58a315 --- a/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php @@ -39,7 +39,7 @@ public function testGetValueDeveloperMode() ->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 } @@ -70,7 +70,7 @@ public function getValueFromStorageDataProvider() public function testGetValueDefaultModeSaving() { - $this->markTestSkipped('MAGETWO-35794'); + $versionType = 'integer'; $this->appState ->expects($this->once()) ->method('getMode') @@ -80,8 +80,8 @@ public function testGetValueDefaultModeSaving() ->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 bf04e81dbc254..818eecb0040f5 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 @@ public function load() { 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 8ead7fd47b117..9c8eed675fd1c 100644 --- a/lib/internal/Magento/Framework/Archive/AbstractArchive.php +++ b/lib/internal/Magento/Framework/Archive/AbstractArchive.php @@ -35,7 +35,7 @@ protected function _writeFile($destination, $data) * * @param string $source * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _readFile($source) { @@ -43,7 +43,9 @@ protected function _readFile($source) 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 f824c06a7b041..549c3b8849fe7 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 @@ public function open($mode = 'w+', $chmod = 0666) 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 @@ protected function _open($mode) $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 @@ protected function _write($data) $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 @@ protected function _read($length) $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 @@ protected function _isReadableMode($mode) 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 46452bfa6e49d..ada3317e13918 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 @@ protected function _open($mode) $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 @@ protected function _write($data) $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 @@ protected function _read($length) $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 52d18ed04f043..dc5204d294785 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 @@ protected function _open($mode) $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 @@ protected function _write($data) $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 d8a532e0cc25a..0b69b98930cd7 100644 --- a/lib/internal/Magento/Framework/Archive/Tar.php +++ b/lib/internal/Magento/Framework/Archive/Tar.php @@ -240,7 +240,7 @@ protected function _getCurrentPath() * @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 @@ protected function _createTar($skipRoot = false, $finalize = false) $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 @@ protected function _composeHeader($long = false) * * @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 @@ protected function _unpackCurrentTar($destination) $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 @@ protected function _unpackCurrentTar($destination) $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 f980455dd5a6a..8c5020946fcd3 100644 --- a/lib/internal/Magento/Framework/Backup/AbstractBackup.php +++ b/lib/internal/Magento/Framework/Backup/AbstractBackup.php @@ -138,13 +138,15 @@ public function getTime() * 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 4efd0c3600ba0..273fe476f67d0 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 ba120c4561584..d7827cea421f2 100644 --- a/lib/internal/Magento/Framework/Backup/Factory.php +++ b/lib/internal/Magento/Framework/Backup/Factory.php @@ -71,12 +71,17 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan * * @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 24ffe43be56c4..2a36caf8e5522 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 @@ public function rollback() /** * Implementation Create Backup functionality for Filesystem * - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @return boolean */ public function create() @@ -106,14 +106,16 @@ public function create() 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 @@ public function create() $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 @@ public function create() $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 @@ public function getFtpConnectString() * 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 @@ protected function _checkBackupsDir() $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 @@ protected function _checkBackupsDir() } 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 5a2df37545d25..7e48f22c9e500 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 999302f8438a7..ff750d3c8b1e4 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 @@ public function run() $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 @@ public function run() 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 b9c0a9c6270db..395700ab0bb4e 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 @@ /** * Rollback worker for rolling back via ftp * - * @author Magento Core Team + * @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 @@ public function run() $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 @@ protected function _initFtpClient() $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 @@ protected function _initFtpClient() * 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 @@ protected function _validateFtp() @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 @@ protected function _validateFtp() @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 @@ protected function _unpackSnapshot($tmpDir) /** * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _createTmpDir() { @@ -119,7 +127,9 @@ protected function _createTmpDir() $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 @@ protected function _cleanupFtp() * * @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 @@ protected function _uploadBackupToFtp($tmpDir) $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 452e8a1e8f325..5ae5b404d292c 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 @@ public function rollback() /** * 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 7f4871f3f937e..b2c611c2cf991 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 @@ protected function setUp() } /** - * @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 7d938dbe455f3..9efb46607ff0a 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 @@ public function __construct(array $options = []) 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 . Expected to be positive integer." + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase( + "Invalid value for the node . Expected to be positive integer." + ) ); } diff --git a/lib/internal/Magento/Framework/Code/Generator.php b/lib/internal/Magento/Framework/Code/Generator.php index 35026a88b69d1..03ac500f47dac 100644 --- a/lib/internal/Magento/Framework/Code/Generator.php +++ b/lib/internal/Magento/Framework/Code/Generator.php @@ -69,7 +69,7 @@ public function getGeneratedEntities() * * @param string $className * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException * @throws \InvalidArgumentException */ public function generateClass($className) @@ -102,7 +102,9 @@ public function generateClass($className) $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 @@ public function getObjectManager() * @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 90898124ced2a..945f1879afc3b 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 @@ public function getResultFileName($className) /** * @param string $fileName * @param string $content - * @throws FilesystemException + * @throws FileSystemException * @return bool */ public function writeResultFile($fileName, $content) @@ -101,7 +101,7 @@ public function writeResultFile($fileName, $content) try { $success = $this->filesystemDriver->rename($tmpFile, $fileName); - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { if (!file_exists($fileName)) { throw $e; } else { @@ -164,7 +164,7 @@ private function _makeDirectory($directory) $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 efa21cde844f6..e01f4c529c827 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 @@ public function testGetGeneratedEntities() } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @dataProvider generateValidClassDataProvider */ public function testGenerateClass($className, $entityType) @@ -117,7 +117,7 @@ public function testGenerateClassWithWrongName() } /** - * @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 054cee5cdb830..2244c9f5d4a18 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 @@ public function testInvalidSequence() '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 74fa005dae7a4..da7d3a62f2705 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 @@ public function testValidate() } /** - * @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 b278d42c55637..8fffbc9c27063 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 @@ public function testValidateIfClassHasExtraArgumentInTheParentConstructor() $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 @@ public function testValidateIfClassHasMissingRequiredArguments() $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 @@ public function testValidateIfClassHasIncompatibleArguments() $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 @@ public function testValidateWrongOrderForParentArguments() $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 @@ public function testValidateWrongOptionalParamsType() $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 30667c6727828..b40b91bb42e01 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 @@ public function testClassArgumentAlreadyInjectedIntoContext() 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 @@ public function testClassArgumentWithAlreadyInjectedInterface() 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 acaeaa41033ed..0b0c00c72dc87 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 @@ public function testInvalidClass() $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 b3831d4c930a1..0000000000000 --- a/lib/internal/Magento/Framework/Code/ValidationException.php +++ /dev/null @@ -1,10 +0,0 @@ -_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 6fdfe35b430e5..644d863313a80 100644 --- a/lib/internal/Magento/Framework/Code/Validator/ConstructorArgumentTypes.php +++ b/lib/internal/Magento/Framework/Code/Validator/ConstructorArgumentTypes.php @@ -37,7 +37,7 @@ public function __construct( * * @param string $className * @return bool - * @throws \Magento\Framework\Code\ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className) { @@ -49,8 +49,11 @@ public function validate($className) }, $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 63929f4a08ad7..62cd9b7675e48 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 @@ public function __construct(\Magento\Framework\Code\Reader\ArgumentsReader $argu * * @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 @@ public function validate($className) } $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 @@ public function validate($className) ); 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 @@ public function validate($className) } $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 eec24881210de..18ebce1fbad12 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 @@ public function __construct(\Magento\Framework\Code\Reader\ArgumentsReader $argu * * @param string $className * @return bool - * @throws ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className) { @@ -62,10 +61,15 @@ public function validate($className) 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 ff78fc59a5acf..45d50b84a3b66 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 @@ public function __construct(\Magento\Framework\Code\Reader\ArgumentsReader $argu * * @param string $className * @return bool - * @throws ValidationException + * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className) { @@ -62,15 +61,15 @@ public function validate($className) 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 df90607007d76..9a55182aa375a 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 323069c5488d5..acdd49eeee201 100644 --- a/lib/internal/Magento/Framework/Config/AbstractXml.php +++ b/lib/internal/Magento/Framework/Config/AbstractXml.php @@ -68,7 +68,7 @@ abstract protected function _extractData(\DOMDocument $dom); * * @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 @@ protected function _merge($configFiles) 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 @@ protected function _merge($configFiles) * * @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 @@ protected function _isRuntimeValidated() */ 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 57c18e8e6eb02..1dbae5f157562 100644 --- a/lib/internal/Magento/Framework/Config/Dom.php +++ b/lib/internal/Magento/Framework/Config/Dom.php @@ -13,6 +13,8 @@ /** * Class Dom + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Dom { @@ -223,7 +225,7 @@ protected function _getNodePathByParent(\DOMElement $node, $parentPath) * 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 @@ protected function _getMatchedNode($nodePath) $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 fad1d245cfd9b..992158c6edf63 100644 --- a/lib/internal/Magento/Framework/Config/Reader/Filesystem.php +++ b/lib/internal/Magento/Framework/Config/Reader/Filesystem.php @@ -126,7 +126,7 @@ public function read($scope = null) * * @param array $fileList * @return array - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _readFiles($fileList) { @@ -140,14 +140,18 @@ protected function _readFiles($fileList) $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 228d2bfd55561..d759359f4ef03 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 @@ public function mergeDataProvider() } /** - * @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 99b86f3505dbc..bef2654e8c296 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 @@ public function testReadWithoutFiles() } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Invalid Document */ public function testReadWithInvalidDom() @@ -111,7 +111,7 @@ public function testReadWithInvalidDom() } /** - * @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 5628898c95b4b..008d5ecfc3627 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 @@ public function testGetVarValue() } /** - * @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 902c7c99dee79..a37021e1fbc83 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 = <<addChild($key, $value); @@ -89,7 +93,9 @@ private function _assocToXml(array $array, $rootName, \SimpleXMLElement $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 056b58b3541e1..f7c6a18bba136 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 @@ public function testAssocToXmlExceptionByKey() /** * @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 9aec56e0970fd..0000000000000 --- a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/AdapterException.php +++ /dev/null @@ -1,13 +0,0 @@ -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 @@ public function updateFromSelect(Select $select, $table) } 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 df6bf9d109dc2..6af4e98427bbf 100644 --- a/lib/internal/Magento/Framework/DB/DBException.php +++ b/lib/internal/Magento/Framework/DB/DBException.php @@ -10,6 +10,6 @@ * * @author Magento Core Team */ -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 0c701803e9b30..5f125b76935ed 100644 --- a/lib/internal/Magento/Framework/DB/MapperFactory.php +++ b/lib/internal/Magento/Framework/DB/MapperFactory.php @@ -33,13 +33,18 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan * @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 74e3d926c5681..67cb7d0ac6be3 100644 --- a/lib/internal/Magento/Framework/DB/MapperInterface.php +++ b/lib/internal/Magento/Framework/DB/MapperInterface.php @@ -77,7 +77,7 @@ public function addExpressionFieldToSelect($alias, $expression, $fields); * * @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 68b24e06b5c90..c764157be4ca4 100644 --- a/lib/internal/Magento/Framework/DB/QueryBuilder.php +++ b/lib/internal/Magento/Framework/DB/QueryBuilder.php @@ -75,7 +75,7 @@ public function setResource(\Magento\Framework\Model\Resource\Db\AbstractDb $res /** * @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 a78004fb03e48..dea7d2da39a06 100644 --- a/lib/internal/Magento/Framework/DB/QueryFactory.php +++ b/lib/internal/Magento/Framework/DB/QueryFactory.php @@ -32,13 +32,18 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan * @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 e0a7b800b5df3..e2449c2bc8498 100644 --- a/lib/internal/Magento/Framework/DB/Tree.php +++ b/lib/internal/Magento/Framework/DB/Tree.php @@ -97,7 +97,9 @@ public function __construct($config = []) // 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 @@ public function __construct($config = []) $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 80aa840e9de05..e9ea215876818 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 0768805c048cd..7dcffa444c719 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 4fa01c2316739..0000000000000 --- a/lib/internal/Magento/Framework/Data/Argument/MissingOptionalValueException.php +++ /dev/null @@ -1,14 +0,0 @@ -_conn = $conn; diff --git a/lib/internal/Magento/Framework/Data/FormFactory.php b/lib/internal/Magento/Framework/Data/FormFactory.php index cd35382e26446..57267e2413b63 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 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan * * @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 6fc4110a9e59e..f6efdfefcd541 100644 --- a/lib/internal/Magento/Framework/Data/SearchResultIteratorFactory.php +++ b/lib/internal/Magento/Framework/Data/SearchResultIteratorFactory.php @@ -29,14 +29,14 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan * @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 a5d09d08ca9a1..3e8b81ea66770 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 @@ public function __construct(array $elements = null) * * @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 @@ public function importElements(array $elements) 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 @@ public function importElements(array $elements) * * @param string $elementId * @return void - * @throws Exception + * @throws LocalizedException */ protected function _assertParentRelation($elementId) { @@ -85,8 +92,11 @@ protected function _assertParentRelation($elementId) $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 @@ protected function _assertParentRelation($elementId) $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 @@ protected function _assertParentRelation($elementId) $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 @@ public function exportElements() * @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 @@ public function getAttribute($elementId, $attribute) * @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 @@ public function renameElement($oldId, $newId) * @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 @@ public function getGroupChildNames($parentId, $groupName) * @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 @@ private function _isParentRecursively($childId, $potentialParentId) * @param int|null $offset * @param string $alias * @return void - * @throws Exception + * @throws LocalizedException */ protected function _insertChild($targetParentId, $elementId, $offset, $alias) { @@ -568,17 +593,27 @@ protected function _insertChild($targetParentId, $elementId, $offset, $alias) // 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 @@ protected function _insertChild($targetParentId, $elementId, $offset, $alias) * * @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 @@ private function _assertElementExists($elementId) * * @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 0d2336846b991..666655aefd385 --- 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 @@ public function printLogQueryLoggingDataProvider() } /** - * @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 9ebd3bc85e148..cf9ef32ca805c 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 @@ protected function setUp() } /** - * @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 4b994828b51d1..87dfd68d30a0f 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 @@ public function importExportElementsDataProvider() * @param array $elements * @return void * @dataProvider importExceptionDataProvider - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testImportException($elements) { @@ -184,7 +184,7 @@ public function testCreateGetHasElement() /** * @return void - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testCreateElementException() { @@ -365,7 +365,7 @@ public function setAsChildOffsetDataProvider() * @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 @@ public function reorderChildDataProvider() /** * @return void - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testReorderChildException() { @@ -516,7 +516,7 @@ public function reorderSiblingDataProvider() /** * @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 9185fc38c03fa..76ee991295b0e 100644 --- a/lib/internal/Magento/Framework/Encryption/Crypt.php +++ b/lib/internal/Magento/Framework/Encryption/Crypt.php @@ -55,7 +55,9 @@ public function __construct($key, $cipher = MCRYPT_BLOWFISH, $mode = MCRYPT_MODE 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 @@ public function __construct($key, $cipher = MCRYPT_BLOWFISH, $mode = MCRYPT_MODE /* 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 6b003e09e285f..4c430da55d513 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 @@ public function getConstructorExceptionData() /** * @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 2c7320a4e0106..0000000000000 --- a/lib/internal/Magento/Framework/Exception.php +++ /dev/null @@ -1,33 +0,0 @@ -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 @@ protected function assertWritable($path) * * @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 @@ protected function assertIsFile($path) * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function create($path = null) { @@ -92,7 +94,7 @@ public function create($path = null) * @param string $newPath * @param WriteInterface $targetDirectory * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function renameFile($path, $newPath, WriteInterface $targetDirectory = null) { @@ -113,7 +115,7 @@ public function renameFile($path, $newPath, WriteInterface $targetDirectory = nu * @param string $destination * @param WriteInterface $targetDirectory * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function copyFile($path, $destination, WriteInterface $targetDirectory = null) { @@ -136,7 +138,7 @@ public function copyFile($path, $destination, WriteInterface $targetDirectory = * @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 @@ public function createSymlink($path, $destination, WriteInterface $targetDirecto * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function delete($path = null) { @@ -180,7 +182,7 @@ public function delete($path = null) * @param string $path * @param int $permissions * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function changePermissions($path, $permissions) { @@ -194,7 +196,7 @@ public function changePermissions($path, $permissions) * @param string $path * @param int|null $modificationTime * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function touch($path, $modificationTime = null) { @@ -209,7 +211,7 @@ public function touch($path, $modificationTime = null) * * @param null $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws \Magento\Framework\Exception\FileSystemException */ public function isWritable($path = null) { @@ -239,7 +241,7 @@ public function openFile($path, $mode = 'w') * @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 65c0de80d1f76..71ac8bcba0a28 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 @@ public function create($path = null); * * @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 @@ public function delete($path = null); * @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 @@ public function renameFile($path, $newPath, WriteInterface $targetDirectory = nu * @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 @@ public function copyFile($path, $destination, WriteInterface $targetDirectory = * @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 @@ public function createSymlink($path, $destination, WriteInterface $targetDirecto * @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 @@ public function changePermissions($path, $permissions); * @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 @@ public function openFile($path, $mode = 'w'); * @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 438ce7202543f..2174a010a6c19 100644 --- a/lib/internal/Magento/Framework/Filesystem/DirectoryList.php +++ b/lib/internal/Magento/Framework/Filesystem/DirectoryList.php @@ -228,13 +228,15 @@ public function getUrlPath($code) * 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 e053ca69564b7..67320447f5470 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 @@ protected function getWarningMessage() * * @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 @@ public function isExists($path) * * @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 @@ public function stat($path) * * @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 @@ public function isReadable($path) * * @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 @@ public function isFile($path) * * @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 @@ public function isDirectory($path) * @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 @@ public function fileGetContents($path, $flag = null, $context = null) * * @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 @@ public function getParentDirectory($path) * @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 @@ public function createDirectory($path, $permissions) * * @param string $path * @return string[] - * @throws FilesystemException + * @throws FileSystemException */ public function readDirectory($path) { @@ -204,7 +222,7 @@ public function readDirectory($path) 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 @@ public function readDirectory($path) * @param string $pattern * @param string $path * @return string[] - * @throws FilesystemException + * @throws FileSystemException */ public function search($pattern, $path) { @@ -231,7 +249,7 @@ public function search($pattern, $path) * @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 @@ public function rename($oldPath, $newPath, DriverInterface $targetDriver = null) } } 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 @@ public function rename($oldPath, $newPath, DriverInterface $targetDriver = null) * @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 @@ public function copy($source, $destination, DriverInterface $targetDriver = null $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 @@ public function copy($source, $destination, DriverInterface $targetDriver = null * @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 @@ public function symlink($source, $destination, DriverInterface $targetDriver = n $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 @@ public function symlink($source, $destination, DriverInterface $targetDriver = n * * @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 @@ public function deleteFile($path) * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function deleteDirectory($path) { @@ -351,8 +376,11 @@ public function deleteDirectory($path) } $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 @@ public function deleteDirectory($path) * @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 @@ public function changePermissions($path, $permissions) * @param string $path * @param int|null $modificationTime * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function touch($path, $modificationTime = null) { @@ -393,8 +424,11 @@ public function touch($path, $modificationTime = null) $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 @@ public function touch($path, $modificationTime = null) * @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 @@ public function filePutContents($path, $content, $mode = null) * @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 @@ public function fileOpen($path, $mode) * @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 @@ public function fileReadLine($resource, $length, $ending = null) * @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 @@ public function fileRead($resource, $length) * @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 @@ public function fileGetCsv($resource, $length = 0, $delimiter = ',', $enclosure * * @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 @@ public function fileTell($resource) * @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 @@ public function endOfFile($resource) * * @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 @@ public function fileClose($resource) * @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 @@ public function fileWrite($resource, $data) * @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 @@ public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure * * @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 @@ public function fileFlush($resource) * @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 @@ public function fileLock($resource, $lockMode = LOCK_EX) * * @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 @@ protected function getScheme($scheme = null) * * @param string $path * @return string[] - * @throws FilesystemException + * @throws FileSystemException */ public function readDirectoryRecursively($path = null) { @@ -725,7 +793,7 @@ public function readDirectoryRecursively($path = null) $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 0c760c1daa45b..2e60f74c6f15f 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 @@ public function stat($path) * @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 @@ public function fileGetContents($path, $flags = null, $context = null) * @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 @@ public function filePutContents($path, $content, $mode = null, $context = null) * @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 @@ public function fileOpen($path, $mode) $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 @@ public function fileOpen($path, $mode) * @param int $length * @param string $ending [optional] * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileReadLine($resource, $length, $ending = null) { @@ -228,15 +234,15 @@ protected function getScheme($scheme = null) * * @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 c02447ee8c48f..66e544311a8c4 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 @@ public function isExists($path); * * @param string $path * @return array - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function stat($path); @@ -34,7 +36,7 @@ public function stat($path); * * @param string $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function isReadable($path); @@ -43,7 +45,7 @@ public function isReadable($path); * * @param string $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function isFile($path); @@ -52,7 +54,7 @@ public function isFile($path); * * @param string $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function isDirectory($path); @@ -63,7 +65,7 @@ public function isDirectory($path); * @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 @@ public function fileGetContents($path, $flag = null, $context = null); * * @param string $path * @return bool - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function isWritable($path); @@ -90,7 +92,7 @@ public function getParentDirectory($path); * @param string $path * @param int $permissions * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function createDirectory($path, $permissions); @@ -99,7 +101,7 @@ public function createDirectory($path, $permissions); * * @param string $path * @return array - * @throws FilesystemException + * @throws FileSystemException */ public function readDirectory($path); @@ -108,7 +110,7 @@ public function readDirectory($path); * * @param string|null $path * @return array - * @throws \Magento\Framework\Filesystem\FilesystemException + * @throws FileSystemException */ public function readDirectoryRecursively($path = null); @@ -118,7 +120,7 @@ public function readDirectoryRecursively($path = null); * @param string $pattern * @param string $path * @return array - * @throws FilesystemException + * @throws FileSystemException */ public function search($pattern, $path); @@ -129,7 +131,7 @@ public function search($pattern, $path); * @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 @@ public function rename($oldPath, $newPath, DriverInterface $targetDriver = null) * @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 @@ public function copy($source, $destination, DriverInterface $targetDriver = null * @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 @@ public function symlink($source, $destination, DriverInterface $targetDriver = n * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function deleteFile($path); @@ -169,7 +171,7 @@ public function deleteFile($path); * * @param string $path * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function deleteDirectory($path); @@ -179,7 +181,7 @@ public function deleteDirectory($path); * @param string $path * @param int $permissions * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function changePermissions($path, $permissions); @@ -189,7 +191,7 @@ public function changePermissions($path, $permissions); * @param string $path * @param int|null $modificationTime * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function touch($path, $modificationTime = null); @@ -200,7 +202,7 @@ public function touch($path, $modificationTime = null); * @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 @@ public function filePutContents($path, $content, $mode = null); * @param string $path * @param string $mode * @return resource - * @throws FilesystemException + * @throws FileSystemException */ public function fileOpen($path, $mode); @@ -221,7 +223,7 @@ public function fileOpen($path, $mode); * @param int $length * @param string $ending [optional] * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileReadLine($resource, $length, $ending = null); @@ -231,7 +233,7 @@ public function fileReadLine($resource, $length, $ending = null); * @param resource $resource * @param int $length * @return string - * @throws FilesystemException + * @throws FileSystemException */ public function fileRead($resource, $length); @@ -244,7 +246,7 @@ public function fileRead($resource, $length); * @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 @@ public function fileGetCsv($resource, $length = 0, $delimiter = ',', $enclosure * * @param resource $resource * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileTell($resource); @@ -264,7 +266,7 @@ public function fileTell($resource); * @param int $offset * @param int $whence * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileSeek($resource, $offset, $whence = SEEK_SET); @@ -281,7 +283,7 @@ public function endOfFile($resource); * * @param resource $resource * @return boolean - * @throws FilesystemException + * @throws FileSystemException */ public function fileClose($resource); @@ -291,7 +293,7 @@ public function fileClose($resource); * @param resource $resource * @param string $data * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function fileWrite($resource, $data); @@ -303,7 +305,7 @@ public function fileWrite($resource, $data); * @param string $delimiter * @param string $enclosure * @return int - * @throws FilesystemException + * @throws FileSystemException */ public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure = '"'); @@ -312,7 +314,7 @@ public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure * * @param resource $resource * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function fileFlush($resource); @@ -322,7 +324,7 @@ public function fileFlush($resource); * @param resource $resource * @param int $lockMode * @return bool - * @throws FilesystemException + * @throws FileSystemException */ public function fileLock($resource, $lockMode = LOCK_EX); @@ -331,7 +333,7 @@ public function fileLock($resource, $lockMode = LOCK_EX); * * @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 a62e34d932172..06964e61aa9f0 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 @@ protected function open() * 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 a2f0995c2938c..fc5efbb17710e 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 @@ public function __construct($path, DriverInterface $driver, $mode) * 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 @@ protected function assertValid() * * @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 @@ public function write($data) * @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 @@ public function writeCsv(array $data, $delimiter = ',', $enclosure = '"') * 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 d83d89d83a1ff..cf36ee69758f9 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 @@ public function write($data); * @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 @@ public function writeCsv(array $data, $delimiter = ',', $enclosure = '"'); * 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 1624a74b57541..ed850baec96a9 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/Ftp.php @@ -74,7 +74,7 @@ public function open(array $args = []) { 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 @@ public function open(array $args = []) } 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 @@ public function open(array $args = []) 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 dffe2d6695e5b..3d94334dcae56 100644 --- a/lib/internal/Magento/Framework/Filesystem/Io/IoException.php +++ b/lib/internal/Magento/Framework/Filesystem/Io/IoException.php @@ -9,6 +9,6 @@ /** * 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 20b847670670c..d749a5dd5d4bf 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 @@ public function testUnknownType() /** * @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 bcd02a4d3a76d..6d28b1f25034c 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 @@ public function testFilePutContents() } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testFilePutContentsFail() { @@ -129,7 +129,7 @@ public function testFilePutContentsFail() } /** - * @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 26e6cb01ba5ea..016fb70e27d37 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 @@ public function tearDown() } /** - * @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 af2a4f6445957..4216bf42b2e19 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 @@ public function tearDown() } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testInstanceFileNotExists() { @@ -73,7 +73,7 @@ public function testInstanceFileNotExists() } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testInstanceFileAlreadyExists() { @@ -121,7 +121,7 @@ public function testFlush() } /** - * @expectedException \Magento\Framework\Filesystem\FilesystemException + * @expectedException \Magento\Framework\Exception\FileSystemException */ public function testWriteException() { @@ -129,12 +129,14 @@ public function testWriteException() $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 @@ public function testWriteCsvException() $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 3a7742a7efb1f..35f2ee5a1b5f2 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php +++ b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php @@ -682,7 +682,7 @@ protected function _prepareDestination($destination = null, $newName = null) 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 02a15478b09c3..8b60402950192 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 @@ public function setup() $this->filesystemMock ->expects($this->once()) ->method('getDirectoryWrite') - ->will($this->returnValue( $this->writeMock)); + ->willReturn($this->writeMock); $this->imageMagic = $objectManager ->getObject( @@ -85,7 +85,7 @@ public function watermarkDataProvider() */ 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 d8582f819bf4f..c945033d93316 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 @@ public function validate($pluginClass, $interceptedType) } 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 @@ public function validate($pluginClass, $interceptedType) ) || $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 @@ public function validate($pluginClass, $interceptedType) $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 @@ public function validate($pluginClass, $interceptedType) 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 @@ protected function validateMethodsParameters(array $pluginParameters, array $ori { 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 463282a829dbb..6b1f1bbef4ebf 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 @@ public function testValidate() } /** - * @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 @@ public function testValidateIncorrectInterface() } /** - * @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 @@ public function testValidateIncorrectSubjectType() } /** - * @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 @@ public function testValidateIncompatibleMethodArgumentsCount() } /** - * @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 @@ public function testValidateIncompatibleMethodArgumentsType() } /** - * @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 @@ public function testValidateExtraParameters() } /** - * @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 ffa3d56d90cfb..0000000000000 --- a/lib/internal/Magento/Framework/Mail/Exception.php +++ /dev/null @@ -1,10 +0,0 @@ -_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 554daa553e137..53d1bd04e0720 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 15e5f6ac7b166..0000000000000 --- a/lib/internal/Magento/Framework/Module/Exception.php +++ /dev/null @@ -1,11 +0,0 @@ -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 52cbea3c74f5d..e8ff84ee47676 100644 --- a/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php +++ b/lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php @@ -42,7 +42,7 @@ public function __construct( * @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 @@ public function aroundDispatch( $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 8a760ccec43eb..10e21e701802b 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 @@ public function testAroundDispatchCached() * @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 c13d48075dfb4..81be913e5543c 100644 --- a/lib/internal/Magento/Framework/Object.php +++ b/lib/internal/Magento/Framework/Object.php @@ -494,7 +494,7 @@ public function toString($format = '') * @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 @@ public function __call($method, $args) $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 519021a01914b..911eaf0749cbd 100644 --- a/lib/internal/Magento/Framework/Object/Cache.php +++ b/lib/internal/Magento/Framework/Object/Cache.php @@ -122,7 +122,7 @@ public function load($idx, $default = null) * @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 @@ public function save($object, $idx = null, $tags = null) } 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 @@ public function save($object, $idx = null, $tags = null) * @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 @@ public function reference($refName, $idx) } 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 afcfad8fb5d29..6e66bb3f370ab 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 @@ public function testSaveWhenArgumentIsNotObject() } /** - * @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 @@ public function testSaveAndDeleteWhenHashAlreadyExist() } /** - * @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 3fde1b24d3360..2485e8e156228 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 @@ public function getParentsDataProvider() /** * @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 bfd8a6958a712..6f6595805bafe 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 @@ public function __construct( $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 b9e9b8a27aa94..7ff33f1f72b07 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 @@ public function __construct(\Magento\Framework\App\Resource $resource) * 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 cecf0740fe13b..89efdac63f842 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 @@ public function testCheckConnection() } /** - * @expectedException \Magento\Framework\Session\SaveHandlerException + * @expectedException \Magento\Framework\Exception\SessionException * @expectedExceptionMessage Write DB connection is not available */ public function testCheckConnectionNoConnection() @@ -124,7 +124,7 @@ public function testCheckConnectionNoConnection() } /** - * @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 7fbf90088d087..7ddca4963110c 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 @@ public function __construct( * * @param SessionManagerInterface $session * @return void - * @throws Exception + * @throws SessionException */ public function validate(SessionManagerInterface $session) { @@ -80,7 +83,7 @@ public function validate(SessionManagerInterface $session) } 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 @@ public function validate(SessionManagerInterface $session) * Validate data * * @return bool - * @throws Exception + * @throws SessionException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _validate() @@ -105,14 +108,24 @@ protected function _validate() $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 @@ protected function _validate() $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 @@ protected function _validate() 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 147e9dd587f59..f1407c41b4b02 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 38b06f0d39d74..0652d49d039e0 100644 --- a/lib/internal/Magento/Framework/Shell.php +++ b/lib/internal/Magento/Framework/Shell.php @@ -42,7 +42,7 @@ public function __construct( * @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 @@ public function execute($command, array $arguments = []) $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 @@ public function execute($command, array $arguments = []) $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 3f891b3fc345b..dae36d58f8d63 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 ca2ccc8e291c5..0000000000000 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/ValidationException.php +++ /dev/null @@ -1,12 +0,0 @@ - $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 2744763c7fbfe..8df4113d4392f 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 @@ public function testValidateWithTimestampOutOfSystemRangeThrowsException($range, } /** - * @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 5af6181770b7a..66edf78695dfb 100644 --- a/lib/internal/Magento/Framework/Test/Unit/ObjectTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/ObjectTest.php @@ -328,7 +328,7 @@ public function testToString() /** * 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 43ed43aedf902..093c3df126f8d 100644 --- a/lib/internal/Magento/Framework/Test/Unit/ShellTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/ShellTest.php @@ -111,7 +111,7 @@ public function executeDataProvider() } /** - * @expectedException \Magento\Framework\Exception + * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Command returned non-zero exit code: * @expectedExceptionCode 0 */ @@ -133,7 +133,7 @@ public function testExecuteFailureDetails($command, $commandArgs, $expectedError /* 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 e53d1dd145cbc..456eadcd11b81 100644 --- a/lib/internal/Magento/Framework/Url/ScopeResolver.php +++ b/lib/internal/Magento/Framework/Url/ScopeResolver.php @@ -39,7 +39,9 @@ public function getScope($scopeId = null) { $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 75b457c081394..dfffc00248b5c 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 @@ public function testGetScope($scopeId) } /** - * @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 5c4e34a97356e..5bc402bae8c4b 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 @@ public function testBuilderConfiguration() * 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 8144fc1660bfb..a7e94e698e2e4 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 @@ public function merge(array $assetsToMerge, Asset\LocalInterface $resultAsset) * @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 461ddb41c7456..bbfa28664ed34 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 @@ 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 @@ protected function process() $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 74a1518513ac4..7d5720fb4a8d6 100644 --- a/lib/internal/Magento/Framework/View/Asset/MinifyService.php +++ b/lib/internal/Magento/Framework/View/Asset/MinifyService.php @@ -100,22 +100,28 @@ protected function isEnabled($contentType) * * @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 @@ protected function getAdapter($contentType) * @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 fda21b7564074..4b6801310a375 100644 --- a/lib/internal/Magento/Framework/View/Asset/Repository.php +++ b/lib/internal/Magento/Framework/View/Asset/Repository.php @@ -346,7 +346,7 @@ public function getUrlWithParams($fileId, array $params) * * @param string $fileId * @return array - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public static function extractModule($fileId) { @@ -355,7 +355,9 @@ public static function extractModule($fileId) } $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 f3c8a76bd2896..7fa18b8bb0b96 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 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan * * @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 5ec518abeb1c5..0101382d06c32 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 @@ public function createPreviewImageCopy(ThemeInterface $theme) $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 da5596876a7f1..3e1a690653314 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 @@ public function __construct( * @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 @@ public function uploadPreviewImage($scope, $destinationPath) 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 @@ public function uploadPreviewImage($scope, $destinationPath) $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 278e493e671b8..cf0c87c49d3a4 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -261,12 +261,14 @@ protected function _prepareLayout() * 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 @@ public function getViewFileUrl($fileId, array $params = []) 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 2edd72d7e9d61..db731cdbabed6 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\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 @@ public function __construct( * @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 @@ public function getFiles(ThemeInterface $theme, $filePath) $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 c6b2596c14f49..c2184cfff688e 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -480,7 +480,7 @@ public function renderElement($name, $useCache = true) * * @param string $name * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _renderBlock($name) { @@ -493,7 +493,7 @@ protected function _renderBlock($name) * * @param string $name * @return string - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function _renderUiComponent($name) { @@ -906,12 +906,14 @@ public function getMessagesBlock() * * @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 d3fb8247a2336..e0ebfb972ca90 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 @@ public function generateContainer( /** * @param array $options * @return void - * @throws \Magento\Framework\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ protected function validateOptions($options) { @@ -111,11 +111,10 @@ protected function validateOptions($options) $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 @@ protected function validateOptions($options) || !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 42105c9e90b72..f008321a24922 100644 --- a/lib/internal/Magento/Framework/View/Layout/ProcessorInterface.php +++ b/lib/internal/Magento/Framework/View/Layout/ProcessorInterface.php @@ -93,7 +93,7 @@ public function isCustomerDesignAbstraction(array $abstraction); * 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 d656c2d0448a9..af3f01aa46e20 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 @@ public function interpret(Context $readerContext, Layout\Element $currentElement * * @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 @@ protected function scheduleMove(Layout\ScheduledStructure $scheduledStructure, L [$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 6f438e29c8f21..95c51d545c726 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 @@ public function getPageHandleType($handleName) * 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 @@ public function load($handles = []) 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 @@ protected function _substitutePlaceholders($xmlString) * * @param string $handle * @return string + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getDbUpdateString($handle) { @@ -666,7 +670,7 @@ protected function _saveCache($data, $cacheId, array $cacheTags = []) * 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 @@ protected function _loadFileLayoutUpdatesXml() 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 @@ protected function _logXmlErrors($fileName, $libXmlErrors) * * @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 @@ protected function _getPhysicalTheme(\Magento\Framework\View\Design\ThemeInterfa $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 9fe5599d6a992..f01721a2704d4 100644 --- a/lib/internal/Magento/Framework/View/Page/Config.php +++ b/lib/internal/Magento/Framework/View/Page/Config.php @@ -433,13 +433,15 @@ public function addBodyClass($className) * @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 ebfd7944a88aa..0f3b7cdf09f8d 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 @@ protected function renderAssetHtml($template, $assets) 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 e2f12e786c442..2fab155de5668 100644 --- a/lib/internal/Magento/Framework/View/Result/Page.php +++ b/lib/internal/Magento/Framework/View/Result/Page.php @@ -328,7 +328,7 @@ protected function getViewFileUrl($fileId, array $params = []) 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 d2d76f16bca98..2e31f4d67733e 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 @@ public function testGetAssetsDisabled() } /** - * @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 @@ public function testGetAssetsNoAdapterDefined() 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 1ee041ddd1ec0..60a2d297e4b5b 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 @@ private function mockDesign() } /** - * @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 07c1058228492..3204ae36d8cf8 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 @@ public function testCreateWithWrongThemeType() $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 8218420f5fcd0..603e49038c4e1 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 @@ public function uploadDataProvider() 'checkAllowedExtension' => true, 'save' => true, 'result' => false, - 'exception' => 'Magento\Framework\Exception' + 'exception' => 'Magento\Framework\Exception\LocalizedException' ], [ 'isUploaded' => true, @@ -110,7 +110,7 @@ public function uploadDataProvider() 'checkAllowedExtension' => false, 'save' => true, 'result' => false, - 'exception' => 'Magento\Framework\Exception' + 'exception' => 'Magento\Framework\Exception\LocalizedException' ], [ 'isUploaded' => true, @@ -118,7 +118,7 @@ public function uploadDataProvider() '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 00721963a9bed..1902c4884fe18 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 @@ public function testGetFilesWrongAncestor() { $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 07f1c2aca8be0..547b646035cf9 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 @@ public function processDataProvider() * @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 8d5c858b4e73a..1b3a28a7435e5 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 @@ public function processDataProvider() } /** - * @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 b2f6f82a775fe..281bb8ac0519d 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 = ''; + // @codingStandardsIgnoreEnd /** * @var \Magento\Framework\View\Model\Layout\Merge @@ -291,7 +293,10 @@ public function testLoadDbApp() $handles = ['fixture_handle_one']; $this->_model->load($handles); $this->assertEquals($handles, $this->_model->getHandles()); - $this->assertXmlStringEqualsXmlString('' . self::FIXTURE_LAYOUT_XML . '', $this->_model->asString()); + $this->assertXmlStringEqualsXmlString( + '' . self::FIXTURE_LAYOUT_XML . '', + $this->_model->asString() + ); } public function testGetFileLayoutUpdatesXml() @@ -378,7 +383,7 @@ public function testIsCustomDesignAbstractions() } /** - * @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 e407988f77df3..2917b75f72644 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 @@ public function testRenderAssets($groupOne, $groupTwo, $expectedResult) $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 403522b7aa4dc..ae61cf0509216 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 @@ public function elementAttributeDataProvider() */ 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 06b78b7c35cd5..75b9df3174ca2 100644 --- a/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php +++ b/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php @@ -100,7 +100,9 @@ public function maskException(\Exception $exception) $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 @@ public function maskException(\Exception $exception) } $maskedException = new WebapiException( - $exception->getRawMessage(), + new Phrase($exception->getRawMessage()), $exception->getCode(), $httpCode, $exception->getParameters(), @@ -128,8 +130,6 @@ public function maskException(\Exception $exception) $errors, $stackTrace ); - } elseif ($exception instanceof WebapiException) { - $maskedException = $exception; } else { $message = $exception->getMessage(); $code = $exception->getCode(); @@ -141,7 +141,7 @@ public function maskException(\Exception $exception) $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 b5b46c0e562bc..208202fb0c588 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 @@ public function __construct( 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 34f3936ce563c..ba0091bc725a7 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 @@ public function deserialize($encodedBody) 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 3fe5eb8c0dd14..35c2c95a4d52d 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 @@ public function deserialize($xmlRequestBody) 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 @@ public function deserialize($xmlRequestBody) */ 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 2d3b3e57561cd..d901cda77240e 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 @@ public function get($contentType) 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 75d2a77d1cbd9..df6496e33e57b 100644 --- a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php +++ b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php @@ -9,7 +9,6 @@ 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 @@ protected function _convertValue($value, $type) 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 2ca021aad4738..b98ebe0c941b9 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 @@ public function testSetWebapiExceptionException() { /** 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 @@ public function testSendResponseRenderMessagesException() \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 @@ public function testSendResponseRenderMessagesException() 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 @@ public function testSendResponseRenderMessagesHttpNotAcceptable() /** 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 @@ public function testSendResponseWithException() ); $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 02c762922afb4..08d82718d6b0c 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 @@ public function load($file) /** * @param string $string * @return $this + * @throws \Magento\Framework\Exception\LocalizedException */ public function loadXML($string) { @@ -158,9 +157,12 @@ public function loadXML($string) 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 @@ public function loadXML($string) * @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 aeddfa9afbad0..ed966cb8abfa2 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 @@ public function testGetXml() } /** - * @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 da913b7a32417..e9d7aa483c4c1 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\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 @@ private function deleteDirContents($type) $this->log->log("{$dirPath}{$path}"); try { $dir->delete($path); - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { $this->log->log($e->getMessage()); } } @@ -1232,7 +1232,7 @@ private function deleteDeploymentConfig() try { $this->log->log($absolutePath); $configDir->delete($file); - } catch (FilesystemException $e) { + } catch (FileSystemException $e) { $this->log->log($e->getMessage()); } }