Unit test for #149.
[akelos.git] / vendor / simpletest / simpletest.php
blob075d5b7b7f613f760399b2ea636b98adf5f6f849
1 <?php
2 /**
3 * Global state for SimpleTest and kicker script in future versions.
4 * @package SimpleTest
5 * @subpackage UnitTester
6 * @version $Id: simpletest.php,v 1.6 2006/01/01 23:16:53 lastcraft Exp $
7 */
9 /**#@+
10 * include SimpleTest files
12 if (version_compare(phpversion(), '5') >= 0) {
13 require_once(dirname(__FILE__) . '/reflection_php5.php');
14 } else {
15 require_once(dirname(__FILE__) . '/reflection_php4.php');
17 /**#@-*/
19 /**
20 * Static global directives and options. I hate this
21 * class. It's a mixture of reference hacks, configuration
22 * and previous design screw-ups that I have to maintain
23 * to keep backward compatibility.
24 * @package SimpleTest
26 class SimpleTest {
28 /**
29 * Reads the SimpleTest version from the release file.
30 * @return string Version string.
31 * @static
32 * @access public
34 function getVersion() {
35 $content = file(dirname(__FILE__) . '/VERSION');
36 return trim($content[0]);
39 /**
40 * Sets the name of a test case to ignore, usually
41 * because the class is an abstract case that should
42 * not be run. Once PHP4 is dropped this will disappear
43 * as a public method and "abstract" will rule.
44 * @param string $class Add a class to ignore.
45 * @static
46 * @access public
48 function ignore($class) {
49 $registry = &SimpleTest::_getRegistry();
50 $registry['IgnoreList'][strtolower($class)] = true;
53 /**
54 * Scans the now complete ignore list, and adds
55 * all parent classes to the list. If a class
56 * is not a runnable test case, then it's parents
57 * wouldn't be either. This is syntactic sugar
58 * to cut down on ommissions of ignore()'s or
59 * missing abstract declarations. This cannot
60 * be done whilst loading classes wiithout forcing
61 * a particular order on the class declarations and
62 * the ignore() calls. It's nice to havethe ignore()
63 * calls at the top of teh file.
64 * @param array $classes Class names of interest.
65 * @static
66 * @access public
68 function ignoreParentsIfIgnored($classes) {
69 $registry = &SimpleTest::_getRegistry();
70 foreach ($classes as $class) {
71 if (SimpleTest::isIgnored($class)) {
72 $reflection = new SimpleReflection($class);
73 if ($parent = $reflection->getParent()) {
74 SimpleTest::ignore($parent);
80 /**
81 * Test to see if a test case is in the ignore
82 * list. Quite obviously the ignore list should
83 * be a separate object and will be one day.
84 * This method is internal to SimpleTest. Don't
85 * use it.
86 * @param string $class Class name to test.
87 * @return boolean True if should not be run.
88 * @access public
89 * @static
91 function isIgnored($class) {
92 $registry = &SimpleTest::_getRegistry();
93 return isset($registry['IgnoreList'][strtolower($class)]);
96 /**
97 * @deprecated
99 function setMockBaseClass($mock_base) {
100 $registry = &SimpleTest::_getRegistry();
101 $registry['MockBaseClass'] = $mock_base;
105 * @deprecated
107 function getMockBaseClass() {
108 $registry = &SimpleTest::_getRegistry();
109 return $registry['MockBaseClass'];
113 * Sets proxy to use on all requests for when
114 * testing from behind a firewall. Set host
115 * to false to disable. This will take effect
116 * if there are no other proxy settings.
117 * @param string $proxy Proxy host as URL.
118 * @param string $username Proxy username for authentication.
119 * @param string $password Proxy password for authentication.
120 * @access public
122 function useProxy($proxy, $username = false, $password = false) {
123 $registry = &SimpleTest::_getRegistry();
124 $registry['DefaultProxy'] = $proxy;
125 $registry['DefaultProxyUsername'] = $username;
126 $registry['DefaultProxyPassword'] = $password;
130 * Accessor for default proxy host.
131 * @return string Proxy URL.
132 * @access public
134 function getDefaultProxy() {
135 $registry = &SimpleTest::_getRegistry();
136 return $registry['DefaultProxy'];
140 * Accessor for default proxy username.
141 * @return string Proxy username for authentication.
142 * @access public
144 function getDefaultProxyUsername() {
145 $registry = &SimpleTest::_getRegistry();
146 return $registry['DefaultProxyUsername'];
150 * Accessor for default proxy password.
151 * @return string Proxy password for authentication.
152 * @access public
154 function getDefaultProxyPassword() {
155 $registry = &SimpleTest::_getRegistry();
156 return $registry['DefaultProxyPassword'];
160 * Sets the current test case instance. This
161 * global instance can be used by the mock objects
162 * to send message to the test cases.
163 * @param SimpleTestCase $test Test case to register.
164 * @access public
165 * @static
167 function setCurrent(&$test) {
168 $registry = &SimpleTest::_getRegistry();
169 $registry['CurrentTestCase'] = &$test;
173 * Accessor for current test instance.
174 * @return SimpleTEstCase Currently running test.
175 * @access public
176 * @static
178 function &getCurrent() {
179 $registry = &SimpleTest::_getRegistry();
180 return $registry['CurrentTestCase'];
184 * Accessor for global registry of options.
185 * @return hash All stored values.
186 * @access private
187 * @static
189 function &_getRegistry() {
190 static $registry = false;
191 if (! $registry) {
192 $registry = SimpleTest::_getDefaults();
194 return $registry;
198 * Constant default values.
199 * @return hash All registry defaults.
200 * @access private
201 * @static
203 function _getDefaults() {
204 return array(
205 'StubBaseClass' => 'SimpleStub',
206 'MockBaseClass' => 'SimpleMock',
207 'IgnoreList' => array(),
208 'DefaultProxy' => false,
209 'DefaultProxyUsername' => false,
210 'DefaultProxyPassword' => false);
215 * @deprecated
217 class SimpleTestOptions extends SimpleTest {
220 * @deprecated
222 function getVersion() {
223 return Simpletest::getVersion();
227 * @deprecated
229 function ignore($class) {
230 return Simpletest::ignore($class);
234 * @deprecated
236 function isIgnored($class) {
237 return Simpletest::isIgnored($class);
241 * @deprecated
243 function setMockBaseClass($mock_base) {
244 return Simpletest::setMockBaseClass($mock_base);
248 * @deprecated
250 function getMockBaseClass() {
251 return Simpletest::getMockBaseClass();
255 * @deprecated
257 function useProxy($proxy, $username = false, $password = false) {
258 return Simpletest::useProxy($proxy, $username, $password);
262 * @deprecated
264 function getDefaultProxy() {
265 return Simpletest::getDefaultProxy();
269 * @deprecated
271 function getDefaultProxyUsername() {
272 return Simpletest::getDefaultProxyUsername();
276 * @deprecated
278 function getDefaultProxyPassword() {
279 return Simpletest::getDefaultProxyPassword();