Removed 'base_path' from AkInstaller->setInstalledVersion because Ak:make_dir can...
[akelos.git] / vendor / simpletest / runner.php
blob5becf0b474a7c61224233983c9def5702992bcce
1 <?php
2 /**
3 * Base include file for SimpleTest
4 * @package SimpleTest
5 * @subpackage UnitTester
6 * @version $Id: runner.php,v 1.31 2005/08/03 23:25:13 lastcraft Exp $
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 * Invokes a test method and buffered with setUp()
52 * and tearDown() calls.
53 * @param string $method Test method to call.
54 * @access public
56 function invoke($method) {
57 $this->_test_case->before($method);
58 $this->_test_case->setUp();
59 $this->_test_case->$method();
60 $this->_test_case->tearDown();
61 $this->_test_case->after($method);
65 /**
66 * Do nothing decorator. Just passes the invocation
67 * straight through.
68 * @package SimpleTest
69 * @subpackage UnitTester
71 class SimpleInvokerDecorator {
72 var $_invoker;
74 /**
75 * Stores the invoker to wrap.
76 * @param SimpleInvoker $invoker Test method runner.
78 function SimpleInvokerDecorator(&$invoker) {
79 $this->_invoker = &$invoker;
82 /**
83 * Accessor for test case being run.
84 * @return SimpleTestCase Test case.
85 * @access public
87 function &getTestCase() {
88 return $this->_invoker->getTestCase();
91 /**
92 * Invokes a test method and buffered with setUp()
93 * and tearDown() calls.
94 * @param string $method Test method to call.
95 * @access public
97 function invoke($method) {
98 $this->_invoker->invoke($method);
103 * Extension that traps errors into an error queue.
104 * @package SimpleTest
105 * @subpackage UnitTester
107 class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator {
111 * Stores the invoker to wrap.
112 * @param SimpleInvoker $invoker Test method runner.
114 function SimpleErrorTrappingInvoker(&$invoker) {
115 $this->SimpleInvokerDecorator($invoker);
119 * Invokes a test method and dispatches any
120 * untrapped errors. Called back from
121 * the visiting runner.
122 * @param string $method Test method to call.
123 * @access public
125 function invoke($method) {
126 set_error_handler('simpleTestErrorHandler');
127 parent::invoke($method);
128 $queue = &SimpleErrorQueue::instance();
129 while (list($severity, $message, $file, $line, $globals) = $queue->extract()) {
130 $test_case = &$this->getTestCase();
131 $test_case->error($severity, $message, $file, $line, $globals);
133 restore_error_handler();
138 * The standard runner. Will run every method starting
139 * with test.
140 * @package SimpleTest
141 * @subpackage UnitTester
143 class SimpleRunner {
144 var $_test_case;
145 var $_scorer;
148 * Takes in the test case and reporter to mediate between.
149 * @param SimpleTestCase $test_case Test case to run.
150 * @param SimpleScorer $scorer Reporter to receive events.
152 function SimpleRunner(&$test_case, &$scorer) {
153 $this->_test_case = &$test_case;
154 $this->_scorer = &$scorer;
158 * Accessor for test case being run.
159 * @return SimpleTestCase Test case.
160 * @access public
162 function &getTestCase() {
163 return $this->_test_case;
167 * Runs the test methods in the test case, or not if the
168 * scorer blocks it.
169 * @param SimpleTest $test_case Test case to run test on.
170 * @param string $method Name of test method.
171 * @access public
173 function run() {
174 $methods = get_class_methods(get_class($this->_test_case));
175 $invoker = &$this->_test_case->createInvoker();
176 foreach ($methods as $method) {
177 if (! $this->_isTest($method)) {
178 continue;
180 if ($this->_isConstructor($method)) {
181 continue;
183 if ($this->_scorer->shouldInvoke($this->_test_case->getLabel(), $method)) {
184 $invoker->invoke($method);
190 * Tests to see if the method is the constructor and
191 * so should be ignored.
192 * @param string $method Method name to try.
193 * @return boolean True if constructor.
194 * @access protected
196 function _isConstructor($method) {
197 return SimpleTestCompatibility::isA(
198 $this->_test_case,
199 strtolower($method));
203 * Tests to see if the method is a test that should
204 * be run. Currently any method that starts with 'test'
205 * is a candidate.
206 * @param string $method Method name to try.
207 * @return boolean True if test method.
208 * @access protected
210 function _isTest($method) {
211 return strtolower(substr($method, 0, 4)) == 'test';
215 * Paints the start of a test method.
216 * @param string $test_name Name of test or other label.
217 * @access public
219 function paintMethodStart($test_name) {
220 $this->_scorer->paintMethodStart($test_name);
224 * Paints the end of a test method.
225 * @param string $test_name Name of test or other label.
226 * @access public
228 function paintMethodEnd($test_name) {
229 $this->_scorer->paintMethodEnd($test_name);
233 * Chains to the wrapped reporter.
234 * @param string $message Message is ignored.
235 * @access public
237 function paintPass($message) {
238 $this->_scorer->paintPass($message);
242 * Chains to the wrapped reporter.
243 * @param string $message Message is ignored.
244 * @access public
246 function paintFail($message) {
247 $this->_scorer->paintFail($message);
251 * Chains to the wrapped reporter.
252 * @param string $message Text of error formatted by
253 * the test case.
254 * @access public
256 function paintError($message) {
257 $this->_scorer->paintError($message);
261 * Chains to the wrapped reporter.
262 * @param Exception $exception Object thrown.
263 * @access public
265 function paintException($exception) {
266 $this->_scorer->paintException($exception);
270 * Chains to the wrapped reporter.
271 * @param string $message Text to display.
272 * @access public
274 function paintMessage($message) {
275 $this->_scorer->paintMessage($message);
279 * Chains to the wrapped reporter.
280 * @param string $message Text to display.
281 * @access public
283 function paintFormattedMessage($message) {
284 $this->_scorer->paintFormattedMessage($message);
288 * Chains to the wrapped reporter.
289 * @param string $type Event type as text.
290 * @param mixed $payload Message or object.
291 * @return boolean Should return false if this
292 * type of signal should fail the
293 * test suite.
294 * @access public
296 function paintSignal($type, &$payload) {
297 $this->_scorer->paintSignal($type, $payload);