This repository was archived by the owner on Feb 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestRunner.php
More file actions
109 lines (102 loc) · 2.69 KB
/
TestRunner.php
File metadata and controls
109 lines (102 loc) · 2.69 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
<?php
if (php_sapi_name() !== "cli") {
echo "Must be run from the command line!";
exit(1);
}
function listdir($p) {
$p = realpath($p);
$results = array();
if (is_file($p)) {
return array($p);
}
$dh = opendir($p);
while ($fname = readdir($dh)) {
if ($fname[0] !== "." && $fname !== "..") {
$results[] = realpath($p ."/" . $fname);
}
}
closedir($dh);
return $results;
}
/**
* PHPFileList() takes a starting path and returns a list of php files
*
* @param $p the starting path
* @return a list of php file paths (maybe empty if none found)
*/
function PHPFileList($p) {
$results = array();
$p = realpath($p);
if (is_file($p)) {
return array(realpath($p));
}
if (is_dir($p)) {
$queue = listdir($p);
while ($queue && count($queue) > 0 ) {
$entry = array_pop($queue);
if (is_file($entry)) {
$ext = pathinfo($entry, PATHINFO_EXTENSION);
if ($ext === "php") {
$results[] = $entry;
}
}
if (is_dir($entry) && strpos($entry, $p) === 0 && count($entry) > 0) {
$subDir = listdir($entry);
foreach ($subDir as $entry) {
if ($entry) {
$queue[] = realpath($entry);
}
}
}
$queue = array_unique($queue);
}
}
return $results;
};
// TestPHPFileList() is an example function for testing PHPFileList()
function TestPHPFileList() {
$l1 = PHPFileList(".");
if (count($l1) !== 10) {
echo "Expected 10 entries, got " . (count($l1)) . PHP_EOL;
echo " " . print_r($l1, true) . PHP_EOL;
exit(1);
}
$l2 = PHPFileList("example_testing");
if (count($l2) !== 2) {
echo "Expected 2 entries, got " . (count($l2)) . PHP_EOL;
echo " " . print_r($l2, true) . PHP_EOL;
foreach (listdir("example_testing") as $line) {
echo $line . PHP_EOL;
}
exit(1);
}
}
function TestRunner($thisFilename, $args) {
if (count($args) === 0) {
$args = array(
"."
);
}
foreach ($args as $arg) {
$includeList = PHPFileList($arg);
foreach ($includeList as $phpFile) {
if ($thisFilename !== $phpFile) {
echo "Trying $phpFile" . PHP_EOL;
include($phpFile);
}
}
}
}
if (isset($argv) && count($argv) > 1) {
// array is a FIFO so we use shift instead of pop
$thisFilename = realpath(array_shift($argv));
echo "Running ". basename($thisFilename) . PHP_EOL;
TestRunner($thisFilename, $argv);
echo "Tests completed." . PHP_EOL;
} else {
//echo "Testing the PHPFileList() function" . PHP_EOL;
//TestPHPFileList();
//echo "Success!" . PHP_EOL;
echo "USAGE: php TestRunner.php PATH_TO_TESTS_YOU_WANT_TO_RUN" . PHP_EOL;
}
?>