recorder.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * base include file for SimpleTest
  4. * @package SimpleTest
  5. * @subpackage Extensions
  6. * @author Rene vd O (original code)
  7. * @author Perrick Penet
  8. * @author Marcus Baker
  9. * @version $Id: recorder.php 2011 2011-04-29 08:22:48Z pp11 $
  10. */
  11. /**
  12. * include other SimpleTest class files
  13. */
  14. require_once(dirname(__FILE__) . '/scorer.php');
  15. /**
  16. * A single test result.
  17. * @package SimpleTest
  18. * @subpackage Extensions
  19. */
  20. abstract class SimpleResult {
  21. public $time;
  22. public $breadcrumb;
  23. public $message;
  24. /**
  25. * Records the test result as public members.
  26. * @param array $breadcrumb Test stack at the time of the event.
  27. * @param string $message The messsage to the human.
  28. */
  29. function __construct($breadcrumb, $message) {
  30. list($this->time, $this->breadcrumb, $this->message) =
  31. array(time(), $breadcrumb, $message);
  32. }
  33. }
  34. /**
  35. * A single pass captured for later.
  36. * @package SimpleTest
  37. * @subpackage Extensions
  38. */
  39. class SimpleResultOfPass extends SimpleResult { }
  40. /**
  41. * A single failure captured for later.
  42. * @package SimpleTest
  43. * @subpackage Extensions
  44. */
  45. class SimpleResultOfFail extends SimpleResult { }
  46. /**
  47. * A single exception captured for later.
  48. * @package SimpleTest
  49. * @subpackage Extensions
  50. */
  51. class SimpleResultOfException extends SimpleResult { }
  52. /**
  53. * Array-based test recorder. Returns an array
  54. * with timestamp, status, test name and message for each pass and failure.
  55. * @package SimpleTest
  56. * @subpackage Extensions
  57. */
  58. class Recorder extends SimpleReporterDecorator {
  59. public $results = array();
  60. /**
  61. * Stashes the pass as a SimpleResultOfPass
  62. * for later retrieval.
  63. * @param string $message Pass message to be displayed
  64. * eventually.
  65. */
  66. function paintPass($message) {
  67. parent::paintPass($message);
  68. $this->results[] = new SimpleResultOfPass(parent::getTestList(), $message);
  69. }
  70. /**
  71. * Stashes the fail as a SimpleResultOfFail
  72. * for later retrieval.
  73. * @param string $message Failure message to be displayed
  74. * eventually.
  75. */
  76. function paintFail($message) {
  77. parent::paintFail($message);
  78. $this->results[] = new SimpleResultOfFail(parent::getTestList(), $message);
  79. }
  80. /**
  81. * Stashes the exception as a SimpleResultOfException
  82. * for later retrieval.
  83. * @param string $message Exception message to be displayed
  84. * eventually.
  85. */
  86. function paintException($message) {
  87. parent::paintException($message);
  88. $this->results[] = new SimpleResultOfException(parent::getTestList(), $message);
  89. }
  90. }
  91. ?>