コード例 #1
0
ファイル: zesk-generate-tests.php プロジェクト: zesk/zesk
function generate_class_tests($file, $dest_path, $class)
{
    global $verbose;
    include_once $file;
    $x = new ReflectionClass("{$class}");
    if ($x->isAbstract() || $x->isInternal() || $x->isInterface()) {
        if ($verbose) {
            echo "Class {$class} is internal, abstract, or an interface ... skipping.\n";
        }
        return;
    }
    $class_test_file = true;
    $old_dest_file = path($dest_path, "class.{$class}.phpt");
    $dest_file = path($dest_path, "{$class}.phpt");
    if (file_exists($old_dest_file) && !file_exists($dest_file)) {
        echo "svn mv {$old_dest_file} {$dest_file}\n";
        return;
    }
    if (file_exists($dest_file)) {
        if (zesk::getb('force-create') || zesk::getb('force-create-classes')) {
            if ($verbose) {
                echo "Overwriting destination file {$dest_file} due to force flags...\n";
            }
        } else {
            if ($verbose) {
                echo "Skipping because destination file {$dest_file} exists ...\n";
            }
            // Set flag so file is not generated, but static function tests are
            $class_test_file = false;
        }
    }
    $contents = test_file_header($file, $dest_file, false);
    $functions = extract_class_functions($x, $class);
    $exclude_functions = array();
    $has_non_static_methods = false;
    foreach ($functions as $method => $params) {
        if (in_array($method, $exclude_functions)) {
            continue;
        }
        $param_list = array();
        foreach ($params as $k => $v) {
            $param_list[] = '$' . $k;
            $contents[] = '$' . $k . ' = ' . PHP::dump($v) . ";";
        }
        if (begins($method, "new ")) {
            $prefix = '$testx = ';
            $has_non_static_methods = true;
        } else {
            if (begins($method, "::")) {
                $method_name = str_replace('::', '', $method);
                $method_object = $x->getMethod($method_name);
                $methodParams = $method_object->getParameters();
                generate_static_class_method_test($file, $dest_path, $class, $method_name, $methodParams);
                continue;
            } else {
                if (begins($method, "->")) {
                    $prefix = '$testx';
                    $has_non_static_methods = true;
                } else {
                    continue;
                }
            }
        }
        $contents[] = $prefix . $method . '(' . implode(", ", $param_list) . ');';
        $contents[] = "";
    }
    if (!$class_test_file) {
        return;
    }
    if (!$has_non_static_methods) {
        return;
    }
    $contents[] = "echo basename(__FILE__) . \": success\\n\";";
    if (!zesk::getb('dry-run')) {
        file_put_contents($dest_file, implode("\n", $contents));
        chmod($dest_file, 0775);
        echo "Wrote {$dest_file} ...\n";
    } else {
        echo "Would write {$dest_file} ...\n";
    }
}
コード例 #2
0
ファイル: index.php プロジェクト: vbarbarosh/app_file_manager
     } else {
         $middle = render_str('foobar/audio', array('src' => 'image.php?' . http_build_query(array('f' => $file->realpath()))));
     }
     break;
 case 'video/mp4':
     if (begins($file->realpath(), $_SERVER['DOCUMENT_ROOT'])) {
         $middle = render_str('foobar/video', array('src' => replace_prefix($file->realpath(), $_SERVER['DOCUMENT_ROOT'], '/')));
     } else {
         $middle = render_str('foobar/video', array('src' => 'image.php?' . http_build_query(array('f' => $file->realpath()))));
     }
     break;
 case 'image/svg+xml':
 case 'image/png':
 case 'image/jpeg':
 case 'image/gif':
     if (begins($file->realpath(), $_SERVER['DOCUMENT_ROOT'])) {
         $middle = render_str('foobar/thumbnail', array('src' => replace_prefix($file->realpath(), $_SERVER['DOCUMENT_ROOT'], '/')));
     } else {
         $middle = render_str('foobar/thumbnail', array('src' => 'image.php?' . http_build_query(array('f' => $file->realpath()))));
     }
     break;
 case 'application/zip':
     $fields = array(new TableField('Name', 'name'), new TableFieldFormat('CRC', 'crc', 'dechex'), new TableFieldFormat('Size', 'size', 'format_bytes'), new TableFieldFormat('Compressed', 'comp_size', 'format_bytes'), new TableField('Method', 'comp_method'), new TableFieldFormat('Time', 'mtime', 'format_date_mysql'));
     $zip = new ZipArchive();
     $zip->open($file->realpath());
     $rows = array();
     for ($index = 0, $end = $zip->numFiles; $index < $end; ++$index) {
         $rows[] = new TableRow($zip->statIndex($index), $fields);
     }
     $zip->close();
     $middle = render_str('foobar/table', compact('fields', 'rows'));