Example #1
0
 public function testInstall()
 {
     $this->_shell->expects($this->once())->method('execute')->with('php -f %s -- --option1 %s --option2 %s', array($this->_installerScript, 'value1', 'value 2'));
     $this->_object->expects($this->once())->method('_bootstrap');
     $this->_object->expects($this->once())->method('_reindex');
     $this->_object->install(array('option1' => 'value1', 'option2' => 'value 2'));
 }
Example #2
0
 public function testCleanup()
 {
     $expectedSqlFile = __DIR__ . DIRECTORY_SEPARATOR . 'drop_create_database.sql';
     $this->_model->expects($this->once())->method('_createScript')->with($expectedSqlFile, 'DROP DATABASE `schema`; CREATE DATABASE `schema`');
     $this->_shell->expects($this->once())->method('execute')->with('mysql --protocol=TCP --host=%s --user=%s --password=%s %s < %s', array('host', 'user', 'pass', 'schema', $expectedSqlFile));
     $this->_model->cleanup();
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * Builds application mocked object, so it will produce tracked events, used for fixture application testing
  *
  * @return Magento_Application|PHPUnit_Framework_MockObject_MockObject
  */
 protected function _buildApplicationForFixtures()
 {
     $test = $this;
     $funcShellEvent = function ($command, $arguments) use($test) {
         $command = vsprintf($command, $arguments);
         if (strpos($command, 'uninstall') !== false) {
             $test->addAppEvent('uninstall');
         } else {
             if (strpos($command, 'install') !== false) {
                 $test->addAppEvent('install');
             }
         }
     };
     $this->_shell->expects($this->any())->method('execute')->will($this->returnCallback($funcShellEvent));
     $app = $this->getMock('Magento_Application', array('_bootstrap', '_reindex', '_updateFilesystemPermissions', '_cleanupMage'), array($this->_config, $this->_shell));
     // @codingStandardsIgnoreStart
     $app->expects($this->any())->method('_bootstrap')->will($this->returnCallback(function () use($test, $app) {
         $test->addAppEvent('bootstrap');
         return $app;
     }));
     $app->expects($this->any())->method('_reindex')->will($this->returnCallback(function () use($test, $app) {
         $test->addAppEvent('reindex');
         return $app;
     }));
     $app->expects($this->any())->method('_updateFilesystemPermissions')->will($this->returnCallback(function () use($test, $app) {
         $test->addAppEvent('updateFilesystemPermissions');
         return $app;
     }));
     // @codingStandardsIgnoreEnd
     return $app;
 }
Example #5
0
 /**
  * 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));
         }
     }
 }
Example #6
0
 /**
  * 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);
     }
 }
Example #7
0
 public function testRunWithScripts()
 {
     $scenarioFile = realpath(__DIR__ . '/_files/scenario_with_scripts.jmx');
     $scriptBefore = realpath(__DIR__ . '/_files/scenario_with_scripts_before.php');
     $scriptAfter = realpath(__DIR__ . '/_files/scenario_with_scripts_after.php');
     $this->_shell->expects($this->at(0))->method('execute')->with('php %s', array($scriptBefore))->will($this->returnValue('fixture output'));
     $this->_shell->expects($this->at(3))->method('execute')->with('php %s --beforeOutput=%s --scenarioExecutions=%s', array($scriptAfter, 'fixture output', 4));
     $this->_object->run($scenarioFile, $this->_scenarioParams);
 }
Example #8
0
 /**
  * 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);
 }
Example #9
0
 public function testApplyFixturesIncompatibleSetReinstallation()
 {
     $this->_shell->expects($this->at(0))->method('execute')->with($this->stringContains('--uninstall'), $this->contains($this->_installerScript));
     $this->_shell->expects($this->at(1))->method('execute')->with($this->logicalNot($this->stringContains('--uninstall')), $this->contains($this->_installerScript));
     $this->_shell->expects($this->at(2))->method('execute')->with($this->stringContains('--uninstall'), $this->contains($this->_installerScript));
     $this->_shell->expects($this->at(3))->method('execute')->with($this->logicalNot($this->stringContains('--uninstall')), $this->contains($this->_installerScript));
     $fixtures = $this->_getFixtureFiles(array('fixture1', 'fixture2'));
     $this->_object->applyFixtures($fixtures);
     $incompatibleSet = $this->_getFixtureFiles(array('fixture1'));
     $this->_object->applyFixtures($incompatibleSet);
 }
Example #10
0
 /**
  * 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;
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * 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;
 }
Example #13
0
 /**
  * @expectedException Magento_Performance_Scenario_FailureException
  * @expectedExceptionMessage command failure message
  */
 public function testRunException()
 {
     $failure = new Magento_Exception('Command returned non-zero exit code.', 0, new Exception('command failure message', 1));
     $this->_shell->expects($this->any())->method('execute')->will($this->throwException($failure));
     $this->_object->run($this->_scenarioFile, $this->_scenarioArgs);
 }
Example #14
0
 /**
  * @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');
 }
Example #15
0
 public function testRun()
 {
     $this->_shell->expects($this->at(0))->method('execute')->with('java -jar %s -n -t %s %s %s %s %s', array('JMeter.jar', $this->_scenarioFile, '-Jhost=127.0.0.1', '-Jpath=/', '-Jusers=1', '-Jloops=2'));
     $this->_shell->expects($this->at(1))->method('execute')->with('java -jar %s -n -t %s -l %s %s %s %s %s', array('JMeter.jar', $this->_scenarioFile, $this->_reportFile, '-Jhost=127.0.0.1', '-Jpath=/', '-Jusers=2', '-Jloops=1'));
     $this->_object->run($this->_scenarioFile, $this->_scenarioParams);
 }
 /**
  * Run reindex
  *
  * @return Application
  */
 public function reindex()
 {
     $this->_shell->execute('php -f ' . MAGENTO_BASE_DIR . '/shell/indexer.php -- reindexall');
     return $this;
 }
 /**
  * Run reindex
  *
  * @return Application
  */
 public function reindex()
 {
     $this->_shell->execute('php -f ' . TOOLKIT_BASE_DIR . '/indexer.php -- reindexall');
     return $this;
 }
Example #18
0
            }
            $pattern = $workingDir . DIRECTORY_SEPARATOR . $pattern;
            $items = glob($pattern, GLOB_BRACE);
            if (empty($items)) {
                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();
Example #19
0
 public function testRunReport()
 {
     $this->_shell->expects($this->once())->method('execute')->with('jmeter -n -t %s -l %s %s %s %s %s', array($this->_scenarioFile, $this->_reportFile, '-Jhost=127.0.0.1', '-Jpath=/', '-Jusers=2', '-Jloops=3'));
     $this->_object->run($this->_scenario, $this->_reportFile);
 }
Example #20
0
 public function testOutput()
 {
     $fixture = uniqid();
     $this->expectOutputString($fixture . PHP_EOL);
     $shell = new Magento_Shell();
     $shell->output($fixture);
 }