/lib/limb/tests_runner/lib/simpletest/simpletest.php

https://github.com/limb-php-framework/limb-app-buildman · PHP · 282 lines · 111 code · 26 blank · 145 comment · 5 complexity · 6395b1654ed8e2fffe3c8bca159b2d51 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 4378 2006-10-27 10:04:53Z pachanga $
  7. */
  8. /**#@+
  9. * include SimpleTest files
  10. */
  11. if (version_compare(phpversion(), '5') >= 0) {
  12. require_once(dirname(__FILE__) . '/reflection_php5.php');
  13. } else {
  14. require_once(dirname(__FILE__) . '/reflection_php4.php');
  15. }
  16. /**#@-*/
  17. /**
  18. * Static global directives and options. I hate this
  19. * class. It's a mixture of reference hacks, configuration
  20. * and previous design screw-ups that I have to maintain
  21. * to keep backward compatibility.
  22. * @package SimpleTest
  23. */
  24. class SimpleTest {
  25. /**
  26. * Reads the SimpleTest version from the release file.
  27. * @return string Version string.
  28. * @static
  29. * @access public
  30. */
  31. function getVersion() {
  32. $content = file(dirname(__FILE__) . '/VERSION');
  33. return trim($content[0]);
  34. }
  35. /**
  36. * Sets the name of a test case to ignore, usually
  37. * because the class is an abstract case that should
  38. * not be run. Once PHP4 is dropped this will disappear
  39. * as a public method and "abstract" will rule.
  40. * @param string $class Add a class to ignore.
  41. * @static
  42. * @access public
  43. */
  44. function ignore($class) {
  45. $registry = &SimpleTest::_getRegistry();
  46. $registry['IgnoreList'][strtolower($class)] = true;
  47. }
  48. /**
  49. * Scans the now complete ignore list, and adds
  50. * all parent classes to the list. If a class
  51. * is not a runnable test case, then it's parents
  52. * wouldn't be either. This is syntactic sugar
  53. * to cut down on ommissions of ignore()'s or
  54. * missing abstract declarations. This cannot
  55. * be done whilst loading classes wiithout forcing
  56. * a particular order on the class declarations and
  57. * the ignore() calls. It's nice to havethe ignore()
  58. * calls at the top of teh file.
  59. * @param array $classes Class names of interest.
  60. * @static
  61. * @access public
  62. */
  63. function ignoreParentsIfIgnored($classes) {
  64. $registry = &SimpleTest::_getRegistry();
  65. foreach ($classes as $class) {
  66. if (SimpleTest::isIgnored($class)) {
  67. $reflection = new SimpleReflection($class);
  68. if ($parent = $reflection->getParent()) {
  69. SimpleTest::ignore($parent);
  70. }
  71. }
  72. }
  73. }
  74. /**
  75. * Test to see if a test case is in the ignore
  76. * list. Quite obviously the ignore list should
  77. * be a separate object and will be one day.
  78. * This method is internal to SimpleTest. Don't
  79. * use it.
  80. * @param string $class Class name to test.
  81. * @return boolean True if should not be run.
  82. * @access public
  83. * @static
  84. */
  85. function isIgnored($class) {
  86. $registry = &SimpleTest::_getRegistry();
  87. return isset($registry['IgnoreList'][strtolower($class)]);
  88. }
  89. /**
  90. * @deprecated
  91. */
  92. function setMockBaseClass($mock_base) {
  93. $registry = &SimpleTest::_getRegistry();
  94. $registry['MockBaseClass'] = $mock_base;
  95. }
  96. /**
  97. * @deprecated
  98. */
  99. function getMockBaseClass() {
  100. $registry = &SimpleTest::_getRegistry();
  101. return $registry['MockBaseClass'];
  102. }
  103. /**
  104. * Sets proxy to use on all requests for when
  105. * testing from behind a firewall. Set host
  106. * to false to disable. This will take effect
  107. * if there are no other proxy settings.
  108. * @param string $proxy Proxy host as URL.
  109. * @param string $username Proxy username for authentication.
  110. * @param string $password Proxy password for authentication.
  111. * @access public
  112. */
  113. function useProxy($proxy, $username = false, $password = false) {
  114. $registry = &SimpleTest::_getRegistry();
  115. $registry['DefaultProxy'] = $proxy;
  116. $registry['DefaultProxyUsername'] = $username;
  117. $registry['DefaultProxyPassword'] = $password;
  118. }
  119. /**
  120. * Accessor for default proxy host.
  121. * @return string Proxy URL.
  122. * @access public
  123. */
  124. function getDefaultProxy() {
  125. $registry = &SimpleTest::_getRegistry();
  126. return $registry['DefaultProxy'];
  127. }
  128. /**
  129. * Accessor for default proxy username.
  130. * @return string Proxy username for authentication.
  131. * @access public
  132. */
  133. function getDefaultProxyUsername() {
  134. $registry = &SimpleTest::_getRegistry();
  135. return $registry['DefaultProxyUsername'];
  136. }
  137. /**
  138. * Accessor for default proxy password.
  139. * @return string Proxy password for authentication.
  140. * @access public
  141. */
  142. function getDefaultProxyPassword() {
  143. $registry = &SimpleTest::_getRegistry();
  144. return $registry['DefaultProxyPassword'];
  145. }
  146. /**
  147. * Sets the current test case instance. This
  148. * global instance can be used by the mock objects
  149. * to send message to the test cases.
  150. * @param SimpleTestCase $test Test case to register.
  151. * @access public
  152. * @static
  153. */
  154. function setCurrent(&$test) {
  155. $registry = &SimpleTest::_getRegistry();
  156. $registry['CurrentTestCase'] = &$test;
  157. }
  158. /**
  159. * Accessor for current test instance.
  160. * @return SimpleTEstCase Currently running test.
  161. * @access public
  162. * @static
  163. */
  164. function &getCurrent() {
  165. $registry = &SimpleTest::_getRegistry();
  166. return $registry['CurrentTestCase'];
  167. }
  168. /**
  169. * Accessor for global registry of options.
  170. * @return hash All stored values.
  171. * @access private
  172. * @static
  173. */
  174. function &_getRegistry() {
  175. static $registry = false;
  176. if (! $registry) {
  177. $registry = SimpleTest::_getDefaults();
  178. }
  179. return $registry;
  180. }
  181. /**
  182. * Constant default values.
  183. * @return hash All registry defaults.
  184. * @access private
  185. * @static
  186. */
  187. function _getDefaults() {
  188. return array(
  189. 'StubBaseClass' => 'SimpleStub',
  190. 'MockBaseClass' => 'SimpleMock',
  191. 'IgnoreList' => array(),
  192. 'DefaultProxy' => false,
  193. 'DefaultProxyUsername' => false,
  194. 'DefaultProxyPassword' => false);
  195. }
  196. }
  197. /**
  198. * @deprecated
  199. */
  200. class SimpleTestOptions extends SimpleTest {
  201. /**
  202. * @deprecated
  203. */
  204. function getVersion() {
  205. return Simpletest::getVersion();
  206. }
  207. /**
  208. * @deprecated
  209. */
  210. function ignore($class) {
  211. return Simpletest::ignore($class);
  212. }
  213. /**
  214. * @deprecated
  215. */
  216. function isIgnored($class) {
  217. return Simpletest::isIgnored($class);
  218. }
  219. /**
  220. * @deprecated
  221. */
  222. function setMockBaseClass($mock_base) {
  223. return Simpletest::setMockBaseClass($mock_base);
  224. }
  225. /**
  226. * @deprecated
  227. */
  228. function getMockBaseClass() {
  229. return Simpletest::getMockBaseClass();
  230. }
  231. /**
  232. * @deprecated
  233. */
  234. function useProxy($proxy, $username = false, $password = false) {
  235. return Simpletest::useProxy($proxy, $username, $password);
  236. }
  237. /**
  238. * @deprecated
  239. */
  240. function getDefaultProxy() {
  241. return Simpletest::getDefaultProxy();
  242. }
  243. /**
  244. * @deprecated
  245. */
  246. function getDefaultProxyUsername() {
  247. return Simpletest::getDefaultProxyUsername();
  248. }
  249. /**
  250. * @deprecated
  251. */
  252. function getDefaultProxyPassword() {
  253. return Simpletest::getDefaultProxyPassword();
  254. }
  255. }
  256. ?>