Example #1
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();
 }