diff --git a/app/code/Magento/Backend/Model/Session/AdminConfig.php b/app/code/Magento/Backend/Model/Session/AdminConfig.php index 155a9b09528fc..9dced89caf30d 100644 --- a/app/code/Magento/Backend/Model/Session/AdminConfig.php +++ b/app/code/Magento/Backend/Model/Session/AdminConfig.php @@ -84,6 +84,7 @@ public function __construct( $adminPath = $this->extractAdminPath(); $this->setCookiePath($adminPath); $this->setName($sessionName); + $this->setCookieSecure($this->_httpRequest->isSecure()); } /** diff --git a/app/code/Magento/Backend/Test/Unit/Model/Session/AdminConfigTest.php b/app/code/Magento/Backend/Test/Unit/Model/Session/AdminConfigTest.php index 24baab2a0298e..a521d497fe55e 100644 --- a/app/code/Magento/Backend/Test/Unit/Model/Session/AdminConfigTest.php +++ b/app/code/Magento/Backend/Test/Unit/Model/Session/AdminConfigTest.php @@ -105,12 +105,14 @@ public function testSetCookiePathNonDefault() } /** - * Test for setting session name for admin - * + * Test for setting session name and secure_cookie for admin + * @dataProvider requestSecureDataProvider + * @param $secureRequest */ - public function testSetSessionNameByConstructor() + public function testSetSessionSettingsByConstructor($secureRequest) { $sessionName = 'admin'; + $this->requestMock->expects($this->once())->method('isSecure')->willReturn($secureRequest); $validatorMock = $this->getMockBuilder('Magento\Framework\Validator\ValidatorInterface') ->disableOriginalConstructor() @@ -136,5 +138,11 @@ public function testSetSessionNameByConstructor() ] ); $this->assertSame($sessionName, $adminConfig->getName()); + $this->assertSame($secureRequest, $adminConfig->getCookieSecure()); + } + + public function requestSecureDataProvider() + { + return [[true], [false]]; } } diff --git a/lib/internal/Magento/Framework/Setup/BackupRollback.php b/lib/internal/Magento/Framework/Setup/BackupRollback.php index 4b7584f4709be..92b7a12711277 100644 --- a/lib/internal/Magento/Framework/Setup/BackupRollback.php +++ b/lib/internal/Magento/Framework/Setup/BackupRollback.php @@ -197,7 +197,6 @@ public function codeRollback($rollbackFile, $type = Factory::TYPE_FILESYSTEM) */ public function dbBackup($time) { - $this->setAreaCode(); /** @var \Magento\Framework\Backup\Db $dbBackup */ $dbBackup = $this->objectManager->create('Magento\Framework\Backup\Db'); $dbBackup->setRootDir($this->directoryList->getRoot()); @@ -233,7 +232,6 @@ public function dbRollback($rollbackFile) if (!$this->file->isExists($this->backupsDir . '/' . $rollbackFile)) { throw new LocalizedException(new Phrase('The rollback file does not exist.')); } - $this->setAreaCode(); /** @var \Magento\Framework\Backup\Db $dbRollback */ $dbRollback = $this->objectManager->create('Magento\Framework\Backup\Db'); $dbRollback->setRootDir($this->directoryList->getRoot()); @@ -253,22 +251,6 @@ public function dbRollback($rollbackFile) $this->log->logSuccess('DB rollback completed successfully.'); } - /** - * Sets area code to start a session for database backup and rollback - * - * @return void - */ - private function setAreaCode() - { - $areaCode = 'adminhtml'; - /** @var \Magento\Framework\App\State $appState */ - $appState = $this->objectManager->get('Magento\Framework\App\State'); - $appState->setAreaCode($areaCode); - /** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */ - $configLoader = $this->objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface'); - $this->objectManager->configure($configLoader->load($areaCode)); - } - /** * Get paths that should be excluded during iterative searches for locations for code backup only * diff --git a/setup/pub/magento/setup/complete-backup.js b/setup/pub/magento/setup/complete-backup.js index 5cfc61e8a15c7..70c9ecfd113fb 100644 --- a/setup/pub/magento/setup/complete-backup.js +++ b/setup/pub/magento/setup/complete-backup.js @@ -10,7 +10,7 @@ angular.module('complete-backup', ['ngStorage']) if ($localStorage.backupInfo) { $scope.backupInfoPassed = $localStorage.backupInfo; } - + $scope.type = $state.current.type; $scope.progressCounter = BACKUPCOUNTER; @@ -111,13 +111,20 @@ angular.module('complete-backup', ['ngStorage']) $scope.files = files; $scope.updateOnProcessed($scope.create.responseType); $scope.stopProgress(); + $scope.disableMeintenanceMode(); }, fail: function() { $scope.requestFailedHandler($scope.create); + $scope.disableMeintenanceMode(); } } }; + $scope.disableMeintenanceMode = function() { + $http.post('index.php/maintenance/index', {'disable' : true}).success(function(data) { + }); + }; + $scope.isCompleted = function() { return $scope.maintenance.processed && $scope.check.processed diff --git a/setup/src/Magento/Setup/Console/Command/BackupCommand.php b/setup/src/Magento/Setup/Console/Command/BackupCommand.php index e9e6e16fdf5b4..622b65e6a92a2 100644 --- a/setup/src/Magento/Setup/Console/Command/BackupCommand.php +++ b/setup/src/Magento/Setup/Console/Command/BackupCommand.php @@ -132,6 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $inputOptionProvided = true; } if ($input->getOption(self::INPUT_KEY_DB)) { + $this->setAreaCode(); $backupHandler->dbBackup($time); $inputOptionProvided = true; } @@ -147,4 +148,20 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->maintenanceMode->set(false); } } + + /** + * Sets area code to start a session for database backup and rollback + * + * @return void + */ + private function setAreaCode() + { + $areaCode = 'adminhtml'; + /** @var \Magento\Framework\App\State $appState */ + $appState = $this->objectManager->get('Magento\Framework\App\State'); + $appState->setAreaCode($areaCode); + /** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */ + $configLoader = $this->objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface'); + $this->objectManager->configure($configLoader->load($areaCode)); + } } diff --git a/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php b/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php index c08bfaa1290bd..8d41b82bd8931 100644 --- a/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php +++ b/setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php @@ -280,6 +280,7 @@ private function takeBackup(InputInterface $input, OutputInterface $output) } if ($input->getOption(self::INPUT_KEY_BACKUP_DB)) { $dbBackup = $this->backupRollbackFactory->create($output); + $this->setAreaCode(); $dbBackup->dbBackup($time); } } @@ -359,4 +360,20 @@ private function checkDependencies(array $modules) } return $messages; } + + /** + * Sets area code to start a session for database backup and rollback + * + * @return void + */ + private function setAreaCode() + { + $areaCode = 'adminhtml'; + /** @var \Magento\Framework\App\State $appState */ + $appState = $this->objectManager->get('Magento\Framework\App\State'); + $appState->setAreaCode($areaCode); + /** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */ + $configLoader = $this->objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface'); + $this->objectManager->configure($configLoader->load($areaCode)); + } } diff --git a/setup/src/Magento/Setup/Console/Command/RollbackCommand.php b/setup/src/Magento/Setup/Console/Command/RollbackCommand.php index 13be58d9f73b4..7264138ad08d2 100644 --- a/setup/src/Magento/Setup/Console/Command/RollbackCommand.php +++ b/setup/src/Magento/Setup/Console/Command/RollbackCommand.php @@ -157,6 +157,7 @@ private function doRollback(InputInterface $input, OutputInterface $output) $inputOptionProvided = true; } if ($input->getOption(self::INPUT_KEY_DB_BACKUP_FILE)) { + $this->setAreaCode(); $rollbackHandler->dbRollback($input->getOption(self::INPUT_KEY_DB_BACKUP_FILE)); $inputOptionProvided = true; } @@ -166,4 +167,20 @@ private function doRollback(InputInterface $input, OutputInterface $output) ); } } + + /** + * Sets area code to start a session for database backup and rollback + * + * @return void + */ + private function setAreaCode() + { + $areaCode = 'adminhtml'; + /** @var \Magento\Framework\App\State $appState */ + $appState = $this->objectManager->get('Magento\Framework\App\State'); + $appState->setAreaCode($areaCode); + /** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */ + $configLoader = $this->objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface'); + $this->objectManager->configure($configLoader->load($areaCode)); + } } diff --git a/setup/src/Magento/Setup/Controller/Maintenance.php b/setup/src/Magento/Setup/Controller/Maintenance.php index 1bcfdd2af321e..073cfb4389de8 100644 --- a/setup/src/Magento/Setup/Controller/Maintenance.php +++ b/setup/src/Magento/Setup/Controller/Maintenance.php @@ -8,6 +8,7 @@ use Magento\Framework\App\MaintenanceMode; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\JsonModel; +use Zend\Json\Json; class Maintenance extends AbstractActionController { @@ -36,7 +37,9 @@ public function __construct(MaintenanceMode $maintenanceMode) public function indexAction() { try { - $this->maintenanceMode->set(true); + $params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY); + $action = isset($params['disable']) && $params['disable'] ? false : true; + $this->maintenanceMode->set($action); return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]); } catch (\Exception $e) { return new JsonModel( diff --git a/setup/src/Magento/Setup/Controller/Session.php b/setup/src/Magento/Setup/Controller/Session.php index b8c318bad9be1..60dca02721977 100644 --- a/setup/src/Magento/Setup/Controller/Session.php +++ b/setup/src/Magento/Setup/Controller/Session.php @@ -6,23 +6,31 @@ namespace Magento\Setup\Controller; use Zend\Mvc\Controller\AbstractActionController; -use Magento\Setup\Model\ObjectManagerProvider; +use Zend\View\Model\JsonModel; use Zend\View\Model\ViewModel; class Session extends AbstractActionController { /** - * @var \Magento\Framework\ObjectManagerInterface + * @var \Zend\ServiceManager\ServiceManager */ - private $objectManager; + private $serviceManager; /** + * @var \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider + */ + private $objectManagerProvider; + + /** + * @param \Zend\ServiceManager\ServiceManager $serviceManager * @param \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider */ public function __construct( - ObjectManagerProvider $objectManagerProvider + \Zend\ServiceManager\ServiceManager $serviceManager, + \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider ) { - $this->objectManager = $objectManagerProvider->get(); + $this->serviceManager = $serviceManager; + $this->objectManagerProvider = $objectManagerProvider; } /** @@ -33,15 +41,16 @@ public function __construct( public function prolongAction() { try { - if ($this->objectManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { + if ($this->serviceManager->get('Magento\Framework\App\DeploymentConfig')->isAvailable()) { + $objectManager = $this->objectManagerProvider->get(); /** @var \Magento\Framework\App\State $adminAppState */ - $adminAppState = $this->objectManager->get('Magento\Framework\App\State'); + $adminAppState = $objectManager->get('Magento\Framework\App\State'); $adminAppState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMIN); /* @var \Magento\Backend\Model\Auth\Session $session */ - $sessionConfig = $this->objectManager->get('Magento\Backend\Model\Session\AdminConfig'); + $sessionConfig = $objectManager->get('Magento\Backend\Model\Session\AdminConfig'); $sessionConfig->setCookiePath('/setup'); - $session = $this->objectManager->create( + $session = $objectManager->create( 'Magento\Backend\Model\Auth\Session', [ 'sessionConfig' => $sessionConfig, @@ -49,11 +58,11 @@ public function prolongAction() ] ); $session->prolong(); - return \Zend_Json::encode(['success' => true]); + return new JsonModel(['success' => true]); } } catch (\Exception $e) { } - return \Zend_Json::encode(['success' => false]); + return new JsonModel(['success' => false]); } /** diff --git a/setup/src/Magento/Setup/Model/Cron/AbstractJob.php b/setup/src/Magento/Setup/Model/Cron/AbstractJob.php index b6bbec0fdc3dc..735e81c6f116e 100644 --- a/setup/src/Magento/Setup/Model/Cron/AbstractJob.php +++ b/setup/src/Magento/Setup/Model/Cron/AbstractJob.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Magento\Framework\App\Cache; +use Magento\Framework\ObjectManagerInterface; /** * Abstract class for jobs run by setup:cron:run command @@ -48,6 +49,11 @@ abstract class AbstractJob */ protected $status; + /** + * @var ObjectManagerInterface + */ + protected $objectManager; + /** * Constructor @@ -70,9 +76,9 @@ public function __construct( $this->name = $name; $this->params = $params; - $objectManager = $objectManagerProvider->get(); - $this->cleanupFiles = $objectManager->get('Magento\Framework\App\State\CleanupFiles'); - $this->cache = $objectManager->get('Magento\Framework\App\Cache'); + $this->objectManager = $objectManagerProvider->get(); + $this->cleanupFiles = $this->objectManager->get('Magento\Framework\App\State\CleanupFiles'); + $this->cache = $this->objectManager->get('Magento\Framework\App\Cache'); } /** diff --git a/setup/src/Magento/Setup/Model/Cron/JobComponentUninstall.php b/setup/src/Magento/Setup/Model/Cron/JobComponentUninstall.php index 588ac12881418..7d0e40a956a8d 100644 --- a/setup/src/Magento/Setup/Model/Cron/JobComponentUninstall.php +++ b/setup/src/Magento/Setup/Model/Cron/JobComponentUninstall.php @@ -39,7 +39,7 @@ class JobComponentUninstall extends AbstractJob /** * @var \Magento\Framework\ObjectManagerInterface */ - private $objectManager; + protected $objectManager; /** * @var \Magento\Setup\Model\Updater diff --git a/setup/src/Magento/Setup/Model/Cron/JobDbRollback.php b/setup/src/Magento/Setup/Model/Cron/JobDbRollback.php index ffb48a2085d90..5ff8240280be3 100644 --- a/setup/src/Magento/Setup/Model/Cron/JobDbRollback.php +++ b/setup/src/Magento/Setup/Model/Cron/JobDbRollback.php @@ -54,6 +54,7 @@ public function execute() $rollbackHandler = $this->backupRollbackFactory->create($this->output); $dbBackupFile = $this->params['backup_file_name']; if (!empty($dbBackupFile)) { + $this->setAreaCode(); $rollbackHandler->dbRollback(basename($dbBackupFile)); } else { $this->status->add( @@ -70,4 +71,20 @@ public function execute() ); } } + + /** + * Sets area code to start a session for database backup and rollback + * + * @return void + */ + private function setAreaCode() + { + $areaCode = 'adminhtml'; + /** @var \Magento\Framework\App\State $appState */ + $appState = $this->objectManager->get('Magento\Framework\App\State'); + $appState->setAreaCode($areaCode); + /** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */ + $configLoader = $this->objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface'); + $this->objectManager->configure($configLoader->load($areaCode)); + } } diff --git a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php index 3cff8f077ac54..78432801e0fa7 100644 --- a/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php +++ b/setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php @@ -16,6 +16,7 @@ use Zend\EventManager\ListenerAggregateInterface; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; +use Zend\Mvc\Router\Http\RouteMatch; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; use Zend\Stdlib\RequestInterface; @@ -39,6 +40,18 @@ class InitParamListener implements ListenerAggregateInterface, FactoryInterface */ private $listeners = []; + /** + * List of controllers which should be skipped from auth check + * + * @var array + */ + private $controllersToSkip = [ + 'Magento\Setup\Controller\Session', + 'Magento\Setup\Controller\Install', + 'Magento\Setup\Controller\Success' + + ]; + /** * {@inheritdoc} */ @@ -80,11 +93,12 @@ public function onBootstrap(MvcEvent $e) $serviceManager->setService('Magento\Framework\App\Filesystem\DirectoryList', $directoryList); $serviceManager->setService('Magento\Framework\Filesystem', $this->createFilesystem($directoryList)); - $eventManager = $application->getEventManager(); - $eventManager->attach(MvcEvent::EVENT_DISPATCH, [$this, 'authPreDispatch'], 1); + if (!($application->getRequest() instanceof Request)) { + $eventManager = $application->getEventManager(); + $eventManager->attach(MvcEvent::EVENT_DISPATCH, [$this, 'authPreDispatch'], 100); + } } - /** * Check if user login * @@ -94,12 +108,11 @@ public function onBootstrap(MvcEvent $e) */ public function authPreDispatch($event) { - $controller = $event->getTarget(); - if ( - !$controller instanceof \Magento\Setup\Controller\Session && - !$controller instanceof \Magento\Setup\Controller\Install && - !$controller instanceof \Magento\Setup\Controller\Success - ) { + /** @var RouteMatch $routeMatch */ + $routeMatch = $event->getRouteMatch(); + $controller = $routeMatch->getParam('controller'); + + if (!in_array($controller, $this->controllersToSkip)) { /** @var Application $application */ $application = $event->getApplication(); $serviceManager = $application->getServiceManager(); @@ -119,7 +132,12 @@ public function authPreDispatch($event) ); if (!$objectManager->get('Magento\Backend\Model\Auth')->isLoggedIn()) { - $controller->plugin('redirect')->toUrl('index.php/session/unlogin'); + $response = $event->getResponse(); + $response->getHeaders()->addHeaderLine('Location', 'index.php/session/unlogin'); + $response->setStatusCode(302); + + $event->stopPropagation(); + return $response; } } } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/BackupCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/BackupCommandTest.php index 78b4bf38511ab..4ecc35504b24f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/BackupCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/BackupCommandTest.php @@ -58,9 +58,30 @@ public function setUp() ->method('create') ->willReturn($this->backupRollback); $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); + $appState = $this->getMock( + 'Magento\Framework\App\State', + [], + [], + '', + false + ); + $configLoader = $this->getMockForAbstractClass( + 'Magento\Framework\ObjectManager\ConfigLoaderInterface', + [], + '', + false + ); + $configLoader->expects($this->any())->method('load')->willReturn([]); + $this->objectManager->expects($this->any()) ->method('get') - ->will($this->returnValue($this->backupRollbackFactory)); + ->will( + $this->returnValueMap([ + ['Magento\Framework\Setup\BackupRollbackFactory', $this->backupRollbackFactory], + ['Magento\Framework\App\State', $appState], + ['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader], + ]) + ); $command = new BackupCommand( $objectManagerProvider, $maintenanceMode, diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleUninstallCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleUninstallCommandTest.php index 4781cb29badf6..1c2c74b56a0d2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleUninstallCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/ModuleUninstallCommandTest.php @@ -124,6 +124,13 @@ public function setUp() $this->cache = $this->getMock('Magento\Framework\App\Cache', [], [], '', false); $this->cleanupFiles = $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false); $objectManagerProvider->expects($this->any())->method('get')->willReturn($objectManager); + $configLoader = $this->getMockForAbstractClass( + 'Magento\Framework\ObjectManager\ConfigLoaderInterface', + [], + '', + false + ); + $configLoader->expects($this->any())->method('load')->willReturn([]); $objectManager->expects($this->any()) ->method('get') ->will($this->returnValueMap([ @@ -133,6 +140,7 @@ public function setUp() ['Magento\Framework\App\State\CleanupFiles', $this->cleanupFiles], ['Magento\Framework\App\State', $this->getMock('Magento\Framework\App\State', [], [], '', false)], ['Magento\Framework\Setup\BackupRollbackFactory', $this->backupRollbackFactory], + ['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader], ])); $composer = $this->getMock('Magento\Framework\Composer\ComposerInformation', [], [], '', false); $composer->expects($this->any()) diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/RollbackCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/RollbackCommandTest.php index 02f9e9956bb57..b94657466c949 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/RollbackCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/RollbackCommandTest.php @@ -73,10 +73,26 @@ public function setUp() $this->backupRollbackFactory->expects($this->any()) ->method('create') ->willReturn($this->backupRollback); + $appState = $this->getMock( + 'Magento\Framework\App\State', + [], + [], + '', + false + ); + $configLoader = $this->getMockForAbstractClass( + 'Magento\Framework\ObjectManager\ConfigLoaderInterface', + [], + '', + false + ); + $configLoader->expects($this->any())->method('load')->willReturn([]); $this->objectManager->expects($this->any()) ->method('get') ->will($this->returnValueMap([ ['Magento\Framework\Setup\BackupRollbackFactory', $this->backupRollbackFactory], + ['Magento\Framework\App\State', $appState], + ['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader], ])); $this->helperSet = $this->getMock('Symfony\Component\Console\Helper\HelperSet', [], [], '', false); $this->question = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper', [], [], '', false); diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/SessionTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/SessionTest.php index 7c1eadba29796..efb1773500777 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/SessionTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/SessionTest.php @@ -20,13 +20,19 @@ class SessionTest extends \PHPUnit_Framework_TestCase */ private $objectManagerProvider; + /** + * @var \Zend\ServiceManager\ServiceManager + */ + private $serviceManager; + public function setUp() { $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false); $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', ['get'], [], '', false); - $objectManagerProvider->expects($this->once())->method('get')->will($this->returnValue($objectManager)); $this->objectManager = $objectManager; $this->objectManagerProvider = $objectManagerProvider; + + $this->serviceManager = $this->getMock('Zend\ServiceManager\ServiceManager', ['get'], [], '', false); } /** @@ -34,6 +40,9 @@ public function setUp() */ public function testUnloginAction() { + $this->objectManagerProvider->expects($this->once())->method('get')->will( + $this->returnValue($this->objectManager) + ); $deployConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', ['isAvailable'], [], '', false); $deployConfigMock->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); @@ -45,11 +54,12 @@ public function testUnloginAction() $sessionConfigMock->expects($this->once())->method('setCookiePath'); $returnValueMap = [ - ['Magento\Framework\App\DeploymentConfig', $deployConfigMock], ['Magento\Framework\App\State', $stateMock], ['Magento\Backend\Model\Session\AdminConfig', $sessionConfigMock] ]; + $this->serviceManager->expects($this->once())->method('get')->will($this->returnValue($deployConfigMock)); + $this->objectManager->expects($this->atLeastOnce()) ->method('get') ->will($this->returnValueMap($returnValueMap)); @@ -58,7 +68,7 @@ public function testUnloginAction() $this->objectManager->expects($this->once()) ->method('create') ->will($this->returnValue($sessionMock)); - $controller = new Session($this->objectManagerProvider); + $controller = new Session($this->serviceManager, $this->objectManagerProvider); $controller->prolongAction(); } @@ -68,7 +78,7 @@ public function testUnloginAction() public function testIndexAction() { /** @var $controller Session */ - $controller = new Session($this->objectManagerProvider); + $controller = new Session($this->serviceManager, $this->objectManagerProvider); $viewModel = $controller->unloginAction(); $this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel); } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobDbRollbackTest.php b/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobDbRollbackTest.php index 0f18eccd1ef82..3c7d57f578916 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobDbRollbackTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobDbRollbackTest.php @@ -48,7 +48,28 @@ public function setup() $output = $this->getMockForAbstractClass('Symfony\Component\Console\Output\OutputInterface', [], '', false); $this->objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false); + $appState = $this->getMock( + 'Magento\Framework\App\State', + [], + [], + '', + false + ); + $configLoader = $this->getMockForAbstractClass( + 'Magento\Framework\ObjectManager\ConfigLoaderInterface', + [], + '', + false + ); + $configLoader->expects($this->any())->method('load')->willReturn([]); $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false); + $objectManager->expects($this->any()) + ->method('get') + ->will($this->returnValueMap([ + ['Magento\Framework\App\State', $appState], + ['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader], + ])); + $this->objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager); $this->jobDbRollback = new JobDbRollback(