forked from flyandi/php-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gentest.php
38 lines (23 loc) · 926 Bytes
/
.gentest.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
<?php
include("src/helpers.php");
foreach(get_defined_functions()["user"] as $fn) {
$__fn = new ReflectionFunction($fn);
$output = array();
$attributes = array();
$name = $__fn->getName();
$params = $__fn->getParameters();
$paramcount = $__fn->getNumberOfParameters();
$paramrequired = $__fn->getNumberOfRequiredParameters();
// create output
foreach($params as $index => $param) {
$optional = $index >= $paramrequired;
$value = "";
$output[] = ($optional ? "//" : "") . "$" . $param->name . " = \"" . $value ."\";";
$attributes[] = ($optional ? "/*" : "") . "$" . $param->name . ($optional ? "*/" : "");
}
$output[] = "";
$output[] = "\$result = " . $name ."(" . implode(", ", $attributes) . ");";
$fn = "test/" . $name . ".php";
if(!file_exists($fn))
file_put_contents($fn, sprintf("<?php\n\ninclude(\"../src/helpers.php\");\n\n%s\n\nvar_dump(\$result);", implode("\n", $output)));
}