Completed
Push — scrutinizer ( 84e9d0...6a9613 )
by Fabio
22:48
created
tests/test_tools/simpletest/reflection_php5.php 1 patch
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -1,274 +1,274 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *	base include file for SimpleTest
4
-     *	@package	SimpleTest
5
-     *	@subpackage	UnitTester
6
-     *	@version	$Id: reflection_php5.php 1398 2006-09-08 19:31:03Z xue $
7
-     */
2
+	/**
3
+	 *	base include file for SimpleTest
4
+	 *	@package	SimpleTest
5
+	 *	@subpackage	UnitTester
6
+	 *	@version	$Id: reflection_php5.php 1398 2006-09-08 19:31:03Z xue $
7
+	 */
8 8
 
9
-    /**
10
-     *    Version specific reflection API.
9
+	/**
10
+	 *    Version specific reflection API.
11 11
 	 *    @package SimpleTest
12 12
 	 *    @subpackage UnitTester
13
-     */
14
-    class SimpleReflection {
15
-        protected $_interface;
13
+	 */
14
+	class SimpleReflection {
15
+		protected $_interface;
16 16
 
17
-        /**
18
-         *    Stashes the class/interface.
19
-         *    @param string $interface    Class or interface
20
-         *                                to inspect.
21
-         */
22
-        function SimpleReflection($interface) {
23
-            $this->_interface = $interface;
24
-        }
17
+		/**
18
+		 *    Stashes the class/interface.
19
+		 *    @param string $interface    Class or interface
20
+		 *                                to inspect.
21
+		 */
22
+		function SimpleReflection($interface) {
23
+			$this->_interface = $interface;
24
+		}
25 25
 
26
-        /**
27
-         *    Checks that a class has been declared. Versions
28
-         *    before PHP5.0.2 need a check that it's not really
29
-         *    an interface.
30
-         *    @return boolean            True if defined.
31
-         *    @access public
32
-         */
33
-        function classExists() {
34
-            if (! class_exists($this->_interface)) {
35
-                return false;
36
-            }
37
-            $reflection = new ReflectionClass($this->_interface);
38
-            return ! $reflection->isInterface();
39
-        }
26
+		/**
27
+		 *    Checks that a class has been declared. Versions
28
+		 *    before PHP5.0.2 need a check that it's not really
29
+		 *    an interface.
30
+		 *    @return boolean            True if defined.
31
+		 *    @access public
32
+		 */
33
+		function classExists() {
34
+			if (! class_exists($this->_interface)) {
35
+				return false;
36
+			}
37
+			$reflection = new ReflectionClass($this->_interface);
38
+			return ! $reflection->isInterface();
39
+		}
40 40
 
41
-        /**
42
-         *    Needed to kill the autoload feature in PHP5
43
-         *    for classes created dynamically.
44
-         *    @return boolean        True if defined.
45
-         *    @access public
46
-         */
47
-        function classExistsSansAutoload() {
48
-            return class_exists($this->_interface, false);
49
-        }
41
+		/**
42
+		 *    Needed to kill the autoload feature in PHP5
43
+		 *    for classes created dynamically.
44
+		 *    @return boolean        True if defined.
45
+		 *    @access public
46
+		 */
47
+		function classExistsSansAutoload() {
48
+			return class_exists($this->_interface, false);
49
+		}
50 50
 
51
-        /**
52
-         *    Checks that a class or interface has been
53
-         *    declared.
54
-         *    @return boolean            True if defined.
55
-         *    @access public
56
-         */
57
-        function classOrInterfaceExists() {
58
-            return $this->_classOrInterfaceExistsWithAutoload($this->_interface, true);
59
-        }
51
+		/**
52
+		 *    Checks that a class or interface has been
53
+		 *    declared.
54
+		 *    @return boolean            True if defined.
55
+		 *    @access public
56
+		 */
57
+		function classOrInterfaceExists() {
58
+			return $this->_classOrInterfaceExistsWithAutoload($this->_interface, true);
59
+		}
60 60
 
61
-        /**
62
-         *    Needed to kill the autoload feature in PHP5
63
-         *    for classes created dynamically.
64
-         *    @return boolean        True if defined.
65
-         *    @access public
66
-         */
67
-        function classOrInterfaceExistsSansAutoload() {
68
-            return $this->_classOrInterfaceExistsWithAutoload($this->_interface, false);
69
-        }
61
+		/**
62
+		 *    Needed to kill the autoload feature in PHP5
63
+		 *    for classes created dynamically.
64
+		 *    @return boolean        True if defined.
65
+		 *    @access public
66
+		 */
67
+		function classOrInterfaceExistsSansAutoload() {
68
+			return $this->_classOrInterfaceExistsWithAutoload($this->_interface, false);
69
+		}
70 70
 
71
-        /**
72
-         *    Needed to select the autoload feature in PHP5
73
-         *    for classes created dynamically.
74
-         *    @param string $interface       Class or interface name.
75
-         *    @param boolean $autoload       True totriggerautoload.
76
-         *    @return boolean                True if interface defined.
77
-         *    @access private
78
-         */
79
-        function _classOrInterfaceExistsWithAutoload($interface, $autoload) {
80
-            if (function_exists('interface_exists')) {
81
-                if (interface_exists($this->_interface, $autoload)) {
82
-                    return true;
83
-                }
84
-            }
85
-            return class_exists($this->_interface, $autoload);
86
-        }
71
+		/**
72
+		 *    Needed to select the autoload feature in PHP5
73
+		 *    for classes created dynamically.
74
+		 *    @param string $interface       Class or interface name.
75
+		 *    @param boolean $autoload       True totriggerautoload.
76
+		 *    @return boolean                True if interface defined.
77
+		 *    @access private
78
+		 */
79
+		function _classOrInterfaceExistsWithAutoload($interface, $autoload) {
80
+			if (function_exists('interface_exists')) {
81
+				if (interface_exists($this->_interface, $autoload)) {
82
+					return true;
83
+				}
84
+			}
85
+			return class_exists($this->_interface, $autoload);
86
+		}
87 87
 
88
-        /**
89
-         *    Gets the list of methods on a class or
90
-         *    interface. Needs to recursively look at all of
91
-         *    the interfaces included.
92
-         *    @returns array              List of method names.
93
-         *    @access public
94
-         */
95
-        function getMethods() {
96
-            return array_unique(get_class_methods($this->_interface));
97
-        }
88
+		/**
89
+		 *    Gets the list of methods on a class or
90
+		 *    interface. Needs to recursively look at all of
91
+		 *    the interfaces included.
92
+		 *    @returns array              List of method names.
93
+		 *    @access public
94
+		 */
95
+		function getMethods() {
96
+			return array_unique(get_class_methods($this->_interface));
97
+		}
98 98
 
99
-        /**
100
-         *    Gets the list of interfaces from a class. If the
101
-         *    class name is actually an interface then just that
102
-         *    interface is returned.
103
-         *    @returns array          List of interfaces.
104
-         *    @access public
105
-         */
106
-        function getInterfaces() {
107
-            $reflection = new ReflectionClass($this->_interface);
108
-            if ($reflection->isInterface()) {
109
-            	return array($this->_interface);
110
-            }
111
-            return $this->_onlyParents($reflection->getInterfaces());
112
-        }
99
+		/**
100
+		 *    Gets the list of interfaces from a class. If the
101
+		 *    class name is actually an interface then just that
102
+		 *    interface is returned.
103
+		 *    @returns array          List of interfaces.
104
+		 *    @access public
105
+		 */
106
+		function getInterfaces() {
107
+			$reflection = new ReflectionClass($this->_interface);
108
+			if ($reflection->isInterface()) {
109
+				return array($this->_interface);
110
+			}
111
+			return $this->_onlyParents($reflection->getInterfaces());
112
+		}
113 113
 
114
-        /**
115
-         *    Gets the list of methods for the implemented
116
-         *    interfaces only.
117
-         *    @returns array      List of enforced method signatures.
118
-         *    @access public
119
-         */
120
-        function getInterfaceMethods() {
121
-            $methods = array();
122
-            foreach ($this->getInterfaces() as $interface) {
123
-                $methods = array_merge($methods, get_class_methods($interface));
124
-            }
125
-            return array_unique($methods);
126
-        }
114
+		/**
115
+		 *    Gets the list of methods for the implemented
116
+		 *    interfaces only.
117
+		 *    @returns array      List of enforced method signatures.
118
+		 *    @access public
119
+		 */
120
+		function getInterfaceMethods() {
121
+			$methods = array();
122
+			foreach ($this->getInterfaces() as $interface) {
123
+				$methods = array_merge($methods, get_class_methods($interface));
124
+			}
125
+			return array_unique($methods);
126
+		}
127 127
 
128
-        /**
129
-         *    Checks to see if the method signature has to be tightly
130
-         *    specified.
131
-         *    @param string $method        Method name.
132
-         *    @returns boolean             True if enforced.
133
-         *    @access private
134
-         */
135
-        function _isInterfaceMethod($method) {
136
-            return in_array($method, $this->getInterfaceMethods());
137
-        }
128
+		/**
129
+		 *    Checks to see if the method signature has to be tightly
130
+		 *    specified.
131
+		 *    @param string $method        Method name.
132
+		 *    @returns boolean             True if enforced.
133
+		 *    @access private
134
+		 */
135
+		function _isInterfaceMethod($method) {
136
+			return in_array($method, $this->getInterfaceMethods());
137
+		}
138 138
 
139
-        /**
140
-         *    Finds the parent class name.
141
-         *    @returns string      Parent class name.
142
-         *    @access public
143
-         */
144
-        function getParent() {
145
-            $reflection = new ReflectionClass($this->_interface);
146
-            $parent = $reflection->getParentClass();
147
-            if ($parent) {
148
-                return $parent->getName();
149
-            }
150
-            return false;
151
-        }
139
+		/**
140
+		 *    Finds the parent class name.
141
+		 *    @returns string      Parent class name.
142
+		 *    @access public
143
+		 */
144
+		function getParent() {
145
+			$reflection = new ReflectionClass($this->_interface);
146
+			$parent = $reflection->getParentClass();
147
+			if ($parent) {
148
+				return $parent->getName();
149
+			}
150
+			return false;
151
+		}
152 152
 
153
-        /**
154
-         *    Determines if the class is abstract.
155
-         *    @returns boolean      True if abstract.
156
-         *    @access public
157
-         */
158
-        function isAbstract() {
159
-            $reflection = new ReflectionClass($this->_interface);
160
-            return $reflection->isAbstract();
161
-        }
153
+		/**
154
+		 *    Determines if the class is abstract.
155
+		 *    @returns boolean      True if abstract.
156
+		 *    @access public
157
+		 */
158
+		function isAbstract() {
159
+			$reflection = new ReflectionClass($this->_interface);
160
+			return $reflection->isAbstract();
161
+		}
162 162
 
163
-        /**
164
-         *    Wittles a list of interfaces down to only the top
165
-         *    level parents.
166
-         *    @param array $interfaces     Reflection API interfaces
167
-         *                                 to reduce.
168
-         *    @returns array               List of parent interface names.
169
-         *    @access private
170
-         */
171
-        function _onlyParents($interfaces) {
172
-            $parents = array();
173
-            foreach ($interfaces as $interface) {
174
-                foreach($interfaces as $possible_parent) {
175
-                    if ($interface->getName() == $possible_parent->getName()) {
176
-                        continue;
177
-                    }
178
-                    if ($interface->isSubClassOf($possible_parent)) {
179
-                        break;
180
-                    }
181
-                }
182
-                $parents[] = $interface->getName();
183
-            }
184
-            return $parents;
185
-        }
163
+		/**
164
+		 *    Wittles a list of interfaces down to only the top
165
+		 *    level parents.
166
+		 *    @param array $interfaces     Reflection API interfaces
167
+		 *                                 to reduce.
168
+		 *    @returns array               List of parent interface names.
169
+		 *    @access private
170
+		 */
171
+		function _onlyParents($interfaces) {
172
+			$parents = array();
173
+			foreach ($interfaces as $interface) {
174
+				foreach($interfaces as $possible_parent) {
175
+					if ($interface->getName() == $possible_parent->getName()) {
176
+						continue;
177
+					}
178
+					if ($interface->isSubClassOf($possible_parent)) {
179
+						break;
180
+					}
181
+				}
182
+				$parents[] = $interface->getName();
183
+			}
184
+			return $parents;
185
+		}
186 186
 
187
-        /**
188
-         *    Gets the source code matching the declaration
189
-         *    of a method.
190
-         *    @param string $name    Method name.
191
-         *    @return string         Method signature up to last
192
-         *                           bracket.
193
-         *    @access public
194
-         */
195
-        function getSignature($name) {
196
-        	if ($name == '__get') {
197
-        		return 'function __get($key)';
198
-        	}
199
-        	if ($name == '__set') {
200
-        		return 'function __set($key, $value)';
201
-        	}
202
-        	if (! is_callable(array($this->_interface, $name))) {
203
-        		return "function $name()";
204
-        	}
205
-        	if ($this->_isInterfaceMethod($name)) {
206
-        	    return $this->_getFullSignature($name);
207
-        	}
208
-        	return "function $name()";
209
-        }
187
+		/**
188
+		 *    Gets the source code matching the declaration
189
+		 *    of a method.
190
+		 *    @param string $name    Method name.
191
+		 *    @return string         Method signature up to last
192
+		 *                           bracket.
193
+		 *    @access public
194
+		 */
195
+		function getSignature($name) {
196
+			if ($name == '__get') {
197
+				return 'function __get($key)';
198
+			}
199
+			if ($name == '__set') {
200
+				return 'function __set($key, $value)';
201
+			}
202
+			if (! is_callable(array($this->_interface, $name))) {
203
+				return "function $name()";
204
+			}
205
+			if ($this->_isInterfaceMethod($name)) {
206
+				return $this->_getFullSignature($name);
207
+			}
208
+			return "function $name()";
209
+		}
210 210
 
211
-        /**
212
-         *    For a signature specified in an interface, full
213
-         *    details must be replicated to be a valid implementation.
214
-         *    @param string $name    Method name.
215
-         *    @return string         Method signature up to last
216
-         *                           bracket.
217
-         *    @access private
218
-         */
219
-        function _getFullSignature($name) {
220
-	        $interface = new ReflectionClass($this->_interface);
221
-	        $method = $interface->getMethod($name);
222
-	        $reference = $method->returnsReference() ? '&' : '';
223
-        	return "function $reference$name(" .
224
-            		implode(', ', $this->_getParameterSignatures($method)) .
225
-            		")";
226
-        }
211
+		/**
212
+		 *    For a signature specified in an interface, full
213
+		 *    details must be replicated to be a valid implementation.
214
+		 *    @param string $name    Method name.
215
+		 *    @return string         Method signature up to last
216
+		 *                           bracket.
217
+		 *    @access private
218
+		 */
219
+		function _getFullSignature($name) {
220
+			$interface = new ReflectionClass($this->_interface);
221
+			$method = $interface->getMethod($name);
222
+			$reference = $method->returnsReference() ? '&' : '';
223
+			return "function $reference$name(" .
224
+					implode(', ', $this->_getParameterSignatures($method)) .
225
+					")";
226
+		}
227 227
 
228
-        /**
229
-         *    Gets the source code for each parameter.
230
-         *    @param ReflectionMethod $method   Method object from
231
-         *										reflection API
232
-         *    @return array                     List of strings, each
233
-         *                                      a snippet of code.
234
-         *    @access private
235
-         */
236
-        function _getParameterSignatures($method) {
237
-        	$signatures = array();
238
-            foreach ($method->getParameters() as $parameter) {
239
-                $type = $parameter->getClass();
240
-            	$signatures[] =
228
+		/**
229
+		 *    Gets the source code for each parameter.
230
+		 *    @param ReflectionMethod $method   Method object from
231
+		 *										reflection API
232
+		 *    @return array                     List of strings, each
233
+		 *                                      a snippet of code.
234
+		 *    @access private
235
+		 */
236
+		function _getParameterSignatures($method) {
237
+			$signatures = array();
238
+			foreach ($method->getParameters() as $parameter) {
239
+				$type = $parameter->getClass();
240
+				$signatures[] =
241 241
 					(! is_null($type) ? $type->getName() . ' ' : '') .
242
-            			($parameter->isPassedByReference() ? '&' : '') .
243
-            			'$' . $this->_suppressSpurious($parameter->getName()) .
244
-            			($this->_isOptional($parameter) ? ' = null' : '');
245
-            }
246
-            return $signatures;
247
-        }
242
+						($parameter->isPassedByReference() ? '&' : '') .
243
+						'$' . $this->_suppressSpurious($parameter->getName()) .
244
+						($this->_isOptional($parameter) ? ' = null' : '');
245
+			}
246
+			return $signatures;
247
+		}
248 248
 
249
-        /**
250
-         *    The SPL library has problems with the
251
-         *    Reflection library. In particular, you can
252
-         *    get extra characters in parameter names :(.
253
-         *    @param string $name    Parameter name.
254
-         *    @return string         Cleaner name.
255
-         *    @access private
256
-         */
257
-        function _suppressSpurious($name) {
258
-            return str_replace(array('[', ']', ' '), '', $name);
259
-        }
249
+		/**
250
+		 *    The SPL library has problems with the
251
+		 *    Reflection library. In particular, you can
252
+		 *    get extra characters in parameter names :(.
253
+		 *    @param string $name    Parameter name.
254
+		 *    @return string         Cleaner name.
255
+		 *    @access private
256
+		 */
257
+		function _suppressSpurious($name) {
258
+			return str_replace(array('[', ']', ' '), '', $name);
259
+		}
260 260
 
261
-        /**
262
-         *    Test of a reflection parameter being optional
263
-         *    that works with early versions of PHP5.
264
-         *    @param reflectionParameter $parameter    Is this optional.
265
-         *    @return boolean                          True if optional.
266
-         *    @access private
267
-         */
268
-        function _isOptional($parameter) {
269
-            if (method_exists($parameter, 'isOptional')) {
270
-                return $parameter->isOptional();
271
-            }
272
-            return false;
273
-        }
274
-    }
275 261
\ No newline at end of file
262
+		/**
263
+		 *    Test of a reflection parameter being optional
264
+		 *    that works with early versions of PHP5.
265
+		 *    @param reflectionParameter $parameter    Is this optional.
266
+		 *    @return boolean                          True if optional.
267
+		 *    @access private
268
+		 */
269
+		function _isOptional($parameter) {
270
+			if (method_exists($parameter, 'isOptional')) {
271
+				return $parameter->isOptional();
272
+			}
273
+			return false;
274
+		}
275
+	}
276 276
\ No newline at end of file
Please login to merge, or discard this patch.
tests/test_tools/simpletest/unit_tester.php 1 patch
Indentation   +343 added lines, -343 removed lines patch added patch discarded remove patch
@@ -1,372 +1,372 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *	base include file for SimpleTest
4
-     *	@package	SimpleTest
5
-     *	@subpackage	UnitTester
6
-     *	@version	$Id: unit_tester.php 1398 2006-09-08 19:31:03Z xue $
7
-     */
2
+	/**
3
+	 *	base include file for SimpleTest
4
+	 *	@package	SimpleTest
5
+	 *	@subpackage	UnitTester
6
+	 *	@version	$Id: unit_tester.php 1398 2006-09-08 19:31:03Z xue $
7
+	 */
8 8
 
9
-    /**#@+
9
+	/**#@+
10 10
      *	include other SimpleTest class files
11 11
      */
12
-    require_once(dirname(__FILE__) . '/test_case.php');
13
-    require_once(dirname(__FILE__) . '/dumper.php');
14
-    /**#@-*/
12
+	require_once(dirname(__FILE__) . '/test_case.php');
13
+	require_once(dirname(__FILE__) . '/dumper.php');
14
+	/**#@-*/
15 15
 
16
-    /**
17
-     *    Standard unit test class for day to day testing
18
-     *    of PHP code XP style. Adds some useful standard
19
-     *    assertions.
16
+	/**
17
+	 *    Standard unit test class for day to day testing
18
+	 *    of PHP code XP style. Adds some useful standard
19
+	 *    assertions.
20 20
 	 *	  @package	SimpleTest
21 21
 	 *	  @subpackage	UnitTester
22
-     */
23
-    class UnitTestCase extends SimpleTestCase {
22
+	 */
23
+	class UnitTestCase extends SimpleTestCase {
24 24
 
25
-        /**
26
-         *    Creates an empty test case. Should be subclassed
27
-         *    with test methods for a functional test case.
28
-         *    @param string $label     Name of test case. Will use
29
-         *                             the class name if none specified.
30
-         *    @access public
31
-         */
32
-        function UnitTestCase($label = false) {
33
-            if (! $label) {
34
-                $label = get_class($this);
35
-            }
36
-            $this->SimpleTestCase($label);
37
-        }
25
+		/**
26
+		 *    Creates an empty test case. Should be subclassed
27
+		 *    with test methods for a functional test case.
28
+		 *    @param string $label     Name of test case. Will use
29
+		 *                             the class name if none specified.
30
+		 *    @access public
31
+		 */
32
+		function UnitTestCase($label = false) {
33
+			if (! $label) {
34
+				$label = get_class($this);
35
+			}
36
+			$this->SimpleTestCase($label);
37
+		}
38 38
 
39
-        /**
40
-         *    Will be true if the value is null.
41
-         *    @param null $value       Supposedly null value.
42
-         *    @param string $message   Message to display.
43
-         *    @return boolean                        True on pass
44
-         *    @access public
45
-         */
46
-        function assertNull($value, $message = "%s") {
47
-            $dumper = new SimpleDumper();
48
-            $message = sprintf(
49
-                    $message,
50
-                    "[" . $dumper->describeValue($value) . "] should be null");
51
-            return $this->assertTrue(! isset($value), $message);
52
-        }
39
+		/**
40
+		 *    Will be true if the value is null.
41
+		 *    @param null $value       Supposedly null value.
42
+		 *    @param string $message   Message to display.
43
+		 *    @return boolean                        True on pass
44
+		 *    @access public
45
+		 */
46
+		function assertNull($value, $message = "%s") {
47
+			$dumper = new SimpleDumper();
48
+			$message = sprintf(
49
+					$message,
50
+					"[" . $dumper->describeValue($value) . "] should be null");
51
+			return $this->assertTrue(! isset($value), $message);
52
+		}
53 53
 
54
-        /**
55
-         *    Will be true if the value is set.
56
-         *    @param mixed $value           Supposedly set value.
57
-         *    @param string $message        Message to display.
58
-         *    @return boolean               True on pass.
59
-         *    @access public
60
-         */
61
-        function assertNotNull($value, $message = "%s") {
62
-            $dumper = new SimpleDumper();
63
-            $message = sprintf(
64
-                    $message,
65
-                    "[" . $dumper->describeValue($value) . "] should not be null");
66
-            return $this->assertTrue(isset($value), $message);
67
-        }
54
+		/**
55
+		 *    Will be true if the value is set.
56
+		 *    @param mixed $value           Supposedly set value.
57
+		 *    @param string $message        Message to display.
58
+		 *    @return boolean               True on pass.
59
+		 *    @access public
60
+		 */
61
+		function assertNotNull($value, $message = "%s") {
62
+			$dumper = new SimpleDumper();
63
+			$message = sprintf(
64
+					$message,
65
+					"[" . $dumper->describeValue($value) . "] should not be null");
66
+			return $this->assertTrue(isset($value), $message);
67
+		}
68 68
 
69
-        /**
70
-         *    Type and class test. Will pass if class
71
-         *    matches the type name or is a subclass or
72
-         *    if not an object, but the type is correct.
73
-         *    @param mixed $object         Object to test.
74
-         *    @param string $type          Type name as string.
75
-         *    @param string $message       Message to display.
76
-         *    @return boolean              True on pass.
77
-         *    @access public
78
-         */
79
-        function assertIsA($object, $type, $message = "%s") {
80
-            return $this->assert(
81
-                    new IsAExpectation($type),
82
-                    $object,
83
-                    $message);
84
-        }
69
+		/**
70
+		 *    Type and class test. Will pass if class
71
+		 *    matches the type name or is a subclass or
72
+		 *    if not an object, but the type is correct.
73
+		 *    @param mixed $object         Object to test.
74
+		 *    @param string $type          Type name as string.
75
+		 *    @param string $message       Message to display.
76
+		 *    @return boolean              True on pass.
77
+		 *    @access public
78
+		 */
79
+		function assertIsA($object, $type, $message = "%s") {
80
+			return $this->assert(
81
+					new IsAExpectation($type),
82
+					$object,
83
+					$message);
84
+		}
85 85
 
86
-        /**
87
-         *    Type and class mismatch test. Will pass if class
88
-         *    name or underling type does not match the one
89
-         *    specified.
90
-         *    @param mixed $object         Object to test.
91
-         *    @param string $type          Type name as string.
92
-         *    @param string $message       Message to display.
93
-         *    @return boolean              True on pass.
94
-         *    @access public
95
-         */
96
-        function assertNotA($object, $type, $message = "%s") {
97
-            return $this->assert(
98
-                    new NotAExpectation($type),
99
-                    $object,
100
-                    $message);
101
-        }
86
+		/**
87
+		 *    Type and class mismatch test. Will pass if class
88
+		 *    name or underling type does not match the one
89
+		 *    specified.
90
+		 *    @param mixed $object         Object to test.
91
+		 *    @param string $type          Type name as string.
92
+		 *    @param string $message       Message to display.
93
+		 *    @return boolean              True on pass.
94
+		 *    @access public
95
+		 */
96
+		function assertNotA($object, $type, $message = "%s") {
97
+			return $this->assert(
98
+					new NotAExpectation($type),
99
+					$object,
100
+					$message);
101
+		}
102 102
 
103
-        /**
104
-         *    Will trigger a pass if the two parameters have
105
-         *    the same value only. Otherwise a fail.
106
-         *    @param mixed $first          Value to compare.
107
-         *    @param mixed $second         Value to compare.
108
-         *    @param string $message       Message to display.
109
-         *    @return boolean              True on pass
110
-         *    @access public
111
-         */
112
-        function assertEqual($first, $second, $message = "%s") {
113
-            return $this->assert(
114
-                    new EqualExpectation($first),
115
-                    $second,
116
-                    $message);
117
-        }
103
+		/**
104
+		 *    Will trigger a pass if the two parameters have
105
+		 *    the same value only. Otherwise a fail.
106
+		 *    @param mixed $first          Value to compare.
107
+		 *    @param mixed $second         Value to compare.
108
+		 *    @param string $message       Message to display.
109
+		 *    @return boolean              True on pass
110
+		 *    @access public
111
+		 */
112
+		function assertEqual($first, $second, $message = "%s") {
113
+			return $this->assert(
114
+					new EqualExpectation($first),
115
+					$second,
116
+					$message);
117
+		}
118 118
 
119
-        /**
120
-         *    Will trigger a pass if the two parameters have
121
-         *    a different value. Otherwise a fail.
122
-         *    @param mixed $first           Value to compare.
123
-         *    @param mixed $second          Value to compare.
124
-         *    @param string $message        Message to display.
125
-         *    @return boolean               True on pass
126
-         *    @access public
127
-         */
128
-        function assertNotEqual($first, $second, $message = "%s") {
129
-            return $this->assert(
130
-                    new NotEqualExpectation($first),
131
-                    $second,
132
-                    $message);
133
-        }
119
+		/**
120
+		 *    Will trigger a pass if the two parameters have
121
+		 *    a different value. Otherwise a fail.
122
+		 *    @param mixed $first           Value to compare.
123
+		 *    @param mixed $second          Value to compare.
124
+		 *    @param string $message        Message to display.
125
+		 *    @return boolean               True on pass
126
+		 *    @access public
127
+		 */
128
+		function assertNotEqual($first, $second, $message = "%s") {
129
+			return $this->assert(
130
+					new NotEqualExpectation($first),
131
+					$second,
132
+					$message);
133
+		}
134 134
 
135
-        /**
136
-         *    Will trigger a pass if the if the first parameter
137
-         *    is near enough to the second by the margin.
138
-         *    @param mixed $first          Value to compare.
139
-         *    @param mixed $second         Value to compare.
140
-         *    @param mixed $margin         Fuzziness of match.
141
-         *    @param string $message       Message to display.
142
-         *    @return boolean              True on pass
143
-         *    @access public
144
-         */
145
-        function assertWithinMargin($first, $second, $margin, $message = "%s") {
146
-            return $this->assert(
147
-                    new WithinMarginExpectation($first, $margin),
148
-                    $second,
149
-                    $message);
150
-        }
135
+		/**
136
+		 *    Will trigger a pass if the if the first parameter
137
+		 *    is near enough to the second by the margin.
138
+		 *    @param mixed $first          Value to compare.
139
+		 *    @param mixed $second         Value to compare.
140
+		 *    @param mixed $margin         Fuzziness of match.
141
+		 *    @param string $message       Message to display.
142
+		 *    @return boolean              True on pass
143
+		 *    @access public
144
+		 */
145
+		function assertWithinMargin($first, $second, $margin, $message = "%s") {
146
+			return $this->assert(
147
+					new WithinMarginExpectation($first, $margin),
148
+					$second,
149
+					$message);
150
+		}
151 151
 
152
-        /**
153
-         *    Will trigger a pass if the two parameters differ
154
-         *    by more than the margin.
155
-         *    @param mixed $first          Value to compare.
156
-         *    @param mixed $second         Value to compare.
157
-         *    @param mixed $margin         Fuzziness of match.
158
-         *    @param string $message       Message to display.
159
-         *    @return boolean              True on pass
160
-         *    @access public
161
-         */
162
-        function assertOutsideMargin($first, $second, $margin, $message = "%s") {
163
-            return $this->assert(
164
-                    new OutsideMarginExpectation($first, $margin),
165
-                    $second,
166
-                    $message);
167
-        }
152
+		/**
153
+		 *    Will trigger a pass if the two parameters differ
154
+		 *    by more than the margin.
155
+		 *    @param mixed $first          Value to compare.
156
+		 *    @param mixed $second         Value to compare.
157
+		 *    @param mixed $margin         Fuzziness of match.
158
+		 *    @param string $message       Message to display.
159
+		 *    @return boolean              True on pass
160
+		 *    @access public
161
+		 */
162
+		function assertOutsideMargin($first, $second, $margin, $message = "%s") {
163
+			return $this->assert(
164
+					new OutsideMarginExpectation($first, $margin),
165
+					$second,
166
+					$message);
167
+		}
168 168
 
169
-        /**
170
-         *    Will trigger a pass if the two parameters have
171
-         *    the same value and same type. Otherwise a fail.
172
-         *    @param mixed $first           Value to compare.
173
-         *    @param mixed $second          Value to compare.
174
-         *    @param string $message        Message to display.
175
-         *    @return boolean               True on pass
176
-         *    @access public
177
-         */
178
-        function assertIdentical($first, $second, $message = "%s") {
179
-            return $this->assert(
180
-                    new IdenticalExpectation($first),
181
-                    $second,
182
-                    $message);
183
-        }
169
+		/**
170
+		 *    Will trigger a pass if the two parameters have
171
+		 *    the same value and same type. Otherwise a fail.
172
+		 *    @param mixed $first           Value to compare.
173
+		 *    @param mixed $second          Value to compare.
174
+		 *    @param string $message        Message to display.
175
+		 *    @return boolean               True on pass
176
+		 *    @access public
177
+		 */
178
+		function assertIdentical($first, $second, $message = "%s") {
179
+			return $this->assert(
180
+					new IdenticalExpectation($first),
181
+					$second,
182
+					$message);
183
+		}
184 184
 
185
-        /**
186
-         *    Will trigger a pass if the two parameters have
187
-         *    the different value or different type.
188
-         *    @param mixed $first           Value to compare.
189
-         *    @param mixed $second          Value to compare.
190
-         *    @param string $message        Message to display.
191
-         *    @return boolean               True on pass
192
-         *    @access public
193
-         */
194
-        function assertNotIdentical($first, $second, $message = "%s") {
195
-            return $this->assert(
196
-                    new NotIdenticalExpectation($first),
197
-                    $second,
198
-                    $message);
199
-        }
185
+		/**
186
+		 *    Will trigger a pass if the two parameters have
187
+		 *    the different value or different type.
188
+		 *    @param mixed $first           Value to compare.
189
+		 *    @param mixed $second          Value to compare.
190
+		 *    @param string $message        Message to display.
191
+		 *    @return boolean               True on pass
192
+		 *    @access public
193
+		 */
194
+		function assertNotIdentical($first, $second, $message = "%s") {
195
+			return $this->assert(
196
+					new NotIdenticalExpectation($first),
197
+					$second,
198
+					$message);
199
+		}
200 200
 
201
-        /**
202
-         *    Will trigger a pass if both parameters refer
203
-         *    to the same object. Fail otherwise.
204
-         *    @param mixed $first           Object reference to check.
205
-         *    @param mixed $second          Hopefully the same object.
206
-         *    @param string $message        Message to display.
207
-         *    @return boolean               True on pass
208
-         *    @access public
209
-         */
210
-        function assertReference($first, $second, $message = "%s") {
211
-            $dumper = new SimpleDumper();
212
-            $message = sprintf(
213
-                    $message,
214
-                    "[" . $dumper->describeValue($first) .
215
-                            "] and [" . $dumper->describeValue($second) .
216
-                            "] should reference the same object");
217
-            return $this->assertTrue(
218
-                    SimpleTestCompatibility::isReference($first, $second),
219
-                    $message);
220
-        }
201
+		/**
202
+		 *    Will trigger a pass if both parameters refer
203
+		 *    to the same object. Fail otherwise.
204
+		 *    @param mixed $first           Object reference to check.
205
+		 *    @param mixed $second          Hopefully the same object.
206
+		 *    @param string $message        Message to display.
207
+		 *    @return boolean               True on pass
208
+		 *    @access public
209
+		 */
210
+		function assertReference($first, $second, $message = "%s") {
211
+			$dumper = new SimpleDumper();
212
+			$message = sprintf(
213
+					$message,
214
+					"[" . $dumper->describeValue($first) .
215
+							"] and [" . $dumper->describeValue($second) .
216
+							"] should reference the same object");
217
+			return $this->assertTrue(
218
+					SimpleTestCompatibility::isReference($first, $second),
219
+					$message);
220
+		}
221 221
 
222
-        /**
223
-         *    Will trigger a pass if both parameters refer
224
-         *    to different objects. Fail otherwise. The objects
225
-         *    have to be identical though.
226
-         *    @param mixed $first           Object reference to check.
227
-         *    @param mixed $second          Hopefully not the same object.
228
-         *    @param string $message        Message to display.
229
-         *    @return boolean               True on pass
230
-         *    @access public
231
-         */
232
-        function assertClone($first, $second, $message = "%s") {
233
-            $dumper = new SimpleDumper();
234
-            $message = sprintf(
235
-                    $message,
236
-                    "[" . $dumper->describeValue($first) .
237
-                            "] and [" . $dumper->describeValue($second) .
238
-                            "] should not be the same object");
239
-            $identical = new IdenticalExpectation($first);
240
-            return $this->assertTrue(
241
-                    $identical->test($second) &&
242
-                            ! SimpleTestCompatibility::isReference($first, $second),
243
-                    $message);
244
-        }
222
+		/**
223
+		 *    Will trigger a pass if both parameters refer
224
+		 *    to different objects. Fail otherwise. The objects
225
+		 *    have to be identical though.
226
+		 *    @param mixed $first           Object reference to check.
227
+		 *    @param mixed $second          Hopefully not the same object.
228
+		 *    @param string $message        Message to display.
229
+		 *    @return boolean               True on pass
230
+		 *    @access public
231
+		 */
232
+		function assertClone($first, $second, $message = "%s") {
233
+			$dumper = new SimpleDumper();
234
+			$message = sprintf(
235
+					$message,
236
+					"[" . $dumper->describeValue($first) .
237
+							"] and [" . $dumper->describeValue($second) .
238
+							"] should not be the same object");
239
+			$identical = new IdenticalExpectation($first);
240
+			return $this->assertTrue(
241
+					$identical->test($second) &&
242
+							! SimpleTestCompatibility::isReference($first, $second),
243
+					$message);
244
+		}
245 245
 
246
-        /**
247
-         *    @deprecated
248
-         */
249
-        function assertCopy($first, $second, $message = "%s") {
250
-            $dumper = new SimpleDumper();
251
-            $message = sprintf(
252
-                    $message,
253
-                    "[" . $dumper->describeValue($first) .
254
-                            "] and [" . $dumper->describeValue($second) .
255
-                            "] should not be the same object");
256
-            return $this->assertFalse(
257
-                    SimpleTestCompatibility::isReference($first, $second),
258
-                    $message);
259
-        }
246
+		/**
247
+		 *    @deprecated
248
+		 */
249
+		function assertCopy($first, $second, $message = "%s") {
250
+			$dumper = new SimpleDumper();
251
+			$message = sprintf(
252
+					$message,
253
+					"[" . $dumper->describeValue($first) .
254
+							"] and [" . $dumper->describeValue($second) .
255
+							"] should not be the same object");
256
+			return $this->assertFalse(
257
+					SimpleTestCompatibility::isReference($first, $second),
258
+					$message);
259
+		}
260 260
 
261
-        /**
262
-         *    Will trigger a pass if the Perl regex pattern
263
-         *    is found in the subject. Fail otherwise.
264
-         *    @param string $pattern    Perl regex to look for including
265
-         *                              the regex delimiters.
266
-         *    @param string $subject    String to search in.
267
-         *    @param string $message    Message to display.
268
-         *    @return boolean           True on pass
269
-         *    @access public
270
-         */
271
-        function assertPattern($pattern, $subject, $message = "%s") {
272
-            return $this->assert(
273
-                    new PatternExpectation($pattern),
274
-                    $subject,
275
-                    $message);
276
-        }
261
+		/**
262
+		 *    Will trigger a pass if the Perl regex pattern
263
+		 *    is found in the subject. Fail otherwise.
264
+		 *    @param string $pattern    Perl regex to look for including
265
+		 *                              the regex delimiters.
266
+		 *    @param string $subject    String to search in.
267
+		 *    @param string $message    Message to display.
268
+		 *    @return boolean           True on pass
269
+		 *    @access public
270
+		 */
271
+		function assertPattern($pattern, $subject, $message = "%s") {
272
+			return $this->assert(
273
+					new PatternExpectation($pattern),
274
+					$subject,
275
+					$message);
276
+		}
277 277
 
278
-        /**
279
-         *	  @deprecated
280
-         */
281
-        function assertWantedPattern($pattern, $subject, $message = "%s") {
282
-        	return $this->assertPattern($pattern, $subject, $message);
283
-        }
278
+		/**
279
+		 *	  @deprecated
280
+		 */
281
+		function assertWantedPattern($pattern, $subject, $message = "%s") {
282
+			return $this->assertPattern($pattern, $subject, $message);
283
+		}
284 284
 
285
-        /**
286
-         *    Will trigger a pass if the perl regex pattern
287
-         *    is not present in subject. Fail if found.
288
-         *    @param string $pattern    Perl regex to look for including
289
-         *                              the regex delimiters.
290
-         *    @param string $subject    String to search in.
291
-         *    @param string $message    Message to display.
292
-         *    @return boolean           True on pass
293
-         *    @access public
294
-         */
295
-        function assertNoPattern($pattern, $subject, $message = "%s") {
296
-            return $this->assert(
297
-                    new NoPatternExpectation($pattern),
298
-                    $subject,
299
-                    $message);
300
-        }
285
+		/**
286
+		 *    Will trigger a pass if the perl regex pattern
287
+		 *    is not present in subject. Fail if found.
288
+		 *    @param string $pattern    Perl regex to look for including
289
+		 *                              the regex delimiters.
290
+		 *    @param string $subject    String to search in.
291
+		 *    @param string $message    Message to display.
292
+		 *    @return boolean           True on pass
293
+		 *    @access public
294
+		 */
295
+		function assertNoPattern($pattern, $subject, $message = "%s") {
296
+			return $this->assert(
297
+					new NoPatternExpectation($pattern),
298
+					$subject,
299
+					$message);
300
+		}
301 301
 
302
-        /**
303
-         *	  @deprecated
304
-         */
305
-        function assertNoUnwantedPattern($pattern, $subject, $message = "%s") {
306
-        	return $this->assertNoPattern($pattern, $subject, $message);
307
-        }
302
+		/**
303
+		 *	  @deprecated
304
+		 */
305
+		function assertNoUnwantedPattern($pattern, $subject, $message = "%s") {
306
+			return $this->assertNoPattern($pattern, $subject, $message);
307
+		}
308 308
 
309
-        /**
310
-         *    Confirms that no errors have occoured so
311
-         *    far in the test method.
312
-         *    @param string $message    Message to display.
313
-         *    @return boolean           True on pass
314
-         *    @access public
315
-         */
316
-        function assertNoErrors($message = "%s") {
317
-            $queue = &SimpleErrorQueue::instance();
318
-            return $this->assertTrue(
319
-                    $queue->isEmpty(),
320
-                    sprintf($message, "Should be no errors"));
321
-        }
309
+		/**
310
+		 *    Confirms that no errors have occoured so
311
+		 *    far in the test method.
312
+		 *    @param string $message    Message to display.
313
+		 *    @return boolean           True on pass
314
+		 *    @access public
315
+		 */
316
+		function assertNoErrors($message = "%s") {
317
+			$queue = &SimpleErrorQueue::instance();
318
+			return $this->assertTrue(
319
+					$queue->isEmpty(),
320
+					sprintf($message, "Should be no errors"));
321
+		}
322 322
 
323
-        /**
324
-         *    Confirms that an error has occoured and
325
-         *    optionally that the error text matches exactly.
326
-         *    @param string $expected   Expected error text or
327
-         *                              false for no check.
328
-         *    @param string $message    Message to display.
329
-         *    @return boolean           True on pass
330
-         *    @access public
331
-         */
332
-        function assertError($expected = false, $message = "%s") {
333
-            $queue = &SimpleErrorQueue::instance();
334
-            if ($queue->isEmpty()) {
335
-                $this->fail(sprintf($message, "Expected error not found"));
336
-                return;
337
-            }
338
-            list($severity, $content, $file, $line, $globals) = $queue->extract();
339
-            $severity = SimpleErrorQueue::getSeverityAsString($severity);
340
-            if (! $expected) {
341
-                return $this->pass(
342
-                        "Captured a PHP error of [$content] severity [$severity] in [$file] line [$line] -> %s");
343
-            }
344
-            $expected = $this->_coerceToExpectation($expected);
345
-            return $this->assert(
346
-                    $expected,
347
-                    $content,
348
-                    "Expected PHP error [$content] severity [$severity] in [$file] line [$line] -> %s");
349
-        }
323
+		/**
324
+		 *    Confirms that an error has occoured and
325
+		 *    optionally that the error text matches exactly.
326
+		 *    @param string $expected   Expected error text or
327
+		 *                              false for no check.
328
+		 *    @param string $message    Message to display.
329
+		 *    @return boolean           True on pass
330
+		 *    @access public
331
+		 */
332
+		function assertError($expected = false, $message = "%s") {
333
+			$queue = &SimpleErrorQueue::instance();
334
+			if ($queue->isEmpty()) {
335
+				$this->fail(sprintf($message, "Expected error not found"));
336
+				return;
337
+			}
338
+			list($severity, $content, $file, $line, $globals) = $queue->extract();
339
+			$severity = SimpleErrorQueue::getSeverityAsString($severity);
340
+			if (! $expected) {
341
+				return $this->pass(
342
+						"Captured a PHP error of [$content] severity [$severity] in [$file] line [$line] -> %s");
343
+			}
344
+			$expected = $this->_coerceToExpectation($expected);
345
+			return $this->assert(
346
+					$expected,
347
+					$content,
348
+					"Expected PHP error [$content] severity [$severity] in [$file] line [$line] -> %s");
349
+		}
350 350
 
351
-        /**
352
-         *    Creates an equality expectation if the
353
-         *    object/value is not already some type
354
-         *    of expectation.
355
-         *    @param mixed $expected      Expected value.
356
-         *    @return SimpleExpectation   Expectation object.
357
-         *    @access private
358
-         */
359
-        function _coerceToExpectation($expected) {
360
-            if (SimpleTestCompatibility::isA($expected, 'SimpleExpectation')) {
361
-                return $expected;
362
-            }
363
-            return new EqualExpectation($expected);
364
-        }
351
+		/**
352
+		 *    Creates an equality expectation if the
353
+		 *    object/value is not already some type
354
+		 *    of expectation.
355
+		 *    @param mixed $expected      Expected value.
356
+		 *    @return SimpleExpectation   Expectation object.
357
+		 *    @access private
358
+		 */
359
+		function _coerceToExpectation($expected) {
360
+			if (SimpleTestCompatibility::isA($expected, 'SimpleExpectation')) {
361
+				return $expected;
362
+			}
363
+			return new EqualExpectation($expected);
364
+		}
365 365
 
366
-        /**
367
-         *    @deprecated
368
-         */
369
-        function assertErrorPattern($pattern, $message = "%s") {
370
-            return $this->assertError(new PatternExpectation($pattern), $message);
371
-        }
372
-    }
366
+		/**
367
+		 *    @deprecated
368
+		 */
369
+		function assertErrorPattern($pattern, $message = "%s") {
370
+			return $this->assertError(new PatternExpectation($pattern), $message);
371
+		}
372
+	}
Please login to merge, or discard this patch.
tests/test_tools/simpletest/mock_objects.php 1 patch
Indentation   +1257 added lines, -1257 removed lines patch added patch discarded remove patch
@@ -1,1272 +1,1272 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *	base include file for SimpleTest
4
-     *	@package	SimpleTest
5
-     *	@subpackage	MockObjects
6
-     *	@version	$Id: mock_objects.php 1532 2006-12-01 12:28:55Z xue $
7
-     */
8
-
9
-    /**#@+
2
+	/**
3
+	 *	base include file for SimpleTest
4
+	 *	@package	SimpleTest
5
+	 *	@subpackage	MockObjects
6
+	 *	@version	$Id: mock_objects.php 1532 2006-12-01 12:28:55Z xue $
7
+	 */
8
+
9
+	/**#@+
10 10
      * include SimpleTest files
11 11
      */
12
-    require_once(dirname(__FILE__) . '/expectation.php');
13
-    require_once(dirname(__FILE__) . '/simpletest.php');
14
-    require_once(dirname(__FILE__) . '/dumper.php');
15
-    if (version_compare(phpversion(), '5') >= 0) {
16
-        require_once(dirname(__FILE__) . '/reflection_php5.php');
17
-    } else {
18
-        require_once(dirname(__FILE__) . '/reflection_php4.php');
19
-    }
20
-    /**#@-*/
21
-
22
-    /**
23
-     * Default character simpletest will substitute for any value
24
-     */
25
-    if (! defined('MOCK_ANYTHING')) {
26
-        define('MOCK_ANYTHING', '*');
27
-    }
28
-
29
-    /**
30
-     *    A wildcard expectation always matches.
12
+	require_once(dirname(__FILE__) . '/expectation.php');
13
+	require_once(dirname(__FILE__) . '/simpletest.php');
14
+	require_once(dirname(__FILE__) . '/dumper.php');
15
+	if (version_compare(phpversion(), '5') >= 0) {
16
+		require_once(dirname(__FILE__) . '/reflection_php5.php');
17
+	} else {
18
+		require_once(dirname(__FILE__) . '/reflection_php4.php');
19
+	}
20
+	/**#@-*/
21
+
22
+	/**
23
+	 * Default character simpletest will substitute for any value
24
+	 */
25
+	if (! defined('MOCK_ANYTHING')) {
26
+		define('MOCK_ANYTHING', '*');
27
+	}
28
+
29
+	/**
30
+	 *    A wildcard expectation always matches.
31 31
 	 *    @package SimpleTest
32 32
 	 *    @subpackage MockObjects
33
-     */
34
-    class AnythingExpectation extends SimpleExpectation {
35
-
36
-        /**
37
-         *    Tests the expectation. Always true.
38
-         *    @param mixed $compare  Ignored.
39
-         *    @return boolean        True.
40
-         *    @access public
41
-         */
42
-        function test($compare) {
43
-            return true;
44
-        }
45
-
46
-        /**
47
-         *    Returns a human readable test message.
48
-         *    @param mixed $compare      Comparison value.
49
-         *    @return string             Description of success
50
-         *                               or failure.
51
-         *    @access public
52
-         */
53
-        function testMessage($compare) {
54
-            $dumper = $this->_getDumper();
55
-            return 'Anything always matches [' . $dumper->describeValue($compare) . ']';
56
-        }
57
-    }
58
-
59
-    /**
60
-     *    Parameter comparison assertion.
33
+	 */
34
+	class AnythingExpectation extends SimpleExpectation {
35
+
36
+		/**
37
+		 *    Tests the expectation. Always true.
38
+		 *    @param mixed $compare  Ignored.
39
+		 *    @return boolean        True.
40
+		 *    @access public
41
+		 */
42
+		function test($compare) {
43
+			return true;
44
+		}
45
+
46
+		/**
47
+		 *    Returns a human readable test message.
48
+		 *    @param mixed $compare      Comparison value.
49
+		 *    @return string             Description of success
50
+		 *                               or failure.
51
+		 *    @access public
52
+		 */
53
+		function testMessage($compare) {
54
+			$dumper = $this->_getDumper();
55
+			return 'Anything always matches [' . $dumper->describeValue($compare) . ']';
56
+		}
57
+	}
58
+
59
+	/**
60
+	 *    Parameter comparison assertion.
61 61
 	 *    @package SimpleTest
62 62
 	 *    @subpackage MockObjects
63
-     */
64
-    class ParametersExpectation extends SimpleExpectation {
65
-        protected $_expected;
66
-
67
-        /**
68
-         *    Sets the expected parameter list.
69
-         *    @param array $parameters  Array of parameters including
70
-         *                              those that are wildcarded.
71
-         *                              If the value is not an array
72
-         *                              then it is considered to match any.
73
-         *    @param mixed $wildcard    Any parameter matching this
74
-         *                              will always match.
75
-         *    @param string $message    Customised message on failure.
76
-         *    @access public
77
-         */
78
-        function ParametersExpectation($expected = false, $message = '%s') {
79
-            $this->SimpleExpectation($message);
80
-            $this->_expected = $expected;
81
-        }
82
-
83
-        /**
84
-         *    Tests the assertion. True if correct.
85
-         *    @param array $parameters     Comparison values.
86
-         *    @return boolean              True if correct.
87
-         *    @access public
88
-         */
89
-        function test($parameters) {
90
-            if (! is_array($this->_expected)) {
91
-                return true;
92
-            }
93
-            if (count($this->_expected) != count($parameters)) {
94
-                return false;
95
-            }
96
-            for ($i = 0; $i < count($this->_expected); $i++) {
97
-                if (! $this->_testParameter($parameters[$i], $this->_expected[$i])) {
98
-                    return false;
99
-                }
100
-            }
101
-            return true;
102
-        }
103
-
104
-        /**
105
-         *    Tests an individual parameter.
106
-         *    @param mixed $parameter    Value to test.
107
-         *    @param mixed $expected     Comparison value.
108
-         *    @return boolean            True if expectation
109
-         *                               fulfilled.
110
-         *    @access private
111
-         */
112
-        function _testParameter($parameter, $expected) {
113
-            $comparison = $this->_coerceToExpectation($expected);
114
-            return $comparison->test($parameter);
115
-        }
116
-
117
-        /**
118
-         *    Returns a human readable test message.
119
-         *    @param array $comparison   Incoming parameter list.
120
-         *    @return string             Description of success
121
-         *                               or failure.
122
-         *    @access public
123
-         */
124
-        function testMessage($parameters) {
125
-            if ($this->test($parameters)) {
126
-                return "Expectation of " . count($this->_expected) .
127
-                        " arguments of [" . $this->_renderArguments($this->_expected) .
128
-                        "] is correct";
129
-            } else {
130
-                return $this->_describeDifference($this->_expected, $parameters);
131
-            }
132
-        }
133
-
134
-        /**
135
-         *    Message to display if expectation differs from
136
-         *    the parameters actually received.
137
-         *    @param array $expected      Expected parameters as list.
138
-         *    @param array $parameters    Actual parameters received.
139
-         *    @return string              Description of difference.
140
-         *    @access private
141
-         */
142
-        function _describeDifference($expected, $parameters) {
143
-            if (count($expected) != count($parameters)) {
144
-                return "Expected " . count($expected) .
145
-                        " arguments of [" . $this->_renderArguments($expected) .
146
-                        "] but got " . count($parameters) .
147
-                        " arguments of [" . $this->_renderArguments($parameters) . "]";
148
-            }
149
-            $messages = array();
150
-            for ($i = 0; $i < count($expected); $i++) {
151
-                $comparison = $this->_coerceToExpectation($expected[$i]);
152
-                if (! $comparison->test($parameters[$i])) {
153
-                    $messages[] = "parameter " . ($i + 1) . " with [" .
154
-                            $comparison->overlayMessage($parameters[$i]) . "]";
155
-                }
156
-            }
157
-            return "Parameter expectation differs at " . implode(" and ", $messages);
158
-        }
159
-
160
-        /**
161
-         *    Creates an identical expectation if the
162
-         *    object/value is not already some type
163
-         *    of expectation.
164
-         *    @param mixed $expected      Expected value.
165
-         *    @return SimpleExpectation   Expectation object.
166
-         *    @access private
167
-         */
168
-        function _coerceToExpectation($expected) {
169
-            if (SimpleExpectation::isExpectation($expected)) {
170
-                return $expected;
171
-            }
172
-            return new IdenticalExpectation($expected);
173
-        }
174
-
175
-        /**
176
-         *    Renders the argument list as a string for
177
-         *    messages.
178
-         *    @param array $args    Incoming arguments.
179
-         *    @return string        Simple description of type and value.
180
-         *    @access private
181
-         */
182
-        function _renderArguments($args) {
183
-            $descriptions = array();
184
-            if (is_array($args)) {
185
-                foreach ($args as $arg) {
186
-                    $dumper = new SimpleDumper();
187
-                    $descriptions[] = $dumper->describeValue($arg);
188
-                }
189
-            }
190
-            return implode(', ', $descriptions);
191
-        }
192
-    }
193
-
194
-    /**
195
-     *    Confirms that the number of calls on a method is as expected.
196
-     */
197
-    class CallCountExpectation extends SimpleExpectation {
198
-        protected $_method;
199
-        protected $_count;
200
-
201
-        /**
202
-         *    Stashes the method and expected count for later
203
-         *    reporting.
204
-         *    @param string $method    Name of method to confirm against.
205
-         *    @param integer $count    Expected number of calls.
206
-         *    @param string $message   Custom error message.
207
-         */
208
-        function CallCountExpectation($method, $count, $message = '%s') {
209
-            $this->_method = $method;
210
-            $this->_count = $count;
211
-            $this->SimpleExpectation($message);
212
-        }
213
-
214
-        /**
215
-         *    Tests the assertion. True if correct.
216
-         *    @param integer $compare     Measured call count.
217
-         *    @return boolean             True if expected.
218
-         *    @access public
219
-         */
220
-        function test($compare) {
221
-            return ($this->_count == $compare);
222
-        }
223
-
224
-        /**
225
-         *    Reports the comparison.
226
-         *    @param integer $compare     Measured call count.
227
-         *    @return string              Message to show.
228
-         *    @access public
229
-         */
230
-        function testMessage($compare) {
231
-            return 'Expected call count for [' . $this->_method .
232
-                    '] was [' . $this->_count .
233
-                    '] got [' . $compare . ']';
234
-        }
235
-    }
236
-
237
-    /**
238
-     *    Confirms that the number of calls on a method is as expected.
239
-     */
240
-    class MinimumCallCountExpectation extends SimpleExpectation {
241
-        protected $_method;
242
-        protected $_count;
243
-
244
-        /**
245
-         *    Stashes the method and expected count for later
246
-         *    reporting.
247
-         *    @param string $method    Name of method to confirm against.
248
-         *    @param integer $count    Minimum number of calls.
249
-         *    @param string $message   Custom error message.
250
-         */
251
-        function MinimumCallCountExpectation($method, $count, $message = '%s') {
252
-            $this->_method = $method;
253
-            $this->_count = $count;
254
-            $this->SimpleExpectation($message);
255
-        }
256
-
257
-        /**
258
-         *    Tests the assertion. True if correct.
259
-         *    @param integer $compare     Measured call count.
260
-         *    @return boolean             True if enough.
261
-         *    @access public
262
-         */
263
-        function test($compare) {
264
-            return ($this->_count <= $compare);
265
-        }
266
-
267
-        /**
268
-         *    Reports the comparison.
269
-         *    @param integer $compare     Measured call count.
270
-         *    @return string              Message to show.
271
-         *    @access public
272
-         */
273
-        function testMessage($compare) {
274
-            return 'Minimum call count for [' . $this->_method .
275
-                    '] was [' . $this->_count .
276
-                    '] got [' . $compare . ']';
277
-        }
278
-    }
279
-
280
-    /**
281
-     *    Confirms that the number of calls on a method is as expected.
282
-     */
283
-    class MaximumCallCountExpectation extends SimpleExpectation {
284
-        protected $_method;
285
-        protected $_count;
286
-
287
-        /**
288
-         *    Stashes the method and expected count for later
289
-         *    reporting.
290
-         *    @param string $method    Name of method to confirm against.
291
-         *    @param integer $count    Minimum number of calls.
292
-         *    @param string $message   Custom error message.
293
-         */
294
-        function MaximumCallCountExpectation($method, $count, $message = '%s') {
295
-            $this->_method = $method;
296
-            $this->_count = $count;
297
-            $this->SimpleExpectation($message);
298
-        }
299
-
300
-        /**
301
-         *    Tests the assertion. True if correct.
302
-         *    @param integer $compare     Measured call count.
303
-         *    @return boolean             True if not over.
304
-         *    @access public
305
-         */
306
-        function test($compare) {
307
-            return ($this->_count >= $compare);
308
-        }
309
-
310
-        /**
311
-         *    Reports the comparison.
312
-         *    @param integer $compare     Measured call count.
313
-         *    @return string              Message to show.
314
-         *    @access public
315
-         */
316
-        function testMessage($compare) {
317
-            return 'Maximum call count for [' . $this->_method .
318
-                    '] was [' . $this->_count .
319
-                    '] got [' . $compare . ']';
320
-        }
321
-    }
322
-
323
-    /**
324
-     *    Retrieves values and references by searching the
325
-     *    parameter lists until a match is found.
63
+	 */
64
+	class ParametersExpectation extends SimpleExpectation {
65
+		protected $_expected;
66
+
67
+		/**
68
+		 *    Sets the expected parameter list.
69
+		 *    @param array $parameters  Array of parameters including
70
+		 *                              those that are wildcarded.
71
+		 *                              If the value is not an array
72
+		 *                              then it is considered to match any.
73
+		 *    @param mixed $wildcard    Any parameter matching this
74
+		 *                              will always match.
75
+		 *    @param string $message    Customised message on failure.
76
+		 *    @access public
77
+		 */
78
+		function ParametersExpectation($expected = false, $message = '%s') {
79
+			$this->SimpleExpectation($message);
80
+			$this->_expected = $expected;
81
+		}
82
+
83
+		/**
84
+		 *    Tests the assertion. True if correct.
85
+		 *    @param array $parameters     Comparison values.
86
+		 *    @return boolean              True if correct.
87
+		 *    @access public
88
+		 */
89
+		function test($parameters) {
90
+			if (! is_array($this->_expected)) {
91
+				return true;
92
+			}
93
+			if (count($this->_expected) != count($parameters)) {
94
+				return false;
95
+			}
96
+			for ($i = 0; $i < count($this->_expected); $i++) {
97
+				if (! $this->_testParameter($parameters[$i], $this->_expected[$i])) {
98
+					return false;
99
+				}
100
+			}
101
+			return true;
102
+		}
103
+
104
+		/**
105
+		 *    Tests an individual parameter.
106
+		 *    @param mixed $parameter    Value to test.
107
+		 *    @param mixed $expected     Comparison value.
108
+		 *    @return boolean            True if expectation
109
+		 *                               fulfilled.
110
+		 *    @access private
111
+		 */
112
+		function _testParameter($parameter, $expected) {
113
+			$comparison = $this->_coerceToExpectation($expected);
114
+			return $comparison->test($parameter);
115
+		}
116
+
117
+		/**
118
+		 *    Returns a human readable test message.
119
+		 *    @param array $comparison   Incoming parameter list.
120
+		 *    @return string             Description of success
121
+		 *                               or failure.
122
+		 *    @access public
123
+		 */
124
+		function testMessage($parameters) {
125
+			if ($this->test($parameters)) {
126
+				return "Expectation of " . count($this->_expected) .
127
+						" arguments of [" . $this->_renderArguments($this->_expected) .
128
+						"] is correct";
129
+			} else {
130
+				return $this->_describeDifference($this->_expected, $parameters);
131
+			}
132
+		}
133
+
134
+		/**
135
+		 *    Message to display if expectation differs from
136
+		 *    the parameters actually received.
137
+		 *    @param array $expected      Expected parameters as list.
138
+		 *    @param array $parameters    Actual parameters received.
139
+		 *    @return string              Description of difference.
140
+		 *    @access private
141
+		 */
142
+		function _describeDifference($expected, $parameters) {
143
+			if (count($expected) != count($parameters)) {
144
+				return "Expected " . count($expected) .
145
+						" arguments of [" . $this->_renderArguments($expected) .
146
+						"] but got " . count($parameters) .
147
+						" arguments of [" . $this->_renderArguments($parameters) . "]";
148
+			}
149
+			$messages = array();
150
+			for ($i = 0; $i < count($expected); $i++) {
151
+				$comparison = $this->_coerceToExpectation($expected[$i]);
152
+				if (! $comparison->test($parameters[$i])) {
153
+					$messages[] = "parameter " . ($i + 1) . " with [" .
154
+							$comparison->overlayMessage($parameters[$i]) . "]";
155
+				}
156
+			}
157
+			return "Parameter expectation differs at " . implode(" and ", $messages);
158
+		}
159
+
160
+		/**
161
+		 *    Creates an identical expectation if the
162
+		 *    object/value is not already some type
163
+		 *    of expectation.
164
+		 *    @param mixed $expected      Expected value.
165
+		 *    @return SimpleExpectation   Expectation object.
166
+		 *    @access private
167
+		 */
168
+		function _coerceToExpectation($expected) {
169
+			if (SimpleExpectation::isExpectation($expected)) {
170
+				return $expected;
171
+			}
172
+			return new IdenticalExpectation($expected);
173
+		}
174
+
175
+		/**
176
+		 *    Renders the argument list as a string for
177
+		 *    messages.
178
+		 *    @param array $args    Incoming arguments.
179
+		 *    @return string        Simple description of type and value.
180
+		 *    @access private
181
+		 */
182
+		function _renderArguments($args) {
183
+			$descriptions = array();
184
+			if (is_array($args)) {
185
+				foreach ($args as $arg) {
186
+					$dumper = new SimpleDumper();
187
+					$descriptions[] = $dumper->describeValue($arg);
188
+				}
189
+			}
190
+			return implode(', ', $descriptions);
191
+		}
192
+	}
193
+
194
+	/**
195
+	 *    Confirms that the number of calls on a method is as expected.
196
+	 */
197
+	class CallCountExpectation extends SimpleExpectation {
198
+		protected $_method;
199
+		protected $_count;
200
+
201
+		/**
202
+		 *    Stashes the method and expected count for later
203
+		 *    reporting.
204
+		 *    @param string $method    Name of method to confirm against.
205
+		 *    @param integer $count    Expected number of calls.
206
+		 *    @param string $message   Custom error message.
207
+		 */
208
+		function CallCountExpectation($method, $count, $message = '%s') {
209
+			$this->_method = $method;
210
+			$this->_count = $count;
211
+			$this->SimpleExpectation($message);
212
+		}
213
+
214
+		/**
215
+		 *    Tests the assertion. True if correct.
216
+		 *    @param integer $compare     Measured call count.
217
+		 *    @return boolean             True if expected.
218
+		 *    @access public
219
+		 */
220
+		function test($compare) {
221
+			return ($this->_count == $compare);
222
+		}
223
+
224
+		/**
225
+		 *    Reports the comparison.
226
+		 *    @param integer $compare     Measured call count.
227
+		 *    @return string              Message to show.
228
+		 *    @access public
229
+		 */
230
+		function testMessage($compare) {
231
+			return 'Expected call count for [' . $this->_method .
232
+					'] was [' . $this->_count .
233
+					'] got [' . $compare . ']';
234
+		}
235
+	}
236
+
237
+	/**
238
+	 *    Confirms that the number of calls on a method is as expected.
239
+	 */
240
+	class MinimumCallCountExpectation extends SimpleExpectation {
241
+		protected $_method;
242
+		protected $_count;
243
+
244
+		/**
245
+		 *    Stashes the method and expected count for later
246
+		 *    reporting.
247
+		 *    @param string $method    Name of method to confirm against.
248
+		 *    @param integer $count    Minimum number of calls.
249
+		 *    @param string $message   Custom error message.
250
+		 */
251
+		function MinimumCallCountExpectation($method, $count, $message = '%s') {
252
+			$this->_method = $method;
253
+			$this->_count = $count;
254
+			$this->SimpleExpectation($message);
255
+		}
256
+
257
+		/**
258
+		 *    Tests the assertion. True if correct.
259
+		 *    @param integer $compare     Measured call count.
260
+		 *    @return boolean             True if enough.
261
+		 *    @access public
262
+		 */
263
+		function test($compare) {
264
+			return ($this->_count <= $compare);
265
+		}
266
+
267
+		/**
268
+		 *    Reports the comparison.
269
+		 *    @param integer $compare     Measured call count.
270
+		 *    @return string              Message to show.
271
+		 *    @access public
272
+		 */
273
+		function testMessage($compare) {
274
+			return 'Minimum call count for [' . $this->_method .
275
+					'] was [' . $this->_count .
276
+					'] got [' . $compare . ']';
277
+		}
278
+	}
279
+
280
+	/**
281
+	 *    Confirms that the number of calls on a method is as expected.
282
+	 */
283
+	class MaximumCallCountExpectation extends SimpleExpectation {
284
+		protected $_method;
285
+		protected $_count;
286
+
287
+		/**
288
+		 *    Stashes the method and expected count for later
289
+		 *    reporting.
290
+		 *    @param string $method    Name of method to confirm against.
291
+		 *    @param integer $count    Minimum number of calls.
292
+		 *    @param string $message   Custom error message.
293
+		 */
294
+		function MaximumCallCountExpectation($method, $count, $message = '%s') {
295
+			$this->_method = $method;
296
+			$this->_count = $count;
297
+			$this->SimpleExpectation($message);
298
+		}
299
+
300
+		/**
301
+		 *    Tests the assertion. True if correct.
302
+		 *    @param integer $compare     Measured call count.
303
+		 *    @return boolean             True if not over.
304
+		 *    @access public
305
+		 */
306
+		function test($compare) {
307
+			return ($this->_count >= $compare);
308
+		}
309
+
310
+		/**
311
+		 *    Reports the comparison.
312
+		 *    @param integer $compare     Measured call count.
313
+		 *    @return string              Message to show.
314
+		 *    @access public
315
+		 */
316
+		function testMessage($compare) {
317
+			return 'Maximum call count for [' . $this->_method .
318
+					'] was [' . $this->_count .
319
+					'] got [' . $compare . ']';
320
+		}
321
+	}
322
+
323
+	/**
324
+	 *    Retrieves values and references by searching the
325
+	 *    parameter lists until a match is found.
326 326
 	 *    @package SimpleTest
327 327
 	 *    @subpackage MockObjects
328
-     */
329
-    class CallMap {
330
-        protected $_map;
331
-
332
-        /**
333
-         *    Creates an empty call map.
334
-         *    @access public
335
-         */
336
-        function CallMap() {
337
-            $this->_map = array();
338
-        }
339
-
340
-        /**
341
-         *    Stashes a value against a method call.
342
-         *    @param array $parameters    Arguments including wildcards.
343
-         *    @param mixed $value         Value copied into the map.
344
-         *    @access public
345
-         */
346
-        function addValue($parameters, $value) {
347
-            $this->addReference($parameters, $value);
348
-        }
349
-
350
-        /**
351
-         *    Stashes a reference against a method call.
352
-         *    @param array $parameters    Array of arguments (including wildcards).
353
-         *    @param mixed $reference     Array reference placed in the map.
354
-         *    @access public
355
-         */
356
-        function addReference($parameters, $reference) {
357
-            $place = count($this->_map);
358
-            $this->_map[$place] = array();
359
-            $this->_map[$place]["params"] = new ParametersExpectation($parameters);
360
-            $this->_map[$place]["content"] = $reference;
361
-        }
362
-
363
-        /**
364
-         *    Searches the call list for a matching parameter
365
-         *    set. Returned by reference.
366
-         *    @param array $parameters    Parameters to search by
367
-         *                                without wildcards.
368
-         *    @return object              Object held in the first matching
369
-         *                                slot, otherwise null.
370
-         *    @access public
371
-         */
372
-        function &findFirstMatch($parameters) {
373
-            $slot = $this->_findFirstSlot($parameters);
374
-            if (!isset($slot)) {
375
-                $null = null;
376
-                return $null;
377
-            }
378
-            return $slot["content"];
379
-        }
380
-
381
-        /**
382
-         *    Searches the call list for a matching parameter
383
-         *    set. True if successful.
384
-         *    @param array $parameters    Parameters to search by
385
-         *                                without wildcards.
386
-         *    @return boolean             True if a match is present.
387
-         *    @access public
388
-         */
389
-        function isMatch($parameters) {
390
-            return ($this->_findFirstSlot($parameters) != null);
391
-        }
392
-
393
-        /**
394
-         *    Searches the map for a matching item.
395
-         *    @param array $parameters    Parameters to search by
396
-         *                                without wildcards.
397
-         *    @return array               Reference to slot or null.
398
-         *    @access private
399
-         */
400
-        function &_findFirstSlot($parameters) {
401
-            $count = count($this->_map);
402
-            for ($i = 0; $i < $count; $i++) {
403
-                if ($this->_map[$i]["params"]->test($parameters)) {
404
-                    return $this->_map[$i];
405
-                }
406
-            }
407
-            $null = null;
408
-            return $null;
409
-        }
410
-    }
411
-
412
-    /**
413
-     *    An empty collection of methods that can have their
414
-     *    return values set and expectations made of the
415
-     *    calls upon them. The mock will assert the
416
-     *    expectations against it's attached test case in
417
-     *    addition to the server stub behaviour.
328
+	 */
329
+	class CallMap {
330
+		protected $_map;
331
+
332
+		/**
333
+		 *    Creates an empty call map.
334
+		 *    @access public
335
+		 */
336
+		function CallMap() {
337
+			$this->_map = array();
338
+		}
339
+
340
+		/**
341
+		 *    Stashes a value against a method call.
342
+		 *    @param array $parameters    Arguments including wildcards.
343
+		 *    @param mixed $value         Value copied into the map.
344
+		 *    @access public
345
+		 */
346
+		function addValue($parameters, $value) {
347
+			$this->addReference($parameters, $value);
348
+		}
349
+
350
+		/**
351
+		 *    Stashes a reference against a method call.
352
+		 *    @param array $parameters    Array of arguments (including wildcards).
353
+		 *    @param mixed $reference     Array reference placed in the map.
354
+		 *    @access public
355
+		 */
356
+		function addReference($parameters, $reference) {
357
+			$place = count($this->_map);
358
+			$this->_map[$place] = array();
359
+			$this->_map[$place]["params"] = new ParametersExpectation($parameters);
360
+			$this->_map[$place]["content"] = $reference;
361
+		}
362
+
363
+		/**
364
+		 *    Searches the call list for a matching parameter
365
+		 *    set. Returned by reference.
366
+		 *    @param array $parameters    Parameters to search by
367
+		 *                                without wildcards.
368
+		 *    @return object              Object held in the first matching
369
+		 *                                slot, otherwise null.
370
+		 *    @access public
371
+		 */
372
+		function &findFirstMatch($parameters) {
373
+			$slot = $this->_findFirstSlot($parameters);
374
+			if (!isset($slot)) {
375
+				$null = null;
376
+				return $null;
377
+			}
378
+			return $slot["content"];
379
+		}
380
+
381
+		/**
382
+		 *    Searches the call list for a matching parameter
383
+		 *    set. True if successful.
384
+		 *    @param array $parameters    Parameters to search by
385
+		 *                                without wildcards.
386
+		 *    @return boolean             True if a match is present.
387
+		 *    @access public
388
+		 */
389
+		function isMatch($parameters) {
390
+			return ($this->_findFirstSlot($parameters) != null);
391
+		}
392
+
393
+		/**
394
+		 *    Searches the map for a matching item.
395
+		 *    @param array $parameters    Parameters to search by
396
+		 *                                without wildcards.
397
+		 *    @return array               Reference to slot or null.
398
+		 *    @access private
399
+		 */
400
+		function &_findFirstSlot($parameters) {
401
+			$count = count($this->_map);
402
+			for ($i = 0; $i < $count; $i++) {
403
+				if ($this->_map[$i]["params"]->test($parameters)) {
404
+					return $this->_map[$i];
405
+				}
406
+			}
407
+			$null = null;
408
+			return $null;
409
+		}
410
+	}
411
+
412
+	/**
413
+	 *    An empty collection of methods that can have their
414
+	 *    return values set and expectations made of the
415
+	 *    calls upon them. The mock will assert the
416
+	 *    expectations against it's attached test case in
417
+	 *    addition to the server stub behaviour.
418 418
 	 *    @package SimpleTest
419 419
 	 *    @subpackage MockObjects
420
-     */
421
-    class SimpleMock {
422
-        protected $_wildcard = MOCK_ANYTHING;
423
-        protected $_is_strict = true;
424
-        protected $_returns;
425
-        protected $_return_sequence;
426
-        protected $_call_counts;
427
-        protected $_expected_counts;
428
-        protected $_max_counts;
429
-        protected $_expected_args;
430
-        protected $_expected_args_at;
431
-
432
-        /**
433
-         *    Creates an empty return list and expectation list.
434
-         *    All call counts are set to zero.
435
-         *    @param SimpleTestCase $test    Test case to test expectations in.
436
-         *    @param mixed $wildcard         Parameter matching wildcard.
437
-         *    @param boolean $is_strict      Enables method name checks on
438
-         *                                   expectations.
439
-         */
440
-        function SimpleMock() {
441
-            $this->_returns = array();
442
-            $this->_return_sequence = array();
443
-            $this->_call_counts = array();
444
-            $test = $this->_getCurrentTestCase();
445
-            $test->tell($this);
446
-            $this->_expected_counts = array();
447
-            $this->_max_counts = array();
448
-            $this->_expected_args = array();
449
-            $this->_expected_args_at = array();
450
-        }
451
-
452
-        /**
453
-         *    Disables a name check when setting expectations.
454
-         *    This hack is needed for the partial mocks.
455
-         *    @access public
456
-         */
457
-        function disableExpectationNameChecks() {
458
-            $this->_is_strict = false;
459
-        }
460
-
461
-        /**
462
-         *    Changes the default wildcard object.
463
-         *    @param mixed $wildcard         Parameter matching wildcard.
464
-         *    @access public
465
-         */
466
-        function setWildcard($wildcard) {
467
-            $this->_wildcard = $wildcard;
468
-        }
469
-
470
-        /**
471
-         *    Finds currently running test.
472
-         *    @return SimpeTestCase    Current test case.
473
-         *    @access protected
474
-         */
475
-        function &_getCurrentTestCase() {
476
-            return SimpleTest::getCurrent();
477
-        }
478
-
479
-        /**
480
-         *    Die if bad arguments array is passed
481
-         *    @param mixed $args     The arguments value to be checked.
482
-         *    @param string $task    Description of task attempt.
483
-         *    @return boolean        Valid arguments
484
-         *    @access private
485
-         */
486
-        function _checkArgumentsIsArray($args, $task) {
487
-        	if (! is_array($args)) {
488
-        		trigger_error(
489
-        			"Cannot $task as \$args parameter is not an array",
490
-        			E_USER_ERROR);
491
-        	}
492
-        }
493
-
494
-        /**
495
-         *    Triggers a PHP error if the method is not part
496
-         *    of this object.
497
-         *    @param string $method        Name of method.
498
-         *    @param string $task          Description of task attempt.
499
-         *    @access protected
500
-         */
501
-        function _dieOnNoMethod($method, $task) {
502
-            if ($this->_is_strict && ! method_exists($this, $method)) {
503
-                trigger_error(
504
-                        "Cannot $task as no ${method}() in class " . get_class($this),
505
-                        E_USER_ERROR);
506
-            }
507
-        }
508
-
509
-        /**
510
-         *    Replaces wildcard matches with wildcard
511
-         *    expectations in the argument list.
512
-         *    @param array $args      Raw argument list.
513
-         *    @return array           Argument list with
514
-         *                            expectations.
515
-         *    @access private
516
-         */
517
-        function _replaceWildcards($args) {
518
-            if ($args === false) {
519
-                return false;
520
-            }
521
-            for ($i = 0; $i < count($args); $i++) {
522
-                if ($args[$i] === $this->_wildcard) {
523
-                    $args[$i] = new AnythingExpectation();
524
-                }
525
-            }
526
-            return $args;
527
-        }
528
-
529
-        /**
530
-         *    Adds one to the call count of a method.
531
-         *    @param string $method        Method called.
532
-         *    @param array $args           Arguments as an array.
533
-         *    @access protected
534
-         */
535
-        function _addCall($method, $args) {
536
-            if (!isset($this->_call_counts[$method])) {
537
-                $this->_call_counts[$method] = 0;
538
-            }
539
-            $this->_call_counts[$method]++;
540
-        }
541
-
542
-        /**
543
-         *    Fetches the call count of a method so far.
544
-         *    @param string $method        Method name called.
545
-         *    @return                      Number of calls so far.
546
-         *    @access public
547
-         */
548
-        function getCallCount($method) {
549
-            $this->_dieOnNoMethod($method, "get call count");
550
-            $method = strtolower($method);
551
-            if (! isset($this->_call_counts[$method])) {
552
-                return 0;
553
-            }
554
-            return $this->_call_counts[$method];
555
-        }
556
-
557
-        /**
558
-         *    Sets a return for a parameter list that will
559
-         *    be passed by value for all calls to this method.
560
-         *    @param string $method       Method name.
561
-         *    @param mixed $value         Result of call passed by value.
562
-         *    @param array $args          List of parameters to match
563
-         *                                including wildcards.
564
-         *    @access public
565
-         */
566
-        function setReturnValue($method, $value, $args = false) {
567
-            $this->_dieOnNoMethod($method, "set return value");
568
-            $args = $this->_replaceWildcards($args);
569
-            $method = strtolower($method);
570
-            if (! isset($this->_returns[$method])) {
571
-                $this->_returns[$method] = new CallMap();
572
-            }
573
-            $this->_returns[$method]->addValue($args, $value);
574
-        }
575
-
576
-        /**
577
-         *    Sets a return for a parameter list that will
578
-         *    be passed by value only when the required call count
579
-         *    is reached.
580
-         *    @param integer $timing   Number of calls in the future
581
-         *                             to which the result applies. If
582
-         *                             not set then all calls will return
583
-         *                             the value.
584
-         *    @param string $method    Method name.
585
-         *    @param mixed $value      Result of call passed by value.
586
-         *    @param array $args       List of parameters to match
587
-         *                             including wildcards.
588
-         *    @access public
589
-         */
590
-        function setReturnValueAt($timing, $method, $value, $args = false) {
591
-            $this->_dieOnNoMethod($method, "set return value sequence");
592
-            $args = $this->_replaceWildcards($args);
593
-            $method = strtolower($method);
594
-            if (! isset($this->_return_sequence[$method])) {
595
-                $this->_return_sequence[$method] = array();
596
-            }
597
-            if (! isset($this->_return_sequence[$method][$timing])) {
598
-                $this->_return_sequence[$method][$timing] = new CallMap();
599
-            }
600
-            $this->_return_sequence[$method][$timing]->addValue($args, $value);
601
-        }
602
-
603
-        /**
604
-         *    Sets a return for a parameter list that will
605
-         *    be passed by reference for all calls.
606
-         *    @param string $method       Method name.
607
-         *    @param mixed $reference     Result of the call will be this object.
608
-         *    @param array $args          List of parameters to match
609
-         *                                including wildcards.
610
-         *    @access public
611
-         */
612
-        function setReturnReference($method, $reference, $args = false) {
613
-            $this->_dieOnNoMethod($method, "set return reference");
614
-            $args = $this->_replaceWildcards($args);
615
-            $method = strtolower($method);
616
-            if (! isset($this->_returns[$method])) {
617
-                $this->_returns[$method] = new CallMap();
618
-            }
619
-            $this->_returns[$method]->addReference($args, $reference);
620
-        }
621
-
622
-        /**
623
-         *    Sets a return for a parameter list that will
624
-         *    be passed by value only when the required call count
625
-         *    is reached.
626
-         *    @param integer $timing    Number of calls in the future
627
-         *                              to which the result applies. If
628
-         *                              not set then all calls will return
629
-         *                              the value.
630
-         *    @param string $method     Method name.
631
-         *    @param mixed $reference   Result of the call will be this object.
632
-         *    @param array $args        List of parameters to match
633
-         *                              including wildcards.
634
-         *    @access public
635
-         */
636
-        function setReturnReferenceAt($timing, $method, $reference, $args = false) {
637
-            $this->_dieOnNoMethod($method, "set return reference sequence");
638
-            $args = $this->_replaceWildcards($args);
639
-            $method = strtolower($method);
640
-            if (! isset($this->_return_sequence[$method])) {
641
-                $this->_return_sequence[$method] = array();
642
-            }
643
-            if (! isset($this->_return_sequence[$method][$timing])) {
644
-                $this->_return_sequence[$method][$timing] = new CallMap();
645
-            }
646
-            $this->_return_sequence[$method][$timing]->addReference($args, $reference);
647
-        }
648
-
649
-        /**
650
-         *    Sets up an expected call with a set of
651
-         *    expected parameters in that call. All
652
-         *    calls will be compared to these expectations
653
-         *    regardless of when the call is made.
654
-         *    @param string $method        Method call to test.
655
-         *    @param array $args           Expected parameters for the call
656
-         *                                 including wildcards.
657
-         *    @param string $message       Overridden message.
658
-         *    @access public
659
-         */
660
-        function expect($method, $args, $message = '%s') {
661
-            $this->_dieOnNoMethod($method, 'set expected arguments');
662
-            $this->_checkArgumentsIsArray($args, 'set expected arguments');
663
-            $args = $this->_replaceWildcards($args);
664
-            $message .= Mock::getExpectationLine();
665
-            $this->_expected_args[strtolower($method)] =
666
-                    new ParametersExpectation($args, $message);
667
-        }
668
-
669
-        /**
670
-         *    @deprecated
671
-         */
672
-        function expectArguments($method, $args, $message = '%s') {
673
-            return $this->expect($method, $args, $message);
674
-        }
675
-
676
-        /**
677
-         *    Sets up an expected call with a set of
678
-         *    expected parameters in that call. The
679
-         *    expected call count will be adjusted if it
680
-         *    is set too low to reach this call.
681
-         *    @param integer $timing    Number of calls in the future at
682
-         *                              which to test. Next call is 0.
683
-         *    @param string $method     Method call to test.
684
-         *    @param array $args        Expected parameters for the call
685
-         *                              including wildcards.
686
-         *    @param string $message    Overridden message.
687
-         *    @access public
688
-         */
689
-        function expectAt($timing, $method, $args, $message = '%s') {
690
-            $this->_dieOnNoMethod($method, 'set expected arguments at time');
691
-            $this->_checkArgumentsIsArray($args, 'set expected arguments at time');
692
-            $args = $this->_replaceWildcards($args);
693
-            if (! isset($this->_expected_args_at[$timing])) {
694
-                $this->_expected_args_at[$timing] = array();
695
-            }
696
-            $method = strtolower($method);
697
-            $message .= Mock::getExpectationLine();
698
-            $this->_expected_args_at[$timing][$method] =
699
-                    new ParametersExpectation($args, $message);
700
-        }
701
-
702
-        /**
703
-         *    @deprecated
704
-         */
705
-        function expectArgumentsAt($timing, $method, $args, $message = '%s') {
706
-            return $this->expectAt($timing, $method, $args, $message);
707
-        }
708
-
709
-        /**
710
-         *    Sets an expectation for the number of times
711
-         *    a method will be called. The tally method
712
-         *    is used to check this.
713
-         *    @param string $method        Method call to test.
714
-         *    @param integer $count        Number of times it should
715
-         *                                 have been called at tally.
716
-         *    @param string $message       Overridden message.
717
-         *    @access public
718
-         */
719
-        function expectCallCount($method, $count, $message = '%s') {
720
-            $this->_dieOnNoMethod($method, 'set expected call count');
721
-            $message .= Mock::getExpectationLine();
722
-            $this->_expected_counts[strtolower($method)] =
723
-                    new CallCountExpectation($method, $count, $message);
724
-        }
725
-
726
-        /**
727
-         *    Sets the number of times a method may be called
728
-         *    before a test failure is triggered.
729
-         *    @param string $method        Method call to test.
730
-         *    @param integer $count        Most number of times it should
731
-         *                                 have been called.
732
-         *    @param string $message       Overridden message.
733
-         *    @access public
734
-         */
735
-        function expectMaximumCallCount($method, $count, $message = '%s') {
736
-            $this->_dieOnNoMethod($method, 'set maximum call count');
737
-            $message .= Mock::getExpectationLine();
738
-            $this->_max_counts[strtolower($method)] =
739
-                    new MaximumCallCountExpectation($method, $count, $message);
740
-        }
741
-
742
-        /**
743
-         *    Sets the number of times to call a method to prevent
744
-         *    a failure on the tally.
745
-         *    @param string $method      Method call to test.
746
-         *    @param integer $count      Least number of times it should
747
-         *                               have been called.
748
-         *    @param string $message     Overridden message.
749
-         *    @access public
750
-         */
751
-        function expectMinimumCallCount($method, $count, $message = '%s') {
752
-            $this->_dieOnNoMethod($method, 'set minimum call count');
753
-            $message .= Mock::getExpectationLine();
754
-            $this->_expected_counts[strtolower($method)] =
755
-                    new MinimumCallCountExpectation($method, $count, $message);
756
-        }
757
-
758
-        /**
759
-         *    Convenience method for barring a method
760
-         *    call.
761
-         *    @param string $method        Method call to ban.
762
-         *    @param string $message       Overridden message.
763
-         *    @access public
764
-         */
765
-        function expectNever($method, $message = '%s') {
766
-            $this->expectMaximumCallCount($method, 0, $message);
767
-        }
768
-
769
-        /**
770
-         *    Convenience method for a single method
771
-         *    call.
772
-         *    @param string $method     Method call to track.
773
-         *    @param array $args        Expected argument list or
774
-         *                              false for any arguments.
775
-         *    @param string $message    Overridden message.
776
-         *    @access public
777
-         */
778
-        function expectOnce($method, $args = false, $message = '%s') {
779
-            $this->expectCallCount($method, 1, $message);
780
-            if ($args !== false) {
781
-                $this->expectArguments($method, $args, $message);
782
-            }
783
-        }
784
-
785
-        /**
786
-         *    Convenience method for requiring a method
787
-         *    call.
788
-         *    @param string $method       Method call to track.
789
-         *    @param array $args          Expected argument list or
790
-         *                                false for any arguments.
791
-         *    @param string $message      Overridden message.
792
-         *    @access public
793
-         */
794
-        function expectAtLeastOnce($method, $args = false, $message = '%s') {
795
-            $this->expectMinimumCallCount($method, 1, $message);
796
-            if ($args !== false) {
797
-                $this->expectArguments($method, $args, $message);
798
-            }
799
-        }
800
-
801
-        /**
802
-         *    @deprecated
803
-         */
804
-        function tally() {
805
-        }
806
-
807
-        /**
808
-         *    Receives event from unit test that the current
809
-         *    test method has finished. Totals up the call
810
-         *    counts and triggers a test assertion if a test
811
-         *    is present for expected call counts.
812
-         *    @param string $method    Current method name.
813
-         *    @access public
814
-         */
815
-        function atTestEnd($method) {
816
-            foreach ($this->_expected_counts as $method => $expectation) {
817
-                $this->_assertTrue(
818
-                        $expectation->test($this->getCallCount($method)),
819
-                        $expectation->overlayMessage($this->getCallCount($method)));
820
-            }
821
-            foreach ($this->_max_counts as $method => $expectation) {
822
-                if ($expectation->test($this->getCallCount($method))) {
823
-                    $this->_assertTrue(
824
-                            true,
825
-                            $expectation->overlayMessage($this->getCallCount($method)));
826
-                }
827
-            }
828
-        }
829
-
830
-        /**
831
-         *    Returns the expected value for the method name
832
-         *    and checks expectations. Will generate any
833
-         *    test assertions as a result of expectations
834
-         *    if there is a test present.
835
-         *    @param string $method       Name of method to simulate.
836
-         *    @param array $args          Arguments as an array.
837
-         *    @return mixed               Stored return.
838
-         *    @access private
839
-         */
840
-        function &_invoke($method, $args) {
841
-            $method = strtolower($method);
842
-            $step = $this->getCallCount($method);
843
-            $this->_addCall($method, $args);
844
-            $this->_checkExpectations($method, $args, $step);
845
-            $result = $this->_getReturn($method, $args, $step);
846
-            return $result;
847
-        }
848
-        /**
849
-         *    Finds the return value matching the incoming
850
-         *    arguments. If there is no matching value found
851
-         *    then an error is triggered.
852
-         *    @param string $method      Method name.
853
-         *    @param array $args         Calling arguments.
854
-         *    @param integer $step       Current position in the
855
-         *                               call history.
856
-         *    @return mixed              Stored return.
857
-         *    @access protected
858
-         */
859
-        function &_getReturn($method, $args, $step) {
860
-            if (isset($this->_return_sequence[$method][$step])) {
861
-                if ($this->_return_sequence[$method][$step]->isMatch($args)) {
862
-                    $result = $this->_return_sequence[$method][$step]->findFirstMatch($args);
863
-                    return $result;
864
-                }
865
-            }
866
-            if (isset($this->_returns[$method])) {
867
-                $result = $this->_returns[$method]->findFirstMatch($args);
868
-                return $result;
869
-            }
870
-            $null = null;
871
-            return $null;
872
-        }
873
-
874
-        /**
875
-         *    Tests the arguments against expectations.
876
-         *    @param string $method        Method to check.
877
-         *    @param array $args           Argument list to match.
878
-         *    @param integer $timing       The position of this call
879
-         *                                 in the call history.
880
-         *    @access private
881
-         */
882
-        function _checkExpectations($method, $args, $timing) {
883
-            if (isset($this->_max_counts[$method])) {
884
-                if (! $this->_max_counts[$method]->test($timing + 1)) {
885
-                    $this->_assertTrue(
886
-                            false,
887
-                            $this->_max_counts[$method]->overlayMessage($timing + 1));
888
-                }
889
-            }
890
-            if (isset($this->_expected_args_at[$timing][$method])) {
891
-                $this->_assertTrue(
892
-                        $this->_expected_args_at[$timing][$method]->test($args),
893
-                        "Mock method [$method] at [$timing] -> " .
894
-                                $this->_expected_args_at[$timing][$method]->overlayMessage($args));
895
-            } elseif (isset($this->_expected_args[$method])) {
896
-                $this->_assertTrue(
897
-                        $this->_expected_args[$method]->test($args),
898
-                        "Mock method [$method] -> " . $this->_expected_args[$method]->overlayMessage($args));
899
-            }
900
-        }
901
-
902
-        /**
903
-         *    Triggers an assertion on the held test case.
904
-         *    Should be overridden when using another test
905
-         *    framework other than the SimpleTest one if the
906
-         *    assertion method has a different name.
907
-         *    @param boolean $assertion     True will pass.
908
-         *    @param string $message        Message that will go with
909
-         *                                  the test event.
910
-         *    @access protected
911
-         */
912
-        function _assertTrue($assertion, $message) {
913
-            $test = $this->_getCurrentTestCase();
914
-            $test->assertTrue($assertion, $message);
915
-        }
916
-    }
917
-
918
-    /**
919
-     *    Static methods only service class for code generation of
920
-     *    mock objects.
420
+	 */
421
+	class SimpleMock {
422
+		protected $_wildcard = MOCK_ANYTHING;
423
+		protected $_is_strict = true;
424
+		protected $_returns;
425
+		protected $_return_sequence;
426
+		protected $_call_counts;
427
+		protected $_expected_counts;
428
+		protected $_max_counts;
429
+		protected $_expected_args;
430
+		protected $_expected_args_at;
431
+
432
+		/**
433
+		 *    Creates an empty return list and expectation list.
434
+		 *    All call counts are set to zero.
435
+		 *    @param SimpleTestCase $test    Test case to test expectations in.
436
+		 *    @param mixed $wildcard         Parameter matching wildcard.
437
+		 *    @param boolean $is_strict      Enables method name checks on
438
+		 *                                   expectations.
439
+		 */
440
+		function SimpleMock() {
441
+			$this->_returns = array();
442
+			$this->_return_sequence = array();
443
+			$this->_call_counts = array();
444
+			$test = $this->_getCurrentTestCase();
445
+			$test->tell($this);
446
+			$this->_expected_counts = array();
447
+			$this->_max_counts = array();
448
+			$this->_expected_args = array();
449
+			$this->_expected_args_at = array();
450
+		}
451
+
452
+		/**
453
+		 *    Disables a name check when setting expectations.
454
+		 *    This hack is needed for the partial mocks.
455
+		 *    @access public
456
+		 */
457
+		function disableExpectationNameChecks() {
458
+			$this->_is_strict = false;
459
+		}
460
+
461
+		/**
462
+		 *    Changes the default wildcard object.
463
+		 *    @param mixed $wildcard         Parameter matching wildcard.
464
+		 *    @access public
465
+		 */
466
+		function setWildcard($wildcard) {
467
+			$this->_wildcard = $wildcard;
468
+		}
469
+
470
+		/**
471
+		 *    Finds currently running test.
472
+		 *    @return SimpeTestCase    Current test case.
473
+		 *    @access protected
474
+		 */
475
+		function &_getCurrentTestCase() {
476
+			return SimpleTest::getCurrent();
477
+		}
478
+
479
+		/**
480
+		 *    Die if bad arguments array is passed
481
+		 *    @param mixed $args     The arguments value to be checked.
482
+		 *    @param string $task    Description of task attempt.
483
+		 *    @return boolean        Valid arguments
484
+		 *    @access private
485
+		 */
486
+		function _checkArgumentsIsArray($args, $task) {
487
+			if (! is_array($args)) {
488
+				trigger_error(
489
+					"Cannot $task as \$args parameter is not an array",
490
+					E_USER_ERROR);
491
+			}
492
+		}
493
+
494
+		/**
495
+		 *    Triggers a PHP error if the method is not part
496
+		 *    of this object.
497
+		 *    @param string $method        Name of method.
498
+		 *    @param string $task          Description of task attempt.
499
+		 *    @access protected
500
+		 */
501
+		function _dieOnNoMethod($method, $task) {
502
+			if ($this->_is_strict && ! method_exists($this, $method)) {
503
+				trigger_error(
504
+						"Cannot $task as no ${method}() in class " . get_class($this),
505
+						E_USER_ERROR);
506
+			}
507
+		}
508
+
509
+		/**
510
+		 *    Replaces wildcard matches with wildcard
511
+		 *    expectations in the argument list.
512
+		 *    @param array $args      Raw argument list.
513
+		 *    @return array           Argument list with
514
+		 *                            expectations.
515
+		 *    @access private
516
+		 */
517
+		function _replaceWildcards($args) {
518
+			if ($args === false) {
519
+				return false;
520
+			}
521
+			for ($i = 0; $i < count($args); $i++) {
522
+				if ($args[$i] === $this->_wildcard) {
523
+					$args[$i] = new AnythingExpectation();
524
+				}
525
+			}
526
+			return $args;
527
+		}
528
+
529
+		/**
530
+		 *    Adds one to the call count of a method.
531
+		 *    @param string $method        Method called.
532
+		 *    @param array $args           Arguments as an array.
533
+		 *    @access protected
534
+		 */
535
+		function _addCall($method, $args) {
536
+			if (!isset($this->_call_counts[$method])) {
537
+				$this->_call_counts[$method] = 0;
538
+			}
539
+			$this->_call_counts[$method]++;
540
+		}
541
+
542
+		/**
543
+		 *    Fetches the call count of a method so far.
544
+		 *    @param string $method        Method name called.
545
+		 *    @return                      Number of calls so far.
546
+		 *    @access public
547
+		 */
548
+		function getCallCount($method) {
549
+			$this->_dieOnNoMethod($method, "get call count");
550
+			$method = strtolower($method);
551
+			if (! isset($this->_call_counts[$method])) {
552
+				return 0;
553
+			}
554
+			return $this->_call_counts[$method];
555
+		}
556
+
557
+		/**
558
+		 *    Sets a return for a parameter list that will
559
+		 *    be passed by value for all calls to this method.
560
+		 *    @param string $method       Method name.
561
+		 *    @param mixed $value         Result of call passed by value.
562
+		 *    @param array $args          List of parameters to match
563
+		 *                                including wildcards.
564
+		 *    @access public
565
+		 */
566
+		function setReturnValue($method, $value, $args = false) {
567
+			$this->_dieOnNoMethod($method, "set return value");
568
+			$args = $this->_replaceWildcards($args);
569
+			$method = strtolower($method);
570
+			if (! isset($this->_returns[$method])) {
571
+				$this->_returns[$method] = new CallMap();
572
+			}
573
+			$this->_returns[$method]->addValue($args, $value);
574
+		}
575
+
576
+		/**
577
+		 *    Sets a return for a parameter list that will
578
+		 *    be passed by value only when the required call count
579
+		 *    is reached.
580
+		 *    @param integer $timing   Number of calls in the future
581
+		 *                             to which the result applies. If
582
+		 *                             not set then all calls will return
583
+		 *                             the value.
584
+		 *    @param string $method    Method name.
585
+		 *    @param mixed $value      Result of call passed by value.
586
+		 *    @param array $args       List of parameters to match
587
+		 *                             including wildcards.
588
+		 *    @access public
589
+		 */
590
+		function setReturnValueAt($timing, $method, $value, $args = false) {
591
+			$this->_dieOnNoMethod($method, "set return value sequence");
592
+			$args = $this->_replaceWildcards($args);
593
+			$method = strtolower($method);
594
+			if (! isset($this->_return_sequence[$method])) {
595
+				$this->_return_sequence[$method] = array();
596
+			}
597
+			if (! isset($this->_return_sequence[$method][$timing])) {
598
+				$this->_return_sequence[$method][$timing] = new CallMap();
599
+			}
600
+			$this->_return_sequence[$method][$timing]->addValue($args, $value);
601
+		}
602
+
603
+		/**
604
+		 *    Sets a return for a parameter list that will
605
+		 *    be passed by reference for all calls.
606
+		 *    @param string $method       Method name.
607
+		 *    @param mixed $reference     Result of the call will be this object.
608
+		 *    @param array $args          List of parameters to match
609
+		 *                                including wildcards.
610
+		 *    @access public
611
+		 */
612
+		function setReturnReference($method, $reference, $args = false) {
613
+			$this->_dieOnNoMethod($method, "set return reference");
614
+			$args = $this->_replaceWildcards($args);
615
+			$method = strtolower($method);
616
+			if (! isset($this->_returns[$method])) {
617
+				$this->_returns[$method] = new CallMap();
618
+			}
619
+			$this->_returns[$method]->addReference($args, $reference);
620
+		}
621
+
622
+		/**
623
+		 *    Sets a return for a parameter list that will
624
+		 *    be passed by value only when the required call count
625
+		 *    is reached.
626
+		 *    @param integer $timing    Number of calls in the future
627
+		 *                              to which the result applies. If
628
+		 *                              not set then all calls will return
629
+		 *                              the value.
630
+		 *    @param string $method     Method name.
631
+		 *    @param mixed $reference   Result of the call will be this object.
632
+		 *    @param array $args        List of parameters to match
633
+		 *                              including wildcards.
634
+		 *    @access public
635
+		 */
636
+		function setReturnReferenceAt($timing, $method, $reference, $args = false) {
637
+			$this->_dieOnNoMethod($method, "set return reference sequence");
638
+			$args = $this->_replaceWildcards($args);
639
+			$method = strtolower($method);
640
+			if (! isset($this->_return_sequence[$method])) {
641
+				$this->_return_sequence[$method] = array();
642
+			}
643
+			if (! isset($this->_return_sequence[$method][$timing])) {
644
+				$this->_return_sequence[$method][$timing] = new CallMap();
645
+			}
646
+			$this->_return_sequence[$method][$timing]->addReference($args, $reference);
647
+		}
648
+
649
+		/**
650
+		 *    Sets up an expected call with a set of
651
+		 *    expected parameters in that call. All
652
+		 *    calls will be compared to these expectations
653
+		 *    regardless of when the call is made.
654
+		 *    @param string $method        Method call to test.
655
+		 *    @param array $args           Expected parameters for the call
656
+		 *                                 including wildcards.
657
+		 *    @param string $message       Overridden message.
658
+		 *    @access public
659
+		 */
660
+		function expect($method, $args, $message = '%s') {
661
+			$this->_dieOnNoMethod($method, 'set expected arguments');
662
+			$this->_checkArgumentsIsArray($args, 'set expected arguments');
663
+			$args = $this->_replaceWildcards($args);
664
+			$message .= Mock::getExpectationLine();
665
+			$this->_expected_args[strtolower($method)] =
666
+					new ParametersExpectation($args, $message);
667
+		}
668
+
669
+		/**
670
+		 *    @deprecated
671
+		 */
672
+		function expectArguments($method, $args, $message = '%s') {
673
+			return $this->expect($method, $args, $message);
674
+		}
675
+
676
+		/**
677
+		 *    Sets up an expected call with a set of
678
+		 *    expected parameters in that call. The
679
+		 *    expected call count will be adjusted if it
680
+		 *    is set too low to reach this call.
681
+		 *    @param integer $timing    Number of calls in the future at
682
+		 *                              which to test. Next call is 0.
683
+		 *    @param string $method     Method call to test.
684
+		 *    @param array $args        Expected parameters for the call
685
+		 *                              including wildcards.
686
+		 *    @param string $message    Overridden message.
687
+		 *    @access public
688
+		 */
689
+		function expectAt($timing, $method, $args, $message = '%s') {
690
+			$this->_dieOnNoMethod($method, 'set expected arguments at time');
691
+			$this->_checkArgumentsIsArray($args, 'set expected arguments at time');
692
+			$args = $this->_replaceWildcards($args);
693
+			if (! isset($this->_expected_args_at[$timing])) {
694
+				$this->_expected_args_at[$timing] = array();
695
+			}
696
+			$method = strtolower($method);
697
+			$message .= Mock::getExpectationLine();
698
+			$this->_expected_args_at[$timing][$method] =
699
+					new ParametersExpectation($args, $message);
700
+		}
701
+
702
+		/**
703
+		 *    @deprecated
704
+		 */
705
+		function expectArgumentsAt($timing, $method, $args, $message = '%s') {
706
+			return $this->expectAt($timing, $method, $args, $message);
707
+		}
708
+
709
+		/**
710
+		 *    Sets an expectation for the number of times
711
+		 *    a method will be called. The tally method
712
+		 *    is used to check this.
713
+		 *    @param string $method        Method call to test.
714
+		 *    @param integer $count        Number of times it should
715
+		 *                                 have been called at tally.
716
+		 *    @param string $message       Overridden message.
717
+		 *    @access public
718
+		 */
719
+		function expectCallCount($method, $count, $message = '%s') {
720
+			$this->_dieOnNoMethod($method, 'set expected call count');
721
+			$message .= Mock::getExpectationLine();
722
+			$this->_expected_counts[strtolower($method)] =
723
+					new CallCountExpectation($method, $count, $message);
724
+		}
725
+
726
+		/**
727
+		 *    Sets the number of times a method may be called
728
+		 *    before a test failure is triggered.
729
+		 *    @param string $method        Method call to test.
730
+		 *    @param integer $count        Most number of times it should
731
+		 *                                 have been called.
732
+		 *    @param string $message       Overridden message.
733
+		 *    @access public
734
+		 */
735
+		function expectMaximumCallCount($method, $count, $message = '%s') {
736
+			$this->_dieOnNoMethod($method, 'set maximum call count');
737
+			$message .= Mock::getExpectationLine();
738
+			$this->_max_counts[strtolower($method)] =
739
+					new MaximumCallCountExpectation($method, $count, $message);
740
+		}
741
+
742
+		/**
743
+		 *    Sets the number of times to call a method to prevent
744
+		 *    a failure on the tally.
745
+		 *    @param string $method      Method call to test.
746
+		 *    @param integer $count      Least number of times it should
747
+		 *                               have been called.
748
+		 *    @param string $message     Overridden message.
749
+		 *    @access public
750
+		 */
751
+		function expectMinimumCallCount($method, $count, $message = '%s') {
752
+			$this->_dieOnNoMethod($method, 'set minimum call count');
753
+			$message .= Mock::getExpectationLine();
754
+			$this->_expected_counts[strtolower($method)] =
755
+					new MinimumCallCountExpectation($method, $count, $message);
756
+		}
757
+
758
+		/**
759
+		 *    Convenience method for barring a method
760
+		 *    call.
761
+		 *    @param string $method        Method call to ban.
762
+		 *    @param string $message       Overridden message.
763
+		 *    @access public
764
+		 */
765
+		function expectNever($method, $message = '%s') {
766
+			$this->expectMaximumCallCount($method, 0, $message);
767
+		}
768
+
769
+		/**
770
+		 *    Convenience method for a single method
771
+		 *    call.
772
+		 *    @param string $method     Method call to track.
773
+		 *    @param array $args        Expected argument list or
774
+		 *                              false for any arguments.
775
+		 *    @param string $message    Overridden message.
776
+		 *    @access public
777
+		 */
778
+		function expectOnce($method, $args = false, $message = '%s') {
779
+			$this->expectCallCount($method, 1, $message);
780
+			if ($args !== false) {
781
+				$this->expectArguments($method, $args, $message);
782
+			}
783
+		}
784
+
785
+		/**
786
+		 *    Convenience method for requiring a method
787
+		 *    call.
788
+		 *    @param string $method       Method call to track.
789
+		 *    @param array $args          Expected argument list or
790
+		 *                                false for any arguments.
791
+		 *    @param string $message      Overridden message.
792
+		 *    @access public
793
+		 */
794
+		function expectAtLeastOnce($method, $args = false, $message = '%s') {
795
+			$this->expectMinimumCallCount($method, 1, $message);
796
+			if ($args !== false) {
797
+				$this->expectArguments($method, $args, $message);
798
+			}
799
+		}
800
+
801
+		/**
802
+		 *    @deprecated
803
+		 */
804
+		function tally() {
805
+		}
806
+
807
+		/**
808
+		 *    Receives event from unit test that the current
809
+		 *    test method has finished. Totals up the call
810
+		 *    counts and triggers a test assertion if a test
811
+		 *    is present for expected call counts.
812
+		 *    @param string $method    Current method name.
813
+		 *    @access public
814
+		 */
815
+		function atTestEnd($method) {
816
+			foreach ($this->_expected_counts as $method => $expectation) {
817
+				$this->_assertTrue(
818
+						$expectation->test($this->getCallCount($method)),
819
+						$expectation->overlayMessage($this->getCallCount($method)));
820
+			}
821
+			foreach ($this->_max_counts as $method => $expectation) {
822
+				if ($expectation->test($this->getCallCount($method))) {
823
+					$this->_assertTrue(
824
+							true,
825
+							$expectation->overlayMessage($this->getCallCount($method)));
826
+				}
827
+			}
828
+		}
829
+
830
+		/**
831
+		 *    Returns the expected value for the method name
832
+		 *    and checks expectations. Will generate any
833
+		 *    test assertions as a result of expectations
834
+		 *    if there is a test present.
835
+		 *    @param string $method       Name of method to simulate.
836
+		 *    @param array $args          Arguments as an array.
837
+		 *    @return mixed               Stored return.
838
+		 *    @access private
839
+		 */
840
+		function &_invoke($method, $args) {
841
+			$method = strtolower($method);
842
+			$step = $this->getCallCount($method);
843
+			$this->_addCall($method, $args);
844
+			$this->_checkExpectations($method, $args, $step);
845
+			$result = $this->_getReturn($method, $args, $step);
846
+			return $result;
847
+		}
848
+		/**
849
+		 *    Finds the return value matching the incoming
850
+		 *    arguments. If there is no matching value found
851
+		 *    then an error is triggered.
852
+		 *    @param string $method      Method name.
853
+		 *    @param array $args         Calling arguments.
854
+		 *    @param integer $step       Current position in the
855
+		 *                               call history.
856
+		 *    @return mixed              Stored return.
857
+		 *    @access protected
858
+		 */
859
+		function &_getReturn($method, $args, $step) {
860
+			if (isset($this->_return_sequence[$method][$step])) {
861
+				if ($this->_return_sequence[$method][$step]->isMatch($args)) {
862
+					$result = $this->_return_sequence[$method][$step]->findFirstMatch($args);
863
+					return $result;
864
+				}
865
+			}
866
+			if (isset($this->_returns[$method])) {
867
+				$result = $this->_returns[$method]->findFirstMatch($args);
868
+				return $result;
869
+			}
870
+			$null = null;
871
+			return $null;
872
+		}
873
+
874
+		/**
875
+		 *    Tests the arguments against expectations.
876
+		 *    @param string $method        Method to check.
877
+		 *    @param array $args           Argument list to match.
878
+		 *    @param integer $timing       The position of this call
879
+		 *                                 in the call history.
880
+		 *    @access private
881
+		 */
882
+		function _checkExpectations($method, $args, $timing) {
883
+			if (isset($this->_max_counts[$method])) {
884
+				if (! $this->_max_counts[$method]->test($timing + 1)) {
885
+					$this->_assertTrue(
886
+							false,
887
+							$this->_max_counts[$method]->overlayMessage($timing + 1));
888
+				}
889
+			}
890
+			if (isset($this->_expected_args_at[$timing][$method])) {
891
+				$this->_assertTrue(
892
+						$this->_expected_args_at[$timing][$method]->test($args),
893
+						"Mock method [$method] at [$timing] -> " .
894
+								$this->_expected_args_at[$timing][$method]->overlayMessage($args));
895
+			} elseif (isset($this->_expected_args[$method])) {
896
+				$this->_assertTrue(
897
+						$this->_expected_args[$method]->test($args),
898
+						"Mock method [$method] -> " . $this->_expected_args[$method]->overlayMessage($args));
899
+			}
900
+		}
901
+
902
+		/**
903
+		 *    Triggers an assertion on the held test case.
904
+		 *    Should be overridden when using another test
905
+		 *    framework other than the SimpleTest one if the
906
+		 *    assertion method has a different name.
907
+		 *    @param boolean $assertion     True will pass.
908
+		 *    @param string $message        Message that will go with
909
+		 *                                  the test event.
910
+		 *    @access protected
911
+		 */
912
+		function _assertTrue($assertion, $message) {
913
+			$test = $this->_getCurrentTestCase();
914
+			$test->assertTrue($assertion, $message);
915
+		}
916
+	}
917
+
918
+	/**
919
+	 *    Static methods only service class for code generation of
920
+	 *    mock objects.
921 921
 	 *    @package SimpleTest
922 922
 	 *    @subpackage MockObjects
923
-     */
924
-    class Mock {
925
-
926
-        /**
927
-         *    Factory for mock object classes.
928
-         *    @access public
929
-         */
930
-        function Mock() {
931
-            trigger_error('Mock factory methods are class only.');
932
-        }
933
-
934
-        /**
935
-         *    Clones a class' interface and creates a mock version
936
-         *    that can have return values and expectations set.
937
-         *    @param string $class         Class to clone.
938
-         *    @param string $mock_class    New class name. Default is
939
-         *                                 the old name with "Mock"
940
-         *                                 prepended.
941
-         *    @param array $methods        Additional methods to add beyond
942
-         *                                 those in th cloned class. Use this
943
-         *                                 to emulate the dynamic addition of
944
-         *                                 methods in the cloned class or when
945
-         *                                 the class hasn't been written yet.
946
-         *    @static
947
-         *    @access public
948
-         */
949
-        static function generate($class, $mock_class = false, $methods = false) {
950
-            $generator = new MockGenerator($class, $mock_class);
951
-            return $generator->generate($methods);
952
-        }
953
-
954
-        /**
955
-         *    Generates a version of a class with selected
956
-         *    methods mocked only. Inherits the old class
957
-         *    and chains the mock methods of an aggregated
958
-         *    mock object.
959
-         *    @param string $class            Class to clone.
960
-         *    @param string $mock_class       New class name.
961
-         *    @param array $methods           Methods to be overridden
962
-         *                                    with mock versions.
963
-         *    @static
964
-         *    @access public
965
-         */
966
-        static function generatePartial($class, $mock_class, $methods) {
967
-            $generator = new MockGenerator($class, $mock_class);
968
-            return $generator->generatePartial($methods);
969
-        }
970
-
971
-        /**
972
-         *    Uses a stack trace to find the line of an assertion.
973
-         *    @param array $stack      Stack frames top most first. Only
974
-         *                             needed if not using the PHP
975
-         *                             backtrace function.
976
-         *    @return string           Location of first expect*
977
-         *                             method embedded in format string.
978
-         *    @access public
979
-         *    @static
980
-         */
981
-        static function getExpectationLine($stack = false) {
982
-            if ($stack === false) {
983
-                $stack = SimpleTestCompatibility::getStackTrace();
984
-            }
985
-            return SimpleDumper::getFormattedAssertionLine($stack);
986
-        }
987
-    }
988
-
989
-    /**
990
-     *    @deprecated
991
-     */
992
-    class Stub extends Mock {
993
-    }
994
-
995
-    /**
996
-     *    Service class for code generation of mock objects.
923
+	 */
924
+	class Mock {
925
+
926
+		/**
927
+		 *    Factory for mock object classes.
928
+		 *    @access public
929
+		 */
930
+		function Mock() {
931
+			trigger_error('Mock factory methods are class only.');
932
+		}
933
+
934
+		/**
935
+		 *    Clones a class' interface and creates a mock version
936
+		 *    that can have return values and expectations set.
937
+		 *    @param string $class         Class to clone.
938
+		 *    @param string $mock_class    New class name. Default is
939
+		 *                                 the old name with "Mock"
940
+		 *                                 prepended.
941
+		 *    @param array $methods        Additional methods to add beyond
942
+		 *                                 those in th cloned class. Use this
943
+		 *                                 to emulate the dynamic addition of
944
+		 *                                 methods in the cloned class or when
945
+		 *                                 the class hasn't been written yet.
946
+		 *    @static
947
+		 *    @access public
948
+		 */
949
+		static function generate($class, $mock_class = false, $methods = false) {
950
+			$generator = new MockGenerator($class, $mock_class);
951
+			return $generator->generate($methods);
952
+		}
953
+
954
+		/**
955
+		 *    Generates a version of a class with selected
956
+		 *    methods mocked only. Inherits the old class
957
+		 *    and chains the mock methods of an aggregated
958
+		 *    mock object.
959
+		 *    @param string $class            Class to clone.
960
+		 *    @param string $mock_class       New class name.
961
+		 *    @param array $methods           Methods to be overridden
962
+		 *                                    with mock versions.
963
+		 *    @static
964
+		 *    @access public
965
+		 */
966
+		static function generatePartial($class, $mock_class, $methods) {
967
+			$generator = new MockGenerator($class, $mock_class);
968
+			return $generator->generatePartial($methods);
969
+		}
970
+
971
+		/**
972
+		 *    Uses a stack trace to find the line of an assertion.
973
+		 *    @param array $stack      Stack frames top most first. Only
974
+		 *                             needed if not using the PHP
975
+		 *                             backtrace function.
976
+		 *    @return string           Location of first expect*
977
+		 *                             method embedded in format string.
978
+		 *    @access public
979
+		 *    @static
980
+		 */
981
+		static function getExpectationLine($stack = false) {
982
+			if ($stack === false) {
983
+				$stack = SimpleTestCompatibility::getStackTrace();
984
+			}
985
+			return SimpleDumper::getFormattedAssertionLine($stack);
986
+		}
987
+	}
988
+
989
+	/**
990
+	 *    @deprecated
991
+	 */
992
+	class Stub extends Mock {
993
+	}
994
+
995
+	/**
996
+	 *    Service class for code generation of mock objects.
997 997
 	 *    @package SimpleTest
998 998
 	 *    @subpackage MockObjects
999
-     */
1000
-    class MockGenerator {
1001
-        protected $_class;
1002
-        protected $_mock_class;
1003
-        protected $_mock_base;
1004
-        protected $_reflection;
1005
-
1006
-        function MockGenerator($class, $mock_class) {
1007
-            $this->_class = $class;
1008
-            $this->_mock_class = $mock_class;
1009
-            $this->_mock_base = SimpleTest::getMockBaseClass();
1010
-            $this->_reflection = new SimpleReflection($this->_class);
1011
-        }
1012
-
1013
-        /**
1014
-         *    Clones a class' interface and creates a mock version
1015
-         *    that can have return values and expectations set.
1016
-         *    @param array $methods        Additional methods to add beyond
1017
-         *                                 those in th cloned class. Use this
1018
-         *                                 to emulate the dynamic addition of
1019
-         *                                 methods in the cloned class or when
1020
-         *                                 the class hasn't been written yet.
1021
-         *    @access public
1022
-         */
1023
-        function generate($methods) {
1024
-            if (! $this->_reflection->classOrInterfaceExists()) {
1025
-                return false;
1026
-            }
1027
-            if (! $this->_mock_class) {
1028
-                $this->_mock_class = 'Mock' . $this->_class;
1029
-            }
1030
-            $mock_reflection = new SimpleReflection($this->_mock_class);
1031
-            if ($mock_reflection->classExistsSansAutoload()) {
1032
-                return false;
1033
-            }
1034
-            return eval(
1035
-                    $this->_createClassCode($methods ? $methods : array()) .
1036
-                    " return true;");
1037
-        }
1038
-
1039
-        /**
1040
-         *    Generates a version of a class with selected
1041
-         *    methods mocked only. Inherits the old class
1042
-         *    and chains the mock methods of an aggregated
1043
-         *    mock object.
1044
-         *    @param array $methods           Methods to be overridden
1045
-         *                                    with mock versions.
1046
-         *    @access public
1047
-         */
1048
-        function generatePartial($methods) {
1049
-            if (! $this->_reflection->classExists($this->_class)) {
1050
-                return false;
1051
-            }
1052
-            $mock_reflection = new SimpleReflection($this->_mock_class);
1053
-            if ($mock_reflection->classExistsSansAutoload()) {
1054
-                trigger_error("Partial mock class [$mock_class] already exists");
1055
-                return false;
1056
-            }
1057
-            return eval($this->_extendClassCode($methods));
1058
-        }
1059
-
1060
-        /**
1061
-         *    The new mock class code as a string.
1062
-         *    @param array $methods          Additional methods.
1063
-         *    @return string                 Code for new mock class.
1064
-         *    @access private
1065
-         */
1066
-        function _createClassCode($methods) {
1067
-            $implements = '';
1068
-            $interfaces = $this->_reflection->getInterfaces();
1069
-            if (function_exists('spl_classes')) {
1070
-            	$interfaces = array_diff($interfaces, array('Traversable'));
1071
-            }
1072
-            if (count($interfaces) > 0) {
1073
-            	$implements = 'implements ' . implode(', ', $interfaces);
1074
-            }
1075
-            $code = "class " . $this->_mock_class . " extends " . $this->_mock_base . " $implements {\n";
1076
-            $code .= "    function " . $this->_mock_class . "() {\n";
1077
-            $code .= "        \$this->" . $this->_mock_base . "();\n";
1078
-            $code .= "    }\n";
1079
-            $code .= $this->_createHandlerCode($methods);
1080
-            $code .= "}\n";
1081
-            return $code;
1082
-        }
1083
-
1084
-        /**
1085
-         *    The extension class code as a string. The class
1086
-         *    composites a mock object and chains mocked methods
1087
-         *    to it.
1088
-         *    @param array  $methods       Mocked methods.
1089
-         *    @return string               Code for a new class.
1090
-         *    @access private
1091
-         */
1092
-        function _extendClassCode($methods) {
1093
-            $code  = "class " . $this->_mock_class . " extends " . $this->_class . " {\n";
1094
-            $code .= "    var \$_mock;\n";
1095
-            $code .= $this->_addMethodList($methods);
1096
-            $code .= "\n";
1097
-            $code .= "    function " . $this->_mock_class . "() {\n";
1098
-            $code .= "        \$this->_mock = new " . $this->_mock_base . "();\n";
1099
-            $code .= "        \$this->_mock->disableExpectationNameChecks();\n";
1100
-            $code .= "    }\n";
1101
-            $code .= $this->_chainMockReturns();
1102
-            $code .= $this->_chainMockExpectations();
1103
-            $code .= $this->_overrideMethods($methods);
1104
-            $code .= "}\n";
1105
-            return $code;
1106
-        }
1107
-
1108
-        /**
1109
-         *    Creates code within a class to generate replaced
1110
-         *    methods. All methods call the _invoke() handler
1111
-         *    with the method name and the arguments in an
1112
-         *    array.
1113
-         *    @param array $methods    Additional methods.
1114
-         *    @access private
1115
-         */
1116
-        function _createHandlerCode($methods) {
1117
-        	$code = '';
1118
-            $methods = array_merge($methods, $this->_reflection->getMethods());
1119
-            foreach ($methods as $method) {
1120
-                if ($this->_isConstructor($method)) {
1121
-                    continue;
1122
-                }
1123
-                $mock_reflection = new SimpleReflection($this->_mock_base);
1124
-                if (in_array($method, $mock_reflection->getMethods())) {
1125
-                    continue;
1126
-                }
1127
-                $code .= "    " . $this->_reflection->getSignature($method) . " {\n";
1128
-                $code .= "        \$args = func_get_args();\n";
1129
-                $code .= "        \$result = &\$this->_invoke(\"$method\", \$args);\n";
1130
-                $code .= "        return \$result;\n";
1131
-                $code .= "    }\n";
1132
-            }
1133
-            return $code;
1134
-        }
1135
-
1136
-        /**
1137
-         *    Tests to see if a special PHP method is about to
1138
-         *    be stubbed by mistake.
1139
-         *    @param string $method    Method name.
1140
-         *    @return boolean          True if special.
1141
-         *    @access private
1142
-         */
1143
-        function _isConstructor($method) {
1144
-            return in_array(
1145
-                    strtolower($method),
1146
-                    array('__construct', '__destruct', '__clone'));
1147
-        }
1148
-
1149
-        /**
1150
-         *    Creates a list of mocked methods for error checking.
1151
-         *    @param array $methods       Mocked methods.
1152
-         *    @return string              Code for a method list.
1153
-         *    @access private
1154
-         */
1155
-        function _addMethodList($methods) {
1156
-            return "    var \$_mocked_methods = array('" . implode("', '", $methods) . "');\n";
1157
-        }
1158
-
1159
-        /**
1160
-         *    Creates code to abandon the expectation if not mocked.
1161
-         *    @param string $alias       Parameter name of method name.
1162
-         *    @return string             Code for bail out.
1163
-         *    @access private
1164
-         */
1165
-        function _bailOutIfNotMocked($alias) {
1166
-            $code  = "        if (! in_array($alias, \$this->_mocked_methods)) {\n";
1167
-            $code .= "            trigger_error(\"Method [$alias] is not mocked\");\n";
1168
-            $code .= "            \$null = null;\n";
1169
-            $code .= "            return \$null;\n";
1170
-            $code .= "        }\n";
1171
-            return $code;
1172
-        }
1173
-
1174
-        /**
1175
-         *    Creates source code for chaining to the composited
1176
-         *    mock object.
1177
-         *    @return string           Code for mock set up.
1178
-         *    @access private
1179
-         */
1180
-        function _chainMockReturns() {
1181
-            $code  = "    function setReturnValue(\$method, \$value, \$args = false) {\n";
1182
-            $code .= $this->_bailOutIfNotMocked("\$method");
1183
-            $code .= "        \$this->_mock->setReturnValue(\$method, \$value, \$args);\n";
1184
-            $code .= "    }\n";
1185
-            $code .= "    function setReturnValueAt(\$timing, \$method, \$value, \$args = false) {\n";
1186
-            $code .= $this->_bailOutIfNotMocked("\$method");
1187
-            $code .= "        \$this->_mock->setReturnValueAt(\$timing, \$method, \$value, \$args);\n";
1188
-            $code .= "    }\n";
1189
-            $code .= "    function setReturnReference(\$method, &\$ref, \$args = false) {\n";
1190
-            $code .= $this->_bailOutIfNotMocked("\$method");
1191
-            $code .= "        \$this->_mock->setReturnReference(\$method, \$ref, \$args);\n";
1192
-            $code .= "    }\n";
1193
-            $code .= "    function setReturnReferenceAt(\$timing, \$method, &\$ref, \$args = false) {\n";
1194
-            $code .= $this->_bailOutIfNotMocked("\$method");
1195
-            $code .= "        \$this->_mock->setReturnReferenceAt(\$timing, \$method, \$ref, \$args);\n";
1196
-            $code .= "    }\n";
1197
-            return $code;
1198
-        }
1199
-
1200
-        /**
1201
-         *    Creates source code for chaining to an aggregated
1202
-         *    mock object.
1203
-         *    @return string                 Code for expectations.
1204
-         *    @access private
1205
-         */
1206
-        function _chainMockExpectations() {
1207
-            $code  = "    function expect(\$method, \$args = false) {\n";
1208
-            $code .= $this->_bailOutIfNotMocked("\$method");
1209
-            $code .= "        \$this->_mock->expect(\$method, \$args);\n";
1210
-            $code .= "    }\n";
1211
-            $code .= "    function expectArguments(\$method, \$args = false) {\n";
1212
-            $code .= $this->_bailOutIfNotMocked("\$method");
1213
-            $code .= "        \$this->_mock->expectArguments(\$method, \$args);\n";
1214
-            $code .= "    }\n";
1215
-            $code .= "    function expectAt(\$timing, \$method, \$args = false) {\n";
1216
-            $code .= $this->_bailOutIfNotMocked("\$method");
1217
-            $code .= "        \$this->_mock->expectArgumentsAt(\$timing, \$method, \$args);\n";
1218
-            $code .= "    }\n";
1219
-            $code .= "    function expectArgumentsAt(\$timing, \$method, \$args = false) {\n";
1220
-            $code .= $this->_bailOutIfNotMocked("\$method");
1221
-            $code .= "        \$this->_mock->expectArgumentsAt(\$timing, \$method, \$args);\n";
1222
-            $code .= "    }\n";
1223
-            $code .= "    function expectCallCount(\$method, \$count) {\n";
1224
-            $code .= $this->_bailOutIfNotMocked("\$method");
1225
-            $code .= "        \$this->_mock->expectCallCount(\$method, \$count);\n";
1226
-            $code .= "    }\n";
1227
-            $code .= "    function expectMaximumCallCount(\$method, \$count) {\n";
1228
-            $code .= $this->_bailOutIfNotMocked("\$method");
1229
-            $code .= "        \$this->_mock->expectMaximumCallCount(\$method, \$count);\n";
1230
-            $code .= "    }\n";
1231
-            $code .= "    function expectMinimumCallCount(\$method, \$count) {\n";
1232
-            $code .= $this->_bailOutIfNotMocked("\$method");
1233
-            $code .= "        \$this->_mock->expectMinimumCallCount(\$method, \$count);\n";
1234
-            $code .= "    }\n";
1235
-            $code .= "    function expectNever(\$method) {\n";
1236
-            $code .= $this->_bailOutIfNotMocked("\$method");
1237
-            $code .= "        \$this->_mock->expectNever(\$method);\n";
1238
-            $code .= "    }\n";
1239
-            $code .= "    function expectOnce(\$method, \$args = false) {\n";
1240
-            $code .= $this->_bailOutIfNotMocked("\$method");
1241
-            $code .= "        \$this->_mock->expectOnce(\$method, \$args);\n";
1242
-            $code .= "    }\n";
1243
-            $code .= "    function expectAtLeastOnce(\$method, \$args = false) {\n";
1244
-            $code .= $this->_bailOutIfNotMocked("\$method");
1245
-            $code .= "        \$this->_mock->expectAtLeastOnce(\$method, \$args);\n";
1246
-            $code .= "    }\n";
1247
-            $code .= "    function tally() {\n";
1248
-            $code .= "        \$this->_mock->tally();\n";
1249
-            $code .= "    }\n";
1250
-            return $code;
1251
-        }
1252
-
1253
-        /**
1254
-         *    Creates source code to override a list of methods
1255
-         *    with mock versions.
1256
-         *    @param array $methods    Methods to be overridden
1257
-         *                             with mock versions.
1258
-         *    @return string           Code for overridden chains.
1259
-         *    @access private
1260
-         */
1261
-        function _overrideMethods($methods) {
1262
-            $code = "";
1263
-            foreach ($methods as $method) {
1264
-                $code .= "    " . $this->_reflection->getSignature($method) . " {\n";
1265
-                $code .= "        \$args = func_get_args();\n";
1266
-                $code .= "        \$result = &\$this->_mock->_invoke(\"$method\", \$args);\n";
1267
-                $code .= "        return \$result;\n";
1268
-                $code .= "    }\n";
1269
-            }
1270
-            return $code;
1271
-        }
1272
-    }
1273 999
\ No newline at end of file
1000
+	 */
1001
+	class MockGenerator {
1002
+		protected $_class;
1003
+		protected $_mock_class;
1004
+		protected $_mock_base;
1005
+		protected $_reflection;
1006
+
1007
+		function MockGenerator($class, $mock_class) {
1008
+			$this->_class = $class;
1009
+			$this->_mock_class = $mock_class;
1010
+			$this->_mock_base = SimpleTest::getMockBaseClass();
1011
+			$this->_reflection = new SimpleReflection($this->_class);
1012
+		}
1013
+
1014
+		/**
1015
+		 *    Clones a class' interface and creates a mock version
1016
+		 *    that can have return values and expectations set.
1017
+		 *    @param array $methods        Additional methods to add beyond
1018
+		 *                                 those in th cloned class. Use this
1019
+		 *                                 to emulate the dynamic addition of
1020
+		 *                                 methods in the cloned class or when
1021
+		 *                                 the class hasn't been written yet.
1022
+		 *    @access public
1023
+		 */
1024
+		function generate($methods) {
1025
+			if (! $this->_reflection->classOrInterfaceExists()) {
1026
+				return false;
1027
+			}
1028
+			if (! $this->_mock_class) {
1029
+				$this->_mock_class = 'Mock' . $this->_class;
1030
+			}
1031
+			$mock_reflection = new SimpleReflection($this->_mock_class);
1032
+			if ($mock_reflection->classExistsSansAutoload()) {
1033
+				return false;
1034
+			}
1035
+			return eval(
1036
+					$this->_createClassCode($methods ? $methods : array()) .
1037
+					" return true;");
1038
+		}
1039
+
1040
+		/**
1041
+		 *    Generates a version of a class with selected
1042
+		 *    methods mocked only. Inherits the old class
1043
+		 *    and chains the mock methods of an aggregated
1044
+		 *    mock object.
1045
+		 *    @param array $methods           Methods to be overridden
1046
+		 *                                    with mock versions.
1047
+		 *    @access public
1048
+		 */
1049
+		function generatePartial($methods) {
1050
+			if (! $this->_reflection->classExists($this->_class)) {
1051
+				return false;
1052
+			}
1053
+			$mock_reflection = new SimpleReflection($this->_mock_class);
1054
+			if ($mock_reflection->classExistsSansAutoload()) {
1055
+				trigger_error("Partial mock class [$mock_class] already exists");
1056
+				return false;
1057
+			}
1058
+			return eval($this->_extendClassCode($methods));
1059
+		}
1060
+
1061
+		/**
1062
+		 *    The new mock class code as a string.
1063
+		 *    @param array $methods          Additional methods.
1064
+		 *    @return string                 Code for new mock class.
1065
+		 *    @access private
1066
+		 */
1067
+		function _createClassCode($methods) {
1068
+			$implements = '';
1069
+			$interfaces = $this->_reflection->getInterfaces();
1070
+			if (function_exists('spl_classes')) {
1071
+				$interfaces = array_diff($interfaces, array('Traversable'));
1072
+			}
1073
+			if (count($interfaces) > 0) {
1074
+				$implements = 'implements ' . implode(', ', $interfaces);
1075
+			}
1076
+			$code = "class " . $this->_mock_class . " extends " . $this->_mock_base . " $implements {\n";
1077
+			$code .= "    function " . $this->_mock_class . "() {\n";
1078
+			$code .= "        \$this->" . $this->_mock_base . "();\n";
1079
+			$code .= "    }\n";
1080
+			$code .= $this->_createHandlerCode($methods);
1081
+			$code .= "}\n";
1082
+			return $code;
1083
+		}
1084
+
1085
+		/**
1086
+		 *    The extension class code as a string. The class
1087
+		 *    composites a mock object and chains mocked methods
1088
+		 *    to it.
1089
+		 *    @param array  $methods       Mocked methods.
1090
+		 *    @return string               Code for a new class.
1091
+		 *    @access private
1092
+		 */
1093
+		function _extendClassCode($methods) {
1094
+			$code  = "class " . $this->_mock_class . " extends " . $this->_class . " {\n";
1095
+			$code .= "    var \$_mock;\n";
1096
+			$code .= $this->_addMethodList($methods);
1097
+			$code .= "\n";
1098
+			$code .= "    function " . $this->_mock_class . "() {\n";
1099
+			$code .= "        \$this->_mock = new " . $this->_mock_base . "();\n";
1100
+			$code .= "        \$this->_mock->disableExpectationNameChecks();\n";
1101
+			$code .= "    }\n";
1102
+			$code .= $this->_chainMockReturns();
1103
+			$code .= $this->_chainMockExpectations();
1104
+			$code .= $this->_overrideMethods($methods);
1105
+			$code .= "}\n";
1106
+			return $code;
1107
+		}
1108
+
1109
+		/**
1110
+		 *    Creates code within a class to generate replaced
1111
+		 *    methods. All methods call the _invoke() handler
1112
+		 *    with the method name and the arguments in an
1113
+		 *    array.
1114
+		 *    @param array $methods    Additional methods.
1115
+		 *    @access private
1116
+		 */
1117
+		function _createHandlerCode($methods) {
1118
+			$code = '';
1119
+			$methods = array_merge($methods, $this->_reflection->getMethods());
1120
+			foreach ($methods as $method) {
1121
+				if ($this->_isConstructor($method)) {
1122
+					continue;
1123
+				}
1124
+				$mock_reflection = new SimpleReflection($this->_mock_base);
1125
+				if (in_array($method, $mock_reflection->getMethods())) {
1126
+					continue;
1127
+				}
1128
+				$code .= "    " . $this->_reflection->getSignature($method) . " {\n";
1129
+				$code .= "        \$args = func_get_args();\n";
1130
+				$code .= "        \$result = &\$this->_invoke(\"$method\", \$args);\n";
1131
+				$code .= "        return \$result;\n";
1132
+				$code .= "    }\n";
1133
+			}
1134
+			return $code;
1135
+		}
1136
+
1137
+		/**
1138
+		 *    Tests to see if a special PHP method is about to
1139
+		 *    be stubbed by mistake.
1140
+		 *    @param string $method    Method name.
1141
+		 *    @return boolean          True if special.
1142
+		 *    @access private
1143
+		 */
1144
+		function _isConstructor($method) {
1145
+			return in_array(
1146
+					strtolower($method),
1147
+					array('__construct', '__destruct', '__clone'));
1148
+		}
1149
+
1150
+		/**
1151
+		 *    Creates a list of mocked methods for error checking.
1152
+		 *    @param array $methods       Mocked methods.
1153
+		 *    @return string              Code for a method list.
1154
+		 *    @access private
1155
+		 */
1156
+		function _addMethodList($methods) {
1157
+			return "    var \$_mocked_methods = array('" . implode("', '", $methods) . "');\n";
1158
+		}
1159
+
1160
+		/**
1161
+		 *    Creates code to abandon the expectation if not mocked.
1162
+		 *    @param string $alias       Parameter name of method name.
1163
+		 *    @return string             Code for bail out.
1164
+		 *    @access private
1165
+		 */
1166
+		function _bailOutIfNotMocked($alias) {
1167
+			$code  = "        if (! in_array($alias, \$this->_mocked_methods)) {\n";
1168
+			$code .= "            trigger_error(\"Method [$alias] is not mocked\");\n";
1169
+			$code .= "            \$null = null;\n";
1170
+			$code .= "            return \$null;\n";
1171
+			$code .= "        }\n";
1172
+			return $code;
1173
+		}
1174
+
1175
+		/**
1176
+		 *    Creates source code for chaining to the composited
1177
+		 *    mock object.
1178
+		 *    @return string           Code for mock set up.
1179
+		 *    @access private
1180
+		 */
1181
+		function _chainMockReturns() {
1182
+			$code  = "    function setReturnValue(\$method, \$value, \$args = false) {\n";
1183
+			$code .= $this->_bailOutIfNotMocked("\$method");
1184
+			$code .= "        \$this->_mock->setReturnValue(\$method, \$value, \$args);\n";
1185
+			$code .= "    }\n";
1186
+			$code .= "    function setReturnValueAt(\$timing, \$method, \$value, \$args = false) {\n";
1187
+			$code .= $this->_bailOutIfNotMocked("\$method");
1188
+			$code .= "        \$this->_mock->setReturnValueAt(\$timing, \$method, \$value, \$args);\n";
1189
+			$code .= "    }\n";
1190
+			$code .= "    function setReturnReference(\$method, &\$ref, \$args = false) {\n";
1191
+			$code .= $this->_bailOutIfNotMocked("\$method");
1192
+			$code .= "        \$this->_mock->setReturnReference(\$method, \$ref, \$args);\n";
1193
+			$code .= "    }\n";
1194
+			$code .= "    function setReturnReferenceAt(\$timing, \$method, &\$ref, \$args = false) {\n";
1195
+			$code .= $this->_bailOutIfNotMocked("\$method");
1196
+			$code .= "        \$this->_mock->setReturnReferenceAt(\$timing, \$method, \$ref, \$args);\n";
1197
+			$code .= "    }\n";
1198
+			return $code;
1199
+		}
1200
+
1201
+		/**
1202
+		 *    Creates source code for chaining to an aggregated
1203
+		 *    mock object.
1204
+		 *    @return string                 Code for expectations.
1205
+		 *    @access private
1206
+		 */
1207
+		function _chainMockExpectations() {
1208
+			$code  = "    function expect(\$method, \$args = false) {\n";
1209
+			$code .= $this->_bailOutIfNotMocked("\$method");
1210
+			$code .= "        \$this->_mock->expect(\$method, \$args);\n";
1211
+			$code .= "    }\n";
1212
+			$code .= "    function expectArguments(\$method, \$args = false) {\n";
1213
+			$code .= $this->_bailOutIfNotMocked("\$method");
1214
+			$code .= "        \$this->_mock->expectArguments(\$method, \$args);\n";
1215
+			$code .= "    }\n";
1216
+			$code .= "    function expectAt(\$timing, \$method, \$args = false) {\n";
1217
+			$code .= $this->_bailOutIfNotMocked("\$method");
1218
+			$code .= "        \$this->_mock->expectArgumentsAt(\$timing, \$method, \$args);\n";
1219
+			$code .= "    }\n";
1220
+			$code .= "    function expectArgumentsAt(\$timing, \$method, \$args = false) {\n";
1221
+			$code .= $this->_bailOutIfNotMocked("\$method");
1222
+			$code .= "        \$this->_mock->expectArgumentsAt(\$timing, \$method, \$args);\n";
1223
+			$code .= "    }\n";
1224
+			$code .= "    function expectCallCount(\$method, \$count) {\n";
1225
+			$code .= $this->_bailOutIfNotMocked("\$method");
1226
+			$code .= "        \$this->_mock->expectCallCount(\$method, \$count);\n";
1227
+			$code .= "    }\n";
1228
+			$code .= "    function expectMaximumCallCount(\$method, \$count) {\n";
1229
+			$code .= $this->_bailOutIfNotMocked("\$method");
1230
+			$code .= "        \$this->_mock->expectMaximumCallCount(\$method, \$count);\n";
1231
+			$code .= "    }\n";
1232
+			$code .= "    function expectMinimumCallCount(\$method, \$count) {\n";
1233
+			$code .= $this->_bailOutIfNotMocked("\$method");
1234
+			$code .= "        \$this->_mock->expectMinimumCallCount(\$method, \$count);\n";
1235
+			$code .= "    }\n";
1236
+			$code .= "    function expectNever(\$method) {\n";
1237
+			$code .= $this->_bailOutIfNotMocked("\$method");
1238
+			$code .= "        \$this->_mock->expectNever(\$method);\n";
1239
+			$code .= "    }\n";
1240
+			$code .= "    function expectOnce(\$method, \$args = false) {\n";
1241
+			$code .= $this->_bailOutIfNotMocked("\$method");
1242
+			$code .= "        \$this->_mock->expectOnce(\$method, \$args);\n";
1243
+			$code .= "    }\n";
1244
+			$code .= "    function expectAtLeastOnce(\$method, \$args = false) {\n";
1245
+			$code .= $this->_bailOutIfNotMocked("\$method");
1246
+			$code .= "        \$this->_mock->expectAtLeastOnce(\$method, \$args);\n";
1247
+			$code .= "    }\n";
1248
+			$code .= "    function tally() {\n";
1249
+			$code .= "        \$this->_mock->tally();\n";
1250
+			$code .= "    }\n";
1251
+			return $code;
1252
+		}
1253
+
1254
+		/**
1255
+		 *    Creates source code to override a list of methods
1256
+		 *    with mock versions.
1257
+		 *    @param array $methods    Methods to be overridden
1258
+		 *                             with mock versions.
1259
+		 *    @return string           Code for overridden chains.
1260
+		 *    @access private
1261
+		 */
1262
+		function _overrideMethods($methods) {
1263
+			$code = "";
1264
+			foreach ($methods as $method) {
1265
+				$code .= "    " . $this->_reflection->getSignature($method) . " {\n";
1266
+				$code .= "        \$args = func_get_args();\n";
1267
+				$code .= "        \$result = &\$this->_mock->_invoke(\"$method\", \$args);\n";
1268
+				$code .= "        return \$result;\n";
1269
+				$code .= "    }\n";
1270
+			}
1271
+			return $code;
1272
+		}
1273
+	}
1274 1274
\ No newline at end of file
Please login to merge, or discard this patch.
tests/test_tools/simpletest/page.php 1 patch
Indentation   +965 added lines, -965 removed lines patch added patch discarded remove patch
@@ -1,974 +1,974 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *	Base include file for SimpleTest
4
-     *	@package	SimpleTest
5
-     *	@subpackage	WebTester
6
-     *	@version	$Id: page.php 1398 2006-09-08 19:31:03Z xue $
7
-     */
8
-
9
-    /**#@+
2
+	/**
3
+	 *	Base include file for SimpleTest
4
+	 *	@package	SimpleTest
5
+	 *	@subpackage	WebTester
6
+	 *	@version	$Id: page.php 1398 2006-09-08 19:31:03Z xue $
7
+	 */
8
+
9
+	/**#@+
10 10
      *	include other SimpleTest class files
11 11
      */
12
-    require_once(dirname(__FILE__) . '/http.php');
13
-    require_once(dirname(__FILE__) . '/parser.php');
14
-    require_once(dirname(__FILE__) . '/tag.php');
15
-    require_once(dirname(__FILE__) . '/form.php');
16
-    require_once(dirname(__FILE__) . '/selector.php');
17
-    /**#@-*/
18
-
19
-    /**
20
-     *    Creates tags and widgets given HTML tag
21
-     *    attributes.
12
+	require_once(dirname(__FILE__) . '/http.php');
13
+	require_once(dirname(__FILE__) . '/parser.php');
14
+	require_once(dirname(__FILE__) . '/tag.php');
15
+	require_once(dirname(__FILE__) . '/form.php');
16
+	require_once(dirname(__FILE__) . '/selector.php');
17
+	/**#@-*/
18
+
19
+	/**
20
+	 *    Creates tags and widgets given HTML tag
21
+	 *    attributes.
22 22
 	 *    @package SimpleTest
23 23
 	 *    @subpackage WebTester
24
-     */
25
-    class SimpleTagBuilder {
26
-
27
-        /**
28
-         *    Factory for the tag objects. Creates the
29
-         *    appropriate tag object for the incoming tag name
30
-         *    and attributes.
31
-         *    @param string $name        HTML tag name.
32
-         *    @param hash $attributes    Element attributes.
33
-         *    @return SimpleTag          Tag object.
34
-         *    @access public
35
-         */
36
-        function createTag($name, $attributes) {
37
-            static $map = array(
38
-                    'a' => 'SimpleAnchorTag',
39
-                    'title' => 'SimpleTitleTag',
40
-                    'button' => 'SimpleButtonTag',
41
-                    'textarea' => 'SimpleTextAreaTag',
42
-                    'option' => 'SimpleOptionTag',
43
-                    'label' => 'SimpleLabelTag',
44
-                    'form' => 'SimpleFormTag',
45
-                    'frame' => 'SimpleFrameTag');
46
-            $attributes = $this->_keysToLowerCase($attributes);
47
-            if (array_key_exists($name, $map)) {
48
-                $tag_class = $map[$name];
49
-                return new $tag_class($attributes);
50
-            } elseif ($name == 'select') {
51
-                return $this->_createSelectionTag($attributes);
52
-            } elseif ($name == 'input') {
53
-                return $this->_createInputTag($attributes);
54
-            }
55
-            return new SimpleTag($name, $attributes);
56
-        }
57
-
58
-        /**
59
-         *    Factory for selection fields.
60
-         *    @param hash $attributes    Element attributes.
61
-         *    @return SimpleTag          Tag object.
62
-         *    @access protected
63
-         */
64
-        function _createSelectionTag($attributes) {
65
-            if (isset($attributes['multiple'])) {
66
-                return new MultipleSelectionTag($attributes);
67
-            }
68
-            return new SimpleSelectionTag($attributes);
69
-        }
70
-
71
-        /**
72
-         *    Factory for input tags.
73
-         *    @param hash $attributes    Element attributes.
74
-         *    @return SimpleTag          Tag object.
75
-         *    @access protected
76
-         */
77
-        function _createInputTag($attributes) {
78
-            if (! isset($attributes['type'])) {
79
-                return new SimpleTextTag($attributes);
80
-            }
81
-            $type = strtolower(trim($attributes['type']));
82
-            $map = array(
83
-                    'submit' => 'SimpleSubmitTag',
84
-                    'image' => 'SimpleImageSubmitTag',
85
-                    'checkbox' => 'SimpleCheckboxTag',
86
-                    'radio' => 'SimpleRadioButtonTag',
87
-                    'text' => 'SimpleTextTag',
88
-                    'hidden' => 'SimpleTextTag',
89
-                    'password' => 'SimpleTextTag',
90
-                    'file' => 'SimpleUploadTag');
91
-            if (array_key_exists($type, $map)) {
92
-                $tag_class = $map[$type];
93
-                return new $tag_class($attributes);
94
-            }
95
-            return false;
96
-        }
97
-
98
-        /**
99
-         *    Make the keys lower case for case insensitive look-ups.
100
-         *    @param hash $map   Hash to convert.
101
-         *    @return hash       Unchanged values, but keys lower case.
102
-         *    @access private
103
-         */
104
-        function _keysToLowerCase($map) {
105
-            $lower = array();
106
-            foreach ($map as $key => $value) {
107
-                $lower[strtolower($key)] = $value;
108
-            }
109
-            return $lower;
110
-        }
111
-    }
112
-
113
-    /**
114
-     *    SAX event handler. Maintains a list of
115
-     *    open tags and dispatches them as they close.
24
+	 */
25
+	class SimpleTagBuilder {
26
+
27
+		/**
28
+		 *    Factory for the tag objects. Creates the
29
+		 *    appropriate tag object for the incoming tag name
30
+		 *    and attributes.
31
+		 *    @param string $name        HTML tag name.
32
+		 *    @param hash $attributes    Element attributes.
33
+		 *    @return SimpleTag          Tag object.
34
+		 *    @access public
35
+		 */
36
+		function createTag($name, $attributes) {
37
+			static $map = array(
38
+					'a' => 'SimpleAnchorTag',
39
+					'title' => 'SimpleTitleTag',
40
+					'button' => 'SimpleButtonTag',
41
+					'textarea' => 'SimpleTextAreaTag',
42
+					'option' => 'SimpleOptionTag',
43
+					'label' => 'SimpleLabelTag',
44
+					'form' => 'SimpleFormTag',
45
+					'frame' => 'SimpleFrameTag');
46
+			$attributes = $this->_keysToLowerCase($attributes);
47
+			if (array_key_exists($name, $map)) {
48
+				$tag_class = $map[$name];
49
+				return new $tag_class($attributes);
50
+			} elseif ($name == 'select') {
51
+				return $this->_createSelectionTag($attributes);
52
+			} elseif ($name == 'input') {
53
+				return $this->_createInputTag($attributes);
54
+			}
55
+			return new SimpleTag($name, $attributes);
56
+		}
57
+
58
+		/**
59
+		 *    Factory for selection fields.
60
+		 *    @param hash $attributes    Element attributes.
61
+		 *    @return SimpleTag          Tag object.
62
+		 *    @access protected
63
+		 */
64
+		function _createSelectionTag($attributes) {
65
+			if (isset($attributes['multiple'])) {
66
+				return new MultipleSelectionTag($attributes);
67
+			}
68
+			return new SimpleSelectionTag($attributes);
69
+		}
70
+
71
+		/**
72
+		 *    Factory for input tags.
73
+		 *    @param hash $attributes    Element attributes.
74
+		 *    @return SimpleTag          Tag object.
75
+		 *    @access protected
76
+		 */
77
+		function _createInputTag($attributes) {
78
+			if (! isset($attributes['type'])) {
79
+				return new SimpleTextTag($attributes);
80
+			}
81
+			$type = strtolower(trim($attributes['type']));
82
+			$map = array(
83
+					'submit' => 'SimpleSubmitTag',
84
+					'image' => 'SimpleImageSubmitTag',
85
+					'checkbox' => 'SimpleCheckboxTag',
86
+					'radio' => 'SimpleRadioButtonTag',
87
+					'text' => 'SimpleTextTag',
88
+					'hidden' => 'SimpleTextTag',
89
+					'password' => 'SimpleTextTag',
90
+					'file' => 'SimpleUploadTag');
91
+			if (array_key_exists($type, $map)) {
92
+				$tag_class = $map[$type];
93
+				return new $tag_class($attributes);
94
+			}
95
+			return false;
96
+		}
97
+
98
+		/**
99
+		 *    Make the keys lower case for case insensitive look-ups.
100
+		 *    @param hash $map   Hash to convert.
101
+		 *    @return hash       Unchanged values, but keys lower case.
102
+		 *    @access private
103
+		 */
104
+		function _keysToLowerCase($map) {
105
+			$lower = array();
106
+			foreach ($map as $key => $value) {
107
+				$lower[strtolower($key)] = $value;
108
+			}
109
+			return $lower;
110
+		}
111
+	}
112
+
113
+	/**
114
+	 *    SAX event handler. Maintains a list of
115
+	 *    open tags and dispatches them as they close.
116 116
 	 *    @package SimpleTest
117 117
 	 *    @subpackage WebTester
118
-     */
119
-    class SimplePageBuilder extends SimpleSaxListener {
120
-        protected $_tags;
121
-        protected $_page;
122
-        protected $_private_content_tag;
123
-
124
-        /**
125
-         *    Sets the builder up empty.
126
-         *    @access public
127
-         */
128
-        function SimplePageBuilder() {
129
-            $this->SimpleSaxListener();
130
-        }
131
-
132
-        /**
133
-         *    Frees up any references so as to allow the PHP garbage
134
-         *    collection from unset() to work.
135
-         *    @access public
136
-         */
137
-        function free() {
138
-            unset($this->_tags);
139
-            unset($this->_page);
140
-            unset($this->_private_content_tags);
141
-        }
142
-
143
-        /**
144
-         *    Reads the raw content and send events
145
-         *    into the page to be built.
146
-         *    @param $response SimpleHttpResponse  Fetched response.
147
-         *    @return SimplePage                   Newly parsed page.
148
-         *    @access public
149
-         */
150
-        function &parse($response) {
151
-            $this->_tags = array();
152
-            $this->_page = $this->_createPage($response);
153
-            $parser = $this->_createParser($this);
154
-            $parser->parse($response->getContent());
155
-            $this->_page->acceptPageEnd();
156
-            return $this->_page;
157
-        }
158
-
159
-        /**
160
-         *    Creates an empty page.
161
-         *    @return SimplePage        New unparsed page.
162
-         *    @access protected
163
-         */
164
-        function &_createPage($response) {
165
-            $page = new SimplePage($response);
166
-            return $page;
167
-        }
168
-
169
-        /**
170
-         *    Creates the parser used with the builder.
171
-         *    @param $listener SimpleSaxListener   Target of parser.
172
-         *    @return SimpleSaxParser              Parser to generate
173
-         *                                         events for the builder.
174
-         *    @access protected
175
-         */
176
-        function &_createParser($listener) {
177
-            $parser = new SimpleHtmlSaxParser($listener);
178
-            return $parser;
179
-        }
180
-
181
-        /**
182
-         *    Start of element event. Opens a new tag.
183
-         *    @param string $name         Element name.
184
-         *    @param hash $attributes     Attributes without content
185
-         *                                are marked as true.
186
-         *    @return boolean             False on parse error.
187
-         *    @access public
188
-         */
189
-        function startElement($name, $attributes) {
190
-            $factory = new SimpleTagBuilder();
191
-            $tag = $factory->createTag($name, $attributes);
192
-            if (! $tag) {
193
-                return true;
194
-            }
195
-            if ($tag->getTagName() == 'label') {
196
-                $this->_page->acceptLabelStart($tag);
197
-                $this->_openTag($tag);
198
-                return true;
199
-            }
200
-            if ($tag->getTagName() == 'form') {
201
-                $this->_page->acceptFormStart($tag);
202
-                return true;
203
-            }
204
-            if ($tag->getTagName() == 'frameset') {
205
-                $this->_page->acceptFramesetStart($tag);
206
-                return true;
207
-            }
208
-            if ($tag->getTagName() == 'frame') {
209
-                $this->_page->acceptFrame($tag);
210
-                return true;
211
-            }
212
-            if ($tag->isPrivateContent() && ! isset($this->_private_content_tag)) {
213
-                $this->_private_content_tag = $tag;
214
-            }
215
-            if ($tag->expectEndTag()) {
216
-                $this->_openTag($tag);
217
-                return true;
218
-            }
219
-            $this->_page->acceptTag($tag);
220
-            return true;
221
-        }
222
-
223
-        /**
224
-         *    End of element event.
225
-         *    @param string $name        Element name.
226
-         *    @return boolean            False on parse error.
227
-         *    @access public
228
-         */
229
-        function endElement($name) {
230
-            if ($name == 'label') {
231
-                $this->_page->acceptLabelEnd();
232
-                return true;
233
-            }
234
-            if ($name == 'form') {
235
-                $this->_page->acceptFormEnd();
236
-                return true;
237
-            }
238
-            if ($name == 'frameset') {
239
-                $this->_page->acceptFramesetEnd();
240
-                return true;
241
-            }
242
-            if ($this->_hasNamedTagOnOpenTagStack($name)) {
243
-                $tag = array_pop($this->_tags[$name]);
244
-                if ($tag->isPrivateContent() && $this->_private_content_tag->getTagName() == $name) {
245
-                    unset($this->_private_content_tag);
246
-                }
247
-                $this->_addContentTagToOpenTags($tag);
248
-                $this->_page->acceptTag($tag);
249
-                return true;
250
-            }
251
-            return true;
252
-        }
253
-
254
-        /**
255
-         *    Test to see if there are any open tags awaiting
256
-         *    closure that match the tag name.
257
-         *    @param string $name        Element name.
258
-         *    @return boolean            True if any are still open.
259
-         *    @access private
260
-         */
261
-        function _hasNamedTagOnOpenTagStack($name) {
262
-            return isset($this->_tags[$name]) && (count($this->_tags[$name]) > 0);
263
-        }
264
-
265
-        /**
266
-         *    Unparsed, but relevant data. The data is added
267
-         *    to every open tag.
268
-         *    @param string $text        May include unparsed tags.
269
-         *    @return boolean            False on parse error.
270
-         *    @access public
271
-         */
272
-        function addContent($text) {
273
-            if (isset($this->_private_content_tag)) {
274
-                $this->_private_content_tag->addContent($text);
275
-            } else {
276
-                $this->_addContentToAllOpenTags($text);
277
-            }
278
-            return true;
279
-        }
280
-
281
-        /**
282
-         *    Any content fills all currently open tags unless it
283
-         *    is part of an option tag.
284
-         *    @param string $text        May include unparsed tags.
285
-         *    @access private
286
-         */
287
-        function _addContentToAllOpenTags($text) {
288
-            foreach (array_keys($this->_tags) as $name) {
289
-                for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) {
290
-                    $this->_tags[$name][$i]->addContent($text);
291
-                }
292
-            }
293
-        }
294
-
295
-        /**
296
-         *    Parsed data in tag form. The parsed tag is added
297
-         *    to every open tag. Used for adding options to select
298
-         *    fields only.
299
-         *    @param SimpleTag $tag        Option tags only.
300
-         *    @access private
301
-         */
302
-        function _addContentTagToOpenTags($tag) {
303
-            if ($tag->getTagName() != 'option') {
304
-                return;
305
-            }
306
-            foreach (array_keys($this->_tags) as $name) {
307
-                for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) {
308
-                    $this->_tags[$name][$i]->addTag($tag);
309
-                }
310
-            }
311
-        }
312
-
313
-        /**
314
-         *    Opens a tag for receiving content. Multiple tags
315
-         *    will be receiving input at the same time.
316
-         *    @param SimpleTag $tag        New content tag.
317
-         *    @access private
318
-         */
319
-        function _openTag($tag) {
320
-            $name = $tag->getTagName();
321
-            if (! in_array($name, array_keys($this->_tags))) {
322
-                $this->_tags[$name] = array();
323
-            }
324
-            $this->_tags[$name][] = $tag;
325
-        }
326
-    }
327
-
328
-    /**
329
-     *    A wrapper for a web page.
118
+	 */
119
+	class SimplePageBuilder extends SimpleSaxListener {
120
+		protected $_tags;
121
+		protected $_page;
122
+		protected $_private_content_tag;
123
+
124
+		/**
125
+		 *    Sets the builder up empty.
126
+		 *    @access public
127
+		 */
128
+		function SimplePageBuilder() {
129
+			$this->SimpleSaxListener();
130
+		}
131
+
132
+		/**
133
+		 *    Frees up any references so as to allow the PHP garbage
134
+		 *    collection from unset() to work.
135
+		 *    @access public
136
+		 */
137
+		function free() {
138
+			unset($this->_tags);
139
+			unset($this->_page);
140
+			unset($this->_private_content_tags);
141
+		}
142
+
143
+		/**
144
+		 *    Reads the raw content and send events
145
+		 *    into the page to be built.
146
+		 *    @param $response SimpleHttpResponse  Fetched response.
147
+		 *    @return SimplePage                   Newly parsed page.
148
+		 *    @access public
149
+		 */
150
+		function &parse($response) {
151
+			$this->_tags = array();
152
+			$this->_page = $this->_createPage($response);
153
+			$parser = $this->_createParser($this);
154
+			$parser->parse($response->getContent());
155
+			$this->_page->acceptPageEnd();
156
+			return $this->_page;
157
+		}
158
+
159
+		/**
160
+		 *    Creates an empty page.
161
+		 *    @return SimplePage        New unparsed page.
162
+		 *    @access protected
163
+		 */
164
+		function &_createPage($response) {
165
+			$page = new SimplePage($response);
166
+			return $page;
167
+		}
168
+
169
+		/**
170
+		 *    Creates the parser used with the builder.
171
+		 *    @param $listener SimpleSaxListener   Target of parser.
172
+		 *    @return SimpleSaxParser              Parser to generate
173
+		 *                                         events for the builder.
174
+		 *    @access protected
175
+		 */
176
+		function &_createParser($listener) {
177
+			$parser = new SimpleHtmlSaxParser($listener);
178
+			return $parser;
179
+		}
180
+
181
+		/**
182
+		 *    Start of element event. Opens a new tag.
183
+		 *    @param string $name         Element name.
184
+		 *    @param hash $attributes     Attributes without content
185
+		 *                                are marked as true.
186
+		 *    @return boolean             False on parse error.
187
+		 *    @access public
188
+		 */
189
+		function startElement($name, $attributes) {
190
+			$factory = new SimpleTagBuilder();
191
+			$tag = $factory->createTag($name, $attributes);
192
+			if (! $tag) {
193
+				return true;
194
+			}
195
+			if ($tag->getTagName() == 'label') {
196
+				$this->_page->acceptLabelStart($tag);
197
+				$this->_openTag($tag);
198
+				return true;
199
+			}
200
+			if ($tag->getTagName() == 'form') {
201
+				$this->_page->acceptFormStart($tag);
202
+				return true;
203
+			}
204
+			if ($tag->getTagName() == 'frameset') {
205
+				$this->_page->acceptFramesetStart($tag);
206
+				return true;
207
+			}
208
+			if ($tag->getTagName() == 'frame') {
209
+				$this->_page->acceptFrame($tag);
210
+				return true;
211
+			}
212
+			if ($tag->isPrivateContent() && ! isset($this->_private_content_tag)) {
213
+				$this->_private_content_tag = $tag;
214
+			}
215
+			if ($tag->expectEndTag()) {
216
+				$this->_openTag($tag);
217
+				return true;
218
+			}
219
+			$this->_page->acceptTag($tag);
220
+			return true;
221
+		}
222
+
223
+		/**
224
+		 *    End of element event.
225
+		 *    @param string $name        Element name.
226
+		 *    @return boolean            False on parse error.
227
+		 *    @access public
228
+		 */
229
+		function endElement($name) {
230
+			if ($name == 'label') {
231
+				$this->_page->acceptLabelEnd();
232
+				return true;
233
+			}
234
+			if ($name == 'form') {
235
+				$this->_page->acceptFormEnd();
236
+				return true;
237
+			}
238
+			if ($name == 'frameset') {
239
+				$this->_page->acceptFramesetEnd();
240
+				return true;
241
+			}
242
+			if ($this->_hasNamedTagOnOpenTagStack($name)) {
243
+				$tag = array_pop($this->_tags[$name]);
244
+				if ($tag->isPrivateContent() && $this->_private_content_tag->getTagName() == $name) {
245
+					unset($this->_private_content_tag);
246
+				}
247
+				$this->_addContentTagToOpenTags($tag);
248
+				$this->_page->acceptTag($tag);
249
+				return true;
250
+			}
251
+			return true;
252
+		}
253
+
254
+		/**
255
+		 *    Test to see if there are any open tags awaiting
256
+		 *    closure that match the tag name.
257
+		 *    @param string $name        Element name.
258
+		 *    @return boolean            True if any are still open.
259
+		 *    @access private
260
+		 */
261
+		function _hasNamedTagOnOpenTagStack($name) {
262
+			return isset($this->_tags[$name]) && (count($this->_tags[$name]) > 0);
263
+		}
264
+
265
+		/**
266
+		 *    Unparsed, but relevant data. The data is added
267
+		 *    to every open tag.
268
+		 *    @param string $text        May include unparsed tags.
269
+		 *    @return boolean            False on parse error.
270
+		 *    @access public
271
+		 */
272
+		function addContent($text) {
273
+			if (isset($this->_private_content_tag)) {
274
+				$this->_private_content_tag->addContent($text);
275
+			} else {
276
+				$this->_addContentToAllOpenTags($text);
277
+			}
278
+			return true;
279
+		}
280
+
281
+		/**
282
+		 *    Any content fills all currently open tags unless it
283
+		 *    is part of an option tag.
284
+		 *    @param string $text        May include unparsed tags.
285
+		 *    @access private
286
+		 */
287
+		function _addContentToAllOpenTags($text) {
288
+			foreach (array_keys($this->_tags) as $name) {
289
+				for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) {
290
+					$this->_tags[$name][$i]->addContent($text);
291
+				}
292
+			}
293
+		}
294
+
295
+		/**
296
+		 *    Parsed data in tag form. The parsed tag is added
297
+		 *    to every open tag. Used for adding options to select
298
+		 *    fields only.
299
+		 *    @param SimpleTag $tag        Option tags only.
300
+		 *    @access private
301
+		 */
302
+		function _addContentTagToOpenTags($tag) {
303
+			if ($tag->getTagName() != 'option') {
304
+				return;
305
+			}
306
+			foreach (array_keys($this->_tags) as $name) {
307
+				for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) {
308
+					$this->_tags[$name][$i]->addTag($tag);
309
+				}
310
+			}
311
+		}
312
+
313
+		/**
314
+		 *    Opens a tag for receiving content. Multiple tags
315
+		 *    will be receiving input at the same time.
316
+		 *    @param SimpleTag $tag        New content tag.
317
+		 *    @access private
318
+		 */
319
+		function _openTag($tag) {
320
+			$name = $tag->getTagName();
321
+			if (! in_array($name, array_keys($this->_tags))) {
322
+				$this->_tags[$name] = array();
323
+			}
324
+			$this->_tags[$name][] = $tag;
325
+		}
326
+	}
327
+
328
+	/**
329
+	 *    A wrapper for a web page.
330 330
 	 *    @package SimpleTest
331 331
 	 *    @subpackage WebTester
332
-     */
333
-    class SimplePage {
334
-        protected $_links;
335
-        protected $_title;
336
-        protected $_last_widget;
337
-        protected $_label;
338
-        protected $_left_over_labels;
339
-        protected $_open_forms;
340
-        protected $_complete_forms;
341
-        protected $_frameset;
342
-        protected $_frames;
343
-        protected $_frameset_nesting_level;
344
-        protected $_transport_error;
345
-        protected $_raw;
346
-        protected $_text;
347
-        protected $_sent;
348
-        protected $_headers;
349
-        protected $_method;
350
-        protected $_url;
351
-        protected $_request_data;
352
-
353
-        /**
354
-         *    Parses a page ready to access it's contents.
355
-         *    @param SimpleHttpResponse $response     Result of HTTP fetch.
356
-         *    @access public
357
-         */
358
-        function SimplePage($response = false) {
359
-            $this->_links = array();
360
-            $this->_title = false;
361
-            $this->_left_over_labels = array();
362
-            $this->_open_forms = array();
363
-            $this->_complete_forms = array();
364
-            $this->_frameset = false;
365
-            $this->_frames = array();
366
-            $this->_frameset_nesting_level = 0;
367
-            $this->_text = false;
368
-            if ($response) {
369
-                $this->_extractResponse($response);
370
-            } else {
371
-                $this->_noResponse();
372
-            }
373
-        }
374
-
375
-        /**
376
-         *    Extracts all of the response information.
377
-         *    @param SimpleHttpResponse $response    Response being parsed.
378
-         *    @access private
379
-         */
380
-        function _extractResponse($response) {
381
-            $this->_transport_error = $response->getError();
382
-            $this->_raw = $response->getContent();
383
-            $this->_sent = $response->getSent();
384
-            $this->_headers = $response->getHeaders();
385
-            $this->_method = $response->getMethod();
386
-            $this->_url = $response->getUrl();
387
-            $this->_request_data = $response->getRequestData();
388
-        }
389
-
390
-        /**
391
-         *    Sets up a missing response.
392
-         *    @access private
393
-         */
394
-        function _noResponse() {
395
-            $this->_transport_error = 'No page fetched yet';
396
-            $this->_raw = false;
397
-            $this->_sent = false;
398
-            $this->_headers = false;
399
-            $this->_method = 'GET';
400
-            $this->_url = false;
401
-            $this->_request_data = false;
402
-        }
403
-
404
-        /**
405
-         *    Original request as bytes sent down the wire.
406
-         *    @return mixed              Sent content.
407
-         *    @access public
408
-         */
409
-        function getRequest() {
410
-            return $this->_sent;
411
-        }
412
-
413
-        /**
414
-         *    Accessor for raw text of page.
415
-         *    @return string        Raw unparsed content.
416
-         *    @access public
417
-         */
418
-        function getRaw() {
419
-            return $this->_raw;
420
-        }
421
-
422
-        /**
423
-         *    Accessor for plain text of page as a text browser
424
-         *    would see it.
425
-         *    @return string        Plain text of page.
426
-         *    @access public
427
-         */
428
-        function getText() {
429
-            if (! $this->_text) {
430
-                $this->_text = SimpleHtmlSaxParser::normalise($this->_raw);
431
-            }
432
-            return $this->_text;
433
-        }
434
-
435
-        /**
436
-         *    Accessor for raw headers of page.
437
-         *    @return string       Header block as text.
438
-         *    @access public
439
-         */
440
-        function getHeaders() {
441
-            if ($this->_headers) {
442
-                return $this->_headers->getRaw();
443
-            }
444
-            return false;
445
-        }
446
-
447
-        /**
448
-         *    Original request method.
449
-         *    @return string        GET, POST or HEAD.
450
-         *    @access public
451
-         */
452
-        function getMethod() {
453
-            return $this->_method;
454
-        }
455
-
456
-        /**
457
-         *    Original resource name.
458
-         *    @return SimpleUrl        Current url.
459
-         *    @access public
460
-         */
461
-        function getUrl() {
462
-            return $this->_url;
463
-        }
464
-
465
-        /**
466
-         *    Original request data.
467
-         *    @return mixed              Sent content.
468
-         *    @access public
469
-         */
470
-        function getRequestData() {
471
-            return $this->_request_data;
472
-        }
473
-
474
-        /**
475
-         *    Accessor for last error.
476
-         *    @return string        Error from last response.
477
-         *    @access public
478
-         */
479
-        function getTransportError() {
480
-            return $this->_transport_error;
481
-        }
482
-
483
-        /**
484
-         *    Accessor for current MIME type.
485
-         *    @return string    MIME type as string; e.g. 'text/html'
486
-         *    @access public
487
-         */
488
-        function getMimeType() {
489
-            if ($this->_headers) {
490
-                return $this->_headers->getMimeType();
491
-            }
492
-            return false;
493
-        }
494
-
495
-        /**
496
-         *    Accessor for HTTP response code.
497
-         *    @return integer    HTTP response code received.
498
-         *    @access public
499
-         */
500
-        function getResponseCode() {
501
-            if ($this->_headers) {
502
-                return $this->_headers->getResponseCode();
503
-            }
504
-            return false;
505
-        }
506
-
507
-        /**
508
-         *    Accessor for last Authentication type. Only valid
509
-         *    straight after a challenge (401).
510
-         *    @return string    Description of challenge type.
511
-         *    @access public
512
-         */
513
-        function getAuthentication() {
514
-            if ($this->_headers) {
515
-                return $this->_headers->getAuthentication();
516
-            }
517
-            return false;
518
-        }
519
-
520
-        /**
521
-         *    Accessor for last Authentication realm. Only valid
522
-         *    straight after a challenge (401).
523
-         *    @return string    Name of security realm.
524
-         *    @access public
525
-         */
526
-        function getRealm() {
527
-            if ($this->_headers) {
528
-                return $this->_headers->getRealm();
529
-            }
530
-            return false;
531
-        }
532
-
533
-        /**
534
-         *    Accessor for current frame focus. Will be
535
-         *    false as no frames.
536
-         *    @return array    Always empty.
537
-         *    @access public
538
-         */
539
-        function getFrameFocus() {
540
-            return array();
541
-        }
542
-
543
-        /**
544
-         *    Sets the focus by index. The integer index starts from 1.
545
-         *    @param integer $choice    Chosen frame.
546
-         *    @return boolean           Always false.
547
-         *    @access public
548
-         */
549
-        function setFrameFocusByIndex($choice) {
550
-            return false;
551
-        }
552
-
553
-        /**
554
-         *    Sets the focus by name. Always fails for a leaf page.
555
-         *    @param string $name    Chosen frame.
556
-         *    @return boolean        False as no frames.
557
-         *    @access public
558
-         */
559
-        function setFrameFocus($name) {
560
-            return false;
561
-        }
562
-
563
-        /**
564
-         *    Clears the frame focus. Does nothing for a leaf page.
565
-         *    @access public
566
-         */
567
-        function clearFrameFocus() {
568
-        }
569
-
570
-        /**
571
-         *    Adds a tag to the page.
572
-         *    @param SimpleTag $tag        Tag to accept.
573
-         *    @access public
574
-         */
575
-        function acceptTag($tag) {
576
-            if ($tag->getTagName() == "a") {
577
-                $this->_addLink($tag);
578
-            } elseif ($tag->getTagName() == "title") {
579
-                $this->_setTitle($tag);
580
-            } elseif ($this->_isFormElement($tag->getTagName())) {
581
-                for ($i = 0; $i < count($this->_open_forms); $i++) {
582
-                    $this->_open_forms[$i]->addWidget($tag);
583
-                }
584
-                $this->_last_widget = $tag;
585
-            }
586
-        }
587
-
588
-        /**
589
-         *    Opens a label for a described widget.
590
-         *    @param SimpleFormTag $tag      Tag to accept.
591
-         *    @access public
592
-         */
593
-        function acceptLabelStart($tag) {
594
-            $this->_label = $tag;
595
-            unset($this->_last_widget);
596
-        }
597
-
598
-        /**
599
-         *    Closes the most recently opened label.
600
-         *    @access public
601
-         */
602
-        function acceptLabelEnd() {
603
-            if (isset($this->_label)) {
604
-                if (isset($this->_last_widget)) {
605
-                    $this->_last_widget->setLabel($this->_label->getText());
606
-                    unset($this->_last_widget);
607
-                } else {
608
-                    $this->_left_over_labels[] = SimpleTestCompatibility::copy($this->_label);
609
-                }
610
-                unset($this->_label);
611
-            }
612
-        }
613
-
614
-        /**
615
-         *    Tests to see if a tag is a possible form
616
-         *    element.
617
-         *    @param string $name     HTML element name.
618
-         *    @return boolean         True if form element.
619
-         *    @access private
620
-         */
621
-        function _isFormElement($name) {
622
-            return in_array($name, array('input', 'button', 'textarea', 'select'));
623
-        }
624
-
625
-        /**
626
-         *    Opens a form. New widgets go here.
627
-         *    @param SimpleFormTag $tag      Tag to accept.
628
-         *    @access public
629
-         */
630
-        function acceptFormStart($tag) {
631
-            $this->_open_forms[] = new SimpleForm($tag, $this->getUrl());
632
-        }
633
-
634
-        /**
635
-         *    Closes the most recently opened form.
636
-         *    @access public
637
-         */
638
-        function acceptFormEnd() {
639
-            if (count($this->_open_forms)) {
640
-                $this->_complete_forms[] = array_pop($this->_open_forms);
641
-            }
642
-        }
643
-
644
-        /**
645
-         *    Opens a frameset. A frameset may contain nested
646
-         *    frameset tags.
647
-         *    @param SimpleFramesetTag $tag      Tag to accept.
648
-         *    @access public
649
-         */
650
-        function acceptFramesetStart($tag) {
651
-            if (! $this->_isLoadingFrames()) {
652
-                $this->_frameset = $tag;
653
-            }
654
-            $this->_frameset_nesting_level++;
655
-        }
656
-
657
-        /**
658
-         *    Closes the most recently opened frameset.
659
-         *    @access public
660
-         */
661
-        function acceptFramesetEnd() {
662
-            if ($this->_isLoadingFrames()) {
663
-                $this->_frameset_nesting_level--;
664
-            }
665
-        }
666
-
667
-        /**
668
-         *    Takes a single frame tag and stashes it in
669
-         *    the current frame set.
670
-         *    @param SimpleFrameTag $tag      Tag to accept.
671
-         *    @access public
672
-         */
673
-        function acceptFrame($tag) {
674
-            if ($this->_isLoadingFrames()) {
675
-                if ($tag->getAttribute('src')) {
676
-                    $this->_frames[] = $tag;
677
-                }
678
-            }
679
-        }
680
-
681
-        /**
682
-         *    Test to see if in the middle of reading
683
-         *    a frameset.
684
-         *    @return boolean        True if inframeset.
685
-         *    @access private
686
-         */
687
-        function _isLoadingFrames() {
688
-            if (! $this->_frameset) {
689
-                return false;
690
-            }
691
-            return ($this->_frameset_nesting_level > 0);
692
-        }
693
-
694
-        /**
695
-         *    Test to see if link is an absolute one.
696
-         *    @param string $url     Url to test.
697
-         *    @return boolean        True if absolute.
698
-         *    @access protected
699
-         */
700
-        function _linkIsAbsolute($url) {
701
-            $parsed = new SimpleUrl($url);
702
-            return (boolean)($parsed->getScheme() && $parsed->getHost());
703
-        }
704
-
705
-        /**
706
-         *    Adds a link to the page.
707
-         *    @param SimpleAnchorTag $tag      Link to accept.
708
-         *    @access protected
709
-         */
710
-        function _addLink($tag) {
711
-            $this->_links[] = $tag;
712
-        }
713
-
714
-        /**
715
-         *    Marker for end of complete page. Any work in
716
-         *    progress can now be closed.
717
-         *    @access public
718
-         */
719
-        function acceptPageEnd() {
720
-            while (count($this->_open_forms)) {
721
-                $this->_complete_forms[] = array_pop($this->_open_forms);
722
-            }
723
-            foreach ($this->_left_over_labels as $label) {
724
-                for ($i = 0, $count = count($this->_complete_forms); $i < $count; $i++) {
725
-                    $this->_complete_forms[$i]->attachLabelBySelector(
726
-                            new SimpleById($label->getFor()),
727
-                            $label->getText());
728
-                }
729
-            }
730
-        }
731
-
732
-        /**
733
-         *    Test for the presence of a frameset.
734
-         *    @return boolean        True if frameset.
735
-         *    @access public
736
-         */
737
-        function hasFrames() {
738
-            return (boolean)$this->_frameset;
739
-        }
740
-
741
-        /**
742
-         *    Accessor for frame name and source URL for every frame that
743
-         *    will need to be loaded. Immediate children only.
744
-         *    @return boolean/array     False if no frameset or
745
-         *                              otherwise a hash of frame URLs.
746
-         *                              The key is either a numerical
747
-         *                              base one index or the name attribute.
748
-         *    @access public
749
-         */
750
-        function getFrameset() {
751
-            if (! $this->_frameset) {
752
-                return false;
753
-            }
754
-            $urls = array();
755
-            for ($i = 0; $i < count($this->_frames); $i++) {
756
-                $name = $this->_frames[$i]->getAttribute('name');
757
-                $url = new SimpleUrl($this->_frames[$i]->getAttribute('src'));
758
-                $urls[$name ? $name : $i + 1] = $url->makeAbsolute($this->getUrl());
759
-            }
760
-            return $urls;
761
-        }
762
-
763
-        /**
764
-         *    Fetches a list of loaded frames.
765
-         *    @return array/string    Just the URL for a single page.
766
-         *    @access public
767
-         */
768
-        function getFrames() {
769
-            $url = $this->getUrl();
770
-            return $url->asString();
771
-        }
772
-
773
-        /**
774
-         *    Accessor for a list of all fixed links.
775
-         *    @return array   List of urls with scheme of
776
-         *                    http or https and hostname.
777
-         *    @access public
778
-         */
779
-        function getAbsoluteUrls() {
780
-            $all = array();
781
-            foreach ($this->_links as $link) {
782
-                if ($this->_linkIsAbsolute($link->getHref())) {
783
-                    $all[] = $link->getHref();
784
-                }
785
-            }
786
-            return $all;
787
-        }
788
-
789
-        /**
790
-         *    Accessor for a list of all relative links.
791
-         *    @return array      List of urls without hostname.
792
-         *    @access public
793
-         */
794
-        function getRelativeUrls() {
795
-            $all = array();
796
-            foreach ($this->_links as $link) {
797
-                if (! $this->_linkIsAbsolute($link->getHref())) {
798
-                    $all[] = $link->getHref();
799
-                }
800
-            }
801
-            return $all;
802
-        }
803
-
804
-        /**
805
-         *    Accessor for URLs by the link label. Label will match
806
-         *    regardess of whitespace issues and case.
807
-         *    @param string $label    Text of link.
808
-         *    @return array           List of links with that label.
809
-         *    @access public
810
-         */
811
-        function getUrlsByLabel($label) {
812
-            $matches = array();
813
-            foreach ($this->_links as $link) {
814
-                if ($link->getText() == $label) {
815
-                    $matches[] = $this->_getUrlFromLink($link);
816
-                }
817
-            }
818
-            return $matches;
819
-        }
820
-
821
-        /**
822
-         *    Accessor for a URL by the id attribute.
823
-         *    @param string $id       Id attribute of link.
824
-         *    @return SimpleUrl       URL with that id of false if none.
825
-         *    @access public
826
-         */
827
-        function getUrlById($id) {
828
-            foreach ($this->_links as $link) {
829
-                if ($link->getAttribute('id') === (string)$id) {
830
-                    return $this->_getUrlFromLink($link);
831
-                }
832
-            }
833
-            return false;
834
-        }
835
-
836
-        /**
837
-         *    Converts a link into a target URL.
838
-         *    @param SimpleAnchor $link    Parsed link.
839
-         *    @return SimpleUrl            URL with frame target if any.
840
-         *    @access private
841
-         */
842
-        function _getUrlFromLink($link) {
843
-            $url = $this->_makeAbsolute($link->getHref());
844
-            if ($link->getAttribute('target')) {
845
-                $url->setTarget($link->getAttribute('target'));
846
-            }
847
-            return $url;
848
-        }
849
-
850
-        /**
851
-         *    Expands expandomatic URLs into fully qualified
852
-         *    URLs.
853
-         *    @param SimpleUrl $url        Relative URL.
854
-         *    @return SimpleUrl            Absolute URL.
855
-         *    @access protected
856
-         */
857
-        function _makeAbsolute($url) {
858
-            if (! is_object($url)) {
859
-                $url = new SimpleUrl($url);
860
-            }
861
-            return $url->makeAbsolute($this->getUrl());
862
-        }
863
-
864
-        /**
865
-         *    Sets the title tag contents.
866
-         *    @param SimpleTitleTag $tag    Title of page.
867
-         *    @access protected
868
-         */
869
-        function _setTitle($tag) {
870
-            $this->_title = $tag;
871
-        }
872
-
873
-        /**
874
-         *    Accessor for parsed title.
875
-         *    @return string     Title or false if no title is present.
876
-         *    @access public
877
-         */
878
-        function getTitle() {
879
-            if ($this->_title) {
880
-                return $this->_title->getText();
881
-            }
882
-            return false;
883
-        }
884
-
885
-        /**
886
-         *    Finds a held form by button label. Will only
887
-         *    search correctly built forms.
888
-         *    @param SimpleSelector $selector       Button finder.
889
-         *    @return SimpleForm                    Form object containing
890
-         *                                          the button.
891
-         *    @access public
892
-         */
893
-        function &getFormBySubmit($selector) {
894
-            for ($i = 0; $i < count($this->_complete_forms); $i++) {
895
-                if ($this->_complete_forms[$i]->hasSubmit($selector)) {
896
-                    return $this->_complete_forms[$i];
897
-                }
898
-            }
899
-            $null = null;
900
-            return $null;
901
-        }
902
-
903
-        /**
904
-         *    Finds a held form by image using a selector.
905
-         *    Will only search correctly built forms.
906
-         *    @param SimpleSelector $selector  Image finder.
907
-         *    @return SimpleForm               Form object containing
908
-         *                                     the image.
909
-         *    @access public
910
-         */
911
-        function &getFormByImage($selector) {
912
-            for ($i = 0; $i < count($this->_complete_forms); $i++) {
913
-                if ($this->_complete_forms[$i]->hasImage($selector)) {
914
-                    return $this->_complete_forms[$i];
915
-                }
916
-            }
917
-            $null = null;
918
-            return $null;
919
-        }
920
-
921
-        /**
922
-         *    Finds a held form by the form ID. A way of
923
-         *    identifying a specific form when we have control
924
-         *    of the HTML code.
925
-         *    @param string $id     Form label.
926
-         *    @return SimpleForm    Form object containing the matching ID.
927
-         *    @access public
928
-         */
929
-        function &getFormById($id) {
930
-            for ($i = 0; $i < count($this->_complete_forms); $i++) {
931
-                if ($this->_complete_forms[$i]->getId() == $id) {
932
-                    return $this->_complete_forms[$i];
933
-                }
934
-            }
935
-            $null = null;
936
-            return $null;
937
-        }
938
-
939
-        /**
940
-         *    Sets a field on each form in which the field is
941
-         *    available.
942
-         *    @param SimpleSelector $selector    Field finder.
943
-         *    @param string $value               Value to set field to.
944
-         *    @return boolean                    True if value is valid.
945
-         *    @access public
946
-         */
947
-        function setField($selector, $value) {
948
-            $is_set = false;
949
-            for ($i = 0; $i < count($this->_complete_forms); $i++) {
950
-                if ($this->_complete_forms[$i]->setField($selector, $value)) {
951
-                    $is_set = true;
952
-                }
953
-            }
954
-            return $is_set;
955
-        }
956
-
957
-        /**
958
-         *    Accessor for a form element value within a page.
959
-         *    @param SimpleSelector $selector    Field finder.
960
-         *    @return string/boolean             A string if the field is
961
-         *                                       present, false if unchecked
962
-         *                                       and null if missing.
963
-         *    @access public
964
-         */
965
-        function getField($selector) {
966
-            for ($i = 0; $i < count($this->_complete_forms); $i++) {
967
-                $value = $this->_complete_forms[$i]->getValue($selector);
968
-                if (isset($value)) {
969
-                    return $value;
970
-                }
971
-            }
972
-            return null;
973
-        }
974
-    }
332
+	 */
333
+	class SimplePage {
334
+		protected $_links;
335
+		protected $_title;
336
+		protected $_last_widget;
337
+		protected $_label;
338
+		protected $_left_over_labels;
339
+		protected $_open_forms;
340
+		protected $_complete_forms;
341
+		protected $_frameset;
342
+		protected $_frames;
343
+		protected $_frameset_nesting_level;
344
+		protected $_transport_error;
345
+		protected $_raw;
346
+		protected $_text;
347
+		protected $_sent;
348
+		protected $_headers;
349
+		protected $_method;
350
+		protected $_url;
351
+		protected $_request_data;
352
+
353
+		/**
354
+		 *    Parses a page ready to access it's contents.
355
+		 *    @param SimpleHttpResponse $response     Result of HTTP fetch.
356
+		 *    @access public
357
+		 */
358
+		function SimplePage($response = false) {
359
+			$this->_links = array();
360
+			$this->_title = false;
361
+			$this->_left_over_labels = array();
362
+			$this->_open_forms = array();
363
+			$this->_complete_forms = array();
364
+			$this->_frameset = false;
365
+			$this->_frames = array();
366
+			$this->_frameset_nesting_level = 0;
367
+			$this->_text = false;
368
+			if ($response) {
369
+				$this->_extractResponse($response);
370
+			} else {
371
+				$this->_noResponse();
372
+			}
373
+		}
374
+
375
+		/**
376
+		 *    Extracts all of the response information.
377
+		 *    @param SimpleHttpResponse $response    Response being parsed.
378
+		 *    @access private
379
+		 */
380
+		function _extractResponse($response) {
381
+			$this->_transport_error = $response->getError();
382
+			$this->_raw = $response->getContent();
383
+			$this->_sent = $response->getSent();
384
+			$this->_headers = $response->getHeaders();
385
+			$this->_method = $response->getMethod();
386
+			$this->_url = $response->getUrl();
387
+			$this->_request_data = $response->getRequestData();
388
+		}
389
+
390
+		/**
391
+		 *    Sets up a missing response.
392
+		 *    @access private
393
+		 */
394
+		function _noResponse() {
395
+			$this->_transport_error = 'No page fetched yet';
396
+			$this->_raw = false;
397
+			$this->_sent = false;
398
+			$this->_headers = false;
399
+			$this->_method = 'GET';
400
+			$this->_url = false;
401
+			$this->_request_data = false;
402
+		}
403
+
404
+		/**
405
+		 *    Original request as bytes sent down the wire.
406
+		 *    @return mixed              Sent content.
407
+		 *    @access public
408
+		 */
409
+		function getRequest() {
410
+			return $this->_sent;
411
+		}
412
+
413
+		/**
414
+		 *    Accessor for raw text of page.
415
+		 *    @return string        Raw unparsed content.
416
+		 *    @access public
417
+		 */
418
+		function getRaw() {
419
+			return $this->_raw;
420
+		}
421
+
422
+		/**
423
+		 *    Accessor for plain text of page as a text browser
424
+		 *    would see it.
425
+		 *    @return string        Plain text of page.
426
+		 *    @access public
427
+		 */
428
+		function getText() {
429
+			if (! $this->_text) {
430
+				$this->_text = SimpleHtmlSaxParser::normalise($this->_raw);
431
+			}
432
+			return $this->_text;
433
+		}
434
+
435
+		/**
436
+		 *    Accessor for raw headers of page.
437
+		 *    @return string       Header block as text.
438
+		 *    @access public
439
+		 */
440
+		function getHeaders() {
441
+			if ($this->_headers) {
442
+				return $this->_headers->getRaw();
443
+			}
444
+			return false;
445
+		}
446
+
447
+		/**
448
+		 *    Original request method.
449
+		 *    @return string        GET, POST or HEAD.
450
+		 *    @access public
451
+		 */
452
+		function getMethod() {
453
+			return $this->_method;
454
+		}
455
+
456
+		/**
457
+		 *    Original resource name.
458
+		 *    @return SimpleUrl        Current url.
459
+		 *    @access public
460
+		 */
461
+		function getUrl() {
462
+			return $this->_url;
463
+		}
464
+
465
+		/**
466
+		 *    Original request data.
467
+		 *    @return mixed              Sent content.
468
+		 *    @access public
469
+		 */
470
+		function getRequestData() {
471
+			return $this->_request_data;
472
+		}
473
+
474
+		/**
475
+		 *    Accessor for last error.
476
+		 *    @return string        Error from last response.
477
+		 *    @access public
478
+		 */
479
+		function getTransportError() {
480
+			return $this->_transport_error;
481
+		}
482
+
483
+		/**
484
+		 *    Accessor for current MIME type.
485
+		 *    @return string    MIME type as string; e.g. 'text/html'
486
+		 *    @access public
487
+		 */
488
+		function getMimeType() {
489
+			if ($this->_headers) {
490
+				return $this->_headers->getMimeType();
491
+			}
492
+			return false;
493
+		}
494
+
495
+		/**
496
+		 *    Accessor for HTTP response code.
497
+		 *    @return integer    HTTP response code received.
498
+		 *    @access public
499
+		 */
500
+		function getResponseCode() {
501
+			if ($this->_headers) {
502
+				return $this->_headers->getResponseCode();
503
+			}
504
+			return false;
505
+		}
506
+
507
+		/**
508
+		 *    Accessor for last Authentication type. Only valid
509
+		 *    straight after a challenge (401).
510
+		 *    @return string    Description of challenge type.
511
+		 *    @access public
512
+		 */
513
+		function getAuthentication() {
514
+			if ($this->_headers) {
515
+				return $this->_headers->getAuthentication();
516
+			}
517
+			return false;
518
+		}
519
+
520
+		/**
521
+		 *    Accessor for last Authentication realm. Only valid
522
+		 *    straight after a challenge (401).
523
+		 *    @return string    Name of security realm.
524
+		 *    @access public
525
+		 */
526
+		function getRealm() {
527
+			if ($this->_headers) {
528
+				return $this->_headers->getRealm();
529
+			}
530
+			return false;
531
+		}
532
+
533
+		/**
534
+		 *    Accessor for current frame focus. Will be
535
+		 *    false as no frames.
536
+		 *    @return array    Always empty.
537
+		 *    @access public
538
+		 */
539
+		function getFrameFocus() {
540
+			return array();
541
+		}
542
+
543
+		/**
544
+		 *    Sets the focus by index. The integer index starts from 1.
545
+		 *    @param integer $choice    Chosen frame.
546
+		 *    @return boolean           Always false.
547
+		 *    @access public
548
+		 */
549
+		function setFrameFocusByIndex($choice) {
550
+			return false;
551
+		}
552
+
553
+		/**
554
+		 *    Sets the focus by name. Always fails for a leaf page.
555
+		 *    @param string $name    Chosen frame.
556
+		 *    @return boolean        False as no frames.
557
+		 *    @access public
558
+		 */
559
+		function setFrameFocus($name) {
560
+			return false;
561
+		}
562
+
563
+		/**
564
+		 *    Clears the frame focus. Does nothing for a leaf page.
565
+		 *    @access public
566
+		 */
567
+		function clearFrameFocus() {
568
+		}
569
+
570
+		/**
571
+		 *    Adds a tag to the page.
572
+		 *    @param SimpleTag $tag        Tag to accept.
573
+		 *    @access public
574
+		 */
575
+		function acceptTag($tag) {
576
+			if ($tag->getTagName() == "a") {
577
+				$this->_addLink($tag);
578
+			} elseif ($tag->getTagName() == "title") {
579
+				$this->_setTitle($tag);
580
+			} elseif ($this->_isFormElement($tag->getTagName())) {
581
+				for ($i = 0; $i < count($this->_open_forms); $i++) {
582
+					$this->_open_forms[$i]->addWidget($tag);
583
+				}
584
+				$this->_last_widget = $tag;
585
+			}
586
+		}
587
+
588
+		/**
589
+		 *    Opens a label for a described widget.
590
+		 *    @param SimpleFormTag $tag      Tag to accept.
591
+		 *    @access public
592
+		 */
593
+		function acceptLabelStart($tag) {
594
+			$this->_label = $tag;
595
+			unset($this->_last_widget);
596
+		}
597
+
598
+		/**
599
+		 *    Closes the most recently opened label.
600
+		 *    @access public
601
+		 */
602
+		function acceptLabelEnd() {
603
+			if (isset($this->_label)) {
604
+				if (isset($this->_last_widget)) {
605
+					$this->_last_widget->setLabel($this->_label->getText());
606
+					unset($this->_last_widget);
607
+				} else {
608
+					$this->_left_over_labels[] = SimpleTestCompatibility::copy($this->_label);
609
+				}
610
+				unset($this->_label);
611
+			}
612
+		}
613
+
614
+		/**
615
+		 *    Tests to see if a tag is a possible form
616
+		 *    element.
617
+		 *    @param string $name     HTML element name.
618
+		 *    @return boolean         True if form element.
619
+		 *    @access private
620
+		 */
621
+		function _isFormElement($name) {
622
+			return in_array($name, array('input', 'button', 'textarea', 'select'));
623
+		}
624
+
625
+		/**
626
+		 *    Opens a form. New widgets go here.
627
+		 *    @param SimpleFormTag $tag      Tag to accept.
628
+		 *    @access public
629
+		 */
630
+		function acceptFormStart($tag) {
631
+			$this->_open_forms[] = new SimpleForm($tag, $this->getUrl());
632
+		}
633
+
634
+		/**
635
+		 *    Closes the most recently opened form.
636
+		 *    @access public
637
+		 */
638
+		function acceptFormEnd() {
639
+			if (count($this->_open_forms)) {
640
+				$this->_complete_forms[] = array_pop($this->_open_forms);
641
+			}
642
+		}
643
+
644
+		/**
645
+		 *    Opens a frameset. A frameset may contain nested
646
+		 *    frameset tags.
647
+		 *    @param SimpleFramesetTag $tag      Tag to accept.
648
+		 *    @access public
649
+		 */
650
+		function acceptFramesetStart($tag) {
651
+			if (! $this->_isLoadingFrames()) {
652
+				$this->_frameset = $tag;
653
+			}
654
+			$this->_frameset_nesting_level++;
655
+		}
656
+
657
+		/**
658
+		 *    Closes the most recently opened frameset.
659
+		 *    @access public
660
+		 */
661
+		function acceptFramesetEnd() {
662
+			if ($this->_isLoadingFrames()) {
663
+				$this->_frameset_nesting_level--;
664
+			}
665
+		}
666
+
667
+		/**
668
+		 *    Takes a single frame tag and stashes it in
669
+		 *    the current frame set.
670
+		 *    @param SimpleFrameTag $tag      Tag to accept.
671
+		 *    @access public
672
+		 */
673
+		function acceptFrame($tag) {
674
+			if ($this->_isLoadingFrames()) {
675
+				if ($tag->getAttribute('src')) {
676
+					$this->_frames[] = $tag;
677
+				}
678
+			}
679
+		}
680
+
681
+		/**
682
+		 *    Test to see if in the middle of reading
683
+		 *    a frameset.
684
+		 *    @return boolean        True if inframeset.
685
+		 *    @access private
686
+		 */
687
+		function _isLoadingFrames() {
688
+			if (! $this->_frameset) {
689
+				return false;
690
+			}
691
+			return ($this->_frameset_nesting_level > 0);
692
+		}
693
+
694
+		/**
695
+		 *    Test to see if link is an absolute one.
696
+		 *    @param string $url     Url to test.
697
+		 *    @return boolean        True if absolute.
698
+		 *    @access protected
699
+		 */
700
+		function _linkIsAbsolute($url) {
701
+			$parsed = new SimpleUrl($url);
702
+			return (boolean)($parsed->getScheme() && $parsed->getHost());
703
+		}
704
+
705
+		/**
706
+		 *    Adds a link to the page.
707
+		 *    @param SimpleAnchorTag $tag      Link to accept.
708
+		 *    @access protected
709
+		 */
710
+		function _addLink($tag) {
711
+			$this->_links[] = $tag;
712
+		}
713
+
714
+		/**
715
+		 *    Marker for end of complete page. Any work in
716
+		 *    progress can now be closed.
717
+		 *    @access public
718
+		 */
719
+		function acceptPageEnd() {
720
+			while (count($this->_open_forms)) {
721
+				$this->_complete_forms[] = array_pop($this->_open_forms);
722
+			}
723
+			foreach ($this->_left_over_labels as $label) {
724
+				for ($i = 0, $count = count($this->_complete_forms); $i < $count; $i++) {
725
+					$this->_complete_forms[$i]->attachLabelBySelector(
726
+							new SimpleById($label->getFor()),
727
+							$label->getText());
728
+				}
729
+			}
730
+		}
731
+
732
+		/**
733
+		 *    Test for the presence of a frameset.
734
+		 *    @return boolean        True if frameset.
735
+		 *    @access public
736
+		 */
737
+		function hasFrames() {
738
+			return (boolean)$this->_frameset;
739
+		}
740
+
741
+		/**
742
+		 *    Accessor for frame name and source URL for every frame that
743
+		 *    will need to be loaded. Immediate children only.
744
+		 *    @return boolean/array     False if no frameset or
745
+		 *                              otherwise a hash of frame URLs.
746
+		 *                              The key is either a numerical
747
+		 *                              base one index or the name attribute.
748
+		 *    @access public
749
+		 */
750
+		function getFrameset() {
751
+			if (! $this->_frameset) {
752
+				return false;
753
+			}
754
+			$urls = array();
755
+			for ($i = 0; $i < count($this->_frames); $i++) {
756
+				$name = $this->_frames[$i]->getAttribute('name');
757
+				$url = new SimpleUrl($this->_frames[$i]->getAttribute('src'));
758
+				$urls[$name ? $name : $i + 1] = $url->makeAbsolute($this->getUrl());
759
+			}
760
+			return $urls;
761
+		}
762
+
763
+		/**
764
+		 *    Fetches a list of loaded frames.
765
+		 *    @return array/string    Just the URL for a single page.
766
+		 *    @access public
767
+		 */
768
+		function getFrames() {
769
+			$url = $this->getUrl();
770
+			return $url->asString();
771
+		}
772
+
773
+		/**
774
+		 *    Accessor for a list of all fixed links.
775
+		 *    @return array   List of urls with scheme of
776
+		 *                    http or https and hostname.
777
+		 *    @access public
778
+		 */
779
+		function getAbsoluteUrls() {
780
+			$all = array();
781
+			foreach ($this->_links as $link) {
782
+				if ($this->_linkIsAbsolute($link->getHref())) {
783
+					$all[] = $link->getHref();
784
+				}
785
+			}
786
+			return $all;
787
+		}
788
+
789
+		/**
790
+		 *    Accessor for a list of all relative links.
791
+		 *    @return array      List of urls without hostname.
792
+		 *    @access public
793
+		 */
794
+		function getRelativeUrls() {
795
+			$all = array();
796
+			foreach ($this->_links as $link) {
797
+				if (! $this->_linkIsAbsolute($link->getHref())) {
798
+					$all[] = $link->getHref();
799
+				}
800
+			}
801
+			return $all;
802
+		}
803
+
804
+		/**
805
+		 *    Accessor for URLs by the link label. Label will match
806
+		 *    regardess of whitespace issues and case.
807
+		 *    @param string $label    Text of link.
808
+		 *    @return array           List of links with that label.
809
+		 *    @access public
810
+		 */
811
+		function getUrlsByLabel($label) {
812
+			$matches = array();
813
+			foreach ($this->_links as $link) {
814
+				if ($link->getText() == $label) {
815
+					$matches[] = $this->_getUrlFromLink($link);
816
+				}
817
+			}
818
+			return $matches;
819
+		}
820
+
821
+		/**
822
+		 *    Accessor for a URL by the id attribute.
823
+		 *    @param string $id       Id attribute of link.
824
+		 *    @return SimpleUrl       URL with that id of false if none.
825
+		 *    @access public
826
+		 */
827
+		function getUrlById($id) {
828
+			foreach ($this->_links as $link) {
829
+				if ($link->getAttribute('id') === (string)$id) {
830
+					return $this->_getUrlFromLink($link);
831
+				}
832
+			}
833
+			return false;
834
+		}
835
+
836
+		/**
837
+		 *    Converts a link into a target URL.
838
+		 *    @param SimpleAnchor $link    Parsed link.
839
+		 *    @return SimpleUrl            URL with frame target if any.
840
+		 *    @access private
841
+		 */
842
+		function _getUrlFromLink($link) {
843
+			$url = $this->_makeAbsolute($link->getHref());
844
+			if ($link->getAttribute('target')) {
845
+				$url->setTarget($link->getAttribute('target'));
846
+			}
847
+			return $url;
848
+		}
849
+
850
+		/**
851
+		 *    Expands expandomatic URLs into fully qualified
852
+		 *    URLs.
853
+		 *    @param SimpleUrl $url        Relative URL.
854
+		 *    @return SimpleUrl            Absolute URL.
855
+		 *    @access protected
856
+		 */
857
+		function _makeAbsolute($url) {
858
+			if (! is_object($url)) {
859
+				$url = new SimpleUrl($url);
860
+			}
861
+			return $url->makeAbsolute($this->getUrl());
862
+		}
863
+
864
+		/**
865
+		 *    Sets the title tag contents.
866
+		 *    @param SimpleTitleTag $tag    Title of page.
867
+		 *    @access protected
868
+		 */
869
+		function _setTitle($tag) {
870
+			$this->_title = $tag;
871
+		}
872
+
873
+		/**
874
+		 *    Accessor for parsed title.
875
+		 *    @return string     Title or false if no title is present.
876
+		 *    @access public
877
+		 */
878
+		function getTitle() {
879
+			if ($this->_title) {
880
+				return $this->_title->getText();
881
+			}
882
+			return false;
883
+		}
884
+
885
+		/**
886
+		 *    Finds a held form by button label. Will only
887
+		 *    search correctly built forms.
888
+		 *    @param SimpleSelector $selector       Button finder.
889
+		 *    @return SimpleForm                    Form object containing
890
+		 *                                          the button.
891
+		 *    @access public
892
+		 */
893
+		function &getFormBySubmit($selector) {
894
+			for ($i = 0; $i < count($this->_complete_forms); $i++) {
895
+				if ($this->_complete_forms[$i]->hasSubmit($selector)) {
896
+					return $this->_complete_forms[$i];
897
+				}
898
+			}
899
+			$null = null;
900
+			return $null;
901
+		}
902
+
903
+		/**
904
+		 *    Finds a held form by image using a selector.
905
+		 *    Will only search correctly built forms.
906
+		 *    @param SimpleSelector $selector  Image finder.
907
+		 *    @return SimpleForm               Form object containing
908
+		 *                                     the image.
909
+		 *    @access public
910
+		 */
911
+		function &getFormByImage($selector) {
912
+			for ($i = 0; $i < count($this->_complete_forms); $i++) {
913
+				if ($this->_complete_forms[$i]->hasImage($selector)) {
914
+					return $this->_complete_forms[$i];
915
+				}
916
+			}
917
+			$null = null;
918
+			return $null;
919
+		}
920
+
921
+		/**
922
+		 *    Finds a held form by the form ID. A way of
923
+		 *    identifying a specific form when we have control
924
+		 *    of the HTML code.
925
+		 *    @param string $id     Form label.
926
+		 *    @return SimpleForm    Form object containing the matching ID.
927
+		 *    @access public
928
+		 */
929
+		function &getFormById($id) {
930
+			for ($i = 0; $i < count($this->_complete_forms); $i++) {
931
+				if ($this->_complete_forms[$i]->getId() == $id) {
932
+					return $this->_complete_forms[$i];
933
+				}
934
+			}
935
+			$null = null;
936
+			return $null;
937
+		}
938
+
939
+		/**
940
+		 *    Sets a field on each form in which the field is
941
+		 *    available.
942
+		 *    @param SimpleSelector $selector    Field finder.
943
+		 *    @param string $value               Value to set field to.
944
+		 *    @return boolean                    True if value is valid.
945
+		 *    @access public
946
+		 */
947
+		function setField($selector, $value) {
948
+			$is_set = false;
949
+			for ($i = 0; $i < count($this->_complete_forms); $i++) {
950
+				if ($this->_complete_forms[$i]->setField($selector, $value)) {
951
+					$is_set = true;
952
+				}
953
+			}
954
+			return $is_set;
955
+		}
956
+
957
+		/**
958
+		 *    Accessor for a form element value within a page.
959
+		 *    @param SimpleSelector $selector    Field finder.
960
+		 *    @return string/boolean             A string if the field is
961
+		 *                                       present, false if unchecked
962
+		 *                                       and null if missing.
963
+		 *    @access public
964
+		 */
965
+		function getField($selector) {
966
+			for ($i = 0; $i < count($this->_complete_forms); $i++) {
967
+				$value = $this->_complete_forms[$i]->getValue($selector);
968
+				if (isset($value)) {
969
+					return $value;
970
+				}
971
+			}
972
+			return null;
973
+		}
974
+	}
Please login to merge, or discard this patch.
tests/test_tools/simpletest/detached.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -1,95 +1,95 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *	base include file for SimpleTest
4
-     *	@package	SimpleTest
5
-     *	@subpackage	UnitTester
6
-     *	@version	$Id: detached.php 1398 2006-09-08 19:31:03Z xue $
7
-     */
2
+	/**
3
+	 *	base include file for SimpleTest
4
+	 *	@package	SimpleTest
5
+	 *	@subpackage	UnitTester
6
+	 *	@version	$Id: detached.php 1398 2006-09-08 19:31:03Z xue $
7
+	 */
8 8
 
9
-    /**#@+
9
+	/**#@+
10 10
      *	include other SimpleTest class files
11 11
      */
12
-    require_once(dirname(__FILE__) . '/xml.php');
13
-    require_once(dirname(__FILE__) . '/shell_tester.php');
14
-    /**#@-*/
12
+	require_once(dirname(__FILE__) . '/xml.php');
13
+	require_once(dirname(__FILE__) . '/shell_tester.php');
14
+	/**#@-*/
15 15
 
16
-    /**
17
-     *    Runs an XML formated test in a separate process.
16
+	/**
17
+	 *    Runs an XML formated test in a separate process.
18 18
 	 *	  @package SimpleTest
19 19
 	 *	  @subpackage UnitTester
20
-     */
21
-    class DetachedTestCase {
22
-        protected $_command;
23
-        protected $_dry_command;
24
-        protected $_size;
20
+	 */
21
+	class DetachedTestCase {
22
+		protected $_command;
23
+		protected $_dry_command;
24
+		protected $_size;
25 25
 
26
-        /**
27
-         *    Sets the location of the remote test.
28
-         *    @param string $command       Test script.
29
-         *    @param string $dry_command   Script for dry run.
30
-         *    @access public
31
-         */
32
-        function DetachedTestCase($command, $dry_command = false) {
33
-            $this->_command = $command;
34
-            $this->_dry_command = $dry_command ? $dry_command : $command;
35
-            $this->_size = false;
36
-        }
26
+		/**
27
+		 *    Sets the location of the remote test.
28
+		 *    @param string $command       Test script.
29
+		 *    @param string $dry_command   Script for dry run.
30
+		 *    @access public
31
+		 */
32
+		function DetachedTestCase($command, $dry_command = false) {
33
+			$this->_command = $command;
34
+			$this->_dry_command = $dry_command ? $dry_command : $command;
35
+			$this->_size = false;
36
+		}
37 37
 
38
-        /**
39
-         *    Accessor for the test name for subclasses.
40
-         *    @return string       Name of the test.
41
-         *    @access public
42
-         */
43
-        function getLabel() {
44
-            return $this->_command;
45
-        }
38
+		/**
39
+		 *    Accessor for the test name for subclasses.
40
+		 *    @return string       Name of the test.
41
+		 *    @access public
42
+		 */
43
+		function getLabel() {
44
+			return $this->_command;
45
+		}
46 46
 
47
-        /**
48
-         *    Runs the top level test for this class. Currently
49
-         *    reads the data as a single chunk. I'll fix this
50
-         *    once I have added iteration to the browser.
51
-         *    @param SimpleReporter $reporter    Target of test results.
52
-         *    @returns boolean                   True if no failures.
53
-         *    @access public
54
-         */
55
-        function run($reporter) {
47
+		/**
48
+		 *    Runs the top level test for this class. Currently
49
+		 *    reads the data as a single chunk. I'll fix this
50
+		 *    once I have added iteration to the browser.
51
+		 *    @param SimpleReporter $reporter    Target of test results.
52
+		 *    @returns boolean                   True if no failures.
53
+		 *    @access public
54
+		 */
55
+		function run($reporter) {
56 56
 			$shell = new SimpleShell();
57 57
 			$shell->execute($this->_command);
58
-            $parser = $this->_createParser($reporter);
59
-            if (! $parser->parse($shell->getOutput())) {
60
-                trigger_error('Cannot parse incoming XML from [' . $this->_command . ']');
61
-                return false;
62
-            }
63
-            return true;
64
-        }
58
+			$parser = $this->_createParser($reporter);
59
+			if (! $parser->parse($shell->getOutput())) {
60
+				trigger_error('Cannot parse incoming XML from [' . $this->_command . ']');
61
+				return false;
62
+			}
63
+			return true;
64
+		}
65 65
 
66
-        /**
67
-         *    Accessor for the number of subtests.
68
-         *    @return integer       Number of test cases.
69
-         *    @access public
70
-         */
71
-        function getSize() {
72
-            if ($this->_size === false) {
66
+		/**
67
+		 *    Accessor for the number of subtests.
68
+		 *    @return integer       Number of test cases.
69
+		 *    @access public
70
+		 */
71
+		function getSize() {
72
+			if ($this->_size === false) {
73 73
 				$shell = new SimpleShell();
74 74
 				$shell->execute($this->_dry_command);
75
-                $reporter = new SimpleReporter();
76
-                $parser = $this->_createParser($reporter);
77
-                if (! $parser->parse($shell->getOutput())) {
78
-                    trigger_error('Cannot parse incoming XML from [' . $this->_dry_command . ']');
79
-                    return false;
80
-                }
81
-                $this->_size = $reporter->getTestCaseCount();
82
-            }
83
-            return $this->_size;
84
-        }
75
+				$reporter = new SimpleReporter();
76
+				$parser = $this->_createParser($reporter);
77
+				if (! $parser->parse($shell->getOutput())) {
78
+					trigger_error('Cannot parse incoming XML from [' . $this->_dry_command . ']');
79
+					return false;
80
+				}
81
+				$this->_size = $reporter->getTestCaseCount();
82
+			}
83
+			return $this->_size;
84
+		}
85 85
 
86
-        /**
87
-         *    Creates the XML parser.
88
-         *    @param SimpleReporter $reporter    Target of test results.
89
-         *    @return SimpleTestXmlListener      XML reader.
90
-         *    @access protected
91
-         */
92
-        function &_createParser($reporter) {
93
-            return new SimpleTestXmlParser($reporter);
94
-        }
95
-    }
96 86
\ No newline at end of file
87
+		/**
88
+		 *    Creates the XML parser.
89
+		 *    @param SimpleReporter $reporter    Target of test results.
90
+		 *    @return SimpleTestXmlListener      XML reader.
91
+		 *    @access protected
92
+		 */
93
+		function &_createParser($reporter) {
94
+			return new SimpleTestXmlParser($reporter);
95
+		}
96
+	}
97 97
\ No newline at end of file
Please login to merge, or discard this patch.
tests/test_tools/simpletest/scorer.php 1 patch
Indentation   +767 added lines, -767 removed lines patch added patch discarded remove patch
@@ -1,776 +1,776 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *	base include file for SimpleTest
4
-     *	@package	SimpleTest
5
-     *	@subpackage	UnitTester
6
-     *	@version	$Id: scorer.php 1532 2006-12-01 12:28:55Z xue $
7
-     */
8
-
9
-    /**#@+*/
10
-    require_once(dirname(__FILE__) . '/invoker.php');
11
-    /**#@-*/
12
-
13
-    /**
14
-     *    Can recieve test events and display them. Display
15
-     *    is achieved by making display methods available
16
-     *    and visiting the incoming event.
2
+	/**
3
+	 *	base include file for SimpleTest
4
+	 *	@package	SimpleTest
5
+	 *	@subpackage	UnitTester
6
+	 *	@version	$Id: scorer.php 1532 2006-12-01 12:28:55Z xue $
7
+	 */
8
+
9
+	/**#@+*/
10
+	require_once(dirname(__FILE__) . '/invoker.php');
11
+	/**#@-*/
12
+
13
+	/**
14
+	 *    Can recieve test events and display them. Display
15
+	 *    is achieved by making display methods available
16
+	 *    and visiting the incoming event.
17 17
 	 *	  @package SimpleTest
18 18
 	 *	  @subpackage UnitTester
19
-     *    @abstract
20
-     */
21
-    class SimpleScorer {
22
-        protected $_passes;
23
-        protected $_fails;
24
-        protected $_exceptions;
25
-        protected $_is_dry_run;
26
-
27
-        /**
28
-         *    Starts the test run with no results.
29
-         *    @access public
30
-         */
31
-        function SimpleScorer() {
32
-            $this->_passes = 0;
33
-            $this->_fails = 0;
34
-            $this->_exceptions = 0;
35
-            $this->_is_dry_run = false;
36
-        }
37
-
38
-        /**
39
-         *    Signals that the next evaluation will be a dry
40
-         *    run. That is, the structure events will be
41
-         *    recorded, but no tests will be run.
42
-         *    @param boolean $is_dry        Dry run if true.
43
-         *    @access public
44
-         */
45
-        function makeDry($is_dry = true) {
46
-            $this->_is_dry_run = $is_dry;
47
-        }
48
-
49
-        /**
50
-         *    The reporter has a veto on what should be run.
51
-         *    @param string $test_case_name  name of test case.
52
-         *    @param string $method          Name of test method.
53
-         *    @access public
54
-         */
55
-        function shouldInvoke($test_case_name, $method) {
56
-            return ! $this->_is_dry_run;
57
-        }
58
-
59
-        /**
60
-         *    Can wrap the invoker in preperation for running
61
-         *    a test.
62
-         *    @param SimpleInvoker $invoker   Individual test runner.
63
-         *    @return SimpleInvoker           Wrapped test runner.
64
-         *    @access public
65
-         */
66
-        function &createInvoker($invoker) {
67
-            return $invoker;
68
-        }
69
-
70
-        /**
71
-         *    Accessor for current status. Will be false
72
-         *    if there have been any failures or exceptions.
73
-         *    Used for command line tools.
74
-         *    @return boolean        True if no failures.
75
-         *    @access public
76
-         */
77
-        function getStatus() {
78
-            if ($this->_exceptions + $this->_fails > 0) {
79
-                return false;
80
-            }
81
-            return true;
82
-        }
83
-
84
-        /**
85
-         *    Paints the start of a group test.
86
-         *    @param string $test_name     Name of test or other label.
87
-         *    @param integer $size         Number of test cases starting.
88
-         *    @access public
89
-         */
90
-        function paintGroupStart($test_name, $size) {
91
-        }
92
-
93
-        /**
94
-         *    Paints the end of a group test.
95
-         *    @param string $test_name     Name of test or other label.
96
-         *    @access public
97
-         */
98
-        function paintGroupEnd($test_name) {
99
-        }
100
-
101
-        /**
102
-         *    Paints the start of a test case.
103
-         *    @param string $test_name     Name of test or other label.
104
-         *    @access public
105
-         */
106
-        function paintCaseStart($test_name) {
107
-        }
108
-
109
-        /**
110
-         *    Paints the end of a test case.
111
-         *    @param string $test_name     Name of test or other label.
112
-         *    @access public
113
-         */
114
-        function paintCaseEnd($test_name) {
115
-        }
116
-
117
-        /**
118
-         *    Paints the start of a test method.
119
-         *    @param string $test_name     Name of test or other label.
120
-         *    @access public
121
-         */
122
-        function paintMethodStart($test_name) {
123
-        }
124
-
125
-        /**
126
-         *    Paints the end of a test method.
127
-         *    @param string $test_name     Name of test or other label.
128
-         *    @access public
129
-         */
130
-        function paintMethodEnd($test_name) {
131
-        }
132
-
133
-        /**
134
-         *    Increments the pass count.
135
-         *    @param string $message        Message is ignored.
136
-         *    @access public
137
-         */
138
-        function paintPass($message) {
139
-            $this->_passes++;
140
-        }
141
-
142
-        /**
143
-         *    Increments the fail count.
144
-         *    @param string $message        Message is ignored.
145
-         *    @access public
146
-         */
147
-        function paintFail($message) {
148
-            $this->_fails++;
149
-        }
150
-
151
-        /**
152
-         *    Deals with PHP 4 throwing an error or PHP 5
153
-         *    throwing an exception.
154
-         *    @param string $message    Text of error formatted by
155
-         *                              the test case.
156
-         *    @access public
157
-         */
158
-        function paintError($message) {
159
-            $this->_exceptions++;
160
-        }
161
-
162
-        /**
163
-         *    Accessor for the number of passes so far.
164
-         *    @return integer       Number of passes.
165
-         *    @access public
166
-         */
167
-        function getPassCount() {
168
-            return $this->_passes;
169
-        }
170
-
171
-        /**
172
-         *    Accessor for the number of fails so far.
173
-         *    @return integer       Number of fails.
174
-         *    @access public
175
-         */
176
-        function getFailCount() {
177
-            return $this->_fails;
178
-        }
179
-
180
-        /**
181
-         *    Accessor for the number of untrapped errors
182
-         *    so far.
183
-         *    @return integer       Number of exceptions.
184
-         *    @access public
185
-         */
186
-        function getExceptionCount() {
187
-            return $this->_exceptions;
188
-        }
189
-
190
-        /**
191
-         *    Paints a simple supplementary message.
192
-         *    @param string $message        Text to display.
193
-         *    @access public
194
-         */
195
-        function paintMessage($message) {
196
-        }
197
-
198
-        /**
199
-         *    Paints a formatted ASCII message such as a
200
-         *    variable dump.
201
-         *    @param string $message        Text to display.
202
-         *    @access public
203
-         */
204
-        function paintFormattedMessage($message) {
205
-        }
206
-
207
-        /**
208
-         *    By default just ignores user generated events.
209
-         *    @param string $type        Event type as text.
210
-         *    @param mixed $payload      Message or object.
211
-         *    @access public
212
-         */
213
-        function paintSignal($type, $payload) {
214
-        }
215
-    }
216
-
217
-    /**
218
-     *    Recipient of generated test messages that can display
219
-     *    page footers and headers. Also keeps track of the
220
-     *    test nesting. This is the main base class on which
221
-     *    to build the finished test (page based) displays.
19
+	 *    @abstract
20
+	 */
21
+	class SimpleScorer {
22
+		protected $_passes;
23
+		protected $_fails;
24
+		protected $_exceptions;
25
+		protected $_is_dry_run;
26
+
27
+		/**
28
+		 *    Starts the test run with no results.
29
+		 *    @access public
30
+		 */
31
+		function SimpleScorer() {
32
+			$this->_passes = 0;
33
+			$this->_fails = 0;
34
+			$this->_exceptions = 0;
35
+			$this->_is_dry_run = false;
36
+		}
37
+
38
+		/**
39
+		 *    Signals that the next evaluation will be a dry
40
+		 *    run. That is, the structure events will be
41
+		 *    recorded, but no tests will be run.
42
+		 *    @param boolean $is_dry        Dry run if true.
43
+		 *    @access public
44
+		 */
45
+		function makeDry($is_dry = true) {
46
+			$this->_is_dry_run = $is_dry;
47
+		}
48
+
49
+		/**
50
+		 *    The reporter has a veto on what should be run.
51
+		 *    @param string $test_case_name  name of test case.
52
+		 *    @param string $method          Name of test method.
53
+		 *    @access public
54
+		 */
55
+		function shouldInvoke($test_case_name, $method) {
56
+			return ! $this->_is_dry_run;
57
+		}
58
+
59
+		/**
60
+		 *    Can wrap the invoker in preperation for running
61
+		 *    a test.
62
+		 *    @param SimpleInvoker $invoker   Individual test runner.
63
+		 *    @return SimpleInvoker           Wrapped test runner.
64
+		 *    @access public
65
+		 */
66
+		function &createInvoker($invoker) {
67
+			return $invoker;
68
+		}
69
+
70
+		/**
71
+		 *    Accessor for current status. Will be false
72
+		 *    if there have been any failures or exceptions.
73
+		 *    Used for command line tools.
74
+		 *    @return boolean        True if no failures.
75
+		 *    @access public
76
+		 */
77
+		function getStatus() {
78
+			if ($this->_exceptions + $this->_fails > 0) {
79
+				return false;
80
+			}
81
+			return true;
82
+		}
83
+
84
+		/**
85
+		 *    Paints the start of a group test.
86
+		 *    @param string $test_name     Name of test or other label.
87
+		 *    @param integer $size         Number of test cases starting.
88
+		 *    @access public
89
+		 */
90
+		function paintGroupStart($test_name, $size) {
91
+		}
92
+
93
+		/**
94
+		 *    Paints the end of a group test.
95
+		 *    @param string $test_name     Name of test or other label.
96
+		 *    @access public
97
+		 */
98
+		function paintGroupEnd($test_name) {
99
+		}
100
+
101
+		/**
102
+		 *    Paints the start of a test case.
103
+		 *    @param string $test_name     Name of test or other label.
104
+		 *    @access public
105
+		 */
106
+		function paintCaseStart($test_name) {
107
+		}
108
+
109
+		/**
110
+		 *    Paints the end of a test case.
111
+		 *    @param string $test_name     Name of test or other label.
112
+		 *    @access public
113
+		 */
114
+		function paintCaseEnd($test_name) {
115
+		}
116
+
117
+		/**
118
+		 *    Paints the start of a test method.
119
+		 *    @param string $test_name     Name of test or other label.
120
+		 *    @access public
121
+		 */
122
+		function paintMethodStart($test_name) {
123
+		}
124
+
125
+		/**
126
+		 *    Paints the end of a test method.
127
+		 *    @param string $test_name     Name of test or other label.
128
+		 *    @access public
129
+		 */
130
+		function paintMethodEnd($test_name) {
131
+		}
132
+
133
+		/**
134
+		 *    Increments the pass count.
135
+		 *    @param string $message        Message is ignored.
136
+		 *    @access public
137
+		 */
138
+		function paintPass($message) {
139
+			$this->_passes++;
140
+		}
141
+
142
+		/**
143
+		 *    Increments the fail count.
144
+		 *    @param string $message        Message is ignored.
145
+		 *    @access public
146
+		 */
147
+		function paintFail($message) {
148
+			$this->_fails++;
149
+		}
150
+
151
+		/**
152
+		 *    Deals with PHP 4 throwing an error or PHP 5
153
+		 *    throwing an exception.
154
+		 *    @param string $message    Text of error formatted by
155
+		 *                              the test case.
156
+		 *    @access public
157
+		 */
158
+		function paintError($message) {
159
+			$this->_exceptions++;
160
+		}
161
+
162
+		/**
163
+		 *    Accessor for the number of passes so far.
164
+		 *    @return integer       Number of passes.
165
+		 *    @access public
166
+		 */
167
+		function getPassCount() {
168
+			return $this->_passes;
169
+		}
170
+
171
+		/**
172
+		 *    Accessor for the number of fails so far.
173
+		 *    @return integer       Number of fails.
174
+		 *    @access public
175
+		 */
176
+		function getFailCount() {
177
+			return $this->_fails;
178
+		}
179
+
180
+		/**
181
+		 *    Accessor for the number of untrapped errors
182
+		 *    so far.
183
+		 *    @return integer       Number of exceptions.
184
+		 *    @access public
185
+		 */
186
+		function getExceptionCount() {
187
+			return $this->_exceptions;
188
+		}
189
+
190
+		/**
191
+		 *    Paints a simple supplementary message.
192
+		 *    @param string $message        Text to display.
193
+		 *    @access public
194
+		 */
195
+		function paintMessage($message) {
196
+		}
197
+
198
+		/**
199
+		 *    Paints a formatted ASCII message such as a
200
+		 *    variable dump.
201
+		 *    @param string $message        Text to display.
202
+		 *    @access public
203
+		 */
204
+		function paintFormattedMessage($message) {
205
+		}
206
+
207
+		/**
208
+		 *    By default just ignores user generated events.
209
+		 *    @param string $type        Event type as text.
210
+		 *    @param mixed $payload      Message or object.
211
+		 *    @access public
212
+		 */
213
+		function paintSignal($type, $payload) {
214
+		}
215
+	}
216
+
217
+	/**
218
+	 *    Recipient of generated test messages that can display
219
+	 *    page footers and headers. Also keeps track of the
220
+	 *    test nesting. This is the main base class on which
221
+	 *    to build the finished test (page based) displays.
222 222
 	 *	  @package SimpleTest
223 223
 	 *	  @subpackage UnitTester
224
-     */
225
-    class SimpleReporter extends SimpleScorer {
226
-        protected $_test_stack;
227
-        protected $_size;
228
-        protected $_progress;
229
-
230
-        /**
231
-         *    Starts the display with no results in.
232
-         *    @access public
233
-         */
234
-        function SimpleReporter() {
235
-            $this->SimpleScorer();
236
-            $this->_test_stack = array();
237
-            $this->_size = null;
238
-            $this->_progress = 0;
239
-        }
240
-
241
-        /**
242
-         *    Paints the start of a group test. Will also paint
243
-         *    the page header and footer if this is the
244
-         *    first test. Will stash the size if the first
245
-         *    start.
246
-         *    @param string $test_name   Name of test that is starting.
247
-         *    @param integer $size       Number of test cases starting.
248
-         *    @access public
249
-         */
250
-        function paintGroupStart($test_name, $size) {
251
-            if (! isset($this->_size)) {
252
-                $this->_size = $size;
253
-            }
254
-            if (count($this->_test_stack) == 0) {
255
-                $this->paintHeader($test_name);
256
-            }
257
-            $this->_test_stack[] = $test_name;
258
-        }
259
-
260
-        /**
261
-         *    Paints the end of a group test. Will paint the page
262
-         *    footer if the stack of tests has unwound.
263
-         *    @param string $test_name   Name of test that is ending.
264
-         *    @param integer $progress   Number of test cases ending.
265
-         *    @access public
266
-         */
267
-        function paintGroupEnd($test_name) {
268
-            array_pop($this->_test_stack);
269
-            if (count($this->_test_stack) == 0) {
270
-                $this->paintFooter($test_name);
271
-            }
272
-        }
273
-
274
-        /**
275
-         *    Paints the start of a test case. Will also paint
276
-         *    the page header and footer if this is the
277
-         *    first test. Will stash the size if the first
278
-         *    start.
279
-         *    @param string $test_name   Name of test that is starting.
280
-         *    @access public
281
-         */
282
-        function paintCaseStart($test_name) {
283
-            if (! isset($this->_size)) {
284
-                $this->_size = 1;
285
-            }
286
-            if (count($this->_test_stack) == 0) {
287
-                $this->paintHeader($test_name);
288
-            }
289
-            $this->_test_stack[] = $test_name;
290
-        }
291
-
292
-        /**
293
-         *    Paints the end of a test case. Will paint the page
294
-         *    footer if the stack of tests has unwound.
295
-         *    @param string $test_name   Name of test that is ending.
296
-         *    @access public
297
-         */
298
-        function paintCaseEnd($test_name) {
299
-            $this->_progress++;
300
-            array_pop($this->_test_stack);
301
-            if (count($this->_test_stack) == 0) {
302
-                $this->paintFooter($test_name);
303
-            }
304
-        }
305
-
306
-        /**
307
-         *    Paints the start of a test method.
308
-         *    @param string $test_name   Name of test that is starting.
309
-         *    @access public
310
-         */
311
-        function paintMethodStart($test_name) {
312
-            $this->_test_stack[] = $test_name;
313
-        }
314
-
315
-        /**
316
-         *    Paints the end of a test method. Will paint the page
317
-         *    footer if the stack of tests has unwound.
318
-         *    @param string $test_name   Name of test that is ending.
319
-         *    @access public
320
-         */
321
-        function paintMethodEnd($test_name) {
322
-            array_pop($this->_test_stack);
323
-        }
324
-
325
-        /**
326
-         *    Paints the test document header.
327
-         *    @param string $test_name     First test top level
328
-         *                                 to start.
329
-         *    @access public
330
-         *    @abstract
331
-         */
332
-        function paintHeader($test_name) {
333
-        }
334
-
335
-        /**
336
-         *    Paints the test document footer.
337
-         *    @param string $test_name        The top level test.
338
-         *    @access public
339
-         *    @abstract
340
-         */
341
-        function paintFooter($test_name) {
342
-        }
343
-
344
-        /**
345
-         *    Accessor for internal test stack. For
346
-         *    subclasses that need to see the whole test
347
-         *    history for display purposes.
348
-         *    @return array     List of methods in nesting order.
349
-         *    @access public
350
-         */
351
-        function getTestList() {
352
-            return $this->_test_stack;
353
-        }
354
-
355
-        /**
356
-         *    Accessor for total test size in number
357
-         *    of test cases. Null until the first
358
-         *    test is started.
359
-         *    @return integer   Total number of cases at start.
360
-         *    @access public
361
-         */
362
-        function getTestCaseCount() {
363
-            return $this->_size;
364
-        }
365
-
366
-        /**
367
-         *    Accessor for the number of test cases
368
-         *    completed so far.
369
-         *    @return integer   Number of ended cases.
370
-         *    @access public
371
-         */
372
-        function getTestCaseProgress() {
373
-            return $this->_progress;
374
-        }
375
-
376
-        /**
377
-         *    Static check for running in the comand line.
378
-         *    @return boolean        True if CLI.
379
-         *    @access public
380
-         *    @static
381
-         */
382
-        static function inCli() {
383
-            return php_sapi_name() == 'cli';
384
-        }
385
-    }
386
-
387
-    /**
388
-     *    For modifying the behaviour of the visual reporters.
224
+	 */
225
+	class SimpleReporter extends SimpleScorer {
226
+		protected $_test_stack;
227
+		protected $_size;
228
+		protected $_progress;
229
+
230
+		/**
231
+		 *    Starts the display with no results in.
232
+		 *    @access public
233
+		 */
234
+		function SimpleReporter() {
235
+			$this->SimpleScorer();
236
+			$this->_test_stack = array();
237
+			$this->_size = null;
238
+			$this->_progress = 0;
239
+		}
240
+
241
+		/**
242
+		 *    Paints the start of a group test. Will also paint
243
+		 *    the page header and footer if this is the
244
+		 *    first test. Will stash the size if the first
245
+		 *    start.
246
+		 *    @param string $test_name   Name of test that is starting.
247
+		 *    @param integer $size       Number of test cases starting.
248
+		 *    @access public
249
+		 */
250
+		function paintGroupStart($test_name, $size) {
251
+			if (! isset($this->_size)) {
252
+				$this->_size = $size;
253
+			}
254
+			if (count($this->_test_stack) == 0) {
255
+				$this->paintHeader($test_name);
256
+			}
257
+			$this->_test_stack[] = $test_name;
258
+		}
259
+
260
+		/**
261
+		 *    Paints the end of a group test. Will paint the page
262
+		 *    footer if the stack of tests has unwound.
263
+		 *    @param string $test_name   Name of test that is ending.
264
+		 *    @param integer $progress   Number of test cases ending.
265
+		 *    @access public
266
+		 */
267
+		function paintGroupEnd($test_name) {
268
+			array_pop($this->_test_stack);
269
+			if (count($this->_test_stack) == 0) {
270
+				$this->paintFooter($test_name);
271
+			}
272
+		}
273
+
274
+		/**
275
+		 *    Paints the start of a test case. Will also paint
276
+		 *    the page header and footer if this is the
277
+		 *    first test. Will stash the size if the first
278
+		 *    start.
279
+		 *    @param string $test_name   Name of test that is starting.
280
+		 *    @access public
281
+		 */
282
+		function paintCaseStart($test_name) {
283
+			if (! isset($this->_size)) {
284
+				$this->_size = 1;
285
+			}
286
+			if (count($this->_test_stack) == 0) {
287
+				$this->paintHeader($test_name);
288
+			}
289
+			$this->_test_stack[] = $test_name;
290
+		}
291
+
292
+		/**
293
+		 *    Paints the end of a test case. Will paint the page
294
+		 *    footer if the stack of tests has unwound.
295
+		 *    @param string $test_name   Name of test that is ending.
296
+		 *    @access public
297
+		 */
298
+		function paintCaseEnd($test_name) {
299
+			$this->_progress++;
300
+			array_pop($this->_test_stack);
301
+			if (count($this->_test_stack) == 0) {
302
+				$this->paintFooter($test_name);
303
+			}
304
+		}
305
+
306
+		/**
307
+		 *    Paints the start of a test method.
308
+		 *    @param string $test_name   Name of test that is starting.
309
+		 *    @access public
310
+		 */
311
+		function paintMethodStart($test_name) {
312
+			$this->_test_stack[] = $test_name;
313
+		}
314
+
315
+		/**
316
+		 *    Paints the end of a test method. Will paint the page
317
+		 *    footer if the stack of tests has unwound.
318
+		 *    @param string $test_name   Name of test that is ending.
319
+		 *    @access public
320
+		 */
321
+		function paintMethodEnd($test_name) {
322
+			array_pop($this->_test_stack);
323
+		}
324
+
325
+		/**
326
+		 *    Paints the test document header.
327
+		 *    @param string $test_name     First test top level
328
+		 *                                 to start.
329
+		 *    @access public
330
+		 *    @abstract
331
+		 */
332
+		function paintHeader($test_name) {
333
+		}
334
+
335
+		/**
336
+		 *    Paints the test document footer.
337
+		 *    @param string $test_name        The top level test.
338
+		 *    @access public
339
+		 *    @abstract
340
+		 */
341
+		function paintFooter($test_name) {
342
+		}
343
+
344
+		/**
345
+		 *    Accessor for internal test stack. For
346
+		 *    subclasses that need to see the whole test
347
+		 *    history for display purposes.
348
+		 *    @return array     List of methods in nesting order.
349
+		 *    @access public
350
+		 */
351
+		function getTestList() {
352
+			return $this->_test_stack;
353
+		}
354
+
355
+		/**
356
+		 *    Accessor for total test size in number
357
+		 *    of test cases. Null until the first
358
+		 *    test is started.
359
+		 *    @return integer   Total number of cases at start.
360
+		 *    @access public
361
+		 */
362
+		function getTestCaseCount() {
363
+			return $this->_size;
364
+		}
365
+
366
+		/**
367
+		 *    Accessor for the number of test cases
368
+		 *    completed so far.
369
+		 *    @return integer   Number of ended cases.
370
+		 *    @access public
371
+		 */
372
+		function getTestCaseProgress() {
373
+			return $this->_progress;
374
+		}
375
+
376
+		/**
377
+		 *    Static check for running in the comand line.
378
+		 *    @return boolean        True if CLI.
379
+		 *    @access public
380
+		 *    @static
381
+		 */
382
+		static function inCli() {
383
+			return php_sapi_name() == 'cli';
384
+		}
385
+	}
386
+
387
+	/**
388
+	 *    For modifying the behaviour of the visual reporters.
389 389
 	 *	  @package SimpleTest
390 390
 	 *	  @subpackage UnitTester
391
-     */
392
-    class SimpleReporterDecorator {
393
-        protected $_reporter;
394
-
395
-        /**
396
-         *    Mediates between teh reporter and the test case.
397
-         *    @param SimpleScorer $reporter       Reporter to receive events.
398
-         */
399
-        function SimpleReporterDecorator($reporter) {
400
-            $this->_reporter = $reporter;
401
-        }
402
-
403
-        /**
404
-         *    Signals that the next evaluation will be a dry
405
-         *    run. That is, the structure events will be
406
-         *    recorded, but no tests will be run.
407
-         *    @param boolean $is_dry        Dry run if true.
408
-         *    @access public
409
-         */
410
-        function makeDry($is_dry = true) {
411
-            $this->_reporter->makeDry($is_dry);
412
-        }
413
-
414
-        /**
415
-         *    Accessor for current status. Will be false
416
-         *    if there have been any failures or exceptions.
417
-         *    Used for command line tools.
418
-         *    @return boolean        True if no failures.
419
-         *    @access public
420
-         */
421
-        function getStatus() {
422
-            return $this->_reporter->getStatus();
423
-        }
424
-
425
-        /**
426
-         *    The reporter has a veto on what should be run.
427
-         *    @param string $test_case_name  name of test case.
428
-         *    @param string $method          Name of test method.
429
-         *    @return boolean                True if test should be run.
430
-         *    @access public
431
-         */
432
-        function shouldInvoke($test_case_name, $method) {
433
-            return $this->_reporter->shouldInvoke($test_case_name, $method);
434
-        }
435
-
436
-        /**
437
-         *    Can wrap the invoker in preperation for running
438
-         *    a test.
439
-         *    @param SimpleInvoker $invoker   Individual test runner.
440
-         *    @return SimpleInvoker           Wrapped test runner.
441
-         *    @access public
442
-         */
443
-        function &createInvoker($invoker) {
444
-            return $this->_reporter->createInvoker($invoker);
445
-        }
446
-
447
-        /**
448
-         *    Paints the start of a group test.
449
-         *    @param string $test_name     Name of test or other label.
450
-         *    @param integer $size         Number of test cases starting.
451
-         *    @access public
452
-         */
453
-        function paintGroupStart($test_name, $size) {
454
-            $this->_reporter->paintGroupStart($test_name, $size);
455
-        }
456
-
457
-        /**
458
-         *    Paints the end of a group test.
459
-         *    @param string $test_name     Name of test or other label.
460
-         *    @access public
461
-         */
462
-        function paintGroupEnd($test_name) {
463
-            $this->_reporter->paintGroupEnd($test_name);
464
-        }
465
-
466
-        /**
467
-         *    Paints the start of a test case.
468
-         *    @param string $test_name     Name of test or other label.
469
-         *    @access public
470
-         */
471
-        function paintCaseStart($test_name) {
472
-            $this->_reporter->paintCaseStart($test_name);
473
-        }
474
-
475
-        /**
476
-         *    Paints the end of a test case.
477
-         *    @param string $test_name     Name of test or other label.
478
-         *    @access public
479
-         */
480
-        function paintCaseEnd($test_name) {
481
-            $this->_reporter->paintCaseEnd($test_name);
482
-        }
483
-
484
-        /**
485
-         *    Paints the start of a test method.
486
-         *    @param string $test_name     Name of test or other label.
487
-         *    @access public
488
-         */
489
-        function paintMethodStart($test_name) {
490
-            $this->_reporter->paintMethodStart($test_name);
491
-        }
492
-
493
-        /**
494
-         *    Paints the end of a test method.
495
-         *    @param string $test_name     Name of test or other label.
496
-         *    @access public
497
-         */
498
-        function paintMethodEnd($test_name) {
499
-            $this->_reporter->paintMethodEnd($test_name);
500
-        }
501
-
502
-        /**
503
-         *    Chains to the wrapped reporter.
504
-         *    @param string $message        Message is ignored.
505
-         *    @access public
506
-         */
507
-        function paintPass($message) {
508
-            $this->_reporter->paintPass($message);
509
-        }
510
-
511
-        /**
512
-         *    Chains to the wrapped reporter.
513
-         *    @param string $message        Message is ignored.
514
-         *    @access public
515
-         */
516
-        function paintFail($message) {
517
-            $this->_reporter->paintFail($message);
518
-        }
519
-
520
-        /**
521
-         *    Chains to the wrapped reporter.
522
-         *    @param string $message    Text of error formatted by
523
-         *                              the test case.
524
-         *    @access public
525
-         */
526
-        function paintError($message) {
527
-            $this->_reporter->paintError($message);
528
-        }
529
-
530
-        /**
531
-         *    Chains to the wrapped reporter.
532
-         *    @param string $message        Text to display.
533
-         *    @access public
534
-         */
535
-        function paintMessage($message) {
536
-            $this->_reporter->paintMessage($message);
537
-        }
538
-
539
-        /**
540
-         *    Chains to the wrapped reporter.
541
-         *    @param string $message        Text to display.
542
-         *    @access public
543
-         */
544
-        function paintFormattedMessage($message) {
545
-            $this->_reporter->paintFormattedMessage($message);
546
-        }
547
-
548
-        /**
549
-         *    Chains to the wrapped reporter.
550
-         *    @param string $type        Event type as text.
551
-         *    @param mixed $payload      Message or object.
552
-         *    @return boolean            Should return false if this
553
-         *                               type of signal should fail the
554
-         *                               test suite.
555
-         *    @access public
556
-         */
557
-        function paintSignal($type, $payload) {
558
-            $this->_reporter->paintSignal($type, $payload);
559
-        }
560
-    }
561
-
562
-    /**
563
-     *    For sending messages to multiple reporters at
564
-     *    the same time.
391
+	 */
392
+	class SimpleReporterDecorator {
393
+		protected $_reporter;
394
+
395
+		/**
396
+		 *    Mediates between teh reporter and the test case.
397
+		 *    @param SimpleScorer $reporter       Reporter to receive events.
398
+		 */
399
+		function SimpleReporterDecorator($reporter) {
400
+			$this->_reporter = $reporter;
401
+		}
402
+
403
+		/**
404
+		 *    Signals that the next evaluation will be a dry
405
+		 *    run. That is, the structure events will be
406
+		 *    recorded, but no tests will be run.
407
+		 *    @param boolean $is_dry        Dry run if true.
408
+		 *    @access public
409
+		 */
410
+		function makeDry($is_dry = true) {
411
+			$this->_reporter->makeDry($is_dry);
412
+		}
413
+
414
+		/**
415
+		 *    Accessor for current status. Will be false
416
+		 *    if there have been any failures or exceptions.
417
+		 *    Used for command line tools.
418
+		 *    @return boolean        True if no failures.
419
+		 *    @access public
420
+		 */
421
+		function getStatus() {
422
+			return $this->_reporter->getStatus();
423
+		}
424
+
425
+		/**
426
+		 *    The reporter has a veto on what should be run.
427
+		 *    @param string $test_case_name  name of test case.
428
+		 *    @param string $method          Name of test method.
429
+		 *    @return boolean                True if test should be run.
430
+		 *    @access public
431
+		 */
432
+		function shouldInvoke($test_case_name, $method) {
433
+			return $this->_reporter->shouldInvoke($test_case_name, $method);
434
+		}
435
+
436
+		/**
437
+		 *    Can wrap the invoker in preperation for running
438
+		 *    a test.
439
+		 *    @param SimpleInvoker $invoker   Individual test runner.
440
+		 *    @return SimpleInvoker           Wrapped test runner.
441
+		 *    @access public
442
+		 */
443
+		function &createInvoker($invoker) {
444
+			return $this->_reporter->createInvoker($invoker);
445
+		}
446
+
447
+		/**
448
+		 *    Paints the start of a group test.
449
+		 *    @param string $test_name     Name of test or other label.
450
+		 *    @param integer $size         Number of test cases starting.
451
+		 *    @access public
452
+		 */
453
+		function paintGroupStart($test_name, $size) {
454
+			$this->_reporter->paintGroupStart($test_name, $size);
455
+		}
456
+
457
+		/**
458
+		 *    Paints the end of a group test.
459
+		 *    @param string $test_name     Name of test or other label.
460
+		 *    @access public
461
+		 */
462
+		function paintGroupEnd($test_name) {
463
+			$this->_reporter->paintGroupEnd($test_name);
464
+		}
465
+
466
+		/**
467
+		 *    Paints the start of a test case.
468
+		 *    @param string $test_name     Name of test or other label.
469
+		 *    @access public
470
+		 */
471
+		function paintCaseStart($test_name) {
472
+			$this->_reporter->paintCaseStart($test_name);
473
+		}
474
+
475
+		/**
476
+		 *    Paints the end of a test case.
477
+		 *    @param string $test_name     Name of test or other label.
478
+		 *    @access public
479
+		 */
480
+		function paintCaseEnd($test_name) {
481
+			$this->_reporter->paintCaseEnd($test_name);
482
+		}
483
+
484
+		/**
485
+		 *    Paints the start of a test method.
486
+		 *    @param string $test_name     Name of test or other label.
487
+		 *    @access public
488
+		 */
489
+		function paintMethodStart($test_name) {
490
+			$this->_reporter->paintMethodStart($test_name);
491
+		}
492
+
493
+		/**
494
+		 *    Paints the end of a test method.
495
+		 *    @param string $test_name     Name of test or other label.
496
+		 *    @access public
497
+		 */
498
+		function paintMethodEnd($test_name) {
499
+			$this->_reporter->paintMethodEnd($test_name);
500
+		}
501
+
502
+		/**
503
+		 *    Chains to the wrapped reporter.
504
+		 *    @param string $message        Message is ignored.
505
+		 *    @access public
506
+		 */
507
+		function paintPass($message) {
508
+			$this->_reporter->paintPass($message);
509
+		}
510
+
511
+		/**
512
+		 *    Chains to the wrapped reporter.
513
+		 *    @param string $message        Message is ignored.
514
+		 *    @access public
515
+		 */
516
+		function paintFail($message) {
517
+			$this->_reporter->paintFail($message);
518
+		}
519
+
520
+		/**
521
+		 *    Chains to the wrapped reporter.
522
+		 *    @param string $message    Text of error formatted by
523
+		 *                              the test case.
524
+		 *    @access public
525
+		 */
526
+		function paintError($message) {
527
+			$this->_reporter->paintError($message);
528
+		}
529
+
530
+		/**
531
+		 *    Chains to the wrapped reporter.
532
+		 *    @param string $message        Text to display.
533
+		 *    @access public
534
+		 */
535
+		function paintMessage($message) {
536
+			$this->_reporter->paintMessage($message);
537
+		}
538
+
539
+		/**
540
+		 *    Chains to the wrapped reporter.
541
+		 *    @param string $message        Text to display.
542
+		 *    @access public
543
+		 */
544
+		function paintFormattedMessage($message) {
545
+			$this->_reporter->paintFormattedMessage($message);
546
+		}
547
+
548
+		/**
549
+		 *    Chains to the wrapped reporter.
550
+		 *    @param string $type        Event type as text.
551
+		 *    @param mixed $payload      Message or object.
552
+		 *    @return boolean            Should return false if this
553
+		 *                               type of signal should fail the
554
+		 *                               test suite.
555
+		 *    @access public
556
+		 */
557
+		function paintSignal($type, $payload) {
558
+			$this->_reporter->paintSignal($type, $payload);
559
+		}
560
+	}
561
+
562
+	/**
563
+	 *    For sending messages to multiple reporters at
564
+	 *    the same time.
565 565
 	 *	  @package SimpleTest
566 566
 	 *	  @subpackage UnitTester
567
-     */
568
-    class MultipleReporter {
569
-        protected $_reporters = array();
570
-
571
-        /**
572
-         *    Adds a reporter to the subscriber list.
573
-         *    @param SimpleScorer $reporter     Reporter to receive events.
574
-         *    @access public
575
-         */
576
-        function attachReporter($reporter) {
577
-            $this->_reporters[] = $reporter;
578
-        }
579
-
580
-        /**
581
-         *    Signals that the next evaluation will be a dry
582
-         *    run. That is, the structure events will be
583
-         *    recorded, but no tests will be run.
584
-         *    @param boolean $is_dry        Dry run if true.
585
-         *    @access public
586
-         */
587
-        function makeDry($is_dry = true) {
588
-            for ($i = 0; $i < count($this->_reporters); $i++) {
589
-                $this->_reporters[$i]->makeDry($is_dry);
590
-            }
591
-        }
592
-
593
-        /**
594
-         *    Accessor for current status. Will be false
595
-         *    if there have been any failures or exceptions.
596
-         *    If any reporter reports a failure, the whole
597
-         *    suite fails.
598
-         *    @return boolean        True if no failures.
599
-         *    @access public
600
-         */
601
-        function getStatus() {
602
-            for ($i = 0; $i < count($this->_reporters); $i++) {
603
-                if (! $this->_reporters[$i]->getStatus()) {
604
-                    return false;
605
-                }
606
-            }
607
-            return true;
608
-        }
609
-
610
-        /**
611
-         *    The reporter has a veto on what should be run.
612
-         *    It requires all reporters to want to run the method.
613
-         *    @param string $test_case_name  name of test case.
614
-         *    @param string $method          Name of test method.
615
-         *    @access public
616
-         */
617
-        function shouldInvoke($test_case_name, $method) {
618
-            for ($i = 0; $i < count($this->_reporters); $i++) {
619
-                if (! $this->_reporters[$i]->shouldInvoke($test_case_name, $method)) {
620
-                    return false;
621
-                }
622
-            }
623
-            return true;
624
-        }
625
-
626
-        /**
627
-         *    Every reporter gets a chance to wrap the invoker.
628
-         *    @param SimpleInvoker $invoker   Individual test runner.
629
-         *    @return SimpleInvoker           Wrapped test runner.
630
-         *    @access public
631
-         */
632
-        function &createInvoker($invoker) {
633
-            for ($i = 0; $i < count($this->_reporters); $i++) {
634
-                $invoker = $this->_reporters[$i]->createInvoker($invoker);
635
-            }
636
-            return $invoker;
637
-        }
638
-
639
-        /**
640
-         *    Paints the start of a group test.
641
-         *    @param string $test_name     Name of test or other label.
642
-         *    @param integer $size         Number of test cases starting.
643
-         *    @access public
644
-         */
645
-        function paintGroupStart($test_name, $size) {
646
-            for ($i = 0; $i < count($this->_reporters); $i++) {
647
-                $this->_reporters[$i]->paintGroupStart($test_name, $size);
648
-            }
649
-        }
650
-
651
-        /**
652
-         *    Paints the end of a group test.
653
-         *    @param string $test_name     Name of test or other label.
654
-         *    @access public
655
-         */
656
-        function paintGroupEnd($test_name) {
657
-            for ($i = 0; $i < count($this->_reporters); $i++) {
658
-                $this->_reporters[$i]->paintGroupEnd($test_name);
659
-            }
660
-        }
661
-
662
-        /**
663
-         *    Paints the start of a test case.
664
-         *    @param string $test_name     Name of test or other label.
665
-         *    @access public
666
-         */
667
-        function paintCaseStart($test_name) {
668
-            for ($i = 0; $i < count($this->_reporters); $i++) {
669
-                $this->_reporters[$i]->paintCaseStart($test_name);
670
-            }
671
-        }
672
-
673
-        /**
674
-         *    Paints the end of a test case.
675
-         *    @param string $test_name     Name of test or other label.
676
-         *    @access public
677
-         */
678
-        function paintCaseEnd($test_name) {
679
-            for ($i = 0; $i < count($this->_reporters); $i++) {
680
-                $this->_reporters[$i]->paintCaseEnd($test_name);
681
-            }
682
-        }
683
-
684
-        /**
685
-         *    Paints the start of a test method.
686
-         *    @param string $test_name     Name of test or other label.
687
-         *    @access public
688
-         */
689
-        function paintMethodStart($test_name) {
690
-            for ($i = 0; $i < count($this->_reporters); $i++) {
691
-                $this->_reporters[$i]->paintMethodStart($test_name);
692
-            }
693
-        }
694
-
695
-        /**
696
-         *    Paints the end of a test method.
697
-         *    @param string $test_name     Name of test or other label.
698
-         *    @access public
699
-         */
700
-        function paintMethodEnd($test_name) {
701
-            for ($i = 0; $i < count($this->_reporters); $i++) {
702
-                $this->_reporters[$i]->paintMethodEnd($test_name);
703
-            }
704
-        }
705
-
706
-        /**
707
-         *    Chains to the wrapped reporter.
708
-         *    @param string $message        Message is ignored.
709
-         *    @access public
710
-         */
711
-        function paintPass($message) {
712
-            for ($i = 0; $i < count($this->_reporters); $i++) {
713
-                $this->_reporters[$i]->paintPass($message);
714
-            }
715
-        }
716
-
717
-        /**
718
-         *    Chains to the wrapped reporter.
719
-         *    @param string $message        Message is ignored.
720
-         *    @access public
721
-         */
722
-        function paintFail($message) {
723
-            for ($i = 0; $i < count($this->_reporters); $i++) {
724
-                $this->_reporters[$i]->paintFail($message);
725
-            }
726
-        }
727
-
728
-        /**
729
-         *    Chains to the wrapped reporter.
730
-         *    @param string $message    Text of error formatted by
731
-         *                              the test case.
732
-         *    @access public
733
-         */
734
-        function paintError($message) {
735
-            for ($i = 0; $i < count($this->_reporters); $i++) {
736
-                $this->_reporters[$i]->paintError($message);
737
-            }
738
-        }
739
-
740
-        /**
741
-         *    Chains to the wrapped reporter.
742
-         *    @param string $message        Text to display.
743
-         *    @access public
744
-         */
745
-        function paintMessage($message) {
746
-            for ($i = 0; $i < count($this->_reporters); $i++) {
747
-                $this->_reporters[$i]->paintMessage($message);
748
-            }
749
-        }
750
-
751
-        /**
752
-         *    Chains to the wrapped reporter.
753
-         *    @param string $message        Text to display.
754
-         *    @access public
755
-         */
756
-        function paintFormattedMessage($message) {
757
-            for ($i = 0; $i < count($this->_reporters); $i++) {
758
-                $this->_reporters[$i]->paintFormattedMessage($message);
759
-            }
760
-        }
761
-
762
-        /**
763
-         *    Chains to the wrapped reporter.
764
-         *    @param string $type        Event type as text.
765
-         *    @param mixed $payload      Message or object.
766
-         *    @return boolean            Should return false if this
767
-         *                               type of signal should fail the
768
-         *                               test suite.
769
-         *    @access public
770
-         */
771
-        function paintSignal($type, $payload) {
772
-            for ($i = 0; $i < count($this->_reporters); $i++) {
773
-                $this->_reporters[$i]->paintSignal($type, $payload);
774
-            }
775
-        }
776
-    }
777 567
\ No newline at end of file
568
+	 */
569
+	class MultipleReporter {
570
+		protected $_reporters = array();
571
+
572
+		/**
573
+		 *    Adds a reporter to the subscriber list.
574
+		 *    @param SimpleScorer $reporter     Reporter to receive events.
575
+		 *    @access public
576
+		 */
577
+		function attachReporter($reporter) {
578
+			$this->_reporters[] = $reporter;
579
+		}
580
+
581
+		/**
582
+		 *    Signals that the next evaluation will be a dry
583
+		 *    run. That is, the structure events will be
584
+		 *    recorded, but no tests will be run.
585
+		 *    @param boolean $is_dry        Dry run if true.
586
+		 *    @access public
587
+		 */
588
+		function makeDry($is_dry = true) {
589
+			for ($i = 0; $i < count($this->_reporters); $i++) {
590
+				$this->_reporters[$i]->makeDry($is_dry);
591
+			}
592
+		}
593
+
594
+		/**
595
+		 *    Accessor for current status. Will be false
596
+		 *    if there have been any failures or exceptions.
597
+		 *    If any reporter reports a failure, the whole
598
+		 *    suite fails.
599
+		 *    @return boolean        True if no failures.
600
+		 *    @access public
601
+		 */
602
+		function getStatus() {
603
+			for ($i = 0; $i < count($this->_reporters); $i++) {
604
+				if (! $this->_reporters[$i]->getStatus()) {
605
+					return false;
606
+				}
607
+			}
608
+			return true;
609
+		}
610
+
611
+		/**
612
+		 *    The reporter has a veto on what should be run.
613
+		 *    It requires all reporters to want to run the method.
614
+		 *    @param string $test_case_name  name of test case.
615
+		 *    @param string $method          Name of test method.
616
+		 *    @access public
617
+		 */
618
+		function shouldInvoke($test_case_name, $method) {
619
+			for ($i = 0; $i < count($this->_reporters); $i++) {
620
+				if (! $this->_reporters[$i]->shouldInvoke($test_case_name, $method)) {
621
+					return false;
622
+				}
623
+			}
624
+			return true;
625
+		}
626
+
627
+		/**
628
+		 *    Every reporter gets a chance to wrap the invoker.
629
+		 *    @param SimpleInvoker $invoker   Individual test runner.
630
+		 *    @return SimpleInvoker           Wrapped test runner.
631
+		 *    @access public
632
+		 */
633
+		function &createInvoker($invoker) {
634
+			for ($i = 0; $i < count($this->_reporters); $i++) {
635
+				$invoker = $this->_reporters[$i]->createInvoker($invoker);
636
+			}
637
+			return $invoker;
638
+		}
639
+
640
+		/**
641
+		 *    Paints the start of a group test.
642
+		 *    @param string $test_name     Name of test or other label.
643
+		 *    @param integer $size         Number of test cases starting.
644
+		 *    @access public
645
+		 */
646
+		function paintGroupStart($test_name, $size) {
647
+			for ($i = 0; $i < count($this->_reporters); $i++) {
648
+				$this->_reporters[$i]->paintGroupStart($test_name, $size);
649
+			}
650
+		}
651
+
652
+		/**
653
+		 *    Paints the end of a group test.
654
+		 *    @param string $test_name     Name of test or other label.
655
+		 *    @access public
656
+		 */
657
+		function paintGroupEnd($test_name) {
658
+			for ($i = 0; $i < count($this->_reporters); $i++) {
659
+				$this->_reporters[$i]->paintGroupEnd($test_name);
660
+			}
661
+		}
662
+
663
+		/**
664
+		 *    Paints the start of a test case.
665
+		 *    @param string $test_name     Name of test or other label.
666
+		 *    @access public
667
+		 */
668
+		function paintCaseStart($test_name) {
669
+			for ($i = 0; $i < count($this->_reporters); $i++) {
670
+				$this->_reporters[$i]->paintCaseStart($test_name);
671
+			}
672
+		}
673
+
674
+		/**
675
+		 *    Paints the end of a test case.
676
+		 *    @param string $test_name     Name of test or other label.
677
+		 *    @access public
678
+		 */
679
+		function paintCaseEnd($test_name) {
680
+			for ($i = 0; $i < count($this->_reporters); $i++) {
681
+				$this->_reporters[$i]->paintCaseEnd($test_name);
682
+			}
683
+		}
684
+
685
+		/**
686
+		 *    Paints the start of a test method.
687
+		 *    @param string $test_name     Name of test or other label.
688
+		 *    @access public
689
+		 */
690
+		function paintMethodStart($test_name) {
691
+			for ($i = 0; $i < count($this->_reporters); $i++) {
692
+				$this->_reporters[$i]->paintMethodStart($test_name);
693
+			}
694
+		}
695
+
696
+		/**
697
+		 *    Paints the end of a test method.
698
+		 *    @param string $test_name     Name of test or other label.
699
+		 *    @access public
700
+		 */
701
+		function paintMethodEnd($test_name) {
702
+			for ($i = 0; $i < count($this->_reporters); $i++) {
703
+				$this->_reporters[$i]->paintMethodEnd($test_name);
704
+			}
705
+		}
706
+
707
+		/**
708
+		 *    Chains to the wrapped reporter.
709
+		 *    @param string $message        Message is ignored.
710
+		 *    @access public
711
+		 */
712
+		function paintPass($message) {
713
+			for ($i = 0; $i < count($this->_reporters); $i++) {
714
+				$this->_reporters[$i]->paintPass($message);
715
+			}
716
+		}
717
+
718
+		/**
719
+		 *    Chains to the wrapped reporter.
720
+		 *    @param string $message        Message is ignored.
721
+		 *    @access public
722
+		 */
723
+		function paintFail($message) {
724
+			for ($i = 0; $i < count($this->_reporters); $i++) {
725
+				$this->_reporters[$i]->paintFail($message);
726
+			}
727
+		}
728
+
729
+		/**
730
+		 *    Chains to the wrapped reporter.
731
+		 *    @param string $message    Text of error formatted by
732
+		 *                              the test case.
733
+		 *    @access public
734
+		 */
735
+		function paintError($message) {
736
+			for ($i = 0; $i < count($this->_reporters); $i++) {
737
+				$this->_reporters[$i]->paintError($message);
738
+			}
739
+		}
740
+
741
+		/**
742
+		 *    Chains to the wrapped reporter.
743
+		 *    @param string $message        Text to display.
744
+		 *    @access public
745
+		 */
746
+		function paintMessage($message) {
747
+			for ($i = 0; $i < count($this->_reporters); $i++) {
748
+				$this->_reporters[$i]->paintMessage($message);
749
+			}
750
+		}
751
+
752
+		/**
753
+		 *    Chains to the wrapped reporter.
754
+		 *    @param string $message        Text to display.
755
+		 *    @access public
756
+		 */
757
+		function paintFormattedMessage($message) {
758
+			for ($i = 0; $i < count($this->_reporters); $i++) {
759
+				$this->_reporters[$i]->paintFormattedMessage($message);
760
+			}
761
+		}
762
+
763
+		/**
764
+		 *    Chains to the wrapped reporter.
765
+		 *    @param string $type        Event type as text.
766
+		 *    @param mixed $payload      Message or object.
767
+		 *    @return boolean            Should return false if this
768
+		 *                               type of signal should fail the
769
+		 *                               test suite.
770
+		 *    @access public
771
+		 */
772
+		function paintSignal($type, $payload) {
773
+			for ($i = 0; $i < count($this->_reporters); $i++) {
774
+				$this->_reporters[$i]->paintSignal($type, $payload);
775
+			}
776
+		}
777
+	}
778 778
\ No newline at end of file
Please login to merge, or discard this patch.
tests/test_tools/simpletest/expectation.php 1 patch
Indentation   +716 added lines, -716 removed lines patch added patch discarded remove patch
@@ -1,719 +1,719 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *    base include file for SimpleTest
4
-     *    @package    SimpleTest
5
-     *    @subpackage    UnitTester
6
-     *    @version    $Id: expectation.php 1532 2006-12-01 12:28:55Z xue $
7
-     */
8
-
9
-    /**#@+
2
+	/**
3
+	 *    base include file for SimpleTest
4
+	 *    @package    SimpleTest
5
+	 *    @subpackage    UnitTester
6
+	 *    @version    $Id: expectation.php 1532 2006-12-01 12:28:55Z xue $
7
+	 */
8
+
9
+	/**#@+
10 10
      *    include other SimpleTest class files
11 11
      */
12
-    require_once(dirname(__FILE__) . '/dumper.php');
13
-    require_once(dirname(__FILE__) . '/compatibility.php');
14
-    /**#@-*/
15
-
16
-    /**
17
-     *    Assertion that can display failure information.
18
-     *    Also includes various helper methods.
19
-     *    @package SimpleTest
20
-     *    @subpackage UnitTester
21
-     *    @abstract
22
-     */
23
-    class SimpleExpectation {
24
-        protected $_dumper;
25
-        protected $_message;
26
-
27
-        /**
28
-         *    Creates a dumper for displaying values and sets
29
-         *    the test message.
30
-         *    @param string $message    Customised message on failure.
31
-         */
32
-        function SimpleExpectation($message = '%s') {
33
-            $this->_dumper = new SimpleDumper();
34
-            $this->_message = $message;
35
-        }
36
-
37
-        /**
38
-         *    Tests the expectation. True if correct.
39
-         *    @param mixed $compare        Comparison value.
40
-         *    @return boolean              True if correct.
41
-         *    @access public
42
-         *    @abstract
43
-         */
44
-        function test($compare) {
45
-        }
46
-
47
-        /**
48
-         *    Returns a human readable test message.
49
-         *    @param mixed $compare      Comparison value.
50
-         *    @return string             Description of success
51
-         *                               or failure.
52
-         *    @access public
53
-         *    @abstract
54
-         */
55
-        function testMessage($compare) {
56
-        }
57
-
58
-        /**
59
-         *    Overlays the generated message onto the stored user
60
-         *    message. An additional message can be interjected.
61
-         *    @param mixed $compare      Comparison value.
62
-         *    @return string             Description of success
63
-         *                               or failure.
64
-         *    @access public
65
-         */
66
-        function overlayMessage($compare) {
67
-            return sprintf($this->_message, $this->testMessage($compare));
68
-        }
69
-
70
-        /**
71
-         *    Accessor for the dumper.
72
-         *    @return SimpleDumper    Current value dumper.
73
-         *    @access protected
74
-         */
75
-        function &_getDumper() {
76
-            return $this->_dumper;
77
-        }
78
-
79
-        /**
80
-         *    Test to see if a value is an expectation object.
81
-         *    A useful utility method.
82
-         *    @param mixed $expectation    Hopefully an Epectation
83
-         *                                 class.
84
-         *    @return boolean              True if descended from
85
-         *                                 this class.
86
-         *    @access public
87
-         *    @static
88
-         */
89
-        static function isExpectation($expectation) {
90
-            return is_object($expectation) &&
91
-                    SimpleTestCompatibility::isA($expectation, 'SimpleExpectation');
92
-        }
93
-    }
94
-
95
-    /**
96
-     *    Test for equality.
97
-     *      @package SimpleTest
98
-     *      @subpackage UnitTester
99
-     */
100
-    class EqualExpectation extends SimpleExpectation {
101
-        protected $_value;
102
-
103
-        /**
104
-         *    Sets the value to compare against.
105
-         *    @param mixed $value        Test value to match.
106
-         *    @param string $message     Customised message on failure.
107
-         *    @access public
108
-         */
109
-        function EqualExpectation($value, $message = '%s') {
110
-            $this->SimpleExpectation($message);
111
-            $this->_value = $value;
112
-        }
113
-
114
-        /**
115
-         *    Tests the expectation. True if it matches the
116
-         *    held value.
117
-         *    @param mixed $compare        Comparison value.
118
-         *    @return boolean              True if correct.
119
-         *    @access public
120
-         */
121
-        function test($compare) {
122
-            return (($this->_value == $compare) && ($compare == $this->_value));
123
-        }
124
-
125
-        /**
126
-         *    Returns a human readable test message.
127
-         *    @param mixed $compare      Comparison value.
128
-         *    @return string             Description of success
129
-         *                               or failure.
130
-         *    @access public
131
-         */
132
-        function testMessage($compare) {
133
-            if ($this->test($compare)) {
134
-                return "Equal expectation [" . $this->_dumper->describeValue($this->_value) . "]";
135
-            } else {
136
-                return "Equal expectation fails " .
137
-                        $this->_dumper->describeDifference($this->_value, $compare);
138
-            }
139
-        }
140
-
141
-        /**
142
-         *    Accessor for comparison value.
143
-         *    @return mixed       Held value to compare with.
144
-         *    @access protected
145
-         */
146
-        function _getValue() {
147
-            return $this->_value;
148
-        }
149
-    }
150
-
151
-    /**
152
-     *    Test for inequality.
153
-     *      @package SimpleTest
154
-     *      @subpackage UnitTester
155
-     */
156
-    class NotEqualExpectation extends EqualExpectation {
157
-
158
-        /**
159
-         *    Sets the value to compare against.
160
-         *    @param mixed $value       Test value to match.
161
-         *    @param string $message    Customised message on failure.
162
-         *    @access public
163
-         */
164
-        function NotEqualExpectation($value, $message = '%s') {
165
-            $this->EqualExpectation($value, $message);
166
-        }
167
-
168
-        /**
169
-         *    Tests the expectation. True if it differs from the
170
-         *    held value.
171
-         *    @param mixed $compare        Comparison value.
172
-         *    @return boolean              True if correct.
173
-         *    @access public
174
-         */
175
-        function test($compare) {
176
-            return ! parent::test($compare);
177
-        }
178
-
179
-        /**
180
-         *    Returns a human readable test message.
181
-         *    @param mixed $compare      Comparison value.
182
-         *    @return string             Description of success
183
-         *                               or failure.
184
-         *    @access public
185
-         */
186
-        function testMessage($compare) {
187
-            $dumper = $this->_getDumper();
188
-            if ($this->test($compare)) {
189
-                return "Not equal expectation passes " .
190
-                        $dumper->describeDifference($this->_getValue(), $compare);
191
-            } else {
192
-                return "Not equal expectation fails [" .
193
-                        $dumper->describeValue($this->_getValue()) .
194
-                        "] matches";
195
-            }
196
-        }
197
-    }
198
-
199
-    /**
200
-     *    Test for being within a range.
201
-     *      @package SimpleTest
202
-     *      @subpackage UnitTester
203
-     */
204
-    class WithinMarginExpectation extends SimpleExpectation {
205
-        protected $_upper;
206
-        protected $_lower;
207
-
208
-        /**
209
-         *    Sets the value to compare against and the fuzziness of
210
-         *    the match. Used for comparing floating point values.
211
-         *    @param mixed $value        Test value to match.
212
-         *    @param mixed $margin       Fuzziness of match.
213
-         *    @param string $message     Customised message on failure.
214
-         *    @access public
215
-         */
216
-        function WithinMarginExpectation($value, $margin, $message = '%s') {
217
-            $this->SimpleExpectation($message);
218
-            $this->_upper = $value + $margin;
219
-            $this->_lower = $value - $margin;
220
-        }
221
-
222
-        /**
223
-         *    Tests the expectation. True if it matches the
224
-         *    held value.
225
-         *    @param mixed $compare        Comparison value.
226
-         *    @return boolean              True if correct.
227
-         *    @access public
228
-         */
229
-        function test($compare) {
230
-            return (($compare <= $this->_upper) && ($compare >= $this->_lower));
231
-        }
232
-
233
-        /**
234
-         *    Returns a human readable test message.
235
-         *    @param mixed $compare      Comparison value.
236
-         *    @return string             Description of success
237
-         *                               or failure.
238
-         *    @access public
239
-         */
240
-        function testMessage($compare) {
241
-            if ($this->test($compare)) {
242
-                return $this->_withinMessage($compare);
243
-            } else {
244
-                return $this->_outsideMessage($compare);
245
-            }
246
-        }
247
-
248
-        /**
249
-         *    Creates a the message for being within the range.
250
-         *    @param mixed $compare        Value being tested.
251
-         *    @access private
252
-         */
253
-        function _withinMessage($compare) {
254
-            return "Within expectation [" . $this->_dumper->describeValue($this->_lower) . "] and [" .
255
-                    $this->_dumper->describeValue($this->_upper) . "]";
256
-        }
257
-
258
-        /**
259
-         *    Creates a the message for being within the range.
260
-         *    @param mixed $compare        Value being tested.
261
-         *    @access private
262
-         */
263
-        function _outsideMessage($compare) {
264
-            if ($compare > $this->_upper) {
265
-                return "Outside expectation " .
266
-                        $this->_dumper->describeDifference($compare, $this->_upper);
267
-            } else {
268
-                return "Outside expectation " .
269
-                        $this->_dumper->describeDifference($compare, $this->_lower);
270
-            }
271
-        }
272
-    }
273
-
274
-    /**
275
-     *    Test for being outside of a range.
276
-     *      @package SimpleTest
277
-     *      @subpackage UnitTester
278
-     */
279
-    class OutsideMarginExpectation extends WithinMarginExpectation {
280
-
281
-        /**
282
-         *    Sets the value to compare against and the fuzziness of
283
-         *    the match. Used for comparing floating point values.
284
-         *    @param mixed $value        Test value to not match.
285
-         *    @param mixed $margin       Fuzziness of match.
286
-         *    @param string $message     Customised message on failure.
287
-         *    @access public
288
-         */
289
-        function OutsideMarginExpectation($value, $margin, $message = '%s') {
290
-            $this->WithinMarginExpectation($value, $margin, $message);
291
-        }
292
-
293
-        /**
294
-         *    Tests the expectation. True if it matches the
295
-         *    held value.
296
-         *    @param mixed $compare        Comparison value.
297
-         *    @return boolean              True if correct.
298
-         *    @access public
299
-         */
300
-        function test($compare) {
301
-            return ! parent::test($compare);
302
-        }
303
-
304
-        /**
305
-         *    Returns a human readable test message.
306
-         *    @param mixed $compare      Comparison value.
307
-         *    @return string             Description of success
308
-         *                               or failure.
309
-         *    @access public
310
-         */
311
-        function testMessage($compare) {
312
-            if (! $this->test($compare)) {
313
-                return $this->_withinMessage($compare);
314
-            } else {
315
-                return $this->_outsideMessage($compare);
316
-            }
317
-        }
318
-    }
319
-
320
-    /**
321
-     *    Test for identity.
322
-     *    @package SimpleTest
323
-     *    @subpackage UnitTester
324
-     */
325
-    class IdenticalExpectation extends EqualExpectation {
326
-
327
-        /**
328
-         *    Sets the value to compare against.
329
-         *    @param mixed $value       Test value to match.
330
-         *    @param string $message    Customised message on failure.
331
-         *    @access public
332
-         */
333
-        function IdenticalExpectation($value, $message = '%s') {
334
-            $this->EqualExpectation($value, $message);
335
-        }
336
-
337
-        /**
338
-         *    Tests the expectation. True if it exactly
339
-         *    matches the held value.
340
-         *    @param mixed $compare        Comparison value.
341
-         *    @return boolean              True if correct.
342
-         *    @access public
343
-         */
344
-        function test($compare) {
345
-            return SimpleTestCompatibility::isIdentical($this->_getValue(), $compare);
346
-        }
347
-
348
-        /**
349
-         *    Returns a human readable test message.
350
-         *    @param mixed $compare      Comparison value.
351
-         *    @return string             Description of success
352
-         *                               or failure.
353
-         *    @access public
354
-         */
355
-        function testMessage($compare) {
356
-            $dumper = $this->_getDumper();
357
-            if ($this->test($compare)) {
358
-                return "Identical expectation [" . $dumper->describeValue($this->_getValue()) . "]";
359
-            } else {
360
-                return "Identical expectation [" . $dumper->describeValue($this->_getValue()) .
361
-                        "] fails with [" .
362
-                        $dumper->describeValue($compare) . "] " .
363
-                        $dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS);
364
-            }
365
-        }
366
-    }
367
-
368
-    /**
369
-     *    Test for non-identity.
370
-     *    @package SimpleTest
371
-     *    @subpackage UnitTester
372
-     */
373
-    class NotIdenticalExpectation extends IdenticalExpectation {
374
-
375
-        /**
376
-         *    Sets the value to compare against.
377
-         *    @param mixed $value        Test value to match.
378
-         *    @param string $message     Customised message on failure.
379
-         *    @access public
380
-         */
381
-        function NotIdenticalExpectation($value, $message = '%s') {
382
-            $this->IdenticalExpectation($value, $message);
383
-        }
384
-
385
-        /**
386
-         *    Tests the expectation. True if it differs from the
387
-         *    held value.
388
-         *    @param mixed $compare        Comparison value.
389
-         *    @return boolean              True if correct.
390
-         *    @access public
391
-         */
392
-        function test($compare) {
393
-            return ! parent::test($compare);
394
-        }
395
-
396
-        /**
397
-         *    Returns a human readable test message.
398
-         *    @param mixed $compare      Comparison value.
399
-         *    @return string             Description of success
400
-         *                               or failure.
401
-         *    @access public
402
-         */
403
-        function testMessage($compare) {
404
-            $dumper = $this->_getDumper();
405
-            if ($this->test($compare)) {
406
-                return "Not identical expectation passes " .
407
-                        $dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS);
408
-            } else {
409
-                return "Not identical expectation [" . $dumper->describeValue($this->_getValue()) . "] matches";
410
-            }
411
-        }
412
-    }
413
-
414
-    /**
415
-     *    Test for a pattern using Perl regex rules.
416
-     *    @package SimpleTest
417
-     *    @subpackage UnitTester
418
-     */
419
-    class PatternExpectation extends SimpleExpectation {
420
-        protected $_pattern;
421
-
422
-        /**
423
-         *    Sets the value to compare against.
424
-         *    @param string $pattern    Pattern to search for.
425
-         *    @param string $message    Customised message on failure.
426
-         *    @access public
427
-         */
428
-        function PatternExpectation($pattern, $message = '%s') {
429
-            $this->SimpleExpectation($message);
430
-            $this->_pattern = $pattern;
431
-        }
432
-
433
-        /**
434
-         *    Accessor for the pattern.
435
-         *    @return string       Perl regex as string.
436
-         *    @access protected
437
-         */
438
-        function _getPattern() {
439
-            return $this->_pattern;
440
-        }
441
-
442
-        /**
443
-         *    Tests the expectation. True if the Perl regex
444
-         *    matches the comparison value.
445
-         *    @param string $compare        Comparison value.
446
-         *    @return boolean               True if correct.
447
-         *    @access public
448
-         */
449
-        function test($compare) {
450
-            return (boolean)preg_match($this->_getPattern(), $compare);
451
-        }
452
-
453
-        /**
454
-         *    Returns a human readable test message.
455
-         *    @param mixed $compare      Comparison value.
456
-         *    @return string             Description of success
457
-         *                               or failure.
458
-         *    @access public
459
-         */
460
-        function testMessage($compare) {
461
-            if ($this->test($compare)) {
462
-                return $this->_describePatternMatch($this->_getPattern(), $compare);
463
-            } else {
464
-                $dumper = $this->_getDumper();
465
-                return "Pattern [" . $this->_getPattern() .
466
-                        "] not detected in [" .
467
-                        $dumper->describeValue($compare) . "]";
468
-            }
469
-        }
470
-
471
-        /**
472
-         *    Describes a pattern match including the string
473
-         *    found and it's position.
474
-     *    @package SimpleTest
475
-     *    @subpackage UnitTester
476
-         *    @param string $pattern        Regex to match against.
477
-         *    @param string $subject        Subject to search.
478
-         *    @access protected
479
-         */
480
-        function _describePatternMatch($pattern, $subject) {
481
-            preg_match($pattern, $subject, $matches);
482
-            $position = strpos($subject, $matches[0]);
483
-            $dumper = $this->_getDumper();
484
-            return "Pattern [$pattern] detected at character [$position] in [" .
485
-                    $dumper->describeValue($subject) . "] as [" .
486
-                    $matches[0] . "] in region [" .
487
-                    $dumper->clipString($subject, 100, $position) . "]";
488
-        }
489
-    }
490
-
491
-    /**
492
-     *      @deprecated
493
-     */
494
-    class WantedPatternExpectation extends PatternExpectation {
495
-    }
496
-
497
-    /**
498
-     *    Fail if a pattern is detected within the
499
-     *    comparison.
500
-     *      @package SimpleTest
501
-     *      @subpackage UnitTester
502
-     */
503
-    class NoPatternExpectation extends PatternExpectation {
504
-
505
-        /**
506
-         *    Sets the reject pattern
507
-         *    @param string $pattern    Pattern to search for.
508
-         *    @param string $message    Customised message on failure.
509
-         *    @access public
510
-         */
511
-        function NoPatternExpectation($pattern, $message = '%s') {
512
-            $this->PatternExpectation($pattern, $message);
513
-        }
514
-
515
-        /**
516
-         *    Tests the expectation. False if the Perl regex
517
-         *    matches the comparison value.
518
-         *    @param string $compare        Comparison value.
519
-         *    @return boolean               True if correct.
520
-         *    @access public
521
-         */
522
-        function test($compare) {
523
-            return ! parent::test($compare);
524
-        }
525
-
526
-        /**
527
-         *    Returns a human readable test message.
528
-         *    @param string $compare      Comparison value.
529
-         *    @return string              Description of success
530
-         *                                or failure.
531
-         *    @access public
532
-         */
533
-        function testMessage($compare) {
534
-            if ($this->test($compare)) {
535
-                $dumper = $this->_getDumper();
536
-                return "Pattern [" . $this->_getPattern() .
537
-                        "] not detected in [" .
538
-                        $dumper->describeValue($compare) . "]";
539
-            } else {
540
-                return $this->_describePatternMatch($this->_getPattern(), $compare);
541
-            }
542
-        }
543
-    }
544
-
545
-    /**
546
-     *    @package SimpleTest
547
-     *    @subpackage UnitTester
548
-     *      @deprecated
549
-     */
550
-    class UnwantedPatternExpectation extends NoPatternExpectation {
551
-    }
552
-
553
-    /**
554
-     *    Tests either type or class name if it's an object.
555
-     *      @package SimpleTest
556
-     *      @subpackage UnitTester
557
-     */
558
-    class IsAExpectation extends SimpleExpectation {
559
-        protected $_type;
560
-
561
-        /**
562
-         *    Sets the type to compare with.
563
-         *    @param string $type       Type or class name.
564
-         *    @param string $message    Customised message on failure.
565
-         *    @access public
566
-         */
567
-        function IsAExpectation($type, $message = '%s') {
568
-            $this->SimpleExpectation($message);
569
-            $this->_type = $type;
570
-        }
571
-
572
-        /**
573
-         *    Accessor for type to check against.
574
-         *    @return string    Type or class name.
575
-         *    @access protected
576
-         */
577
-        function _getType() {
578
-            return $this->_type;
579
-        }
580
-
581
-        /**
582
-         *    Tests the expectation. True if the type or
583
-         *    class matches the string value.
584
-         *    @param string $compare        Comparison value.
585
-         *    @return boolean               True if correct.
586
-         *    @access public
587
-         */
588
-        function test($compare) {
589
-            if (is_object($compare)) {
590
-                return SimpleTestCompatibility::isA($compare, $this->_type);
591
-            } else {
592
-                return (strtolower(gettype($compare)) == $this->_canonicalType($this->_type));
593
-            }
594
-        }
595
-
596
-        /**
597
-         *    Coerces type name into a gettype() match.
598
-         *    @param string $type        User type.
599
-         *    @return string             Simpler type.
600
-         *    @access private
601
-         */
602
-        function _canonicalType($type) {
603
-            $type = strtolower($type);
604
-            $map = array(
605
-                    'bool' => 'boolean',
606
-                    'float' => 'double',
607
-                    'real' => 'double',
608
-                    'int' => 'integer');
609
-            if (isset($map[$type])) {
610
-                $type = $map[$type];
611
-            }
612
-            return $type;
613
-        }
614
-
615
-        /**
616
-         *    Returns a human readable test message.
617
-         *    @param mixed $compare      Comparison value.
618
-         *    @return string             Description of success
619
-         *                               or failure.
620
-         *    @access public
621
-         */
622
-        function testMessage($compare) {
623
-            $dumper = $this->_getDumper();
624
-            return "Value [" . $dumper->describeValue($compare) .
625
-                    "] should be type [" . $this->_type . "]";
626
-        }
627
-    }
628
-
629
-    /**
630
-     *    Tests either type or class name if it's an object.
631
-     *    Will succeed if the type does not match.
632
-     *      @package SimpleTest
633
-     *      @subpackage UnitTester
634
-     */
635
-    class NotAExpectation extends IsAExpectation {
636
-        protected $_type;
637
-
638
-        /**
639
-         *    Sets the type to compare with.
640
-         *    @param string $type       Type or class name.
641
-         *    @param string $message    Customised message on failure.
642
-         *    @access public
643
-         */
644
-        function NotAExpectation($type, $message = '%s') {
645
-            $this->IsAExpectation($type, $message);
646
-        }
647
-
648
-        /**
649
-         *    Tests the expectation. False if the type or
650
-         *    class matches the string value.
651
-         *    @param string $compare        Comparison value.
652
-         *    @return boolean               True if different.
653
-         *    @access public
654
-         */
655
-        function test($compare) {
656
-            return ! parent::test($compare);
657
-        }
658
-
659
-        /**
660
-         *    Returns a human readable test message.
661
-         *    @param mixed $compare      Comparison value.
662
-         *    @return string             Description of success
663
-         *                               or failure.
664
-         *    @access public
665
-         */
666
-        function testMessage($compare) {
667
-            $dumper = $this->_getDumper();
668
-            return "Value [" . $dumper->describeValue($compare) .
669
-                    "] should not be type [" . $this->_getType() . "]";
670
-        }
671
-    }
672
-
673
-    /**
674
-     *    Tests for existance of a method in an object
675
-     *      @package SimpleTest
676
-     *      @subpackage UnitTester
677
-     */
678
-    class MethodExistsExpectation extends SimpleExpectation {
679
-        protected $_method;
680
-
681
-        /**
682
-         *    Sets the value to compare against.
683
-         *    @param string $method     Method to check.
684
-         *    @param string $message    Customised message on failure.
685
-         *    @access public
686
-         *    @return void
687
-         */
688
-        function MethodExistsExpectation($method, $message = '%s') {
689
-            $this->SimpleExpectation($message);
690
-            $this->_method = $method;
691
-        }
692
-
693
-        /**
694
-         *    Tests the expectation. True if the method exists in the test object.
695
-         *    @param string $compare        Comparison method name.
696
-         *    @return boolean               True if correct.
697
-         *    @access public
698
-         */
699
-        function test($compare) {
700
-            return (boolean)(is_object($compare) && method_exists($compare, $this->_method));
701
-        }
702
-
703
-        /**
704
-         *    Returns a human readable test message.
705
-         *    @param mixed $compare      Comparison value.
706
-         *    @return string             Description of success
707
-         *                               or failure.
708
-         *    @access public
709
-         */
710
-        function testMessage($compare) {
711
-            $dumper = $this->_getDumper();
712
-            if (! is_object($compare)) {
713
-                return 'No method on non-object [' . $dumper->describeValue($compare) . ']';
714
-            }
715
-            $method = $this->_method;
716
-            return "Object [" . $dumper->describeValue($compare) .
717
-                    "] should contain method [$method]";
718
-        }
719
-    }
12
+	require_once(dirname(__FILE__) . '/dumper.php');
13
+	require_once(dirname(__FILE__) . '/compatibility.php');
14
+	/**#@-*/
15
+
16
+	/**
17
+	 *    Assertion that can display failure information.
18
+	 *    Also includes various helper methods.
19
+	 *    @package SimpleTest
20
+	 *    @subpackage UnitTester
21
+	 *    @abstract
22
+	 */
23
+	class SimpleExpectation {
24
+		protected $_dumper;
25
+		protected $_message;
26
+
27
+		/**
28
+		 *    Creates a dumper for displaying values and sets
29
+		 *    the test message.
30
+		 *    @param string $message    Customised message on failure.
31
+		 */
32
+		function SimpleExpectation($message = '%s') {
33
+			$this->_dumper = new SimpleDumper();
34
+			$this->_message = $message;
35
+		}
36
+
37
+		/**
38
+		 *    Tests the expectation. True if correct.
39
+		 *    @param mixed $compare        Comparison value.
40
+		 *    @return boolean              True if correct.
41
+		 *    @access public
42
+		 *    @abstract
43
+		 */
44
+		function test($compare) {
45
+		}
46
+
47
+		/**
48
+		 *    Returns a human readable test message.
49
+		 *    @param mixed $compare      Comparison value.
50
+		 *    @return string             Description of success
51
+		 *                               or failure.
52
+		 *    @access public
53
+		 *    @abstract
54
+		 */
55
+		function testMessage($compare) {
56
+		}
57
+
58
+		/**
59
+		 *    Overlays the generated message onto the stored user
60
+		 *    message. An additional message can be interjected.
61
+		 *    @param mixed $compare      Comparison value.
62
+		 *    @return string             Description of success
63
+		 *                               or failure.
64
+		 *    @access public
65
+		 */
66
+		function overlayMessage($compare) {
67
+			return sprintf($this->_message, $this->testMessage($compare));
68
+		}
69
+
70
+		/**
71
+		 *    Accessor for the dumper.
72
+		 *    @return SimpleDumper    Current value dumper.
73
+		 *    @access protected
74
+		 */
75
+		function &_getDumper() {
76
+			return $this->_dumper;
77
+		}
78
+
79
+		/**
80
+		 *    Test to see if a value is an expectation object.
81
+		 *    A useful utility method.
82
+		 *    @param mixed $expectation    Hopefully an Epectation
83
+		 *                                 class.
84
+		 *    @return boolean              True if descended from
85
+		 *                                 this class.
86
+		 *    @access public
87
+		 *    @static
88
+		 */
89
+		static function isExpectation($expectation) {
90
+			return is_object($expectation) &&
91
+					SimpleTestCompatibility::isA($expectation, 'SimpleExpectation');
92
+		}
93
+	}
94
+
95
+	/**
96
+	 *    Test for equality.
97
+	 *      @package SimpleTest
98
+	 *      @subpackage UnitTester
99
+	 */
100
+	class EqualExpectation extends SimpleExpectation {
101
+		protected $_value;
102
+
103
+		/**
104
+		 *    Sets the value to compare against.
105
+		 *    @param mixed $value        Test value to match.
106
+		 *    @param string $message     Customised message on failure.
107
+		 *    @access public
108
+		 */
109
+		function EqualExpectation($value, $message = '%s') {
110
+			$this->SimpleExpectation($message);
111
+			$this->_value = $value;
112
+		}
113
+
114
+		/**
115
+		 *    Tests the expectation. True if it matches the
116
+		 *    held value.
117
+		 *    @param mixed $compare        Comparison value.
118
+		 *    @return boolean              True if correct.
119
+		 *    @access public
120
+		 */
121
+		function test($compare) {
122
+			return (($this->_value == $compare) && ($compare == $this->_value));
123
+		}
124
+
125
+		/**
126
+		 *    Returns a human readable test message.
127
+		 *    @param mixed $compare      Comparison value.
128
+		 *    @return string             Description of success
129
+		 *                               or failure.
130
+		 *    @access public
131
+		 */
132
+		function testMessage($compare) {
133
+			if ($this->test($compare)) {
134
+				return "Equal expectation [" . $this->_dumper->describeValue($this->_value) . "]";
135
+			} else {
136
+				return "Equal expectation fails " .
137
+						$this->_dumper->describeDifference($this->_value, $compare);
138
+			}
139
+		}
140
+
141
+		/**
142
+		 *    Accessor for comparison value.
143
+		 *    @return mixed       Held value to compare with.
144
+		 *    @access protected
145
+		 */
146
+		function _getValue() {
147
+			return $this->_value;
148
+		}
149
+	}
150
+
151
+	/**
152
+	 *    Test for inequality.
153
+	 *      @package SimpleTest
154
+	 *      @subpackage UnitTester
155
+	 */
156
+	class NotEqualExpectation extends EqualExpectation {
157
+
158
+		/**
159
+		 *    Sets the value to compare against.
160
+		 *    @param mixed $value       Test value to match.
161
+		 *    @param string $message    Customised message on failure.
162
+		 *    @access public
163
+		 */
164
+		function NotEqualExpectation($value, $message = '%s') {
165
+			$this->EqualExpectation($value, $message);
166
+		}
167
+
168
+		/**
169
+		 *    Tests the expectation. True if it differs from the
170
+		 *    held value.
171
+		 *    @param mixed $compare        Comparison value.
172
+		 *    @return boolean              True if correct.
173
+		 *    @access public
174
+		 */
175
+		function test($compare) {
176
+			return ! parent::test($compare);
177
+		}
178
+
179
+		/**
180
+		 *    Returns a human readable test message.
181
+		 *    @param mixed $compare      Comparison value.
182
+		 *    @return string             Description of success
183
+		 *                               or failure.
184
+		 *    @access public
185
+		 */
186
+		function testMessage($compare) {
187
+			$dumper = $this->_getDumper();
188
+			if ($this->test($compare)) {
189
+				return "Not equal expectation passes " .
190
+						$dumper->describeDifference($this->_getValue(), $compare);
191
+			} else {
192
+				return "Not equal expectation fails [" .
193
+						$dumper->describeValue($this->_getValue()) .
194
+						"] matches";
195
+			}
196
+		}
197
+	}
198
+
199
+	/**
200
+	 *    Test for being within a range.
201
+	 *      @package SimpleTest
202
+	 *      @subpackage UnitTester
203
+	 */
204
+	class WithinMarginExpectation extends SimpleExpectation {
205
+		protected $_upper;
206
+		protected $_lower;
207
+
208
+		/**
209
+		 *    Sets the value to compare against and the fuzziness of
210
+		 *    the match. Used for comparing floating point values.
211
+		 *    @param mixed $value        Test value to match.
212
+		 *    @param mixed $margin       Fuzziness of match.
213
+		 *    @param string $message     Customised message on failure.
214
+		 *    @access public
215
+		 */
216
+		function WithinMarginExpectation($value, $margin, $message = '%s') {
217
+			$this->SimpleExpectation($message);
218
+			$this->_upper = $value + $margin;
219
+			$this->_lower = $value - $margin;
220
+		}
221
+
222
+		/**
223
+		 *    Tests the expectation. True if it matches the
224
+		 *    held value.
225
+		 *    @param mixed $compare        Comparison value.
226
+		 *    @return boolean              True if correct.
227
+		 *    @access public
228
+		 */
229
+		function test($compare) {
230
+			return (($compare <= $this->_upper) && ($compare >= $this->_lower));
231
+		}
232
+
233
+		/**
234
+		 *    Returns a human readable test message.
235
+		 *    @param mixed $compare      Comparison value.
236
+		 *    @return string             Description of success
237
+		 *                               or failure.
238
+		 *    @access public
239
+		 */
240
+		function testMessage($compare) {
241
+			if ($this->test($compare)) {
242
+				return $this->_withinMessage($compare);
243
+			} else {
244
+				return $this->_outsideMessage($compare);
245
+			}
246
+		}
247
+
248
+		/**
249
+		 *    Creates a the message for being within the range.
250
+		 *    @param mixed $compare        Value being tested.
251
+		 *    @access private
252
+		 */
253
+		function _withinMessage($compare) {
254
+			return "Within expectation [" . $this->_dumper->describeValue($this->_lower) . "] and [" .
255
+					$this->_dumper->describeValue($this->_upper) . "]";
256
+		}
257
+
258
+		/**
259
+		 *    Creates a the message for being within the range.
260
+		 *    @param mixed $compare        Value being tested.
261
+		 *    @access private
262
+		 */
263
+		function _outsideMessage($compare) {
264
+			if ($compare > $this->_upper) {
265
+				return "Outside expectation " .
266
+						$this->_dumper->describeDifference($compare, $this->_upper);
267
+			} else {
268
+				return "Outside expectation " .
269
+						$this->_dumper->describeDifference($compare, $this->_lower);
270
+			}
271
+		}
272
+	}
273
+
274
+	/**
275
+	 *    Test for being outside of a range.
276
+	 *      @package SimpleTest
277
+	 *      @subpackage UnitTester
278
+	 */
279
+	class OutsideMarginExpectation extends WithinMarginExpectation {
280
+
281
+		/**
282
+		 *    Sets the value to compare against and the fuzziness of
283
+		 *    the match. Used for comparing floating point values.
284
+		 *    @param mixed $value        Test value to not match.
285
+		 *    @param mixed $margin       Fuzziness of match.
286
+		 *    @param string $message     Customised message on failure.
287
+		 *    @access public
288
+		 */
289
+		function OutsideMarginExpectation($value, $margin, $message = '%s') {
290
+			$this->WithinMarginExpectation($value, $margin, $message);
291
+		}
292
+
293
+		/**
294
+		 *    Tests the expectation. True if it matches the
295
+		 *    held value.
296
+		 *    @param mixed $compare        Comparison value.
297
+		 *    @return boolean              True if correct.
298
+		 *    @access public
299
+		 */
300
+		function test($compare) {
301
+			return ! parent::test($compare);
302
+		}
303
+
304
+		/**
305
+		 *    Returns a human readable test message.
306
+		 *    @param mixed $compare      Comparison value.
307
+		 *    @return string             Description of success
308
+		 *                               or failure.
309
+		 *    @access public
310
+		 */
311
+		function testMessage($compare) {
312
+			if (! $this->test($compare)) {
313
+				return $this->_withinMessage($compare);
314
+			} else {
315
+				return $this->_outsideMessage($compare);
316
+			}
317
+		}
318
+	}
319
+
320
+	/**
321
+	 *    Test for identity.
322
+	 *    @package SimpleTest
323
+	 *    @subpackage UnitTester
324
+	 */
325
+	class IdenticalExpectation extends EqualExpectation {
326
+
327
+		/**
328
+		 *    Sets the value to compare against.
329
+		 *    @param mixed $value       Test value to match.
330
+		 *    @param string $message    Customised message on failure.
331
+		 *    @access public
332
+		 */
333
+		function IdenticalExpectation($value, $message = '%s') {
334
+			$this->EqualExpectation($value, $message);
335
+		}
336
+
337
+		/**
338
+		 *    Tests the expectation. True if it exactly
339
+		 *    matches the held value.
340
+		 *    @param mixed $compare        Comparison value.
341
+		 *    @return boolean              True if correct.
342
+		 *    @access public
343
+		 */
344
+		function test($compare) {
345
+			return SimpleTestCompatibility::isIdentical($this->_getValue(), $compare);
346
+		}
347
+
348
+		/**
349
+		 *    Returns a human readable test message.
350
+		 *    @param mixed $compare      Comparison value.
351
+		 *    @return string             Description of success
352
+		 *                               or failure.
353
+		 *    @access public
354
+		 */
355
+		function testMessage($compare) {
356
+			$dumper = $this->_getDumper();
357
+			if ($this->test($compare)) {
358
+				return "Identical expectation [" . $dumper->describeValue($this->_getValue()) . "]";
359
+			} else {
360
+				return "Identical expectation [" . $dumper->describeValue($this->_getValue()) .
361
+						"] fails with [" .
362
+						$dumper->describeValue($compare) . "] " .
363
+						$dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS);
364
+			}
365
+		}
366
+	}
367
+
368
+	/**
369
+	 *    Test for non-identity.
370
+	 *    @package SimpleTest
371
+	 *    @subpackage UnitTester
372
+	 */
373
+	class NotIdenticalExpectation extends IdenticalExpectation {
374
+
375
+		/**
376
+		 *    Sets the value to compare against.
377
+		 *    @param mixed $value        Test value to match.
378
+		 *    @param string $message     Customised message on failure.
379
+		 *    @access public
380
+		 */
381
+		function NotIdenticalExpectation($value, $message = '%s') {
382
+			$this->IdenticalExpectation($value, $message);
383
+		}
384
+
385
+		/**
386
+		 *    Tests the expectation. True if it differs from the
387
+		 *    held value.
388
+		 *    @param mixed $compare        Comparison value.
389
+		 *    @return boolean              True if correct.
390
+		 *    @access public
391
+		 */
392
+		function test($compare) {
393
+			return ! parent::test($compare);
394
+		}
395
+
396
+		/**
397
+		 *    Returns a human readable test message.
398
+		 *    @param mixed $compare      Comparison value.
399
+		 *    @return string             Description of success
400
+		 *                               or failure.
401
+		 *    @access public
402
+		 */
403
+		function testMessage($compare) {
404
+			$dumper = $this->_getDumper();
405
+			if ($this->test($compare)) {
406
+				return "Not identical expectation passes " .
407
+						$dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS);
408
+			} else {
409
+				return "Not identical expectation [" . $dumper->describeValue($this->_getValue()) . "] matches";
410
+			}
411
+		}
412
+	}
413
+
414
+	/**
415
+	 *    Test for a pattern using Perl regex rules.
416
+	 *    @package SimpleTest
417
+	 *    @subpackage UnitTester
418
+	 */
419
+	class PatternExpectation extends SimpleExpectation {
420
+		protected $_pattern;
421
+
422
+		/**
423
+		 *    Sets the value to compare against.
424
+		 *    @param string $pattern    Pattern to search for.
425
+		 *    @param string $message    Customised message on failure.
426
+		 *    @access public
427
+		 */
428
+		function PatternExpectation($pattern, $message = '%s') {
429
+			$this->SimpleExpectation($message);
430
+			$this->_pattern = $pattern;
431
+		}
432
+
433
+		/**
434
+		 *    Accessor for the pattern.
435
+		 *    @return string       Perl regex as string.
436
+		 *    @access protected
437
+		 */
438
+		function _getPattern() {
439
+			return $this->_pattern;
440
+		}
441
+
442
+		/**
443
+		 *    Tests the expectation. True if the Perl regex
444
+		 *    matches the comparison value.
445
+		 *    @param string $compare        Comparison value.
446
+		 *    @return boolean               True if correct.
447
+		 *    @access public
448
+		 */
449
+		function test($compare) {
450
+			return (boolean)preg_match($this->_getPattern(), $compare);
451
+		}
452
+
453
+		/**
454
+		 *    Returns a human readable test message.
455
+		 *    @param mixed $compare      Comparison value.
456
+		 *    @return string             Description of success
457
+		 *                               or failure.
458
+		 *    @access public
459
+		 */
460
+		function testMessage($compare) {
461
+			if ($this->test($compare)) {
462
+				return $this->_describePatternMatch($this->_getPattern(), $compare);
463
+			} else {
464
+				$dumper = $this->_getDumper();
465
+				return "Pattern [" . $this->_getPattern() .
466
+						"] not detected in [" .
467
+						$dumper->describeValue($compare) . "]";
468
+			}
469
+		}
470
+
471
+		/**
472
+		 *    Describes a pattern match including the string
473
+		 *    found and it's position.
474
+		 *    @package SimpleTest
475
+		 *    @subpackage UnitTester
476
+		 *    @param string $pattern        Regex to match against.
477
+		 *    @param string $subject        Subject to search.
478
+		 *    @access protected
479
+		 */
480
+		function _describePatternMatch($pattern, $subject) {
481
+			preg_match($pattern, $subject, $matches);
482
+			$position = strpos($subject, $matches[0]);
483
+			$dumper = $this->_getDumper();
484
+			return "Pattern [$pattern] detected at character [$position] in [" .
485
+					$dumper->describeValue($subject) . "] as [" .
486
+					$matches[0] . "] in region [" .
487
+					$dumper->clipString($subject, 100, $position) . "]";
488
+		}
489
+	}
490
+
491
+	/**
492
+	 *      @deprecated
493
+	 */
494
+	class WantedPatternExpectation extends PatternExpectation {
495
+	}
496
+
497
+	/**
498
+	 *    Fail if a pattern is detected within the
499
+	 *    comparison.
500
+	 *      @package SimpleTest
501
+	 *      @subpackage UnitTester
502
+	 */
503
+	class NoPatternExpectation extends PatternExpectation {
504
+
505
+		/**
506
+		 *    Sets the reject pattern
507
+		 *    @param string $pattern    Pattern to search for.
508
+		 *    @param string $message    Customised message on failure.
509
+		 *    @access public
510
+		 */
511
+		function NoPatternExpectation($pattern, $message = '%s') {
512
+			$this->PatternExpectation($pattern, $message);
513
+		}
514
+
515
+		/**
516
+		 *    Tests the expectation. False if the Perl regex
517
+		 *    matches the comparison value.
518
+		 *    @param string $compare        Comparison value.
519
+		 *    @return boolean               True if correct.
520
+		 *    @access public
521
+		 */
522
+		function test($compare) {
523
+			return ! parent::test($compare);
524
+		}
525
+
526
+		/**
527
+		 *    Returns a human readable test message.
528
+		 *    @param string $compare      Comparison value.
529
+		 *    @return string              Description of success
530
+		 *                                or failure.
531
+		 *    @access public
532
+		 */
533
+		function testMessage($compare) {
534
+			if ($this->test($compare)) {
535
+				$dumper = $this->_getDumper();
536
+				return "Pattern [" . $this->_getPattern() .
537
+						"] not detected in [" .
538
+						$dumper->describeValue($compare) . "]";
539
+			} else {
540
+				return $this->_describePatternMatch($this->_getPattern(), $compare);
541
+			}
542
+		}
543
+	}
544
+
545
+	/**
546
+	 *    @package SimpleTest
547
+	 *    @subpackage UnitTester
548
+	 *      @deprecated
549
+	 */
550
+	class UnwantedPatternExpectation extends NoPatternExpectation {
551
+	}
552
+
553
+	/**
554
+	 *    Tests either type or class name if it's an object.
555
+	 *      @package SimpleTest
556
+	 *      @subpackage UnitTester
557
+	 */
558
+	class IsAExpectation extends SimpleExpectation {
559
+		protected $_type;
560
+
561
+		/**
562
+		 *    Sets the type to compare with.
563
+		 *    @param string $type       Type or class name.
564
+		 *    @param string $message    Customised message on failure.
565
+		 *    @access public
566
+		 */
567
+		function IsAExpectation($type, $message = '%s') {
568
+			$this->SimpleExpectation($message);
569
+			$this->_type = $type;
570
+		}
571
+
572
+		/**
573
+		 *    Accessor for type to check against.
574
+		 *    @return string    Type or class name.
575
+		 *    @access protected
576
+		 */
577
+		function _getType() {
578
+			return $this->_type;
579
+		}
580
+
581
+		/**
582
+		 *    Tests the expectation. True if the type or
583
+		 *    class matches the string value.
584
+		 *    @param string $compare        Comparison value.
585
+		 *    @return boolean               True if correct.
586
+		 *    @access public
587
+		 */
588
+		function test($compare) {
589
+			if (is_object($compare)) {
590
+				return SimpleTestCompatibility::isA($compare, $this->_type);
591
+			} else {
592
+				return (strtolower(gettype($compare)) == $this->_canonicalType($this->_type));
593
+			}
594
+		}
595
+
596
+		/**
597
+		 *    Coerces type name into a gettype() match.
598
+		 *    @param string $type        User type.
599
+		 *    @return string             Simpler type.
600
+		 *    @access private
601
+		 */
602
+		function _canonicalType($type) {
603
+			$type = strtolower($type);
604
+			$map = array(
605
+					'bool' => 'boolean',
606
+					'float' => 'double',
607
+					'real' => 'double',
608
+					'int' => 'integer');
609
+			if (isset($map[$type])) {
610
+				$type = $map[$type];
611
+			}
612
+			return $type;
613
+		}
614
+
615
+		/**
616
+		 *    Returns a human readable test message.
617
+		 *    @param mixed $compare      Comparison value.
618
+		 *    @return string             Description of success
619
+		 *                               or failure.
620
+		 *    @access public
621
+		 */
622
+		function testMessage($compare) {
623
+			$dumper = $this->_getDumper();
624
+			return "Value [" . $dumper->describeValue($compare) .
625
+					"] should be type [" . $this->_type . "]";
626
+		}
627
+	}
628
+
629
+	/**
630
+	 *    Tests either type or class name if it's an object.
631
+	 *    Will succeed if the type does not match.
632
+	 *      @package SimpleTest
633
+	 *      @subpackage UnitTester
634
+	 */
635
+	class NotAExpectation extends IsAExpectation {
636
+		protected $_type;
637
+
638
+		/**
639
+		 *    Sets the type to compare with.
640
+		 *    @param string $type       Type or class name.
641
+		 *    @param string $message    Customised message on failure.
642
+		 *    @access public
643
+		 */
644
+		function NotAExpectation($type, $message = '%s') {
645
+			$this->IsAExpectation($type, $message);
646
+		}
647
+
648
+		/**
649
+		 *    Tests the expectation. False if the type or
650
+		 *    class matches the string value.
651
+		 *    @param string $compare        Comparison value.
652
+		 *    @return boolean               True if different.
653
+		 *    @access public
654
+		 */
655
+		function test($compare) {
656
+			return ! parent::test($compare);
657
+		}
658
+
659
+		/**
660
+		 *    Returns a human readable test message.
661
+		 *    @param mixed $compare      Comparison value.
662
+		 *    @return string             Description of success
663
+		 *                               or failure.
664
+		 *    @access public
665
+		 */
666
+		function testMessage($compare) {
667
+			$dumper = $this->_getDumper();
668
+			return "Value [" . $dumper->describeValue($compare) .
669
+					"] should not be type [" . $this->_getType() . "]";
670
+		}
671
+	}
672
+
673
+	/**
674
+	 *    Tests for existance of a method in an object
675
+	 *      @package SimpleTest
676
+	 *      @subpackage UnitTester
677
+	 */
678
+	class MethodExistsExpectation extends SimpleExpectation {
679
+		protected $_method;
680
+
681
+		/**
682
+		 *    Sets the value to compare against.
683
+		 *    @param string $method     Method to check.
684
+		 *    @param string $message    Customised message on failure.
685
+		 *    @access public
686
+		 *    @return void
687
+		 */
688
+		function MethodExistsExpectation($method, $message = '%s') {
689
+			$this->SimpleExpectation($message);
690
+			$this->_method = $method;
691
+		}
692
+
693
+		/**
694
+		 *    Tests the expectation. True if the method exists in the test object.
695
+		 *    @param string $compare        Comparison method name.
696
+		 *    @return boolean               True if correct.
697
+		 *    @access public
698
+		 */
699
+		function test($compare) {
700
+			return (boolean)(is_object($compare) && method_exists($compare, $this->_method));
701
+		}
702
+
703
+		/**
704
+		 *    Returns a human readable test message.
705
+		 *    @param mixed $compare      Comparison value.
706
+		 *    @return string             Description of success
707
+		 *                               or failure.
708
+		 *    @access public
709
+		 */
710
+		function testMessage($compare) {
711
+			$dumper = $this->_getDumper();
712
+			if (! is_object($compare)) {
713
+				return 'No method on non-object [' . $dumper->describeValue($compare) . ']';
714
+			}
715
+			$method = $this->_method;
716
+			return "Object [" . $dumper->describeValue($compare) .
717
+					"] should contain method [$method]";
718
+		}
719
+	}
Please login to merge, or discard this patch.
tests/test_tools/simpletest/encoding.php 1 patch
Indentation   +502 added lines, -502 removed lines patch added patch discarded remove patch
@@ -1,520 +1,520 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *	base include file for SimpleTest
4
-     *	@package	SimpleTest
5
-     *	@subpackage	WebTester
6
-     *	@version	$Id: encoding.php 1398 2006-09-08 19:31:03Z xue $
7
-     */
8
-
9
-    /**#@+
2
+	/**
3
+	 *	base include file for SimpleTest
4
+	 *	@package	SimpleTest
5
+	 *	@subpackage	WebTester
6
+	 *	@version	$Id: encoding.php 1398 2006-09-08 19:31:03Z xue $
7
+	 */
8
+
9
+	/**#@+
10 10
      *	include other SimpleTest class files
11 11
      */
12
-    require_once(dirname(__FILE__) . '/socket.php');
13
-    /**#@-*/
12
+	require_once(dirname(__FILE__) . '/socket.php');
13
+	/**#@-*/
14 14
 
15
-    /**
16
-     *    Single post parameter.
15
+	/**
16
+	 *    Single post parameter.
17 17
 	 *    @package SimpleTest
18 18
 	 *    @subpackage WebTester
19
-     */
20
-    class SimpleEncodedPair {
21
-        protected $_key;
22
-        protected $_value;
23
-
24
-        /**
25
-         *    Stashes the data for rendering later.
26
-         *    @param string $key       Form element name.
27
-         *    @param string $value     Data to send.
28
-         */
29
-        function SimpleEncodedPair($key, $value) {
30
-            $this->_key = $key;
31
-            $this->_value = $value;
32
-        }
33
-
34
-        /**
35
-         *    The pair as a single string.
36
-         *    @return string        Encoded pair.
37
-         *    @access public
38
-         */
39
-        function asRequest() {
40
-            return $this->_key . '=' . urlencode($this->_value);
41
-        }
42
-
43
-        /**
44
-         *    The MIME part as a string.
45
-         *    @return string        MIME part encoding.
46
-         *    @access public
47
-         */
48
-        function asMime() {
49
-            $part = 'Content-Disposition: form-data; ';
50
-            $part .= "name=\"" . $this->_key . "\"\r\n";
51
-            $part .= "\r\n" . $this->_value;
52
-            return $part;
53
-        }
54
-
55
-        /**
56
-         *    Is this the value we are looking for?
57
-         *    @param string $key    Identifier.
58
-         *    @return boolean       True if matched.
59
-         *    @access public
60
-         */
61
-        function isKey($key) {
62
-            return $key == $this->_key;
63
-        }
64
-
65
-        /**
66
-         *    Is this the value we are looking for?
67
-         *    @return string       Identifier.
68
-         *    @access public
69
-         */
70
-        function getKey() {
71
-            return $this->_key;
72
-        }
73
-
74
-        /**
75
-         *    Is this the value we are looking for?
76
-         *    @return string       Content.
77
-         *    @access public
78
-         */
79
-        function getValue() {
80
-            return $this->_value;
81
-        }
82
-    }
83
-
84
-    /**
85
-     *    Single post parameter.
19
+	 */
20
+	class SimpleEncodedPair {
21
+		protected $_key;
22
+		protected $_value;
23
+
24
+		/**
25
+		 *    Stashes the data for rendering later.
26
+		 *    @param string $key       Form element name.
27
+		 *    @param string $value     Data to send.
28
+		 */
29
+		function SimpleEncodedPair($key, $value) {
30
+			$this->_key = $key;
31
+			$this->_value = $value;
32
+		}
33
+
34
+		/**
35
+		 *    The pair as a single string.
36
+		 *    @return string        Encoded pair.
37
+		 *    @access public
38
+		 */
39
+		function asRequest() {
40
+			return $this->_key . '=' . urlencode($this->_value);
41
+		}
42
+
43
+		/**
44
+		 *    The MIME part as a string.
45
+		 *    @return string        MIME part encoding.
46
+		 *    @access public
47
+		 */
48
+		function asMime() {
49
+			$part = 'Content-Disposition: form-data; ';
50
+			$part .= "name=\"" . $this->_key . "\"\r\n";
51
+			$part .= "\r\n" . $this->_value;
52
+			return $part;
53
+		}
54
+
55
+		/**
56
+		 *    Is this the value we are looking for?
57
+		 *    @param string $key    Identifier.
58
+		 *    @return boolean       True if matched.
59
+		 *    @access public
60
+		 */
61
+		function isKey($key) {
62
+			return $key == $this->_key;
63
+		}
64
+
65
+		/**
66
+		 *    Is this the value we are looking for?
67
+		 *    @return string       Identifier.
68
+		 *    @access public
69
+		 */
70
+		function getKey() {
71
+			return $this->_key;
72
+		}
73
+
74
+		/**
75
+		 *    Is this the value we are looking for?
76
+		 *    @return string       Content.
77
+		 *    @access public
78
+		 */
79
+		function getValue() {
80
+			return $this->_value;
81
+		}
82
+	}
83
+
84
+	/**
85
+	 *    Single post parameter.
86 86
 	 *    @package SimpleTest
87 87
 	 *    @subpackage WebTester
88
-     */
89
-    class SimpleAttachment {
90
-        protected $_key;
91
-        protected $_content;
92
-        protected $_filename;
93
-
94
-        /**
95
-         *    Stashes the data for rendering later.
96
-         *    @param string $key          Key to add value to.
97
-         *    @param string $content      Raw data.
98
-         *    @param hash $filename       Original filename.
99
-         */
100
-        function SimpleAttachment($key, $content, $filename) {
101
-            $this->_key = $key;
102
-            $this->_content = $content;
103
-            $this->_filename = $filename;
104
-        }
105
-
106
-        /**
107
-         *    The pair as a single string.
108
-         *    @return string        Encoded pair.
109
-         *    @access public
110
-         */
111
-        function asRequest() {
112
-            return '';
113
-        }
114
-
115
-        /**
116
-         *    The MIME part as a string.
117
-         *    @return string        MIME part encoding.
118
-         *    @access public
119
-         */
120
-        function asMime() {
121
-            $part = 'Content-Disposition: form-data; ';
122
-            $part .= 'name="' . $this->_key . '"; ';
123
-            $part .= 'filename="' . $this->_filename . '"';
124
-            $part .= "\r\nContent-Type: " . $this->_deduceMimeType();
125
-            $part .= "\r\n\r\n" . $this->_content;
126
-            return $part;
127
-        }
128
-
129
-        /**
130
-         *    Attempts to figure out the MIME type from the
131
-         *    file extension and the content.
132
-         *    @return string        MIME type.
133
-         *    @access private
134
-         */
135
-        function _deduceMimeType() {
136
-            if ($this->_isOnlyAscii($this->_content)) {
137
-                return 'text/plain';
138
-            }
139
-            return 'application/octet-stream';
140
-        }
141
-
142
-        /**
143
-         *    Tests each character is in the range 0-127.
144
-         *    @param string $ascii    String to test.
145
-         *    @access private
146
-         */
147
-        function _isOnlyAscii($ascii) {
148
-            for ($i = 0, $length = strlen($ascii); $i < $length; $i++) {
149
-                if (ord($ascii[$i]) > 127) {
150
-                    return false;
151
-                }
152
-            }
153
-            return true;
154
-        }
155
-
156
-        /**
157
-         *    Is this the value we are looking for?
158
-         *    @param string $key    Identifier.
159
-         *    @return boolean       True if matched.
160
-         *    @access public
161
-         */
162
-        function isKey($key) {
163
-            return $key == $this->_key;
164
-        }
165
-
166
-        /**
167
-         *    Is this the value we are looking for?
168
-         *    @return string       Identifier.
169
-         *    @access public
170
-         */
171
-        function getKey() {
172
-            return $this->_key;
173
-        }
174
-
175
-        /**
176
-         *    Is this the value we are looking for?
177
-         *    @return string       Content.
178
-         *    @access public
179
-         */
180
-        function getValue() {
181
-            return $this->_filename;
182
-        }
183
-    }
184
-
185
-    /**
186
-     *    Bundle of GET/POST parameters. Can include
187
-     *    repeated parameters.
88
+	 */
89
+	class SimpleAttachment {
90
+		protected $_key;
91
+		protected $_content;
92
+		protected $_filename;
93
+
94
+		/**
95
+		 *    Stashes the data for rendering later.
96
+		 *    @param string $key          Key to add value to.
97
+		 *    @param string $content      Raw data.
98
+		 *    @param hash $filename       Original filename.
99
+		 */
100
+		function SimpleAttachment($key, $content, $filename) {
101
+			$this->_key = $key;
102
+			$this->_content = $content;
103
+			$this->_filename = $filename;
104
+		}
105
+
106
+		/**
107
+		 *    The pair as a single string.
108
+		 *    @return string        Encoded pair.
109
+		 *    @access public
110
+		 */
111
+		function asRequest() {
112
+			return '';
113
+		}
114
+
115
+		/**
116
+		 *    The MIME part as a string.
117
+		 *    @return string        MIME part encoding.
118
+		 *    @access public
119
+		 */
120
+		function asMime() {
121
+			$part = 'Content-Disposition: form-data; ';
122
+			$part .= 'name="' . $this->_key . '"; ';
123
+			$part .= 'filename="' . $this->_filename . '"';
124
+			$part .= "\r\nContent-Type: " . $this->_deduceMimeType();
125
+			$part .= "\r\n\r\n" . $this->_content;
126
+			return $part;
127
+		}
128
+
129
+		/**
130
+		 *    Attempts to figure out the MIME type from the
131
+		 *    file extension and the content.
132
+		 *    @return string        MIME type.
133
+		 *    @access private
134
+		 */
135
+		function _deduceMimeType() {
136
+			if ($this->_isOnlyAscii($this->_content)) {
137
+				return 'text/plain';
138
+			}
139
+			return 'application/octet-stream';
140
+		}
141
+
142
+		/**
143
+		 *    Tests each character is in the range 0-127.
144
+		 *    @param string $ascii    String to test.
145
+		 *    @access private
146
+		 */
147
+		function _isOnlyAscii($ascii) {
148
+			for ($i = 0, $length = strlen($ascii); $i < $length; $i++) {
149
+				if (ord($ascii[$i]) > 127) {
150
+					return false;
151
+				}
152
+			}
153
+			return true;
154
+		}
155
+
156
+		/**
157
+		 *    Is this the value we are looking for?
158
+		 *    @param string $key    Identifier.
159
+		 *    @return boolean       True if matched.
160
+		 *    @access public
161
+		 */
162
+		function isKey($key) {
163
+			return $key == $this->_key;
164
+		}
165
+
166
+		/**
167
+		 *    Is this the value we are looking for?
168
+		 *    @return string       Identifier.
169
+		 *    @access public
170
+		 */
171
+		function getKey() {
172
+			return $this->_key;
173
+		}
174
+
175
+		/**
176
+		 *    Is this the value we are looking for?
177
+		 *    @return string       Content.
178
+		 *    @access public
179
+		 */
180
+		function getValue() {
181
+			return $this->_filename;
182
+		}
183
+	}
184
+
185
+	/**
186
+	 *    Bundle of GET/POST parameters. Can include
187
+	 *    repeated parameters.
188 188
 	 *    @package SimpleTest
189 189
 	 *    @subpackage WebTester
190
-     */
191
-    class SimpleEncoding {
192
-        protected $_request;
193
-
194
-        /**
195
-         *    Starts empty.
196
-         *    @param array $query       Hash of parameters.
197
-         *                              Multiple values are
198
-         *                              as lists on a single key.
199
-         *    @access public
200
-         */
201
-        function SimpleEncoding($query = false) {
202
-            if (! $query) {
203
-                $query = array();
204
-            }
205
-            $this->clear();
206
-            $this->merge($query);
207
-        }
208
-
209
-        /**
210
-         *    Empties the request of parameters.
211
-         *    @access public
212
-         */
213
-        function clear() {
214
-            $this->_request = array();
215
-        }
216
-
217
-        /**
218
-         *    Adds a parameter to the query.
219
-         *    @param string $key            Key to add value to.
220
-         *    @param string/array $value    New data.
221
-         *    @access public
222
-         */
223
-        function add($key, $value) {
224
-            if ($value === false) {
225
-                return;
226
-            }
227
-            if (is_array($value)) {
228
-                foreach ($value as $item) {
229
-                    $this->_addPair($key, $item);
230
-                }
231
-            } else {
232
-                $this->_addPair($key, $value);
233
-            }
234
-        }
235
-
236
-        /**
237
-         *    Adds a new value into the request.
238
-         *    @param string $key            Key to add value to.
239
-         *    @param string/array $value    New data.
240
-         *    @access private
241
-         */
242
-        function _addPair($key, $value) {
243
-            $this->_request[] = new SimpleEncodedPair($key, $value);
244
-        }
245
-
246
-        /**
247
-         *    Adds a MIME part to the query. Does nothing for a
248
-         *    form encoded packet.
249
-         *    @param string $key          Key to add value to.
250
-         *    @param string $content      Raw data.
251
-         *    @param hash $filename       Original filename.
252
-         *    @access public
253
-         */
254
-        function attach($key, $content, $filename) {
255
-            $this->_request[] = new SimpleAttachment($key, $content, $filename);
256
-        }
257
-
258
-        /**
259
-         *    Adds a set of parameters to this query.
260
-         *    @param array/SimpleQueryString $query  Multiple values are
261
-         *                                           as lists on a single key.
262
-         *    @access public
263
-         */
264
-        function merge($query) {
265
-            if (is_object($query)) {
266
-                $this->_request = array_merge($this->_request, $query->getAll());
267
-            } elseif (is_array($query)) {
268
-                foreach ($query as $key => $value) {
269
-                    $this->add($key, $value);
270
-                }
271
-            }
272
-        }
273
-
274
-        /**
275
-         *    Accessor for single value.
276
-         *    @return string/array    False if missing, string
277
-         *                            if present and array if
278
-         *                            multiple entries.
279
-         *    @access public
280
-         */
281
-        function getValue($key) {
282
-            $values = array();
283
-            foreach ($this->_request as $pair) {
284
-                if ($pair->isKey($key)) {
285
-                    $values[] = $pair->getValue();
286
-                }
287
-            }
288
-            if (count($values) == 0) {
289
-                return false;
290
-            } elseif (count($values) == 1) {
291
-                return $values[0];
292
-            } else {
293
-                return $values;
294
-            }
295
-        }
296
-
297
-        /**
298
-         *    Accessor for listing of pairs.
299
-         *    @return array        All pair objects.
300
-         *    @access public
301
-         */
302
-        function getAll() {
303
-            return $this->_request;
304
-        }
305
-
306
-        /**
307
-         *    Renders the query string as a URL encoded
308
-         *    request part.
309
-         *    @return string        Part of URL.
310
-         *    @access protected
311
-         */
312
-        function _encode() {
313
-            $statements = array();
314
-            foreach ($this->_request as $pair) {
315
-                if ($statement = $pair->asRequest()) {
316
-                    $statements[] = $statement;
317
-                }
318
-            }
319
-            return implode('&', $statements);
320
-        }
321
-    }
322
-
323
-    /**
324
-     *    Bundle of GET parameters. Can include
325
-     *    repeated parameters.
190
+	 */
191
+	class SimpleEncoding {
192
+		protected $_request;
193
+
194
+		/**
195
+		 *    Starts empty.
196
+		 *    @param array $query       Hash of parameters.
197
+		 *                              Multiple values are
198
+		 *                              as lists on a single key.
199
+		 *    @access public
200
+		 */
201
+		function SimpleEncoding($query = false) {
202
+			if (! $query) {
203
+				$query = array();
204
+			}
205
+			$this->clear();
206
+			$this->merge($query);
207
+		}
208
+
209
+		/**
210
+		 *    Empties the request of parameters.
211
+		 *    @access public
212
+		 */
213
+		function clear() {
214
+			$this->_request = array();
215
+		}
216
+
217
+		/**
218
+		 *    Adds a parameter to the query.
219
+		 *    @param string $key            Key to add value to.
220
+		 *    @param string/array $value    New data.
221
+		 *    @access public
222
+		 */
223
+		function add($key, $value) {
224
+			if ($value === false) {
225
+				return;
226
+			}
227
+			if (is_array($value)) {
228
+				foreach ($value as $item) {
229
+					$this->_addPair($key, $item);
230
+				}
231
+			} else {
232
+				$this->_addPair($key, $value);
233
+			}
234
+		}
235
+
236
+		/**
237
+		 *    Adds a new value into the request.
238
+		 *    @param string $key            Key to add value to.
239
+		 *    @param string/array $value    New data.
240
+		 *    @access private
241
+		 */
242
+		function _addPair($key, $value) {
243
+			$this->_request[] = new SimpleEncodedPair($key, $value);
244
+		}
245
+
246
+		/**
247
+		 *    Adds a MIME part to the query. Does nothing for a
248
+		 *    form encoded packet.
249
+		 *    @param string $key          Key to add value to.
250
+		 *    @param string $content      Raw data.
251
+		 *    @param hash $filename       Original filename.
252
+		 *    @access public
253
+		 */
254
+		function attach($key, $content, $filename) {
255
+			$this->_request[] = new SimpleAttachment($key, $content, $filename);
256
+		}
257
+
258
+		/**
259
+		 *    Adds a set of parameters to this query.
260
+		 *    @param array/SimpleQueryString $query  Multiple values are
261
+		 *                                           as lists on a single key.
262
+		 *    @access public
263
+		 */
264
+		function merge($query) {
265
+			if (is_object($query)) {
266
+				$this->_request = array_merge($this->_request, $query->getAll());
267
+			} elseif (is_array($query)) {
268
+				foreach ($query as $key => $value) {
269
+					$this->add($key, $value);
270
+				}
271
+			}
272
+		}
273
+
274
+		/**
275
+		 *    Accessor for single value.
276
+		 *    @return string/array    False if missing, string
277
+		 *                            if present and array if
278
+		 *                            multiple entries.
279
+		 *    @access public
280
+		 */
281
+		function getValue($key) {
282
+			$values = array();
283
+			foreach ($this->_request as $pair) {
284
+				if ($pair->isKey($key)) {
285
+					$values[] = $pair->getValue();
286
+				}
287
+			}
288
+			if (count($values) == 0) {
289
+				return false;
290
+			} elseif (count($values) == 1) {
291
+				return $values[0];
292
+			} else {
293
+				return $values;
294
+			}
295
+		}
296
+
297
+		/**
298
+		 *    Accessor for listing of pairs.
299
+		 *    @return array        All pair objects.
300
+		 *    @access public
301
+		 */
302
+		function getAll() {
303
+			return $this->_request;
304
+		}
305
+
306
+		/**
307
+		 *    Renders the query string as a URL encoded
308
+		 *    request part.
309
+		 *    @return string        Part of URL.
310
+		 *    @access protected
311
+		 */
312
+		function _encode() {
313
+			$statements = array();
314
+			foreach ($this->_request as $pair) {
315
+				if ($statement = $pair->asRequest()) {
316
+					$statements[] = $statement;
317
+				}
318
+			}
319
+			return implode('&', $statements);
320
+		}
321
+	}
322
+
323
+	/**
324
+	 *    Bundle of GET parameters. Can include
325
+	 *    repeated parameters.
326 326
 	 *    @package SimpleTest
327 327
 	 *    @subpackage WebTester
328
-     */
329
-    class SimpleGetEncoding extends SimpleEncoding {
330
-
331
-        /**
332
-         *    Starts empty.
333
-         *    @param array $query       Hash of parameters.
334
-         *                              Multiple values are
335
-         *                              as lists on a single key.
336
-         *    @access public
337
-         */
338
-        function SimpleGetEncoding($query = false) {
339
-            $this->SimpleEncoding($query);
340
-        }
341
-
342
-        /**
343
-         *    HTTP request method.
344
-         *    @return string        Always GET.
345
-         *    @access public
346
-         */
347
-        function getMethod() {
348
-            return 'GET';
349
-        }
350
-
351
-        /**
352
-         *    Writes no extra headers.
353
-         *    @param SimpleSocket $socket        Socket to write to.
354
-         *    @access public
355
-         */
356
-        function writeHeadersTo($socket) {
357
-        }
358
-
359
-        /**
360
-         *    No data is sent to the socket as the data is encoded into
361
-         *    the URL.
362
-         *    @param SimpleSocket $socket        Socket to write to.
363
-         *    @access public
364
-         */
365
-        function writeTo($socket) {
366
-        }
367
-
368
-        /**
369
-         *    Renders the query string as a URL encoded
370
-         *    request part for attaching to a URL.
371
-         *    @return string        Part of URL.
372
-         *    @access public
373
-         */
374
-        function asUrlRequest() {
375
-            return $this->_encode();
376
-        }
377
-    }
378
-
379
-    /**
380
-     *    Bundle of URL parameters for a HEAD request.
328
+	 */
329
+	class SimpleGetEncoding extends SimpleEncoding {
330
+
331
+		/**
332
+		 *    Starts empty.
333
+		 *    @param array $query       Hash of parameters.
334
+		 *                              Multiple values are
335
+		 *                              as lists on a single key.
336
+		 *    @access public
337
+		 */
338
+		function SimpleGetEncoding($query = false) {
339
+			$this->SimpleEncoding($query);
340
+		}
341
+
342
+		/**
343
+		 *    HTTP request method.
344
+		 *    @return string        Always GET.
345
+		 *    @access public
346
+		 */
347
+		function getMethod() {
348
+			return 'GET';
349
+		}
350
+
351
+		/**
352
+		 *    Writes no extra headers.
353
+		 *    @param SimpleSocket $socket        Socket to write to.
354
+		 *    @access public
355
+		 */
356
+		function writeHeadersTo($socket) {
357
+		}
358
+
359
+		/**
360
+		 *    No data is sent to the socket as the data is encoded into
361
+		 *    the URL.
362
+		 *    @param SimpleSocket $socket        Socket to write to.
363
+		 *    @access public
364
+		 */
365
+		function writeTo($socket) {
366
+		}
367
+
368
+		/**
369
+		 *    Renders the query string as a URL encoded
370
+		 *    request part for attaching to a URL.
371
+		 *    @return string        Part of URL.
372
+		 *    @access public
373
+		 */
374
+		function asUrlRequest() {
375
+			return $this->_encode();
376
+		}
377
+	}
378
+
379
+	/**
380
+	 *    Bundle of URL parameters for a HEAD request.
381 381
 	 *    @package SimpleTest
382 382
 	 *    @subpackage WebTester
383
-     */
384
-    class SimpleHeadEncoding extends SimpleGetEncoding {
385
-
386
-        /**
387
-         *    Starts empty.
388
-         *    @param array $query       Hash of parameters.
389
-         *                              Multiple values are
390
-         *                              as lists on a single key.
391
-         *    @access public
392
-         */
393
-        function SimpleHeadEncoding($query = false) {
394
-            $this->SimpleGetEncoding($query);
395
-        }
396
-
397
-        /**
398
-         *    HTTP request method.
399
-         *    @return string        Always HEAD.
400
-         *    @access public
401
-         */
402
-        function getMethod() {
403
-            return 'HEAD';
404
-        }
405
-    }
406
-
407
-    /**
408
-     *    Bundle of POST parameters. Can include
409
-     *    repeated parameters.
383
+	 */
384
+	class SimpleHeadEncoding extends SimpleGetEncoding {
385
+
386
+		/**
387
+		 *    Starts empty.
388
+		 *    @param array $query       Hash of parameters.
389
+		 *                              Multiple values are
390
+		 *                              as lists on a single key.
391
+		 *    @access public
392
+		 */
393
+		function SimpleHeadEncoding($query = false) {
394
+			$this->SimpleGetEncoding($query);
395
+		}
396
+
397
+		/**
398
+		 *    HTTP request method.
399
+		 *    @return string        Always HEAD.
400
+		 *    @access public
401
+		 */
402
+		function getMethod() {
403
+			return 'HEAD';
404
+		}
405
+	}
406
+
407
+	/**
408
+	 *    Bundle of POST parameters. Can include
409
+	 *    repeated parameters.
410 410
 	 *    @package SimpleTest
411 411
 	 *    @subpackage WebTester
412
-     */
413
-    class SimplePostEncoding extends SimpleEncoding {
414
-
415
-        /**
416
-         *    Starts empty.
417
-         *    @param array $query       Hash of parameters.
418
-         *                              Multiple values are
419
-         *                              as lists on a single key.
420
-         *    @access public
421
-         */
422
-        function SimplePostEncoding($query = false) {
423
-            $this->SimpleEncoding($query);
424
-        }
425
-
426
-        /**
427
-         *    HTTP request method.
428
-         *    @return string        Always POST.
429
-         *    @access public
430
-         */
431
-        function getMethod() {
432
-            return 'POST';
433
-        }
434
-
435
-        /**
436
-         *    Dispatches the form headers down the socket.
437
-         *    @param SimpleSocket $socket        Socket to write to.
438
-         *    @access public
439
-         */
440
-        function writeHeadersTo($socket) {
441
-            $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n");
442
-            $socket->write("Content-Type: application/x-www-form-urlencoded\r\n");
443
-        }
444
-
445
-        /**
446
-         *    Dispatches the form data down the socket.
447
-         *    @param SimpleSocket $socket        Socket to write to.
448
-         *    @access public
449
-         */
450
-        function writeTo($socket) {
451
-            $socket->write($this->_encode());
452
-        }
453
-
454
-        /**
455
-         *    Renders the query string as a URL encoded
456
-         *    request part for attaching to a URL.
457
-         *    @return string        Part of URL.
458
-         *    @access public
459
-         */
460
-        function asUrlRequest() {
461
-            return '';
462
-        }
463
-    }
464
-
465
-    /**
466
-     *    Bundle of POST parameters in the multipart
467
-     *    format. Can include file uploads.
412
+	 */
413
+	class SimplePostEncoding extends SimpleEncoding {
414
+
415
+		/**
416
+		 *    Starts empty.
417
+		 *    @param array $query       Hash of parameters.
418
+		 *                              Multiple values are
419
+		 *                              as lists on a single key.
420
+		 *    @access public
421
+		 */
422
+		function SimplePostEncoding($query = false) {
423
+			$this->SimpleEncoding($query);
424
+		}
425
+
426
+		/**
427
+		 *    HTTP request method.
428
+		 *    @return string        Always POST.
429
+		 *    @access public
430
+		 */
431
+		function getMethod() {
432
+			return 'POST';
433
+		}
434
+
435
+		/**
436
+		 *    Dispatches the form headers down the socket.
437
+		 *    @param SimpleSocket $socket        Socket to write to.
438
+		 *    @access public
439
+		 */
440
+		function writeHeadersTo($socket) {
441
+			$socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n");
442
+			$socket->write("Content-Type: application/x-www-form-urlencoded\r\n");
443
+		}
444
+
445
+		/**
446
+		 *    Dispatches the form data down the socket.
447
+		 *    @param SimpleSocket $socket        Socket to write to.
448
+		 *    @access public
449
+		 */
450
+		function writeTo($socket) {
451
+			$socket->write($this->_encode());
452
+		}
453
+
454
+		/**
455
+		 *    Renders the query string as a URL encoded
456
+		 *    request part for attaching to a URL.
457
+		 *    @return string        Part of URL.
458
+		 *    @access public
459
+		 */
460
+		function asUrlRequest() {
461
+			return '';
462
+		}
463
+	}
464
+
465
+	/**
466
+	 *    Bundle of POST parameters in the multipart
467
+	 *    format. Can include file uploads.
468 468
 	 *    @package SimpleTest
469 469
 	 *    @subpackage WebTester
470
-     */
471
-    class SimpleMultipartEncoding extends SimplePostEncoding {
472
-        protected $_boundary;
473
-
474
-        /**
475
-         *    Starts empty.
476
-         *    @param array $query       Hash of parameters.
477
-         *                              Multiple values are
478
-         *                              as lists on a single key.
479
-         *    @access public
480
-         */
481
-        function SimpleMultipartEncoding($query = false, $boundary = false) {
482
-            $this->SimplePostEncoding($query);
483
-            $this->_boundary = ($boundary === false ? uniqid('st') : $boundary);
484
-        }
485
-
486
-        /**
487
-         *    Dispatches the form headers down the socket.
488
-         *    @param SimpleSocket $socket        Socket to write to.
489
-         *    @access public
490
-         */
491
-        function writeHeadersTo($socket) {
492
-            $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n");
493
-            $socket->write("Content-Type: multipart/form-data, boundary=" . $this->_boundary . "\r\n");
494
-        }
495
-
496
-        /**
497
-         *    Dispatches the form data down the socket.
498
-         *    @param SimpleSocket $socket        Socket to write to.
499
-         *    @access public
500
-         */
501
-        function writeTo($socket) {
502
-            $socket->write($this->_encode());
503
-        }
504
-
505
-        /**
506
-         *    Renders the query string as a URL encoded
507
-         *    request part.
508
-         *    @return string        Part of URL.
509
-         *    @access public
510
-         */
511
-        function _encode() {
512
-            $stream = '';
513
-            foreach ($this->_request as $pair) {
514
-                $stream .= "--" . $this->_boundary . "\r\n";
515
-                $stream .= $pair->asMime() . "\r\n";
516
-            }
517
-            $stream .= "--" . $this->_boundary . "--\r\n";
518
-            return $stream;
519
-        }
520
-    }
521 470
\ No newline at end of file
471
+	 */
472
+	class SimpleMultipartEncoding extends SimplePostEncoding {
473
+		protected $_boundary;
474
+
475
+		/**
476
+		 *    Starts empty.
477
+		 *    @param array $query       Hash of parameters.
478
+		 *                              Multiple values are
479
+		 *                              as lists on a single key.
480
+		 *    @access public
481
+		 */
482
+		function SimpleMultipartEncoding($query = false, $boundary = false) {
483
+			$this->SimplePostEncoding($query);
484
+			$this->_boundary = ($boundary === false ? uniqid('st') : $boundary);
485
+		}
486
+
487
+		/**
488
+		 *    Dispatches the form headers down the socket.
489
+		 *    @param SimpleSocket $socket        Socket to write to.
490
+		 *    @access public
491
+		 */
492
+		function writeHeadersTo($socket) {
493
+			$socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n");
494
+			$socket->write("Content-Type: multipart/form-data, boundary=" . $this->_boundary . "\r\n");
495
+		}
496
+
497
+		/**
498
+		 *    Dispatches the form data down the socket.
499
+		 *    @param SimpleSocket $socket        Socket to write to.
500
+		 *    @access public
501
+		 */
502
+		function writeTo($socket) {
503
+			$socket->write($this->_encode());
504
+		}
505
+
506
+		/**
507
+		 *    Renders the query string as a URL encoded
508
+		 *    request part.
509
+		 *    @return string        Part of URL.
510
+		 *    @access public
511
+		 */
512
+		function _encode() {
513
+			$stream = '';
514
+			foreach ($this->_request as $pair) {
515
+				$stream .= "--" . $this->_boundary . "\r\n";
516
+				$stream .= $pair->asMime() . "\r\n";
517
+			}
518
+			$stream .= "--" . $this->_boundary . "--\r\n";
519
+			return $stream;
520
+		}
521
+	}
522 522
\ No newline at end of file
Please login to merge, or discard this patch.
tests/test_tools/simpletest/exceptions.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,45 +1,45 @@
 block discarded – undo
1 1
 <?php
2
-    /**
3
-     *	base include file for SimpleTest
4
-     *	@package	SimpleTest
5
-     *	@subpackage	UnitTester
6
-     *	@version	$Id: exceptions.php 1398 2006-09-08 19:31:03Z xue $
7
-     */
2
+	/**
3
+	 *	base include file for SimpleTest
4
+	 *	@package	SimpleTest
5
+	 *	@subpackage	UnitTester
6
+	 *	@version	$Id: exceptions.php 1398 2006-09-08 19:31:03Z xue $
7
+	 */
8 8
 
9
-    /**#@+
9
+	/**#@+
10 10
      * Includes SimpleTest files and defined the root constant
11 11
      * for dependent libraries.
12 12
      */
13
-    require_once(dirname(__FILE__) . '/invoker.php');
13
+	require_once(dirname(__FILE__) . '/invoker.php');
14 14
 
15
-    /**
16
-     *    Extension that traps exceptions and turns them into
17
-     *    an error message.
15
+	/**
16
+	 *    Extension that traps exceptions and turns them into
17
+	 *    an error message.
18 18
 	 *	  @package SimpleTest
19 19
 	 *	  @subpackage UnitTester
20
-     */
21
-    class SimpleExceptionTrappingInvoker extends SimpleInvokerDecorator {
20
+	 */
21
+	class SimpleExceptionTrappingInvoker extends SimpleInvokerDecorator {
22 22
 
23
-        /**
24
-         *    Stores the invoker to be wrapped.
25
-         *    @param SimpleInvoker $invoker   Test method runner.
26
-         */
27
-        function SimpleExceptionTrappingInvoker($invoker) {
28
-            $this->SimpleInvokerDecorator($invoker);
29
-        }
23
+		/**
24
+		 *    Stores the invoker to be wrapped.
25
+		 *    @param SimpleInvoker $invoker   Test method runner.
26
+		 */
27
+		function SimpleExceptionTrappingInvoker($invoker) {
28
+			$this->SimpleInvokerDecorator($invoker);
29
+		}
30 30
 
31
-        /**
32
-         *    Invokes a test method and dispatches any
33
-         *    untrapped errors.
34
-         *    @param string $method    Test method to call.
35
-         *    @access public
36
-         */
37
-        function invoke($method) {
38
-            try {
39
-                parent::invoke($method);
40
-            } catch (Exception $exception) {
41
-                $test_case = $this->getTestCase();
42
-                $test_case->exception($exception);
43
-            }
44
-        }
45
-    }
46 31
\ No newline at end of file
32
+		/**
33
+		 *    Invokes a test method and dispatches any
34
+		 *    untrapped errors.
35
+		 *    @param string $method    Test method to call.
36
+		 *    @access public
37
+		 */
38
+		function invoke($method) {
39
+			try {
40
+				parent::invoke($method);
41
+			} catch (Exception $exception) {
42
+				$test_case = $this->getTestCase();
43
+				$test_case->exception($exception);
44
+			}
45
+		}
46
+	}
47 47
\ No newline at end of file
Please login to merge, or discard this patch.