예제 #1
0
 /**
  * Updates test guy class.
  *
  * @since 1.0.0
  *
  * @access public
  * @param SuiteEvent $e Event object.
  */
 public function updateGuy(SuiteEvent $e)
 {
     $settings = $e->getSettings();
     $guyFile = $settings['path'] . $settings['class_name'] . '.php';
     // load guy class to see hash
     $handle = fopen($guyFile, "r");
     if ($handle) {
         $line = fgets($handle);
         if (preg_match('~\\[STAMP\\] ([a-f0-9]*)~', $line, $matches)) {
             $hash = $matches[1];
             $currentHash = Actor::genHash(SuiteManager::$actions, $settings);
             // regenerate guy class when hashes do not match
             if ($hash != $currentHash) {
                 codecept_debug("Rebuilding {$settings['class_name']}...");
                 $guyGenerator = new Actor($settings);
                 fclose($handle);
                 $generated = $guyGenerator->produce();
                 file_put_contents($guyFile, $generated);
                 return;
             }
         }
         fclose($handle);
     }
 }
예제 #2
0
 /**
  * Builds actors for suites.
  *
  * @since 1.0.0
  *
  * @access protected
  * @param string $configFile Alternative config file name.
  */
 protected function buildActorsForConfig($configFile)
 {
     $config = $this->getGlobalConfig($configFile);
     $suites = $this->getSuites($configFile);
     $path = pathinfo($configFile);
     $dir = isset($path['dirname']) ? $path['dirname'] : getcwd();
     foreach ($config['include'] as $subConfig) {
         $this->output->writeln("<comment>Included Configuration: {$subConfig}</comment>");
         $this->buildActorsForConfig($dir . DIRECTORY_SEPARATOR . $subConfig);
     }
     if (!empty($suites)) {
         $this->output->writeln("<info>Building Actor classes for suites: " . implode(', ', $suites) . '</info>');
     }
     foreach ($suites as $suite) {
         $settings = $this->getSuiteConfig($suite, $configFile);
         $gen = new ActorGenerator($settings);
         $this->output->writeln('<info>' . Configuration::config()['namespace'] . '\\' . $gen->getActorName() . "</info> includes modules: " . implode(', ', $gen->getModules()));
         $contents = $gen->produce();
         @mkdir($settings['path'], 0755, true);
         $file = $settings['path'] . $this->getClassName($settings['class_name']) . '.php';
         $this->save($file, $contents, true);
         $this->output->writeln("{$settings['class_name']}.php generated successfully. " . $gen->getNumMethods() . " methods added");
     }
 }