This repository was archived by the owner on Nov 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_method_tests.php
More file actions
142 lines (110 loc) · 3.08 KB
/
make_method_tests.php
File metadata and controls
142 lines (110 loc) · 3.08 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Actually this is not working. Just leave it for reference.
*/
header("HTTP/1.1 401 Unauthorized");
exit;
define('TAGETPATH', './test');
require_once './includes.inc.php';
use Pirl\PirlDataTypePrimitive;
foreach ($schema['methods'] as $method_name => $params) {
echo "<h3>" . $method_name ."</h3>";
$class_name = makeClassName($method_name);
printMe('Class name base', $class_name);
$valid_arguments = $params[0];
$argument_class_names = array();
if (count($valid_arguments)) {
printMe('Valid arguments', $valid_arguments);
// Get argument definition Classes.
foreach ($valid_arguments as $type) {
$primitiveType = PirlDataTypePrimitive::typeMap($type);
if ($primitiveType) {
$argument_class_names[] = $primitiveType;
}
else {
$argument_class_names[] = $type;
}
}
printMe('Valid arguments class names', $argument_class_names);
}
$return_type = $params[1];
printMe('Return value type', $return_type);
// $constructor_content = makeConstructorContent($ordered_params);
// $setters = makeSetFunctions($ordered_params);
//
// $return_array = makeReturnArray($ordered_params);
//
//
//
// $properties = makeProperties($ordered_params);
// printMe ('Properties', $properties);
// printMe ('Constructor', "__construct(" . $constructor . ")");
// printMe ('ConstructorContent', $constructor_content);
// printMe ('Set<PROPERTY>', $setters);
// printMe ('Return Array', $return_array);
$data = array (
"<?php\n",
// TODO THIS DOSN'T WORK: Drupal Namespace not recognized.
"use Drupal\\pirl\\Controller\\PirlController;\n",
"/**",
" * Test for $method_name.",
" */",
"class " . $class_name . "Test extends \\PHPUnit_Framework_TestCase {\n",
makeConstructor(),
"",
" /**",
" * Testing.",
" */",
" public function test" . $class_name . "Initial() {\n",
makeTestUnparameterised(),
" }",
"}",
);
file_put_contents ( TAGETPATH . '/' . $class_name . 'Test.generated.php', implode("\n",$data));
echo "<hr />";
}
// echo "<h1>SCHEMA</h1>";
// var_dump($schema);
/**
* Make Class name.
*
* @param string $input -
* Method name
*
* @return string
* Derived Class name.
*/
function makeClassName($input) {
$return = '';
foreach (explode('_', $input) as $part) {
$return .= ucfirst($part);
}
return $return;
}
/**
* Create constructor content.
*
*/
function makeConstructor() {
$val[] = ' protected $controller;' . "\n";
$val[] = ' public function __construct(){';
$val[] = ' $this->controller = new PirlController();';
$val[] = ' }';
// Required params first.
return implode("\n",$val);
}
/**
* Create test for unparameterised call.
*
*/
function makeTestUnparameterised() {
global $valid_arguments, $method_name, $return_type;
if (count($valid_arguments) == 0) {
$val[] = ' $x = $this->controller->client->' . $method_name . '();';
$val[] = ' $this->assertEquals($x->getType($schema = TRUE), "' . $return_type . '");';
return implode("\n",$val);
}
else {
return "";
}
}