forked from locutusjs/locutus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpjstest.php
More file actions
executable file
·115 lines (99 loc) · 2.74 KB
/
Copy pathphpjstest.php
File metadata and controls
executable file
·115 lines (99 loc) · 2.74 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
113
114
115
#!/usr/bin/php -q
<?php
error_reporting(E_ALL);
require_once "PHPJS_Library/PHPJS/Library.php";
// Check for CLI
if ((php_sapi_name() != 'cli')) {
die("CLI Only");
}
$dir = realpath(dirname(__FILE__)."/..")."/functions";
$PHPJS_Tester_Shell = new PHPJS_Library_Tester_Shell($dir);
// Parse commands
$arg1 = "all";
if (isset($argv[1])) {
$arg1 = $argv[1];
}
$arg2 = "run";
if (isset($argv[2])) {
$arg2 = $argv[2];
}
$funcName = $arg1;
$mode = $arg2;
$modes = array("all", "category", "from");
// Load function if nescessary
if (!in_array($funcName, $modes) && $funcName !== false && strlen($funcName) > 1) {
if (strpos($funcName, "/") !== false || strpos($funcName, ".") !== false) {
// Convert a path to plain function name
$funcName = basename($funcName, ".js");
}
if (!$PHPJS_Tester_Shell->functionExists($funcName)) {
die("Function '".$funcName."' does not exist\n");
} else {
$Function = $PHPJS_Tester_Shell->getFunction($funcName);
}
} else {
$mode = $arg1;
$funcName = $arg2;
}
// Choose mode & execute
$hr = str_repeat("=", 75)."\n";
switch($mode) {
case "testcode":
echo $Function->testCode();
break;
case "debug":
echo "Info\n";
echo $hr;
echo "source file: ". $Function->getRealPath()."\n";
echo "tester file: ". $Function->getTesterPath()."\n";
echo "\n\n";
echo "Examples\n";
echo $hr;
print_r($Function->DocBlock->getExamples());
echo "\n\n";
echo "Dependencies\n";
echo $hr;
print_r($Function->getDependencies());
echo "\n\n";
echo "Output\n";
echo $hr;
$Function->testFunction(true);
echo "\n\n";
echo "Test result\n";
echo $hr;
$Function->testFunction(false);
echo "\n\n";
echo "Js Lint result\n";
echo $hr;
$Function->testFunction(false, false, true);
break;
case "output":
$Function->testFunction(true);
break;
case "php":
$Function->testFunction(false, true);
break;
case "from":
$PHPJS_Tester_Shell->setSelection("from::".$funcName);
$PHPJS_Tester_Shell->test();
break;
case "category":
$PHPJS_Tester_Shell->setSelection("category::".$funcName);
$PHPJS_Tester_Shell->test();
break;
case "all":
$PHPJS_Tester_Shell->setSelection("all");
$PHPJS_Tester_Shell->test();
break;
case "run":
echo $Function->testFunction();
echo "\n\n";
echo "Js Lint result\n";
echo $hr;
$Function->testFunction(false, false, true);
break;
default:
die("Unknown command: ".$mode);
break;
}
?>