Fixing content type ordering when content_type is not defined.
[akelos.git] / vendor / simpletest / scorer.php
blobcd5866e83e95e606dee971048016a867f86f4c27
1 <?php
2 /**
3 * base include file for SimpleTest
4 * @package SimpleTest
5 * @subpackage UnitTester
6 * @version $Id: scorer.php,v 1.12 2006/02/06 06:05:18 lastcraft Exp $
7 */
9 /**#@+*/
10 require_once(dirname(__FILE__) . '/invoker.php');
11 /**#@-*/
13 /**
14 * Can recieve test events and display them. Display
15 * is achieved by making display methods available
16 * and visiting the incoming event.
17 * @package SimpleTest
18 * @subpackage UnitTester
19 * @abstract
21 class SimpleScorer {
22 var $_passes;
23 var $_fails;
24 var $_exceptions;
25 var $_is_dry_run;
27 /**
28 * Starts the test run with no results.
29 * @access public
31 function SimpleScorer() {
32 $this->_passes = 0;
33 $this->_fails = 0;
34 $this->_exceptions = 0;
35 $this->_is_dry_run = false;
38 /**
39 * Signals that the next evaluation will be a dry
40 * run. That is, the structure events will be
41 * recorded, but no tests will be run.
42 * @param boolean $is_dry Dry run if true.
43 * @access public
45 function makeDry($is_dry = true) {
46 $this->_is_dry_run = $is_dry;
49 /**
50 * The reporter has a veto on what should be run.
51 * @param string $test_case_name name of test case.
52 * @param string $method Name of test method.
53 * @access public
55 function shouldInvoke($test_case_name, $method) {
56 return ! $this->_is_dry_run;
59 /**
60 * Can wrap the invoker in preperation for running
61 * a test.
62 * @param SimpleInvoker $invoker Individual test runner.
63 * @return SimpleInvoker Wrapped test runner.
64 * @access public
66 function &createInvoker(&$invoker) {
67 return $invoker;
70 /**
71 * Accessor for current status. Will be false
72 * if there have been any failures or exceptions.
73 * Used for command line tools.
74 * @return boolean True if no failures.
75 * @access public
77 function getStatus() {
78 if ($this->_exceptions + $this->_fails > 0) {
79 return false;
81 return true;
84 /**
85 * Paints the start of a group test.
86 * @param string $test_name Name of test or other label.
87 * @param integer $size Number of test cases starting.
88 * @access public
90 function paintGroupStart($test_name, $size) {
93 /**
94 * Paints the end of a group test.
95 * @param string $test_name Name of test or other label.
96 * @access public
98 function paintGroupEnd($test_name) {
102 * Paints the start of a test case.
103 * @param string $test_name Name of test or other label.
104 * @access public
106 function paintCaseStart($test_name) {
110 * Paints the end of a test case.
111 * @param string $test_name Name of test or other label.
112 * @access public
114 function paintCaseEnd($test_name) {
118 * Paints the start of a test method.
119 * @param string $test_name Name of test or other label.
120 * @access public
122 function paintMethodStart($test_name) {
126 * Paints the end of a test method.
127 * @param string $test_name Name of test or other label.
128 * @access public
130 function paintMethodEnd($test_name) {
134 * Increments the pass count.
135 * @param string $message Message is ignored.
136 * @access public
138 function paintPass($message) {
139 $this->_passes++;
143 * Increments the fail count.
144 * @param string $message Message is ignored.
145 * @access public
147 function paintFail($message) {
148 $this->_fails++;
152 * Deals with PHP 4 throwing an error or PHP 5
153 * throwing an exception.
154 * @param string $message Text of error formatted by
155 * the test case.
156 * @access public
158 function paintError($message) {
159 $this->_exceptions++;
163 * Accessor for the number of passes so far.
164 * @return integer Number of passes.
165 * @access public
167 function getPassCount() {
168 return $this->_passes;
172 * Accessor for the number of fails so far.
173 * @return integer Number of fails.
174 * @access public
176 function getFailCount() {
177 return $this->_fails;
181 * Accessor for the number of untrapped errors
182 * so far.
183 * @return integer Number of exceptions.
184 * @access public
186 function getExceptionCount() {
187 return $this->_exceptions;
191 * Paints a simple supplementary message.
192 * @param string $message Text to display.
193 * @access public
195 function paintMessage($message) {
199 * Paints a formatted ASCII message such as a
200 * variable dump.
201 * @param string $message Text to display.
202 * @access public
204 function paintFormattedMessage($message) {
208 * By default just ignores user generated events.
209 * @param string $type Event type as text.
210 * @param mixed $payload Message or object.
211 * @access public
213 function paintSignal($type, $payload) {
218 * Recipient of generated test messages that can display
219 * page footers and headers. Also keeps track of the
220 * test nesting. This is the main base class on which
221 * to build the finished test (page based) displays.
222 * @package SimpleTest
223 * @subpackage UnitTester
225 class SimpleReporter extends SimpleScorer {
226 var $_test_stack;
227 var $_size;
228 var $_progress;
231 * Starts the display with no results in.
232 * @access public
234 function SimpleReporter() {
235 $this->SimpleScorer();
236 $this->_test_stack = array();
237 $this->_size = null;
238 $this->_progress = 0;
242 * Paints the start of a group test. Will also paint
243 * the page header and footer if this is the
244 * first test. Will stash the size if the first
245 * start.
246 * @param string $test_name Name of test that is starting.
247 * @param integer $size Number of test cases starting.
248 * @access public
250 function paintGroupStart($test_name, $size) {
251 if (! isset($this->_size)) {
252 $this->_size = $size;
254 if (count($this->_test_stack) == 0) {
255 $this->paintHeader($test_name);
257 $this->_test_stack[] = $test_name;
261 * Paints the end of a group test. Will paint the page
262 * footer if the stack of tests has unwound.
263 * @param string $test_name Name of test that is ending.
264 * @param integer $progress Number of test cases ending.
265 * @access public
267 function paintGroupEnd($test_name) {
268 array_pop($this->_test_stack);
269 if (count($this->_test_stack) == 0) {
270 $this->paintFooter($test_name);
275 * Paints the start of a test case. Will also paint
276 * the page header and footer if this is the
277 * first test. Will stash the size if the first
278 * start.
279 * @param string $test_name Name of test that is starting.
280 * @access public
282 function paintCaseStart($test_name) {
283 if (! isset($this->_size)) {
284 $this->_size = 1;
286 if (count($this->_test_stack) == 0) {
287 $this->paintHeader($test_name);
289 $this->_test_stack[] = $test_name;
293 * Paints the end of a test case. Will paint the page
294 * footer if the stack of tests has unwound.
295 * @param string $test_name Name of test that is ending.
296 * @access public
298 function paintCaseEnd($test_name) {
299 $this->_progress++;
300 array_pop($this->_test_stack);
301 if (count($this->_test_stack) == 0) {
302 $this->paintFooter($test_name);
307 * Paints the start of a test method.
308 * @param string $test_name Name of test that is starting.
309 * @access public
311 function paintMethodStart($test_name) {
312 $this->_test_stack[] = $test_name;
316 * Paints the end of a test method. Will paint the page
317 * footer if the stack of tests has unwound.
318 * @param string $test_name Name of test that is ending.
319 * @access public
321 function paintMethodEnd($test_name) {
322 array_pop($this->_test_stack);
326 * Paints the test document header.
327 * @param string $test_name First test top level
328 * to start.
329 * @access public
330 * @abstract
332 function paintHeader($test_name) {
336 * Paints the test document footer.
337 * @param string $test_name The top level test.
338 * @access public
339 * @abstract
341 function paintFooter($test_name) {
345 * Accessor for internal test stack. For
346 * subclasses that need to see the whole test
347 * history for display purposes.
348 * @return array List of methods in nesting order.
349 * @access public
351 function getTestList() {
352 return $this->_test_stack;
356 * Accessor for total test size in number
357 * of test cases. Null until the first
358 * test is started.
359 * @return integer Total number of cases at start.
360 * @access public
362 function getTestCaseCount() {
363 return $this->_size;
367 * Accessor for the number of test cases
368 * completed so far.
369 * @return integer Number of ended cases.
370 * @access public
372 function getTestCaseProgress() {
373 return $this->_progress;
377 * Static check for running in the comand line.
378 * @return boolean True if CLI.
379 * @access public
380 * @static
382 function inCli() {
383 return php_sapi_name() == 'cli';
388 * For modifying the behaviour of the visual reporters.
389 * @package SimpleTest
390 * @subpackage UnitTester
392 class SimpleReporterDecorator {
393 var $_reporter;
396 * Mediates between teh reporter and the test case.
397 * @param SimpleScorer $reporter Reporter to receive events.
399 function SimpleReporterDecorator(&$reporter) {
400 $this->_reporter = &$reporter;
404 * Signals that the next evaluation will be a dry
405 * run. That is, the structure events will be
406 * recorded, but no tests will be run.
407 * @param boolean $is_dry Dry run if true.
408 * @access public
410 function makeDry($is_dry = true) {
411 $this->_reporter->makeDry($is_dry);
415 * Accessor for current status. Will be false
416 * if there have been any failures or exceptions.
417 * Used for command line tools.
418 * @return boolean True if no failures.
419 * @access public
421 function getStatus() {
422 return $this->_reporter->getStatus();
426 * The reporter has a veto on what should be run.
427 * @param string $test_case_name name of test case.
428 * @param string $method Name of test method.
429 * @return boolean True if test should be run.
430 * @access public
432 function shouldInvoke($test_case_name, $method) {
433 return $this->_reporter->shouldInvoke($test_case_name, $method);
437 * Can wrap the invoker in preperation for running
438 * a test.
439 * @param SimpleInvoker $invoker Individual test runner.
440 * @return SimpleInvoker Wrapped test runner.
441 * @access public
443 function &createInvoker(&$invoker) {
444 return $this->_reporter->createInvoker($invoker);
448 * Paints the start of a group test.
449 * @param string $test_name Name of test or other label.
450 * @param integer $size Number of test cases starting.
451 * @access public
453 function paintGroupStart($test_name, $size) {
454 $this->_reporter->paintGroupStart($test_name, $size);
458 * Paints the end of a group test.
459 * @param string $test_name Name of test or other label.
460 * @access public
462 function paintGroupEnd($test_name) {
463 $this->_reporter->paintGroupEnd($test_name);
467 * Paints the start of a test case.
468 * @param string $test_name Name of test or other label.
469 * @access public
471 function paintCaseStart($test_name) {
472 $this->_reporter->paintCaseStart($test_name);
476 * Paints the end of a test case.
477 * @param string $test_name Name of test or other label.
478 * @access public
480 function paintCaseEnd($test_name) {
481 $this->_reporter->paintCaseEnd($test_name);
485 * Paints the start of a test method.
486 * @param string $test_name Name of test or other label.
487 * @access public
489 function paintMethodStart($test_name) {
490 $this->_reporter->paintMethodStart($test_name);
494 * Paints the end of a test method.
495 * @param string $test_name Name of test or other label.
496 * @access public
498 function paintMethodEnd($test_name) {
499 $this->_reporter->paintMethodEnd($test_name);
503 * Chains to the wrapped reporter.
504 * @param string $message Message is ignored.
505 * @access public
507 function paintPass($message) {
508 $this->_reporter->paintPass($message);
512 * Chains to the wrapped reporter.
513 * @param string $message Message is ignored.
514 * @access public
516 function paintFail($message) {
517 $this->_reporter->paintFail($message);
521 * Chains to the wrapped reporter.
522 * @param string $message Text of error formatted by
523 * the test case.
524 * @access public
526 function paintError($message) {
527 $this->_reporter->paintError($message);
531 * Chains to the wrapped reporter.
532 * @param string $message Text to display.
533 * @access public
535 function paintMessage($message) {
536 $this->_reporter->paintMessage($message);
540 * Chains to the wrapped reporter.
541 * @param string $message Text to display.
542 * @access public
544 function paintFormattedMessage($message) {
545 $this->_reporter->paintFormattedMessage($message);
549 * Chains to the wrapped reporter.
550 * @param string $type Event type as text.
551 * @param mixed $payload Message or object.
552 * @return boolean Should return false if this
553 * type of signal should fail the
554 * test suite.
555 * @access public
557 function paintSignal($type, &$payload) {
558 $this->_reporter->paintSignal($type, $payload);
563 * For sending messages to multiple reporters at
564 * the same time.
565 * @package SimpleTest
566 * @subpackage UnitTester
568 class MultipleReporter {
569 var $_reporters = array();
572 * Adds a reporter to the subscriber list.
573 * @param SimpleScorer $reporter Reporter to receive events.
574 * @access public
576 function attachReporter(&$reporter) {
577 $this->_reporters[] = &$reporter;
581 * Signals that the next evaluation will be a dry
582 * run. That is, the structure events will be
583 * recorded, but no tests will be run.
584 * @param boolean $is_dry Dry run if true.
585 * @access public
587 function makeDry($is_dry = true) {
588 for ($i = 0; $i < count($this->_reporters); $i++) {
589 $this->_reporters[$i]->makeDry($is_dry);
594 * Accessor for current status. Will be false
595 * if there have been any failures or exceptions.
596 * If any reporter reports a failure, the whole
597 * suite fails.
598 * @return boolean True if no failures.
599 * @access public
601 function getStatus() {
602 for ($i = 0; $i < count($this->_reporters); $i++) {
603 if (! $this->_reporters[$i]->getStatus()) {
604 return false;
607 return true;
611 * The reporter has a veto on what should be run.
612 * It requires all reporters to want to run the method.
613 * @param string $test_case_name name of test case.
614 * @param string $method Name of test method.
615 * @access public
617 function shouldInvoke($test_case_name, $method) {
618 for ($i = 0; $i < count($this->_reporters); $i++) {
619 if (! $this->_reporters[$i]->shouldInvoke($test_case_name, $method)) {
620 return false;
623 return true;
627 * Every reporter gets a chance to wrap the invoker.
628 * @param SimpleInvoker $invoker Individual test runner.
629 * @return SimpleInvoker Wrapped test runner.
630 * @access public
632 function &createInvoker(&$invoker) {
633 for ($i = 0; $i < count($this->_reporters); $i++) {
634 $invoker = &$this->_reporters[$i]->createInvoker($invoker);
636 return $invoker;
640 * Paints the start of a group test.
641 * @param string $test_name Name of test or other label.
642 * @param integer $size Number of test cases starting.
643 * @access public
645 function paintGroupStart($test_name, $size) {
646 for ($i = 0; $i < count($this->_reporters); $i++) {
647 $this->_reporters[$i]->paintGroupStart($test_name, $size);
652 * Paints the end of a group test.
653 * @param string $test_name Name of test or other label.
654 * @access public
656 function paintGroupEnd($test_name) {
657 for ($i = 0; $i < count($this->_reporters); $i++) {
658 $this->_reporters[$i]->paintGroupEnd($test_name);
663 * Paints the start of a test case.
664 * @param string $test_name Name of test or other label.
665 * @access public
667 function paintCaseStart($test_name) {
668 for ($i = 0; $i < count($this->_reporters); $i++) {
669 $this->_reporters[$i]->paintCaseStart($test_name);
674 * Paints the end of a test case.
675 * @param string $test_name Name of test or other label.
676 * @access public
678 function paintCaseEnd($test_name) {
679 for ($i = 0; $i < count($this->_reporters); $i++) {
680 $this->_reporters[$i]->paintCaseEnd($test_name);
685 * Paints the start of a test method.
686 * @param string $test_name Name of test or other label.
687 * @access public
689 function paintMethodStart($test_name) {
690 for ($i = 0; $i < count($this->_reporters); $i++) {
691 $this->_reporters[$i]->paintMethodStart($test_name);
696 * Paints the end of a test method.
697 * @param string $test_name Name of test or other label.
698 * @access public
700 function paintMethodEnd($test_name) {
701 for ($i = 0; $i < count($this->_reporters); $i++) {
702 $this->_reporters[$i]->paintMethodEnd($test_name);
707 * Chains to the wrapped reporter.
708 * @param string $message Message is ignored.
709 * @access public
711 function paintPass($message) {
712 for ($i = 0; $i < count($this->_reporters); $i++) {
713 $this->_reporters[$i]->paintPass($message);
718 * Chains to the wrapped reporter.
719 * @param string $message Message is ignored.
720 * @access public
722 function paintFail($message) {
723 for ($i = 0; $i < count($this->_reporters); $i++) {
724 $this->_reporters[$i]->paintFail($message);
729 * Chains to the wrapped reporter.
730 * @param string $message Text of error formatted by
731 * the test case.
732 * @access public
734 function paintError($message) {
735 for ($i = 0; $i < count($this->_reporters); $i++) {
736 $this->_reporters[$i]->paintError($message);
741 * Chains to the wrapped reporter.
742 * @param string $message Text to display.
743 * @access public
745 function paintMessage($message) {
746 for ($i = 0; $i < count($this->_reporters); $i++) {
747 $this->_reporters[$i]->paintMessage($message);
752 * Chains to the wrapped reporter.
753 * @param string $message Text to display.
754 * @access public
756 function paintFormattedMessage($message) {
757 for ($i = 0; $i < count($this->_reporters); $i++) {
758 $this->_reporters[$i]->paintFormattedMessage($message);
763 * Chains to the wrapped reporter.
764 * @param string $type Event type as text.
765 * @param mixed $payload Message or object.
766 * @return boolean Should return false if this
767 * type of signal should fail the
768 * test suite.
769 * @access public
771 function paintSignal($type, &$payload) {
772 for ($i = 0; $i < count($this->_reporters); $i++) {
773 $this->_reporters[$i]->paintSignal($type, $payload);