phpunit_test_case.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * adapter for SimpleTest to use PHPUnit test cases
  4. * @package SimpleTest
  5. * @subpackage Extensions
  6. * @version $Id: phpunit_test_case.php 1530 2007-06-04 23:35:45Z lastcraft $
  7. */
  8. /**#@+
  9. * include SimpleTest files
  10. */
  11. require_once(dirname(__FILE__) . '/../unit_tester.php');
  12. require_once(dirname(__FILE__) . '/../expectation.php');
  13. /**#@-*/
  14. /**
  15. * Adapter for sourceforge PHPUnit test case to allow
  16. * legacy test cases to be used with SimpleTest.
  17. * @package SimpleTest
  18. * @subpackage Extensions
  19. */
  20. class TestCase extends SimpleTestCase {
  21. /**
  22. * Constructor. Sets the test name.
  23. * @param $label Test name to display.
  24. * @public
  25. */
  26. function TestCase($label = false) {
  27. $this->SimpleTestCase($label);
  28. }
  29. /**
  30. * Sends pass if the test condition resolves true,
  31. * a fail otherwise.
  32. * @param $condition Condition to test true.
  33. * @param $message Message to display.
  34. * @public
  35. */
  36. function assert($condition, $message = false) {
  37. parent::assert(new TrueExpectation(), $condition, $message);
  38. }
  39. /**
  40. * Will test straight equality if set to loose
  41. * typing, or identity if not.
  42. * @param $first First value.
  43. * @param $second Comparison value.
  44. * @param $message Message to display.
  45. * @public
  46. */
  47. function assertEquals($first, $second, $message = false) {
  48. parent::assert(new EqualExpectation($first), $second, $message);
  49. }
  50. /**
  51. * Simple string equality.
  52. * @param $first First value.
  53. * @param $second Comparison value.
  54. * @param $message Message to display.
  55. * @public
  56. */
  57. function assertEqualsMultilineStrings($first, $second, $message = false) {
  58. parent::assert(new EqualExpectation($first), $second, $message);
  59. }
  60. /**
  61. * Tests a regex match.
  62. * @param $pattern Regex to match.
  63. * @param $subject String to search in.
  64. * @param $message Message to display.
  65. * @public
  66. */
  67. function assertRegexp($pattern, $subject, $message = false) {
  68. parent::assert(new PatternExpectation($pattern), $subject, $message);
  69. }
  70. /**
  71. * Sends an error which we interpret as a fail
  72. * with a different message for compatibility.
  73. * @param $message Message to display.
  74. * @public
  75. */
  76. function error($message) {
  77. parent::fail("Error triggered [$message]");
  78. }
  79. /**
  80. * Accessor for name.
  81. * @public
  82. */
  83. function name() {
  84. return $this->getLabel();
  85. }
  86. }
  87. ?>