blob: 820d7e0a7602dbaa75511e04ade5ad7bf815c8e6 (
plain)
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
|
<?php
/**
* Class for method under test (see gtFunction for non-OO tests)
*/
class gtMethod extends gtTestSubject {
private $className;
private $methodName;
private $constructorArgumentNames;
private $constructorArgumentList = '';
private $constructorInitialisationStatements;
/**
* Construct gtMethod object from the class and method names
*
* @param string $className
* @param string $methodName
*/
public function __construct($className, $methodName) {
$this->className = $className;
$this->methodName = $methodName;
}
/**
* Set the names of the class constructor arguments. Take only mandatory argument names.
*
*/
public function setConstructorArgumentNames() {
$reflectionClass = new ReflectionClass($this->className);
$constructor = $reflectionClass->getConstructor();
foreach($constructor->getParameters() as $i => $param) {
//if(!$param->isOptional()) {
$this->constructorArgumentNames[] = $param->getName();
//}
}
}
/**
* Set the names of the mandatory and optional arguments to the method
*
*/
public function setArgumentNames() {
$methodClass = new reflectionMethod($this->className, $this->methodName);
$parameters = $methodClass->getParameters();
foreach ($methodClass->getParameters() as $i => $param) {
if($param->isOptional()) {
$this->optionalArgumentNames[] = $param->getName();
} else {
$this->mandatoryArgumentNames[] = $param->getName();
}
}
}
/**
* Return the list of constructor argument names
*
* @return array
*/
public function getConstructorArgumentNames() {
return $this->constructorArgumentNames;
}
/**
* Return the name of the method
*
* @return string
*/
public function getName() {
return $this->methodName;
}
/**
* Return the name of the class
*
* @return string
*/
public function getClassName() {
return $this->className;
}
/**
* Set the list of arguments to be passed to the constructor
*
*/
public function setConstructorArgumentList() {
if(count ($this->constructorArgumentNames) > 0) {
for( $i = 0; $i < count( $this->constructorArgumentNames ); $i++) {
$this->constructorArgumentList .= "\$".$this->constructorArgumentNames[$i].", ";
}
$this->constructorArgumentList = substr($this->constructorArgumentList, 0, -2);
}
}
/**
* Return the list of the arguments to be passed to the constructor
*
* @return string
*/
public function getConstructorArgumentList() {
return $this->constructorArgumentList;
}
/**
* Set up the source statements that initialise constructor arguments;
*
*/
public function setConstructorInitStatements() {
if(count ($this->constructorArgumentNames) > 0) {
foreach( $this->constructorArgumentNames as $name) {
$this->constructorInitialisationStatements[] = "\$".$name." = ";
}
}
}
/**
* Return the constructor initialisation statements
*
* @return array
*/
public function getConstructorInitStatements() {
return $this->constructorInitialisationStatements;
}
}
?>
|