/** * テストを実行する * @param string $class クラス名 * @param strgin $method メソッド名 */ public static final function verify($class, $method = null, $block_name = null) { if (!class_exists($class) && Rhaco::import($class)) { $pos = strrpos($class, "."); $class = substr($class, $pos !== false ? $pos + 1 : $pos); } $ref = Info::reflection($class); self::$current_file = $ref->path; self::$current_class = $ref->name; foreach ($ref->methods as $name => $m) { self::$current_method = $name; if ($method === null || $method == $name) { self::execute($m, $block_name); } } self::$current_class = null; self::$current_file = null; self::$current_method = null; return new self(); }
/** * テストを実行する * @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(); }