Back to index

php5  5.3.10
Enumerations | Functions | Variables
find_tested.php File Reference

Go to the source code of this file.

Enumerations

enum  CLASS_NAME
enum  METHOD_NAME
enum  EXTENSION_NAME
enum  IS_DUPLICATE
enum  IS_TESTED
enum  TESTS

Functions

foreach($extension_method_info
as $record
mark_methods_as_tested ($method_info, $phpt_files)
 Marks the "tested" status of methods in $method_info according to whether they are tested in $phpt_files.
 populate_method_info ()
 returns an array containing a record for each defined method.
 get_phpt_files ($dir, &$phpt_file_count, &$all_phpt)
 extract_tests ($file)
 filter_functions ($x)
 map_token_value ($x)

Variables

 $usage
 $num_params = $argc
if($num_params< 2||$num_params > 3) $extension_test_path = $argv[1]
 $extension_method_info = mark_methods_as_tested($extension_method_info, $phpt_files)

Enumeration Type Documentation

enum CLASS_NAME

Definition at line 20 of file find_tested.php.

Definition at line 22 of file find_tested.php.

Definition at line 23 of file find_tested.php.

enum IS_TESTED

Definition at line 24 of file find_tested.php.

Definition at line 21 of file find_tested.php.

enum TESTS

Definition at line 25 of file find_tested.php.


Function Documentation

extract_tests ( file)

Definition at line 196 of file find_tested.php.

                               {
       $code = file_get_contents($file);
       
       if (!preg_match('/--FILE--\s*(.*)\s*--(EXPECTF|EXPECTREGEX|EXPECT)?--/is', $code, $r)) {
//            print "Unable to get code in ".$file."\n";
              return array();
       }
       
       $tokens = token_get_all($r[1]);
       $functions = array_filter($tokens, 'filter_functions');
       $functions = array_map( 'map_token_value',$functions);
       $functions = array_unique($functions);
       
       return $functions;
}

Here is the caller graph for this function:

filter_functions ( x)

Definition at line 212 of file find_tested.php.

                              {
       return $x[0] == 307;
}
get_phpt_files ( dir,
&$  phpt_file_count,
&$  all_phpt 
)

Definition at line 178 of file find_tested.php.

{
    $thisdir = dir($dir.'/'); //include the trailing slash
    while(($file = $thisdir->read()) !== false) {
        if ($file != '.' && $file != '..') {
            $path = $thisdir->path.$file;
            if(is_dir($path) == true) {
                get_phpt_files($path , $phpt_file_count , $all_phpt);
            } else {
                if (preg_match("/\w+\.phpt$/", $file)) {
                    $all_phpt[$phpt_file_count] = $path;
                    $phpt_file_count++;
                }
            }
        }
    }
}
map_token_value ( x)

Definition at line 216 of file find_tested.php.

                             {
       return $x[1];
}
foreach ($extension_method_info as $record) mark_methods_as_tested ( method_info,
phpt_files 
)

Marks the "tested" status of methods in $method_info according to whether they are tested in $phpt_files.

Definition at line 84 of file find_tested.php.

                                                           { 

    foreach($phpt_files as $phpt_file) {
        $tested_functions = extract_tests($phpt_file);

        foreach($tested_functions as $tested_function) {

            // go through method info array marking this funtion as tested
            foreach($method_info as &$current_method_record) {
                if (strcasecmp($tested_function, $current_method_record[METHOD_NAME]) == 0) {
                    // matched the method name
                    if ($current_method_record[IS_DUPLICATE] == true) {
                        // we cannot be sure which class this method corresponds to,
                        // so mark method as needing to be verified 
                        $current_method_record[IS_TESTED] = "verify";
                    } else {
                        $current_method_record[IS_TESTED] = "yes";
                    }
                    $current_method_record[TESTS] .= $phpt_file . "; ";
                }
            }
        }
    }
    return $method_info;
}

Here is the call graph for this function:

returns an array containing a record for each defined method.

Definition at line 113 of file find_tested.php.

                                {
    
    $method_info = array();

    // get functions
    $all_functions = get_defined_functions();
    $internal_functions = $all_functions["internal"];

    foreach ($internal_functions as $function) {
        // populate new method record
        $function_record = array();
        $function_record[CLASS_NAME] = "Function";
        $function_record[METHOD_NAME] = $function;
        $function_record[IS_TESTED] = "no";
        $function_record[TESTS] = "";
        $function_record[IS_DUPLICATE] = false;

        // record the extension that the function belongs to
        $reflectionFunction = new ReflectionFunction($function);
        $extension = $reflectionFunction->getExtension();
        if ($extension != null) {
            $function_record[EXTENSION_NAME] = $extension->getName();
        } else {
            $function_record[EXTENSION_NAME] = "";
        }
        // insert new method record into info array
        $method_info[] = $function_record;
    }

    // get methods
    $all_classes = get_declared_classes();
    foreach ($all_classes as $class) {
        $reflectionClass = new ReflectionClass($class);
        $methods = $reflectionClass->getMethods();
        foreach ($methods as $method) {
            // populate new method record
            $new_method_record = array();
            $new_method_record[CLASS_NAME] = $reflectionClass->getName();
            $new_method_record[METHOD_NAME] = $method->getName();
            $new_method_record[IS_TESTED] = "no";
            $new_method_record[TESTS] = "";

            $extension = $reflectionClass->getExtension();
            if ($extension != null) {
                $new_method_record[EXTENSION_NAME] = $extension->getName();
            } else {
                $new_method_record[EXTENSION_NAME] = "";
            }

            // check for duplicate method names
            $new_method_record[IS_DUPLICATE] = false;
            foreach ($method_info as &$current_record) {
                if (strcmp($current_record[METHOD_NAME], $new_method_record[METHOD_NAME]) == 0) {
                    $new_method_record[IS_DUPLICATE] = true;
                    $current_record[IS_DUPLICATE] = true;
                }
            }
            // insert new method record into info array
            $method_info[] = $new_method_record;
        }
    }

    return $method_info;
}

Variable Documentation

$extension_method_info = mark_methods_as_tested($extension_method_info, $phpt_files)

Definition at line 69 of file find_tested.php.

if ($num_params< 2||$num_params > 3) $extension_test_path = $argv[1]

Definition at line 34 of file find_tested.php.

$num_params = $argc

Definition at line 29 of file find_tested.php.

Initial value:
"verify" for a method means that there is at least one other method of the same name, so test coverage must be verified manually.

USAGE

Definition at line 4 of file find_tested.php.