示例#1
0
 /**
  * Check if all prerequisites for running unit tests are fullfilled or can
  * be fulfilled by using Jumpstorm.
  *
  * @param string $extensionPath Path to the extension to be evaluated
  * @throws \Exception
  */
 protected function _setupUnitTestEnvironment($extensionPath)
 {
     /**
      * getting the neccessary information like magento target from
      * the jumpstorm configuration even jumpstorm is not used to set up
      * the test environment
      */
     if (!$this->_settings->jumpstormIniFile) {
         throw new \Exception("Required information missing in ini file: plugins.CodeCoverage.jumpstormIniFile");
     }
     $jumpstormConfig = new \Zend_Config_Ini($this->_settings->jumpstormIniFile, null, array('allowModifications' => true));
     // check if required ini section is given
     if (!$jumpstormConfig->common) {
         throw new \Exception("Required information missing in jumpstorm ini file: [common]");
     }
     if ($this->_config->token) {
         $jumpstormConfig->common->magento->target = $jumpstormConfig->common->magento->target . '_' . $this->_config->token;
         $jumpstormConfig->common->db->name = $jumpstormConfig->common->db->name . '_' . $this->_config->token;
     }
     $this->_magentoTarget = rtrim($jumpstormConfig->common->magento->target, DIRECTORY_SEPARATOR);
     $this->_testDbName = $jumpstormConfig->common->db->name;
     // import test environment configuration from console: [extensions] section
     $jumpstormConfig->extensions = array('extension' => array('source' => $extensionPath));
     // force (re)installation using jumpstorm
     if ($this->_settings->useJumpstorm) {
         $requiredSections = array('magento', 'unittesting');
         foreach ($requiredSections as $section) {
             if (!$jumpstormConfig->{$section}) {
                 throw new \Exception("Required information missing in jumpstorm ini file: [{$section}]");
             }
         }
         $iniFile = 'tmp/jumpstorm' . (string) $this->_config->token . '.ini';
         $writer = new \Zend_Config_Writer_Ini();
         $writer->write($iniFile, $jumpstormConfig);
         $executable = 'vendor/netresearch/jumpstorm/jumpstorm';
         $params = '';
         if (Logger::VERBOSITY_MAX == Logger::getVerbosity()) {
             $params .= ' -v';
         }
         $command = sprintf('%s magento -c %s %s', $executable, $iniFile, $params) . ' && ' . sprintf('%s unittesting -c %s %s', $executable, $iniFile, $params) . ' && ' . sprintf('%s extensions -c %s %s', $executable, $iniFile, $params);
         Logger::notice('Setting up Magento environment via Jumpstorm');
         $output = $this->_executeCommand($command);
         if (Logger::VERBOSITY_MAX == Logger::getVerbosity()) {
             Logger::log(implode("\n", $output));
         }
         unlink($iniFile);
     }
 }