Esempio n. 1
0
    $matches = false;
    if (preg_match_all('|function\\s+([A-Za-z_][A-Za-z_0-9]*)\\s*\\(([^\\)]*)\\)|', $content, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
            $func = $match[1];
            echo "### {$file} found {$func}\n";
            $params = clean_function_parameters($match[2]);
            generate_function_tests($file, $dest_path, $func, $params);
        }
    }
    if (preg_match_all("/class\\s+([A-Za-z_][A-Za-z_0-9]*)\\s*/", $content, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
            generate_class_tests($file, $dest_path, $match[1]);
        }
    }
}
$argv = avalue($_SERVER, 'argv', array());
$me = basename(array_shift($argv));
function usage()
{
    global $me;
    echo <<<EOF
Generate tests from PHP source files automatically that can be run from a shell script.

Creates a directory "test" beneath any found file with extension:

    .php .inc

And adds functions tests as

    function_name.phpt
<?php

$names = ['Tina', 'Dana', 'Mike', 'Amy', 'Adam'];
$compare = ['Tina', 'Dean', 'Mel', 'Amy', 'Michael'];
function avalue($names)
{
    $result = array_search('Mike', $names);
    var_dump($result);
    if ($result === false) {
        echo "false";
    } else {
        echo "true";
    }
}
avalue($names);
function compare($names, $compare)
{
    $match = 0;
    foreach ($names as $name) {
        if (array_search($name, $compare) !== false) {
            $match++;
        }
    }
    return $match;
}
echo compare($names, $compare);
compare($names, $compare);