Ejemplo n.º 1
0
 /**
  * テストを実行する
  * @param string $class_path パッケージパス
  * @param string $method メソッド名
  * @param string $block_name ブロック名
  */
 public static final function verify($class_path, $method = null, $block_name = null)
 {
     if (is_file(self::path(str_replace(".", "/", $class_path) . "_test.php"))) {
         $file = App::path(str_replace(".", "/", $class_path) . ".php");
         $test = self::path(str_replace(".", "/", $class_path) . "_test.php");
         if (is_file($file)) {
             if (empty($block_name)) {
                 include $test;
             } else {
                 $read = File::read($test);
                 $block = $init = "";
                 foreach (preg_split("/(#\\s*[\\w_]+)\n/", $read, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE) as $v) {
                     if ($v[0][0] == "#") {
                         $block = trim(substr($v[0], 1));
                     } else {
                         if (empty($block)) {
                             $init = $v[0];
                         } else {
                             $blocks[$block] = $v;
                         }
                     }
                 }
                 if (isset($blocks[$block_name])) {
                     self::$current_map_test_file = $test;
                     self::$current_file = $test;
                     $line = sizeof(explode("\n", substr($read, 0, $blocks[$block_name][1]))) - sizeof(explode("\n", $init));
                     ob_start();
                     eval("?>" . $init . str_repeat("\n", $line) . $blocks[$block_name][0]);
                     $result = ob_get_clean();
                     if (preg_match("/(Parse|Fatal) error:.+/", $result, $match)) {
                         throw new ErrorException($match[0]);
                     }
                     self::$current_map_test_file = null;
                 }
             }
         } else {
             throw new InvalidArgumentException($file . " not found (" . $test . ")");
         }
     } else {
         $class = !class_exists($class_path) && !interface_exists($class_path) ? Lib::import($class_path) : $class_path;
         $cname = str_replace(".", "_", $class_path);
         $ref = new InfoClass($class);
         $is_setup = false;
         $is_teardown = false;
         if (method_exists($ref->name(), "__test_setup__")) {
             $m = new ReflectionMethod($ref->name(), "__test_setup__");
             $is_setup = $m->isStatic();
         }
         if (method_exists($ref->name(), "__test_teardown__")) {
             $m = new ReflectionMethod($ref->name(), "__test_teardown__");
             $is_teardown = $m->isStatic();
         }
         self::$current_file = $ref->path();
         self::$current_class = $ref->name();
         foreach (array_merge(array("class" => $ref->class_method()), $ref->self_methods_all()) as $name => $m) {
             self::$current_method = $name;
             if ($method === null || $method == $name) {
                 self::execute($m, $block_name, $class, $is_setup, $is_teardown);
             }
         }
         self::$current_class = null;
         self::$current_file = null;
         self::$current_method = null;
     }
     return new self();
 }
Ejemplo n.º 2
0
 private static function lib($repository)
 {
     if (!$repository->start("lib")) {
         return;
     }
     foreach (Lib::classes(true) as $class_path => $class) {
         $i = new InfoClass($class_path, false);
         $base_dir = Lib::path();
         $search_path = File::absolute($base_dir, str_replace(".", "/", $i->package()));
         $target = is_file($search_path . ".php") ? $search_path . ".php" : (is_file($search_path . "/" . basename($search_path) . ".php") ? $search_path : null);
         if ($target !== null) {
             $tgz_filename = $repository->tgz_path($i->package());
             File::tgz($tgz_filename, $target, $base_dir);
             touch($tgz_filename, File::last_update($target));
             $repository->add($i->package(), $i->name(), File::last_update($i->path()), $i->document());
         }
     }
 }