/** * Run scenario and optionally write results to report file * * @param string $scenarioFile * @param Magento_Performance_Scenario_Arguments $scenarioArguments * @param string|null $reportFile Report file to write results to, NULL disables report creation * @return bool Whether handler was able to process scenario */ public function run($scenarioFile, Magento_Performance_Scenario_Arguments $scenarioArguments, $reportFile = null) { if (pathinfo($scenarioFile, PATHINFO_EXTENSION) != 'jmx') { return false; } list($scenarioCmd, $scenarioCmdArgs) = $this->_buildScenarioCmd($scenarioFile, $scenarioArguments, $reportFile); $this->_shell->execute($scenarioCmd, $scenarioCmdArgs); if ($reportFile) { $this->_verifyReport($reportFile); } return true; }
/** * Run scenario and optionally write results to report file * * @param Magento_Performance_Scenario $scenario * @param string|null $reportFile Report file to write results to, NULL disables report creation * @throws Magento_Exception * @throws Magento_Performance_Scenario_FailureException */ public function run(Magento_Performance_Scenario $scenario, $reportFile = null) { $this->_validateScenarioExecutable(); $cmd = $this->_buildScenarioCmd($scenario, $reportFile); list($scenarioCmd, $scenarioCmdArgs) = $cmd; $this->_shell->execute($scenarioCmd, $scenarioCmdArgs); if ($reportFile) { if (!file_exists($reportFile)) { throw new Magento_Exception("Report file '{$reportFile}' for '{$scenario->getTitle()}' has not been created."); } $reportErrors = $this->_getReportErrors($reportFile); if ($reportErrors) { throw new Magento_Performance_Scenario_FailureException($scenario, implode(PHP_EOL, $reportErrors)); } } }
/** * Run performance testing scenario. * * @param string $scenarioFile * @param array $scenarioParams * @param string|null $reportFile */ protected function _runScenario($scenarioFile, array $scenarioParams, $reportFile = null) { list($scenarioCmd, $scenarioCmdArgs) = $this->_buildScenarioCmd($scenarioFile, $scenarioParams, $reportFile); $this->_shell->execute($scenarioCmd, $scenarioCmdArgs); if ($reportFile) { $this->_verifyReport($reportFile); } }
/** * Perform installation of Magento app * * @param array $options */ protected function _install($options) { $installCmd = 'php -f %s --'; $installCmdArgs = array($this->_installerScript); foreach ($options as $optionName => $optionValue) { $installCmd .= " --{$optionName} %s"; $installCmdArgs[] = $optionValue; } $this->_shell->execute($installCmd, $installCmdArgs); }
/** * Execute scenario and return measurement results * * @param Magento_Performance_Scenario $scenario * @return array */ protected function _executeScenario(Magento_Performance_Scenario $scenario) { list($scenarioCmd, $scenarioCmdArgs) = $this->_buildScenarioCmd($scenario); $result = array('title' => $scenario->getTitle(), 'timestamp' => time(), 'success' => true, 'time' => null, 'exit_code' => 0, 'output' => ''); $executionTime = microtime(true); try { $result['output'] = $this->_shell->execute($scenarioCmd, $scenarioCmdArgs); } catch (Magento_Exception $e) { $result['success'] = false; $result['exit_code'] = $e->getPrevious()->getCode(); $result['output'] = $e->getPrevious()->getMessage(); } $executionTime = microtime(true) - $executionTime; $executionTime *= 1000; // second -> millisecond $result['time'] = (int) round($executionTime); return $result; }
/** * Execute additional before/after scenario PHP script, if it exists * * @param string $scenarioFile * @param string $suffix * @param array $params * @return null|string * @throws Magento_Exception */ protected function _runScenarioAdditionalScript($scenarioFile, $suffix, $params = array()) { // Check existence of additional script $pathinfo = pathinfo($scenarioFile); $scriptFile = $pathinfo['dirname'] . DIRECTORY_SEPARATOR . "{$pathinfo['filename']}_{$suffix}.php"; if (!file_exists($scriptFile)) { return null; } // Run script $cmd = 'php %s'; $execParams = array($scriptFile); foreach ($params as $key => $value) { $cmd .= " --{$key}=%s"; $execParams[] = $value; } $output = $this->_shell->execute($cmd, $execParams); return $output; }
/** * Install application according to installation options * * @return Magento_Application * @throws Magento_Exception */ protected function _install() { $installOptions = $this->_config->getInstallOptions(); if (!$installOptions) { throw new Magento_Exception('Trying to install Magento, but installation options are not set'); } // Populate install options with global options $baseUrl = 'http://' . $this->_config->getApplicationUrlHost() . $this->_config->getApplicationUrlPath(); $installOptions = array_merge($installOptions, array('url' => $baseUrl, 'secure_base_url' => $baseUrl)); $adminOptions = $this->_config->getAdminOptions(); foreach ($adminOptions as $key => $val) { $installOptions['admin_' . $key] = $val; } $installCmd = 'php -f %s --'; $installCmdArgs = array($this->_installerScript); foreach ($installOptions as $optionName => $optionValue) { $installCmd .= " --{$optionName} %s"; $installCmdArgs[] = $optionValue; } $this->_shell->execute($installCmd, $installCmdArgs); $this->_isInstalled = true; $this->_fixtures = array(); return $this; }
/** * @expectedException Magento_Exception * @expectedExceptionMessage Command `non_existing_command` returned non-zero exit code * @expectedExceptionCode 0 */ public function testExecuteFailure() { $shell = new Magento_Shell(); $shell->execute('non_existing_command'); }
/** * Run reindex * * @return Application */ public function reindex() { $this->_shell->execute('php -f ' . MAGENTO_BASE_DIR . '/shell/indexer.php -- reindexall'); return $this; }
throw new Exception("glob() pattern '{$pattern}' returned empty result."); } $list = array_merge($list, $items); } } if (empty($list)) { throw new Exception('List of files or directories to delete is empty.'); } // verbosity argument $verbose = isset($options['v']); // perform "extrusion" $shell = new Magento_Shell($verbose); foreach ($list as $item) { if (!file_exists($item)) { throw new Exception("The file or directory '{$item} is marked for deletion, but it doesn't exist."); } $shell->execute('git --git-dir %s --work-tree %s rm -r -f -- %s', array("{$workingDir}/.git", $workingDir, $item)); if (file_exists($item)) { throw new Exception("The file or directory '{$item}' was supposed to be deleted, but it still exists."); } } exit(0); } catch (Exception $e) { if ($e->getPrevious()) { $message = (string) $e->getPrevious(); } else { $message = $e->getMessage(); } echo $message . PHP_EOL; exit(1); }
/** * Run reindex * * @return Application */ public function reindex() { $this->_shell->execute('php -f ' . TOOLKIT_BASE_DIR . '/indexer.php -- reindexall'); return $this; }