forked from phpredis/phpredis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
112 lines (91 loc) · 3 KB
/
test.php
File metadata and controls
112 lines (91 loc) · 3 KB
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
112
<?php
// phpunit is such a pain to install, we're going with pure-PHP here.
class TestSuite {
public static $errors = array();
public static $warnings = array();
protected function assertFalse($bool) {
$this->assertTrue(!$bool);
}
protected function assertTrue($bool) {
if($bool)
return;
$bt = debug_backtrace(false);
self::$errors []= sprintf("Assertion failed: %s:%d (%s)\n",
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"]);
}
protected function assertLess($a, $b) {
if($a < $b)
return;
$bt = debug_backtrace(false);
self::$errors[] = sprintf("Assertion failed (%s >= %s): %s: %d (%s\n",
print_r($a, true), print_r($b, true),
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"]);
}
protected function assertEquals($a, $b) {
if($a === $b)
return;
$bt = debug_backtrace(false);
self::$errors []= sprintf("Assertion failed (%s !== %s): %s:%d (%s)\n",
print_r($a, true), print_r($b, true),
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"]);
}
protected function markTestSkipped($msg='') {
$bt = debug_backtrace(false);
self::$warnings []= sprintf("Skipped test: %s:%d (%s) %s\n",
$bt[0]["file"], $bt[0]["line"], $bt[1]["function"], $msg);
throw new Exception($msg);
}
public static function run($className, $str_limit) {
$rc = new ReflectionClass($className);
$methods = $rc->GetMethods(ReflectionMethod::IS_PUBLIC);
$i_limit = -1;
$i_idx = 0;
$boo_printed = false;
$arr_ran_methods = Array();
if ($str_limit && is_numeric($str_limit)) {
echo "Limiting to $str_limit tests!\n";
$i_limit = (integer)$str_limit;
} else if ($str_limit) {
echo "Limiting to tests with the substring: '$str_limit'\n";
}
foreach($methods as $m) {
$name = $m->name;
if(substr($name, 0, 4) !== 'test')
continue;
/* If TestRedis.php was envoked with an argument, do a simple
* match against the routine. Useful to limit to one test */
if ($i_limit == -1 && $str_limit && strpos(strtolower($name),strtolower($str_limit))===false)
continue;
if ($i_limit > -1 && $i_idx++ >= $i_limit) {
continue;
}
$arr_ran_methods[] = $name;
$count = count($className::$errors);
$rt = new $className;
try {
$rt->setUp();
$rt->$name();
echo ($count === count($className::$errors)) ? "." : "F";
} catch (Exception $e) {
if ($e instanceof RedisException) {
$className::$errors[] = "Uncaught exception '".$e->getMessage()."' ($name)\n";
echo 'F';
} else {
echo 'S';
}
}
}
echo "\n";
echo implode('', $className::$warnings);
echo " --- tests run ---\n";
echo implode("\n", $arr_ran_methods) . "\n" ;
echo " --- fin ---\n";
if(empty($className::$errors)) {
echo "All tests passed.\n";
return 0;
}
echo implode('', $className::$errors);
return 1;
}
}
?>