-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.php
56 lines (48 loc) · 2.01 KB
/
test.php
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
<?php
// Configuration
$root_dir = __DIR__ . "/src/";
$test_dir = __DIR__ . "/test/";
$test_extension = ".test.php";
error_reporting(0);
$target = isset($argv[1]) ? $argv[1] : "";
// AutoLoad Content Classes
spl_autoload_register(function ($className) use ($root_dir) {
$fileName = '';
if ($lastNameSpacePosition = strpos($className, '\\')) {
$namespace = substr($className, 0, $lastNameSpacePosition);
$className = substr($className, $lastNameSpacePosition + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className);
if (is_file($root_dir . $fileName . '.php')) {
require_once $root_dir . $fileName . '.php';
}
});
// load configuration file
include "config.test.php";
//AutoLoad all test Files
function auto_load_tests(string $test_extension, string $test_dir, string $target)
{
$directory_iterator = new RecursiveDirectoryIterator($test_dir . 'base');
foreach (new RecursiveIteratorIterator($directory_iterator) as $filename => $__) {
if (is_file($filename) && !is_dir($filename) && substr($filename, -strlen(".php")) === ".php") {
require_once($filename);
}
}
$directory_iterator = new RecursiveDirectoryIterator($test_dir . 'cases');
foreach (new RecursiveIteratorIterator($directory_iterator) as $filename => $__) {
if (is_file($filename) && !is_dir($filename) && substr($filename, -strlen($test_extension)) === $test_extension) {
if (!$target) {
require_once($filename);
continue;
}
$name = substr($filename, - (strlen($target) + strlen($test_extension) + 1));
if (substr($name, 0, 1) !== DIRECTORY_SEPARATOR) continue;
$name = substr($name, 1, strlen($target));
if ($name !== $target) continue;
require_once($filename);
}
}
}
auto_load_tests($test_extension, $test_dir, $target);
\test\Test::printResults();