invoker.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Base include file for SimpleTest
  4. * @package SimpleTest
  5. * @subpackage UnitTester
  6. * @version $Id$
  7. */
  8. /**#@+
  9. * Includes SimpleTest files and defined the root constant
  10. * for dependent libraries.
  11. */
  12. require_once(dirname(__FILE__) . '/errors.php');
  13. require_once(dirname(__FILE__) . '/compatibility.php');
  14. require_once(dirname(__FILE__) . '/scorer.php');
  15. require_once(dirname(__FILE__) . '/expectation.php');
  16. require_once(dirname(__FILE__) . '/dumper.php');
  17. if (! defined('SIMPLE_TEST')) {
  18. define('SIMPLE_TEST', dirname(__FILE__) . '/');
  19. }
  20. /**#@-*/
  21. /**
  22. * This is called by the class runner to run a
  23. * single test method. Will also run the setUp()
  24. * and tearDown() methods.
  25. * @package SimpleTest
  26. * @subpackage UnitTester
  27. */
  28. class SimpleInvoker {
  29. private $test_case;
  30. /**
  31. * Stashes the test case for later.
  32. * @param SimpleTestCase $test_case Test case to run.
  33. */
  34. function __construct($test_case) {
  35. $this->test_case = $test_case;
  36. }
  37. /**
  38. * Accessor for test case being run.
  39. * @return SimpleTestCase Test case.
  40. * @access public
  41. */
  42. function getTestCase() {
  43. return $this->test_case;
  44. }
  45. /**
  46. * Runs test level set up. Used for changing
  47. * the mechanics of base test cases.
  48. * @param string $method Test method to call.
  49. * @access public
  50. */
  51. function before($method) {
  52. $this->test_case->before($method);
  53. }
  54. /**
  55. * Invokes a test method and buffered with setUp()
  56. * and tearDown() calls.
  57. * @param string $method Test method to call.
  58. * @access public
  59. */
  60. function invoke($method) {
  61. $this->test_case->setUp();
  62. $this->test_case->$method();
  63. $this->test_case->tearDown();
  64. }
  65. /**
  66. * Runs test level clean up. Used for changing
  67. * the mechanics of base test cases.
  68. * @param string $method Test method to call.
  69. * @access public
  70. */
  71. function after($method) {
  72. $this->test_case->after($method);
  73. }
  74. }
  75. /**
  76. * Do nothing decorator. Just passes the invocation
  77. * straight through.
  78. * @package SimpleTest
  79. * @subpackage UnitTester
  80. */
  81. class SimpleInvokerDecorator {
  82. private $invoker;
  83. /**
  84. * Stores the invoker to wrap.
  85. * @param SimpleInvoker $invoker Test method runner.
  86. */
  87. function __construct($invoker) {
  88. $this->invoker = $invoker;
  89. }
  90. /**
  91. * Accessor for test case being run.
  92. * @return SimpleTestCase Test case.
  93. * @access public
  94. */
  95. function getTestCase() {
  96. return $this->invoker->getTestCase();
  97. }
  98. /**
  99. * Runs test level set up. Used for changing
  100. * the mechanics of base test cases.
  101. * @param string $method Test method to call.
  102. * @access public
  103. */
  104. function before($method) {
  105. $this->invoker->before($method);
  106. }
  107. /**
  108. * Invokes a test method and buffered with setUp()
  109. * and tearDown() calls.
  110. * @param string $method Test method to call.
  111. * @access public
  112. */
  113. function invoke($method) {
  114. $this->invoker->invoke($method);
  115. }
  116. /**
  117. * Runs test level clean up. Used for changing
  118. * the mechanics of base test cases.
  119. * @param string $method Test method to call.
  120. * @access public
  121. */
  122. function after($method) {
  123. $this->invoker->after($method);
  124. }
  125. }
  126. ?>