/** * @dataProvider checkUpdateDataProvider * @param bool $callInbox * @param string $curlRequest */ public function testCheckUpdate($callInbox, $curlRequest) { $mockName = 'Test Product Name'; $mockVersion = '0.0.0'; $mockEdition = 'Test Edition'; $mockUrl = 'http://test-url'; $this->productMetadata->expects($this->once())->method('getName')->willReturn($mockName); $this->productMetadata->expects($this->once())->method('getVersion')->willReturn($mockVersion); $this->productMetadata->expects($this->once())->method('getEdition')->willReturn($mockEdition); $this->urlBuilder->expects($this->once())->method('getUrl')->with('*/*/*')->willReturn($mockUrl); $configValues = ['timeout' => 2, 'useragent' => $mockName . '/' . $mockVersion . ' (' . $mockEdition . ')', 'referer' => $mockUrl]; $lastUpdate = 0; $this->cacheManager->expects($this->once())->method('load')->will($this->returnValue($lastUpdate)); $this->curlFactory->expects($this->at(0))->method('create')->will($this->returnValue($this->curl)); $this->curl->expects($this->once())->method('setConfig')->with($configValues)->willReturnSelf(); $this->curl->expects($this->once())->method('read')->will($this->returnValue($curlRequest)); $this->backendConfig->expects($this->at(0))->method('getValue')->will($this->returnValue('1')); $this->backendConfig->expects($this->once())->method('isSetFlag')->will($this->returnValue(false)); $this->backendConfig->expects($this->at(1))->method('getValue')->will($this->returnValue('http://feed.magento.com')); $this->deploymentConfig->expects($this->once())->method('get')->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE)->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC')); if ($callInbox) { $this->inboxFactory->expects($this->once())->method('create')->will($this->returnValue($this->inboxModel)); $this->inboxModel->expects($this->once())->method('parse')->will($this->returnSelf()); } else { $this->inboxFactory->expects($this->never())->method('create'); $this->inboxModel->expects($this->never())->method('parse'); } $this->feed->checkUpdate(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $notification = 'setup-cron: Please check var/log/update.log for execution summary.'; if (!$this->deploymentConfig->isAvailable()) { $output->writeln($notification); $this->status->add('Magento is not installed.', \Psr\Log\LogLevel::INFO); return \Magento\Framework\Console\Cli::RETURN_SUCCESS; } if (!$this->checkRun()) { $output->writeln($notification); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } try { $this->status->toggleUpdateInProgress(); } catch (\RuntimeException $e) { $this->status->add($e->getMessage(), \Psr\Log\LogLevel::ERROR); $output->writeln($notification); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $returnCode = $this->executeJobsFromQueue(); if ($returnCode != \Magento\Framework\Console\Cli::RETURN_SUCCESS) { $output->writeln($notification); } return $returnCode; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable() && ($input->getOption(self::INPUT_KEY_MEDIA) || $input->getOption(self::INPUT_KEY_DB))) { $output->writeln("<info>No information is available: the Magento application is not installed.</info>"); return; } try { $inputOptionProvided = false; $output->writeln('<info>Enabling maintenance mode</info>'); $this->maintenanceMode->set(true); $time = time(); $backupHandler = $this->backupRollbackFactory->create($output); if ($input->getOption(self::INPUT_KEY_CODE)) { $backupHandler->codeBackup($time); $inputOptionProvided = true; } if ($input->getOption(self::INPUT_KEY_MEDIA)) { $backupHandler->codeBackup($time, Factory::TYPE_MEDIA); $inputOptionProvided = true; } if ($input->getOption(self::INPUT_KEY_DB)) { $backupHandler->dbBackup($time); $inputOptionProvided = true; } if (!$inputOptionProvided) { throw new \InvalidArgumentException('Not enough information provided to take backup.'); } } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } finally { $output->writeln('<info>Disabling maintenance mode</info>'); $this->maintenanceMode->set(false); } }
/** * @param \Magento\Framework\Math\Random $randomGenerator * @param DeploymentConfig $deploymentConfig */ public function __construct(\Magento\Framework\Math\Random $randomGenerator, DeploymentConfig $deploymentConfig) { $this->randomGenerator = $randomGenerator; // load all possible keys $this->keys = preg_split('/\\s+/s', trim($deploymentConfig->get(self::PARAM_CRYPT_KEY))); $this->keyVersion = count($this->keys) - 1; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable() && ($input->getOption(self::INPUT_KEY_MEDIA_BACKUP_FILE) || $input->getOption(self::INPUT_KEY_DB_BACKUP_FILE))) { $output->writeln("<info>No information is available: the Magento application is not installed.</info>"); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $returnValue = \Magento\Framework\Console\Cli::RETURN_SUCCESS; try { $output->writeln('<info>Enabling maintenance mode</info>'); $this->maintenanceMode->set(true); $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('<info>You are about to remove current code and/or database tables. Are you sure?[y/N]<info>', false); if (!$helper->ask($input, $output, $question) && $input->isInteractive()) { return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $this->doRollback($input, $output); $output->writeln('<info>Please set file permission of bin/magento to executable</info>'); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); // we must have an exit code higher than zero to indicate something was wrong $returnValue = \Magento\Framework\Console\Cli::RETURN_FAILURE; } finally { $output->writeln('<info>Disabling maintenance mode</info>'); $this->maintenanceMode->set(false); } return $returnValue; }
public function testExecuteNoOptions() { $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); $this->tester->execute([]); $expected = 'Enabling maintenance mode' . PHP_EOL . 'Not enough information provided to take backup.' . PHP_EOL . 'Disabling maintenance mode' . PHP_EOL; $this->assertSame($expected, $this->tester->getDisplay()); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>No information is available: the Magento application is not installed.</info>"); return; } /** @var DbVersionInfo $dbVersionInfo */ $dbVersionInfo = $this->objectManagerProvider->get()->get('Magento\\Framework\\Module\\DbVersionInfo'); $outdated = $dbVersionInfo->getDbVersionErrors(); if (!empty($outdated)) { $output->writeln("<info>The module code base doesn't match the DB schema and data.</info>"); $versionParser = new VersionParser(); $codebaseUpdateNeeded = false; foreach ($outdated as $row) { if (!$codebaseUpdateNeeded && $row[DbVersionInfo::KEY_CURRENT] !== 'none') { // check if module code base update is needed $currentVersion = $versionParser->parseConstraints($row[DbVersionInfo::KEY_CURRENT]); $requiredVersion = $versionParser->parseConstraints('>' . $row[DbVersionInfo::KEY_REQUIRED]); if ($requiredVersion->matches($currentVersion)) { $codebaseUpdateNeeded = true; } } $output->writeln(sprintf("<info>%20s %10s: %11s -> %-11s</info>", $row[DbVersionInfo::KEY_MODULE], $row[DbVersionInfo::KEY_TYPE], $row[DbVersionInfo::KEY_CURRENT], $row[DbVersionInfo::KEY_REQUIRED])); } if ($codebaseUpdateNeeded) { $output->writeln('<info>Some modules use code versions newer or older than the database. ' . "First update the module code, then run 'setup:upgrade'.</info>"); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } else { $output->writeln("<info>Run 'setup:upgrade' to update your DB schema and data.</info>"); } } else { $output->writeln('<info>All modules are up to date.</info>'); } }
public function testExecuteNotInstalled() { $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); $this->installerFactory->expects($this->never())->method('create'); $tester = new CommandTester($this->command); $tester->execute([]); $this->assertStringMatchesFormat("Store settings can't be saved because the Magento application is not installed.%w", $tester->getDisplay()); }
public function testExecuteNotInstalled() { $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); $this->dbVersionInfo->expects($this->never())->method('getDbVersionErrors'); $tester = new CommandTester($this->command); $tester->execute([]); $this->assertStringMatchesFormat('No information is available: the Magento application is not installed.%w', $tester->getDisplay()); }
public function testExecuteNoConfig() { $this->deploymentConfig->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); $this->installerFactory->expects($this->never())->method('create'); $commandTester = new CommandTester(new DbDataUpgradeCommand($this->installerFactory, $this->deploymentConfig)); $commandTester->execute([]); $this->assertStringMatchesFormat('No information is available: the application is not installed.%w', $commandTester->getDisplay()); }
public function testRemoveModulesFromDeploymentConfig() { $this->output->expects($this->atLeastOnce())->method('writeln'); $this->deploymentConfig->expects($this->once())->method('getConfigData')->willReturn(['moduleA' => 1, 'moduleB' => 1, 'moduleC' => 1, 'moduleD' => 1]); $this->loader->expects($this->once())->method('load')->willReturn(['moduleC' => [], 'moduleD' => []]); $this->writer->expects($this->once())->method('saveConfig')->with([ConfigFilePool::APP_CONFIG => [ConfigOptionsListConstants::KEY_MODULES => ['moduleC' => 1, 'moduleD' => 1]]]); $this->moduleRegistryUninstaller->removeModulesFromDeploymentConfig($this->output, ['moduleA', 'moduleB']); }
public function testExecute() { $this->deploymentConfig->expects($this->once())->method('get')->willReturn('admin_qw12er'); $commandTester = new CommandTester(new InfoAdminUriCommand($this->deploymentConfig)); $commandTester->execute([]); $regexp = '/' . BackendFrontnameGenerator::ADMIN_AREA_PATH_PREFIX . '[a-z0-9]{1,' . BackendFrontnameGenerator::ADMIN_AREA_PATH_RANDOM_PART_LENGTH . '}/'; $this->assertRegExp($regexp, $commandTester->getDisplay(), 'Unexpected Backend Frontname pattern.'); }
/** * Read communication configuration from env.php * * @param string|null $scope * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function read($scope = null) { $configData = $this->deploymentConfig->getConfigData(self::ENV_COMMUNICATION); if ($configData) { $this->envValidator->validate($configData); } return $configData ?: []; }
/** * @param \Magento\Backend\App\Config $config * @param DeploymentConfig $deploymentConfig * @param ScopeConfigInterface $configInterface */ public function __construct( \Magento\Backend\App\Config $config, DeploymentConfig $deploymentConfig, ScopeConfigInterface $configInterface ) { $this->config = $config; $this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME); $this->configInterface = $configInterface; }
public function testGetters() { $this->reader->expects($this->once())->method('load')->willReturn(self::$fixture); $this->assertSame(self::$flattenedFixture, $this->_deploymentConfig->get()); // second time to ensure loader will be invoked only once $this->assertSame(self::$flattenedFixture, $this->_deploymentConfig->get()); $this->assertSame('scalar_value', $this->_deploymentConfig->getSegment('segment1')); $this->assertSame(self::$fixture['segment2'], $this->_deploymentConfig->getSegment('segment2')); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>No information is available: the application is not installed.</info>"); return; } $installer = $this->installFactory->create(new ConsoleLogger($output)); $installer->installSchema(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>Store settings can't be saved because the Magento application is not installed.</info>"); return; } $installer = $this->installerFactory->create(new ConsoleLogger($output)); $installer->installUserConfig($input->getOptions()); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $value = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CUSTOM_OPTION); if ($value) { $output->writeln('<info>The custom deployment configuration value is ' . $value . '</info>'); } else { $output->writeln('<info>The custom deployment configuration value is not set.</info>'); } }
/** * @param Config\Reader $reader * @param \Magento\Framework\Config\ScopeInterface $configScope * @param \Magento\Framework\Config\CacheInterface $cache * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig * @param string $cacheId * @throws \InvalidArgumentException */ public function __construct(Config\Reader $reader, \Magento\Framework\Config\ScopeInterface $configScope, \Magento\Framework\Config\CacheInterface $cache, \Magento\Framework\App\DeploymentConfig $deploymentConfig, $cacheId = 'resourcesCache') { parent::__construct($reader, $configScope, $cache, $cacheId); foreach ($deploymentConfig->getConfigData(ConfigOptionsList::KEY_RESOURCE) as $resourceName => $resourceData) { if (!isset($resourceData['connection'])) { throw new \InvalidArgumentException('Invalid initial resource configuration'); } $this->_connectionNames[$resourceName] = $resourceData['connection']; } }
/** * Constructor * * @param SaveHandlerFactory $saveHandlerFactory * @param DeploymentConfig $deploymentConfig * @param string $default */ public function __construct(SaveHandlerFactory $saveHandlerFactory, DeploymentConfig $deploymentConfig, $default = self::DEFAULT_HANDLER) { $saveMethod = $deploymentConfig->get(\Magento\Framework\Session\Config::PARAM_SESSION_SAVE_METHOD); try { $adapter = $saveHandlerFactory->create($saveMethod); } catch (SessionException $e) { $adapter = $saveHandlerFactory->create($default); } $this->saveHandlerAdapter = $adapter; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->deploymentConfig->isAvailable()) { $output->writeln("<info>No information is available: the Magento application is not installed.</info>"); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $installer = $this->installFactory->create(new ConsoleLogger($output)); $installer->installDataFixtures(); }
public function setUp() { $this->_connectionFactory = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Type\\Db\\ConnectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->_config = $this->getMockBuilder('Magento\\Framework\\App\\Resource\\ConfigInterface')->disableOriginalConstructor()->setMethods(['getConnectionName'])->getMock(); $this->_config->expects($this->any())->method('getConnectionName')->with(self::RESOURCE_NAME)->will($this->returnValue(self::CONNECTION_NAME)); $this->deploymentConfig = $this->getMock('Magento\\Framework\\App\\DeploymentConfig', [], [], '', false); $this->deploymentConfig->expects($this->any())->method('get')->will($this->returnValue(['default' => ['host' => 'localhost', 'dbname' => 'magento', 'username' => 'username'], self::CONNECTION_NAME => ['host' => 'localhost', 'dbname' => 'magento', 'username' => 'username']])); $this->connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface'); $this->connection->expects($this->any())->method('getTableName')->will($this->returnArgument(0)); $this->resource = new Resource($this->_config, $this->_connectionFactory, $this->deploymentConfig, self::TABLE_PREFIX); }
/** * Removes module from deployment configuration * * @param OutputInterface $output * @param string[] $modules * @return void */ public function removeModulesFromDeploymentConfig(OutputInterface $output, array $modules) { $output->writeln('<info>Removing ' . implode(', ', $modules) . ' from module list in deployment configuration</info>'); $configuredModules = $this->deploymentConfig->getConfigData(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES); $existingModules = $this->loader->load($modules); $newModules = []; foreach (array_keys($existingModules) as $module) { $newModules[$module] = isset($configuredModules[$module]) ? $configuredModules[$module] : 0; } $this->writer->saveConfig([\Magento\Framework\Config\File\ConfigFilePool::APP_CONFIG => [\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES => $newModules]], true); }
/** * {@inheritdoc} */ public function createConfig(array $options, DeploymentConfig $deploymentConfig) { $configData = new ConfigData(ConfigFilePool::APP_CONFIG); if (isset($options[self::INPUT_KEY_CUSTOM_OPTION])) { $configData->set(self::CONFIG_PATH_CUSTOM_OPTION, $options[self::INPUT_KEY_CUSTOM_OPTION]); } elseif ($deploymentConfig->get(self::CONFIG_PATH_CUSTOM_OPTION) === null) { // set to default value if it is not already set in deployment configuration $configData->set(self::CONFIG_PATH_CUSTOM_OPTION, 'default custom value'); } return [$configData]; }
/** * @param string|null $fixtureSegment * @param string $inputCacheType * @param string $expectedFrontendId * * @dataProvider getDataProvider */ public function testGet($fixtureSegment, $inputCacheType, $expectedFrontendId) { $this->_deploymentConfig->expects($this->once())->method('getSegment')->with(\Magento\Framework\App\DeploymentConfig\CacheConfig::CONFIG_KEY)->will($this->returnValue($fixtureSegment)); $cacheFrontend = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface'); $this->_cachePool->expects($this->once())->method('get')->with($expectedFrontendId)->will($this->returnValue($cacheFrontend)); $accessProxy = $this->getMock('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', [], [], '', false); $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', $this->identicalTo(['frontend' => $cacheFrontend, 'identifier' => $inputCacheType]))->will($this->returnValue($accessProxy)); $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); // Result has to be cached in memory $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); }
public function setUp() { $this->connectionFactory = $this->getMockBuilder(ConnectionFactoryInterface::class)->setMethods(['create'])->getMockForAbstractClass(); $this->config = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection\\ConfigInterface')->disableOriginalConstructor()->setMethods(['getConnectionName'])->getMock(); $this->config->expects($this->any())->method('getConnectionName')->with(self::RESOURCE_NAME)->will($this->returnValue(self::CONNECTION_NAME)); $this->deploymentConfig = $this->getMock('Magento\\Framework\\App\\DeploymentConfig', [], [], '', false); $this->deploymentConfig->expects($this->any())->method('get')->willReturnMap([[ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/connection-name', null, ['host' => 'localhost', 'dbname' => 'magento', 'username' => 'username']], [ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX, null, self::TABLE_PREFIX]]); $this->connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface'); $this->connection->expects($this->any())->method('getTableName')->will($this->returnArgument(0)); $this->resource = new ResourceConnection($this->config, $this->connectionFactory, $this->deploymentConfig); }
public function setUp() { $this->collector = $this->getMock('Magento\\Setup\\Model\\ConfigOptionsListCollector', [], [], '', false); $this->writer = $this->getMock('Magento\\Framework\\App\\DeploymentConfig\\Writer', [], [], '', false); $this->deploymentConfig = $this->getMock('Magento\\Framework\\App\\DeploymentConfig', [], [], '', false); $this->configOptionsList = $this->getMock('Magento\\Backend\\Setup\\ConfigOptionsList', [], [], '', false); $this->configData = $this->getMock('Magento\\Framework\\Config\\Data\\ConfigData', [], [], '', false); $this->filePermissions = $this->getMock('\\Magento\\Framework\\Setup\\FilePermissions', [], [], '', false); $this->deploymentConfig->expects($this->any())->method('get'); $this->configModel = new ConfigModel($this->collector, $this->writer, $this->deploymentConfig, $this->filePermissions); }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function createConfig(array $options, DeploymentConfig $deploymentConfig) { $configData = new ConfigData(ConfigFilePool::APP_ENV); if (!$deploymentConfig->get(self::CONFIG_PATH_BACKEND_FRONTNAME) && !isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) { $options[self::INPUT_KEY_BACKEND_FRONTNAME] = BackendFrontnameGenerator::generate(); } if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) { $configData->set(self::CONFIG_PATH_BACKEND_FRONTNAME, $options[self::INPUT_KEY_BACKEND_FRONTNAME]); } return [$configData]; }
/** * Retrieve settings for all cache front-ends known to the system * * @return array Format: array('<frontend_id>' => array(<cache_settings>), ...) */ protected function _getCacheSettings() { /* * Merging is intentionally implemented through array_merge() instead of array_replace_recursive() * to avoid "inheritance" of the default settings that become irrelevant as soon as cache storage type changes */ $cacheInfo = $this->deploymentConfig->getConfigData(FrontendPool::KEY_CACHE); if (null !== $cacheInfo) { return array_merge($this->_frontendSettings, $cacheInfo[FrontendPool::KEY_FRONTEND_CACHE]); } return $this->_frontendSettings; }
/** * @param ServiceLocatorInterface $serviceLocator * @param DeploymentConfig $deploymentConfig */ public function __construct(ServiceLocatorInterface $serviceLocator, DeploymentConfig $deploymentConfig) { if ($deploymentConfig->isAvailable()) { $this->navStates = $serviceLocator->get('config')[self::NAV_UPDATER]; $this->navType = self::NAV_UPDATER; $this->titles = $serviceLocator->get('config')[self::NAV_UPDATER . 'Titles']; } else { $this->navStates = $serviceLocator->get('config')[self::NAV_INSTALLER]; $this->navType = self::NAV_INSTALLER; $this->titles = $serviceLocator->get('config')[self::NAV_INSTALLER . 'Titles']; } }