Exemplo n.º 1
0
 public function run(array $config)
 {
     $actionName = $config['actionName'];
     $fileExists = false;
     $classPath = str_replace('_', '/', $actionName);
     $classPath = str_replace('\\', '/', $classPath);
     foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $path) {
         if (file_exists($path . "/{$classPath}.php")) {
             $fileExists = true;
             break;
         }
     }
     if (!$fileExists) {
         return;
     }
     $methodName = $config['methodName'];
     $config = Configure::get('laiz.action.Validator');
     $handleByMethod = (bool) $config['handleByMethod'];
     if ($handleByMethod) {
         if (isset($this->validatorResult->_success)) {
             if ($this->validatorResult->_success) {
                 $methodName = 'valid';
             } else {
                 $methodName = 'invalid';
             }
         }
     }
     $ret = Component_Runner::run($actionName, $config, $methodName);
     if (isset($config['result']['*']) && !$ret) {
         $ret = 'action:' . $config['result']['*'];
     }
     return $ret;
 }
Exemplo n.º 2
0
 /**
  * @param $defaultMethod string
  */
 public function main(array $config, $defaultMethod)
 {
     foreach ($config as $key => $val) {
         if (strlen(trim($val)) === 0) {
             continue;
         }
         $method = $defaultMethod;
         if (strpos($val, '.')) {
             list($class, $method) = explode('.', $val);
         } else {
             $class = $val;
         }
         $thisConfig = array();
         $iniFile = str_replace('_', '/', $class);
         $iniFile = str_replace('\\', '/', $iniFile);
         $cfg = $this->parser->parse($iniFile);
         if ($cfg === false) {
             $cfg = array();
         }
         $ret = Component_Runner::run($class, $cfg, $method);
         if ($ret) {
             return $ret;
         }
     }
 }
Exemplo n.º 3
0
 private function allTest(ActionTests $tests, $container)
 {
     if ($this->a) {
         $assertOption = Assert::VIEW_ALL;
     } else {
         $assertOption = Assert::VIEW_FAILURE;
     }
     if ($this->v) {
         $assertOption |= Assert::VIEW_VERBOSE;
     }
     $assert = new Assert($assertOption);
     // commandline temporarily off
     $commandConfigurable = $container->get('laiz.command.Action');
     $commandConfigurable->setUnuse();
     foreach ($tests as $test) {
         /*
          * Prepare
          */
         $actionName = $test->getActionName();
         // new clean instance
         $actionRunner = $container->create('laiz.action.Runner');
         $opts = $actionRunner->parseOpts($actionName);
         $configs = $actionRunner->getConfigs($opts['actionName']);
         Component_Runner::prepare($test, $configs);
         /*
          * Testing Prepare
          */
         if (method_exists($test, 'testProp')) {
             $test->testProp($assert);
         }
         /*
          * Testing Run
          */
         $methods = get_class_methods($test);
         foreach ($methods as $method) {
             if (!preg_match('/^test/', $method)) {
                 continue;
             }
             if ($method === 'testPrep') {
                 continue;
             }
             // new clean instance
             $action = $container->create($opts['actionName']);
             Component_Runner::prepare($action, $configs);
             // initialize request arguments
             $ref = new ReflectionObject($action);
             $refMethod = $ref->getMethod($method);
             $comment = $refMethod->getDocComment();
             if ($comment && preg_match_all("/@ActionTest +request:(.+)/", $comment, $matches)) {
                 foreach ($matches[1] as $line) {
                     $requests = explode('=', $line, 2);
                     if (count($requests) !== 2) {
                         continue;
                     }
                     if (!property_exists($action, $requests[0])) {
                         continue;
                     }
                     $action->{$requests}[0] = $requests[1];
                 }
             }
             if ($comment && preg_match('/@ActionTest +selfact/', $comment, $matches)) {
                 // need call act method yourself
                 $ret = $action->{$method}($assert);
             } else {
                 if ($comment && preg_match('/@ActionTest +arguments:(.+)/', $comment, $matches)) {
                     // call act method with mock arguments
                     $args = array();
                     foreach (explode(',', $matches[1]) as $arg) {
                         $args[] = $container->create(trim($arg));
                     }
                     $ret = call_user_func_array(array($action, $opts['methodName']), $args);
                     array_unshift($args, $assert);
                     call_user_func_array(array($action, $method), $args);
                 } else {
                     $ret = Component_Runner::exec($action, $opts['methodName']);
                     $action->{$method}($assert);
                 }
             }
             if ($comment && preg_match("/@ActionTest +return:(.+)/", $comment, $matches)) {
                 $this->testReturnValue($assert, $ret, $matches[1]);
             }
         }
     }
     $assert->showResult();
     $commandConfigurable->setUse();
 }