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