1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
 * A simple visual API testing protocol
 *
 * @version    0.1.0
 * @author     Laurent Laville <pear@laurent-laville.org>
 * @access     public
 * @category   Tools and Utilities :: Testing
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
 */
/**
 * Before to run this script, you must:
 * <ol>
 *  <li> identify the class you have to test in line 24
 *  <li> depending of your class copy location, un-comment line 26
 *  <li> if you want to see only methods tested, un-comment line 34
 *  <li> defined all your api names, and parameters values on file api/$className, line 28, 
 *       into a getTestCase() function
 * </ol>
 */

error_reporting(E_ALL);

$className = 'Auth_PrefManager2';
$file = str_replace('_', '/', $className);
//$file = basename($file);
require_once $file . '.php';
require_once "api/$className.php";

define('VISUAL_API_DISPLAY_ALL_METHODS', 1);
define('VISUAL_API_DISPLAY_TESTED_ONLY', 2);

$GLOBALS['_VISUAL_API_DISPLAY'] = VISUAL_API_DISPLAY_ALL_METHODS;
//$GLOBALS['_VISUAL_API_DISPLAY'] = VISUAL_API_DISPLAY_TESTED_ONLY;

$includes = get_included_files();
echo '<h1>included files </h1>';
echo '<pre>';
var_dump($includes);
echo '</pre>';
echo '<hr/>';

$ua = &new $className();
$methods = get_class_methods($className);


echo "<h1>simple API tests for class $className </h1>";

foreach ($methods as $m)
{
    $display = $test = true;
    $static = false;    
    unset($var1, $var2);

    getTestCase($m);

    if ($display)
    {    
        if ($test) {
            if (isset($var1)) {
                if (is_array($var1)) {
                    $p1 = serialize($var1);
                } else {
                    $p1 = $var1;
                }
                $t1 = gettype($var1);

            }
            if (isset($var2)) {
                if (is_array($var2)) {
                    $p2 = serialize($var2);
                } else {
                    $p2 = $var2;
                }
                $t2 = gettype($var2);
            }

            if (isset($var2)) {
                echo "<h2>Method: $m( <i>($t1)</i>'$p1', <i>($t2)</i>'$p2') </h2>";
                if ($static) {
                    $res = call_user_func(array($className,$m), $var1, $var2);
                } else {
                    $res = $ua->$m($var1, $var2);
        	}
            } elseif (isset($var1)) {
                echo "<h2>Method: $m( <i>($t1)</i>'$p1') </h2>";
                if ($static) {
                    $res = call_user_func(array($className,$m), $var1);
                } else {
                    $res = $ua->$m($var1);
                }
            } else {
                echo "<h2>Method: $m() </h2>";
                if ($static) {
                    $res = call_user_func(array($className,$m));
                } else {
                    $res = $ua->$m();
                }
            }

            echo '<pre>';
            var_dump($res);
            echo '</pre>';

        } else {
            echo "<h2>Method: $m </h2>";
            echo '==> not run!';
        }
    }
}
?>