test.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // $Id: test.php 1748 2008-04-14 01:50:41Z lastcraft $
  3. require_once dirname(__FILE__) . '/../../autorun.php';
  4. require_once dirname(__FILE__) . '/../testdox.php';
  5. // uncomment to see test dox in action
  6. //SimpleTest::prefer(new TestDoxReporter());
  7. class TestOfTestDoxReporter extends UnitTestCase
  8. {
  9. function testIsAnInstanceOfSimpleScorerAndReporter() {
  10. $dox = new TestDoxReporter();
  11. $this->assertIsA($dox, 'SimpleScorer');
  12. $this->assertIsA($dox, 'SimpleReporter');
  13. }
  14. function testOutputsNameOfTestCase() {
  15. $dox = new TestDoxReporter();
  16. ob_start();
  17. $dox->paintCaseStart('TestOfTestDoxReporter');
  18. $buffer = ob_get_clean();
  19. $this->assertPattern('/^TestDoxReporter/', $buffer);
  20. }
  21. function testOutputOfTestCaseNameFilteredByConstructParameter() {
  22. $dox = new TestDoxReporter('/^(.*)Test$/');
  23. ob_start();
  24. $dox->paintCaseStart('SomeGreatWidgetTest');
  25. $buffer = ob_get_clean();
  26. $this->assertPattern('/^SomeGreatWidget/', $buffer);
  27. }
  28. function testIfTest_case_patternIsEmptyAssumeEverythingMatches() {
  29. $dox = new TestDoxReporter('');
  30. ob_start();
  31. $dox->paintCaseStart('TestOfTestDoxReporter');
  32. $buffer = ob_get_clean();
  33. $this->assertPattern('/^TestOfTestDoxReporter/', $buffer);
  34. }
  35. function testEmptyLineInsertedWhenCaseEnds() {
  36. $dox = new TestDoxReporter();
  37. ob_start();
  38. $dox->paintCaseEnd('TestOfTestDoxReporter');
  39. $buffer = ob_get_clean();
  40. $this->assertEqual("\n", $buffer);
  41. }
  42. function testPaintsTestMethodInTestDoxFormat() {
  43. $dox = new TestDoxReporter();
  44. ob_start();
  45. $dox->paintMethodStart('testSomeGreatTestCase');
  46. $buffer = ob_get_clean();
  47. $this->assertEqual("- some great test case", $buffer);
  48. unset($buffer);
  49. $random = rand(100, 200);
  50. ob_start();
  51. $dox->paintMethodStart("testRandomNumberIs{$random}");
  52. $buffer = ob_get_clean();
  53. $this->assertEqual("- random number is {$random}", $buffer);
  54. }
  55. function testDoesNotOutputAnythingOnNoneTestMethods() {
  56. $dox = new TestDoxReporter();
  57. ob_start();
  58. $dox->paintMethodStart('nonMatchingMethod');
  59. $buffer = ob_get_clean();
  60. $this->assertEqual('', $buffer);
  61. }
  62. function testPaintMethodAddLineBreak() {
  63. $dox = new TestDoxReporter();
  64. ob_start();
  65. $dox->paintMethodEnd('someMethod');
  66. $buffer = ob_get_clean();
  67. $this->assertEqual("\n", $buffer);
  68. }
  69. function testProperlySpacesSingleLettersInMethodName() {
  70. $dox = new TestDoxReporter();
  71. ob_start();
  72. $dox->paintMethodStart('testAVerySimpleAgainAVerySimpleMethod');
  73. $buffer = ob_get_clean();
  74. $this->assertEqual('- a very simple again a very simple method', $buffer);
  75. }
  76. function testOnFailureThisPrintsFailureNotice() {
  77. $dox = new TestDoxReporter();
  78. ob_start();
  79. $dox->paintFail('');
  80. $buffer = ob_get_clean();
  81. $this->assertEqual(' [FAILED]', $buffer);
  82. }
  83. function testWhenMatchingMethodNamesTestPrefixIsCaseInsensitive() {
  84. $dox = new TestDoxReporter();
  85. ob_start();
  86. $dox->paintMethodStart('TESTSupportsAllUppercaseTestPrefixEvenThoughIDoNotKnowWhyYouWouldDoThat');
  87. $buffer = ob_get_clean();
  88. $this->assertEqual(
  89. '- supports all uppercase test prefix even though i do not know why you would do that',
  90. $buffer
  91. );
  92. }
  93. }
  94. ?>