예제 #1
0
 /**
  * process event
  *
  * @param Charcoal_IEventContext $context   event context
  *
  * @return boolean
  */
 public function processEvent($context)
 {
     $request = $context->getRequest();
     //        $response  = $context->getResponse();
     //        $sequence  = $context->getSequence();
     //        $procedure = $context->getProcedure();
     // get paramter from command line
     $target_module = $request->getString('p1');
     if (strlen($target_module) === 0) {
         echo 'target_module is needed.' . PHP_EOL;
         echo 'charcoal [target_module] [param1] [param2]...' . PHP_EOL;
         return TRUE;
     }
     $context->loadModule($target_module);
     // create shell_command event and push it into the event queue
     /** @var Charcoal_IEvent $event */
     $event = $context->createEvent('shell_command');
     $context->pushEvent($event);
     return b(true);
 }
 /**
  * process event
  *
  * @param Charcoal_IEventContext $context   event context
  *
  * @return Charcoal_Boolean|bool
  */
 public function processEvent($context)
 {
     $request = $context->getRequest();
     //        $response  = $context->getResponse();
     //        $sequence  = $context->getSequence();
     //        $procedure = $context->getProcedure();
     echo PHP_EOL;
     echo "==========================================" . PHP_EOL;
     echo "CharcoalPHP Test Runner" . PHP_EOL;
     echo "   Framework Version:" . Charcoal_Framework::getVersion() . PHP_EOL;
     echo "==========================================" . PHP_EOL;
     // get paramter from command line
     $scenario = $request->getString('scenario');
     $scenario = trim($scenario);
     log_debug("debug,scenario", "scenario: {$scenario}");
     if ($scenario === NULL) {
         echo "actions or scenario parameter must be specified." . PHP_EOL;
         log_error("debug,error,scenario", "actions or scenario parameter must be specified.");
         return TRUE;
     }
     $scenario_file = $this->scenario_dir . '/' . $scenario . '.scenario.ini';
     if (!is_file($scenario_file)) {
         echo "scenario file not found: {$scenario_file}" . PHP_EOL;
         log_error("debug,error,scenario", "scenario file not found: {$scenario_file}");
         return TRUE;
     }
     $scenario_data = parse_ini_file($scenario_file, TRUE);
     log_debug("debug,scenario", "scenario_data: " . print_r($scenario_data, true));
     if (empty($scenario_data)) {
         echo "couldn't read scenario file: {$scenario_file}" . PHP_EOL;
         log_error("debug,error,scenario", "couldn't read scenario file: {$scenario_file}");
         return TRUE;
     }
     foreach ($scenario_data as $section => $data) {
         $target = isset($data['target']) ? $data['target'] : NULL;
         $actions = isset($data['actions']) ? $data['actions'] : NULL;
         $enabled = isset($data['enabled']) ? $data['enabled'] : TRUE;
         log_debug("debug,scenario", "target: {$target}");
         log_debug("debug,scenario", "actions: {$actions}");
         log_debug("debug,scenario", "enabled: {$enabled}");
         if (in_array(strtolower($enabled), array('0', 'false', 'no'))) {
             echo "section[{$section}] is DISABLED. will skip." . PHP_EOL;
             log_warning("debug, scenario", "section[{$section}] is DISABLED.");
             continue;
         }
         if (empty($target)) {
             echo "[WARNING] 'target' is not found at section[{$section}]" . PHP_EOL;
             log_warning("debug, scenario", "'target' is not found at section[{$section}]");
             continue;
         }
         if (empty($actions)) {
             echo "[WARNING] 'actions' is not found at section[{$section}]" . PHP_EOL;
             log_warning("debug, scenario", "'actions' is not found at section[{$section}]");
             continue;
         }
         $target_path = new Charcoal_ObjectPath($target);
         $module_path = '@' . $target_path->getVirtualPath();
         $context->loadModule($module_path);
         log_info("debug,scenario", "loaded module: {$module_path}");
         $event_args = array($section, $target, $actions);
         /** @var Charcoal_IEvent $event */
         $event = $context->createEvent('test', $event_args);
         $context->pushEvent($event);
         log_debug("debug,scenario", "event_args: " . print_r($event_args, true));
         log_debug("debug,scenario", "pushed event: " . print_r($event, true));
     }
     // request fo test summary
     /** @var Charcoal_IEvent $event */
     $event = $context->createEvent('test_summary');
     $context->pushEvent($event);
     return TRUE;
 }