Fixing file upload params ($_FILES) normalization. Closes #75
[akelos.git] / vendor / simpletest / options.php
blob4a87400f52d8c026a8b469546239a92762b51b16
1 <?php
2 /**
3 * base include file for SimpleTest
4 * @package SimpleTest
5 * @version $Id: options.php,v 1.35 2005/02/04 03:48:52 lastcraft Exp $
6 */
8 /**
9 * Static global directives and options.
10 * @package SimpleTest
12 class SimpleTestOptions {
14 /**
15 * Reads the SimpleTest version from the release file.
16 * @return string Version string.
17 * @static
18 * @access public
20 function getVersion() {
21 $content = file(dirname(__FILE__) . '/VERSION');
22 return trim($content[0]);
25 /**
26 * Sets the name of a test case to ignore, usually
27 * because the class is an abstract case that should
28 * not be run.
29 * @param string $class Add a class to ignore.
30 * @static
31 * @access public
33 function ignore($class) {
34 $registry = &SimpleTestOptions::_getRegistry();
35 $registry['IgnoreList'][] = strtolower($class);
38 /**
39 * Test to see if a test case is in the ignore
40 * list.
41 * @param string $class Class name to test.
42 * @return boolean True if should not be run.
43 * @access public
44 * @static
46 function isIgnored($class) {
47 $registry = &SimpleTestOptions::_getRegistry();
48 return in_array(strtolower($class), $registry['IgnoreList']);
51 /**
52 * The base class name is settable here. This is the
53 * class that a new stub will inherited from.
54 * To modify the generated stubs simply extend the
55 * SimpleStub class and set it's name
56 * with this method before any stubs are generated.
57 * @param string $stub_base Server stub class to use.
58 * @static
59 * @access public
61 function setStubBaseClass($stub_base) {
62 $registry = &SimpleTestOptions::_getRegistry();
63 $registry['StubBaseClass'] = $stub_base;
66 /**
67 * Accessor for the currently set stub base class.
68 * @return string Class name to inherit from.
69 * @static
70 * @access public
72 function getStubBaseClass() {
73 $registry = &SimpleTestOptions::_getRegistry();
74 return $registry['StubBaseClass'];
77 /**
78 * The base class name is settable here. This is the
79 * class that a new mock will inherited from.
80 * To modify the generated mocks simply extend the
81 * SimpleMock class and set it's name
82 * with this method before any mocks are generated.
83 * @param string $mock_base Mock base class to use.
84 * @static
85 * @access public
87 function setMockBaseClass($mock_base) {
88 $registry = &SimpleTestOptions::_getRegistry();
89 $registry['MockBaseClass'] = $mock_base;
92 /**
93 * Accessor for the currently set mock base class.
94 * @return string Class name to inherit from.
95 * @static
96 * @access public
98 function getMockBaseClass() {
99 $registry = &SimpleTestOptions::_getRegistry();
100 return $registry['MockBaseClass'];
104 * Adds additional mock code.
105 * @param string $code Extra code that can be added
106 * to the partial mocks for
107 * extra functionality. Useful
108 * when a test tool has overridden
109 * the mock base classes.
110 * @access public
112 function addPartialMockCode($code = '') {
113 $registry = &SimpleTestOptions::_getRegistry();
114 $registry['AdditionalPartialMockCode'] = $code;
118 * Accessor for additional partial mock code.
119 * @return string Extra code.
120 * @access public
122 function getPartialMockCode() {
123 $registry = &SimpleTestOptions::_getRegistry();
124 return $registry['AdditionalPartialMockCode'];
128 * Sets proxy to use on all requests for when
129 * testing from behind a firewall. Set host
130 * to false to disable. This will take effect
131 * if there are no other proxy settings.
132 * @param string $proxy Proxy host as URL.
133 * @param string $username Proxy username for authentication.
134 * @param string $password Proxy password for authentication.
135 * @access public
137 function useProxy($proxy, $username = false, $password = false) {
138 $registry = &SimpleTestOptions::_getRegistry();
139 $registry['DefaultProxy'] = $proxy;
140 $registry['DefaultProxyUsername'] = $username;
141 $registry['DefaultProxyPassword'] = $password;
145 * Accessor for default proxy host.
146 * @return string Proxy URL.
147 * @access public
149 function getDefaultProxy() {
150 $registry = &SimpleTestOptions::_getRegistry();
151 return $registry['DefaultProxy'];
155 * Accessor for default proxy username.
156 * @return string Proxy username for authentication.
157 * @access public
159 function getDefaultProxyUsername() {
160 $registry = &SimpleTestOptions::_getRegistry();
161 return $registry['DefaultProxyUsername'];
165 * Accessor for default proxy password.
166 * @return string Proxy password for authentication.
167 * @access public
169 function getDefaultProxyPassword() {
170 $registry = &SimpleTestOptions::_getRegistry();
171 return $registry['DefaultProxyPassword'];
175 * Accessor for global registry of options.
176 * @return hash All stored values.
177 * @access private
178 * @static
180 function &_getRegistry() {
181 static $registry = false;
182 if (! $registry) {
183 $registry = SimpleTestOptions::_getDefaults();
185 return $registry;
189 * Constant default values.
190 * @return hash All registry defaults.
191 * @access private
192 * @static
194 function _getDefaults() {
195 return array(
196 'StubBaseClass' => 'SimpleStub',
197 'MockBaseClass' => 'SimpleMock',
198 'IgnoreList' => array(),
199 'AdditionalPartialMockCode' => '',
200 'DefaultProxy' => false,
201 'DefaultProxyUsername' => false,
202 'DefaultProxyPassword' => false);
207 * Static methods for compatibility between different
208 * PHP versions.
209 * @package SimpleTest
211 class SimpleTestCompatibility {
214 * Identity test. Drops back to equality + types for PHP5
215 * objects as the === operator counts as the
216 * stronger reference constraint.
217 * @param mixed $first Test subject.
218 * @param mixed $second Comparison object.
219 * @access public
220 * @static
222 function isIdentical($first, $second) {
223 if ($first != $second) {
224 return false;
226 if (version_compare(phpversion(), '5') >= 0) {
227 return SimpleTestCompatibility::_isIdenticalType($first, $second);
229 return ($first === $second);
233 * Recursive type test.
234 * @param mixed $first Test subject.
235 * @param mixed $second Comparison object.
236 * @access private
237 * @static
239 function _isIdenticalType($first, $second) {
240 if (gettype($first) != gettype($second)) {
241 return false;
243 if (is_object($first) && is_object($second)) {
244 if (get_class($first) != get_class($second)) {
245 return false;
247 return SimpleTestCompatibility::_isArrayOfIdenticalTypes(
248 get_object_vars($first),
249 get_object_vars($second));
251 if (is_array($first) && is_array($second)) {
252 return SimpleTestCompatibility::_isArrayOfIdenticalTypes($first, $second);
254 return true;
258 * Recursive type test for each element of an array.
259 * @param mixed $first Test subject.
260 * @param mixed $second Comparison object.
261 * @access private
262 * @static
264 function _isArrayOfIdenticalTypes($first, $second) {
265 if (array_keys($first) != array_keys($second)) {
266 return false;
268 foreach (array_keys($first) as $key) {
269 $is_identical = SimpleTestCompatibility::_isIdenticalType(
270 $first[$key],
271 $second[$key]);
272 if (! $is_identical) {
273 return false;
276 return true;
280 * Test for two variables being aliases.
281 * @param mixed $first Test subject.
282 * @param mixed $second Comparison object.
283 * @access public
284 * @static
286 function isReference(&$first, &$second) {
287 if (version_compare(phpversion(), '5', '>=')
288 && is_object($first)) {
289 return ($first === $second);
291 $temp = $first;
292 $first = uniqid("test");
293 $is_ref = ($first === $second);
294 $first = $temp;
295 return $is_ref;
299 * Test to see if an object is a member of a
300 * class hiearchy.
301 * @param object $object Object to test.
302 * @param string $class Root name of hiearchy.
303 * @access public
304 * @static
306 function isA($object, $class) {
307 if (version_compare(phpversion(), '5') >= 0) {
308 if (! class_exists($class, false)) {
309 return false;
311 eval("\$is_a = \$object instanceof $class;");
312 return $is_a;
314 if (function_exists('is_a')) {
315 return is_a($object, $class);
317 return ((strtolower($class) == get_class($object))
318 or (is_subclass_of($object, $class)));
322 * Autoload safe version of class_exists().
323 * @param string $class Name of class to look for.
324 * @return boolean True if class is defined.
325 * @access public
326 * @static
328 function classExists($class) {
329 if (version_compare(phpversion(), '5') >= 0) {
330 return class_exists($class, false);
331 } else {
332 return class_exists($class);
337 * Sets a socket timeout for each chunk.
338 * @param resource $handle Socket handle.
339 * @param integer $timeout Limit in seconds.
340 * @access public
341 * @static
343 function setTimeout($handle, $timeout) {
344 if (function_exists('stream_set_timeout')) {
345 stream_set_timeout($handle, $timeout, 0);
346 } elseif (function_exists('socket_set_timeout')) {
347 socket_set_timeout($handle, $timeout, 0);
348 } elseif (function_exists('set_socket_timeout')) {
349 set_socket_timeout($handle, $timeout, 0);
354 * Gets the current stack trace topmost first.
355 * @return array List of stack frames.
356 * @access public
357 * @static
359 function getStackTrace() {
360 if (function_exists('debug_backtrace')) {
361 return array_reverse(debug_backtrace());
363 return array();