PageRenderTime 13ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/simpletest/simpletest.php

https://github.com/chregu/fluxcms
PHP | 245 lines | 95 code | 24 blank | 126 comment | 1 complexity | bb7fdc8a3867d6c96585c9556cd1bc79 MD5 | raw file
  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.2 2005/08/16 03:32:11 lastcraft Exp $
  7     */
  8    
  9    /**
 10     *    Static global directives and options.
 11     *	  @package	SimpleTest
 12     */
 13    class SimpleTest {
 14        
 15        /**
 16         *    Reads the SimpleTest version from the release file.
 17         *    @return string        Version string.
 18         *    @static
 19         *    @access public
 20         */
 21        function getVersion() {
 22            $content = file(dirname(__FILE__) . '/VERSION');
 23            return trim($content[0]);
 24        }
 25        
 26        /**
 27         *    Sets the name of a test case to ignore, usually
 28         *    because the class is an abstract case that should
 29         *    not be run.
 30         *    @param string $class        Add a class to ignore.
 31         *    @static
 32         *    @access public
 33         */
 34        function ignore($class) {
 35            $registry = &SimpleTest::_getRegistry();
 36            $registry['IgnoreList'][] = strtolower($class);
 37        }
 38        
 39        /**
 40         *    Test to see if a test case is in the ignore
 41         *    list.
 42         *    @param string $class        Class name to test.
 43         *    @return boolean             True if should not be run.
 44         *    @access public
 45         *    @static
 46         */
 47        function isIgnored($class) {
 48            $registry = &SimpleTest::_getRegistry();
 49            return in_array(strtolower($class), $registry['IgnoreList']);
 50        }
 51        
 52        /**
 53         *    The base class name is settable here. This is the
 54         *    class that a new mock will inherited from.
 55         *    To modify the generated mocks simply extend the
 56         *    SimpleMock class and set it's name
 57         *    with this method before any mocks are generated.
 58         *    @param string $mock_base        Mock base class to use.
 59         *    @static
 60         *    @access public
 61         */
 62        function setMockBaseClass($mock_base) {
 63            $registry = &SimpleTest::_getRegistry();
 64            $registry['MockBaseClass'] = $mock_base;
 65        }
 66        
 67        /**
 68         *    @deprecated
 69         */
 70        function getMockBaseClass() {
 71            $registry = &SimpleTest::_getRegistry();
 72            return $registry['MockBaseClass'];
 73        }
 74        
 75        /**
 76         *    Sets proxy to use on all requests for when
 77         *    testing from behind a firewall. Set host
 78         *    to false to disable. This will take effect
 79         *    if there are no other proxy settings.
 80         *    @param string $proxy     Proxy host as URL.
 81         *    @param string $username  Proxy username for authentication.
 82         *    @param string $password  Proxy password for authentication.
 83         *    @access public
 84         */
 85        function useProxy($proxy, $username = false, $password = false) {
 86            $registry = &SimpleTest::_getRegistry();
 87            $registry['DefaultProxy'] = $proxy;
 88            $registry['DefaultProxyUsername'] = $username;
 89            $registry['DefaultProxyPassword'] = $password;
 90        }
 91        
 92        /**
 93         *    Accessor for default proxy host.
 94         *    @return string       Proxy URL.
 95         *    @access public
 96         */
 97        function getDefaultProxy() {
 98            $registry = &SimpleTest::_getRegistry();
 99            return $registry['DefaultProxy'];
100        }
101        
102        /**
103         *    Accessor for default proxy username.
104         *    @return string    Proxy username for authentication.
105         *    @access public
106         */
107        function getDefaultProxyUsername() {
108            $registry = &SimpleTest::_getRegistry();
109            return $registry['DefaultProxyUsername'];
110        }
111        
112        /**
113         *    Accessor for default proxy password.
114         *    @return string    Proxy password for authentication.
115         *    @access public
116         */
117        function getDefaultProxyPassword() {
118            $registry = &SimpleTest::_getRegistry();
119            return $registry['DefaultProxyPassword'];
120        }
121        
122        /**
123         *    Sets the current test case instance. This
124         *    global instance can be used by the mock objects
125         *    to send message to the test cases.
126         *    @param SimpleTestCase $test        Test case to register.
127         *    @access public
128         *    @static
129         */
130        function setCurrent(&$test) {
131            $registry = &SimpleTest::_getRegistry();
132            $registry['CurrentTestCase'] = &$test;
133        }
134        
135        /**
136         *    Accessor for current test instance.
137         *    @return SimpleTEstCase        Currently running test.
138         *    @access public
139         *    @static
140         */
141        function &getCurrent() {
142            $registry = &SimpleTest::_getRegistry();
143            return $registry['CurrentTestCase'];
144        }
145        
146        /**
147         *    Accessor for global registry of options.
148         *    @return hash           All stored values.
149         *    @access private
150         *    @static
151         */
152        function &_getRegistry() {
153            static $registry = false;
154            if (! $registry) {
155                $registry = SimpleTest::_getDefaults();
156            }
157            return $registry;
158        }
159        
160        /**
161         *    Constant default values.
162         *    @return hash       All registry defaults.
163         *    @access private
164         *    @static
165         */
166        function _getDefaults() {
167            return array(
168                    'StubBaseClass' => 'SimpleStub',
169                    'MockBaseClass' => 'SimpleMock',
170                    'IgnoreList' => array(),
171                    'DefaultProxy' => false,
172                    'DefaultProxyUsername' => false,
173                    'DefaultProxyPassword' => false);
174        }
175    }
176    
177    /**
178     *    @deprecated
179     */
180    class SimpleTestOptions extends SimpleTest {
181        
182        /**
183         *    @deprecated
184         */
185        function getVersion() {
186            return Simpletest::getVersion();
187        }
188        
189        /**
190         *    @deprecated
191         */
192        function ignore($class) {
193            return Simpletest::ignore($class);
194        }
195        
196        /**
197         *    @deprecated
198         */
199        function isIgnored($class) {
200            return Simpletest::isIgnored($class);
201        }
202        
203        /**
204         *    @deprecated
205         */
206        function setMockBaseClass($mock_base) {
207            return Simpletest::setMockBaseClass($mock_base);
208        }
209        
210        /**
211         *    @deprecated
212         */
213        function getMockBaseClass() {
214            return Simpletest::getMockBaseClass();
215        }
216        
217        /**
218         *    @deprecated
219         */
220        function useProxy($proxy, $username = false, $password = false) {
221            return Simpletest::useProxy($proxy, $username, $password);
222        }
223        
224        /**
225         *    @deprecated
226         */
227        function getDefaultProxy() {
228            return Simpletest::getDefaultProxy();
229        }
230        
231        /**
232         *    @deprecated
233         */
234        function getDefaultProxyUsername() {
235            return Simpletest::getDefaultProxyUsername();
236        }
237        
238        /**
239         *    @deprecated
240         */
241        function getDefaultProxyPassword() {
242            return Simpletest::getDefaultProxyPassword();
243        }
244    }
245?>