Merge branch 'MDL-29201_20' of git://github.com/timhunt/moodle into MOODLE_20_STABLE
[moodle.git] / lib / simpletestlib / invoker.php
blobb9f81ff5ab4904a04788e9d89adc9f883e87a8ca
1 <?php
2 /**
3 * Base include file for SimpleTest
4 * @package SimpleTest
5 * @subpackage UnitTester
6 * @version $Id$
7 */
9 /**#@+
10 * Includes SimpleTest files and defined the root constant
11 * for dependent libraries.
13 require_once(dirname(__FILE__) . '/errors.php');
14 require_once(dirname(__FILE__) . '/compatibility.php');
15 require_once(dirname(__FILE__) . '/scorer.php');
16 require_once(dirname(__FILE__) . '/expectation.php');
17 require_once(dirname(__FILE__) . '/dumper.php');
18 if (! defined('SIMPLE_TEST')) {
19 define('SIMPLE_TEST', dirname(__FILE__) . '/');
21 /**#@-*/
23 /**
24 * This is called by the class runner to run a
25 * single test method. Will also run the setUp()
26 * and tearDown() methods.
27 * @package SimpleTest
28 * @subpackage UnitTester
30 class SimpleInvoker {
31 var $_test_case;
33 /**
34 * Stashes the test case for later.
35 * @param SimpleTestCase $test_case Test case to run.
37 function SimpleInvoker(&$test_case) {
38 $this->_test_case = &$test_case;
41 /**
42 * Accessor for test case being run.
43 * @return SimpleTestCase Test case.
44 * @access public
46 function &getTestCase() {
47 return $this->_test_case;
50 /**
51 * Runs test level set up. Used for changing
52 * the mechanics of base test cases.
53 * @param string $method Test method to call.
54 * @access public
56 function before($method) {
57 $this->_test_case->before($method);
60 /**
61 * Invokes a test method and buffered with setUp()
62 * and tearDown() calls.
63 * @param string $method Test method to call.
64 * @access public
66 function invoke($method) {
67 $this->_test_case->setUp();
68 // moodle hack start
69 // note: this breaks PHP4 compatibility!
70 $rethrow = null;
71 try {
72 $this->_test_case->$method();
73 } catch (Exception $e) {
74 $rethrow = $e;
76 $this->_test_case->tearDown();
77 if ($rethrow) {
78 throw $rethrow;
80 // moodle hack end
83 /**
84 * Runs test level clean up. Used for changing
85 * the mechanics of base test cases.
86 * @param string $method Test method to call.
87 * @access public
89 function after($method) {
90 $this->_test_case->after($method);
94 /**
95 * Do nothing decorator. Just passes the invocation
96 * straight through.
97 * @package SimpleTest
98 * @subpackage UnitTester
100 class SimpleInvokerDecorator {
101 var $_invoker;
104 * Stores the invoker to wrap.
105 * @param SimpleInvoker $invoker Test method runner.
107 function SimpleInvokerDecorator(&$invoker) {
108 $this->_invoker = &$invoker;
112 * Accessor for test case being run.
113 * @return SimpleTestCase Test case.
114 * @access public
116 function &getTestCase() {
117 return $this->_invoker->getTestCase();
121 * Runs test level set up. Used for changing
122 * the mechanics of base test cases.
123 * @param string $method Test method to call.
124 * @access public
126 function before($method) {
127 $this->_invoker->before($method);
131 * Invokes a test method and buffered with setUp()
132 * and tearDown() calls.
133 * @param string $method Test method to call.
134 * @access public
136 function invoke($method) {
137 $this->_invoker->invoke($method);
141 * Runs test level clean up. Used for changing
142 * the mechanics of base test cases.
143 * @param string $method Test method to call.
144 * @access public
146 function after($method) {
147 $this->_invoker->after($method);